<s> """<STR_LIT>""" <EOL> import mox <EOL> import unittest <EOL> from nova . compute import vm_states <EOL> from occi import core_model <EOL> from occi . extensions import infrastructure <EOL> from occi_os_api import nova_glue <EOL> from occi_os_api . backends import compute <EOL> from occi_os_api . extensions import os_mixins <EOL> class TestComputeBackend ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> os_template = os_mixins . OsTemplate ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> os_template2 = os_mixins . OsTemplate ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> res_template = os_mixins . ResourceTemplate ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> res_template2 = os_mixins . ResourceTemplate ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . backend = compute . ComputeBackend ( ) <EOL> self . sec_obj = { '<STR_LIT>' : None } <EOL> self . mox = mox . Mox ( ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . mox . UnsetStubs ( ) <EOL> def test_create_for_failure ( self ) : <EOL> """<STR_LIT>""" <EOL> res = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , [ ] ) <EOL> self . assertRaises ( AttributeError , self . backend . create , res , <EOL> self . sec_obj ) <EOL> res = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , <EOL> [ self . os_template ] ) <EOL> res . attributes = { '<STR_LIT>' : <NUM_LIT:2> } <EOL> self . assertRaises ( AttributeError , self . backend . create , res , <EOL> self . sec_obj ) <EOL> def test_update_for_failure ( self ) : <EOL> """<STR_LIT>""" <EOL> res1 = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , [ ] ) <EOL> res1 . attributes = { '<STR_LIT>' : '<STR_LIT:bar>' } <EOL> res2 = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , [ ] ) <EOL> self . assertRaises ( AttributeError , self . backend . update , res1 , res2 , <EOL> self . sec_obj ) <EOL> res2 = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , <EOL> [ core_model . Category ( '<STR_LIT>' , <EOL> '<STR_LIT:bar>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> self . assertRaises ( AttributeError , self . backend . update , res1 , res2 , <EOL> self . sec_obj ) <EOL> def test_action_for_failure ( self ) : <EOL> """<STR_LIT>""" <EOL> res1 = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , [ ] ) <EOL> res1 . attributes = { '<STR_LIT>' : '<STR_LIT:bar>' } <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . get_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) . AndReturn ( <EOL> { <EOL> '<STR_LIT>' : vm_states . STOPPED <EOL> } ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( AttributeError , self . backend . action , res1 , <EOL> infrastructure . STOP , { } , self . sec_obj ) <EOL> self . mox . VerifyAll ( ) <EOL> self . mox . UnsetStubs ( ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . get_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) . AndReturn ( <EOL> { <EOL> '<STR_LIT>' : vm_states . ACTIVE <EOL> } ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( AttributeError , self . backend . action , res1 , <EOL> infrastructure . RESTART , { } , self . sec_obj ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_create_for_sanity ( self ) : <EOL> """<STR_LIT>""" <EOL> res = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , <EOL> [ self . os_template ] ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . create_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) . AndReturn ( <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . create ( res , self . sec_obj ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertEqual ( '<STR_LIT>' , res . attributes [ '<STR_LIT>' ] ) <EOL> self . assertListEqual ( [ infrastructure . STOP , infrastructure . SUSPEND , <EOL> infrastructure . RESTART ] , res . actions ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_retrieve_for_sanity ( self ) : <EOL> """<STR_LIT>""" <EOL> res = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , <EOL> [ self . os_template ] ) <EOL> res . attributes = { '<STR_LIT>' : '<STR_LIT:bar>' } <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . get_vm_state ( mox . IsA ( object ) , <EOL> mox . IsA ( object ) ) . AndReturn ( ( '<STR_LIT>' , [ infrastructure . STOP , <EOL> infrastructure . SUSPEND , <EOL> infrastructure . RESTART ] ) ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . get_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) . AndReturn ( <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:bar>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . retrieve ( res , self . sec_obj ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertIn ( '<STR_LIT>' , res . attributes ) <EOL> self . assertEqual ( '<STR_LIT>' , res . attributes [ '<STR_LIT>' ] ) <EOL> self . assertListEqual ( [ infrastructure . STOP , infrastructure . SUSPEND , <EOL> infrastructure . RESTART ] , res . actions ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_update_for_sanity ( self ) : <EOL> """<STR_LIT>""" <EOL> res1 = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , <EOL> [ self . os_template ] ) <EOL> res1 . attributes = { '<STR_LIT>' : '<STR_LIT:bar>' } <EOL> res2 = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , <EOL> [ self . os_template2 ] ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . rebuild_vm ( mox . IsA ( object ) , mox . IsA ( object ) , <EOL> mox . IsA ( object ) ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . update ( res1 , res2 , self . sec_obj ) <EOL> self . assertIn ( self . os_template2 , res1 . mixins ) <EOL> self . mox . VerifyAll ( ) <EOL> res2 = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , <EOL> [ self . res_template2 ] ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . resize_vm ( mox . IsA ( object ) , mox . IsA ( object ) , <EOL> mox . IsA ( object ) ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . update ( res1 , res2 , self . sec_obj ) <EOL> self . assertIn ( self . res_template2 , res1 . mixins ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_replace_for_sanity ( self ) : <EOL> """<STR_LIT>""" <EOL> self . backend . replace ( None , None , self . sec_obj ) <EOL> def test_delete_for_sanity ( self ) : <EOL> """<STR_LIT>""" <EOL> res = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , <EOL> [ self . os_template ] ) <EOL> res . attributes = { '<STR_LIT>' : '<STR_LIT:bar>' } <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . delete_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . delete ( res , self . sec_obj ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_action_for_sanity ( self ) : <EOL> """<STR_LIT>""" <EOL> res1 = core_model . Resource ( '<STR_LIT>' , infrastructure . COMPUTE , [ ] ) <EOL> res1 . attributes = { '<STR_LIT>' : '<STR_LIT:bar>' } <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . start_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . get_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) . AndReturn ( <EOL> { <EOL> '<STR_LIT>' : vm_states . STOPPED <EOL> } ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . action ( res1 , infrastructure . START , { } , self . sec_obj ) <EOL> self . mox . VerifyAll ( ) <EOL> self . mox . UnsetStubs ( ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . stop_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . get_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) . AndReturn ( <EOL> { <EOL> '<STR_LIT>' : vm_states . ACTIVE <EOL> } ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . action ( res1 , infrastructure . STOP , { } , self . sec_obj ) <EOL> self . mox . VerifyAll ( ) <EOL> self . mox . UnsetStubs ( ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . restart_vm ( mox . IsA ( object ) , mox . IsA ( str ) , <EOL> mox . IsA ( object ) ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . get_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) . AndReturn ( <EOL> { <EOL> '<STR_LIT>' : vm_states . ACTIVE <EOL> } ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . action ( res1 , infrastructure . RESTART , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , self . sec_obj ) <EOL> self . mox . VerifyAll ( ) <EOL> self . mox . UnsetStubs ( ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . suspend_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) <EOL> self . mox . StubOutWithMock ( nova_glue . vm , '<STR_LIT>' ) <EOL> nova_glue . vm . get_vm ( mox . IsA ( object ) , mox . IsA ( object ) ) . AndReturn ( <EOL> { <EOL> '<STR_LIT>' : vm_states . ACTIVE <EOL> } ) <EOL> self . mox . ReplayAll ( ) <EOL> self . backend . action ( res1 , infrastructure . SUSPEND , { } , self . sec_obj ) <EOL> self . mox . VerifyAll ( ) </s>
