<s> """<STR_LIT>""" <EOL> import mox <EOL> from nova import context <EOL> from nova import db <EOL> from nova import exception <EOL> from nova import flags <EOL> from nova import rpc <EOL> from nova import test <EOL> from nova import service <EOL> from nova import manager <EOL> from nova import wsgi <EOL> from nova . compute import manager as compute_manager <EOL> flags . DEFINE_string ( "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> class FakeManager ( manager . Manager ) : <EOL> """<STR_LIT>""" <EOL> def test_method ( self ) : <EOL> return '<STR_LIT>' <EOL> class ExtendedService ( service . Service ) : <EOL> def test_method ( self ) : <EOL> return '<STR_LIT>' <EOL> class ServiceManagerTestCase ( test . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_message_gets_to_manager ( self ) : <EOL> serv = service . Service ( '<STR_LIT:test>' , <EOL> '<STR_LIT:test>' , <EOL> '<STR_LIT:test>' , <EOL> '<STR_LIT>' ) <EOL> serv . start ( ) <EOL> self . assertEqual ( serv . test_method ( ) , '<STR_LIT>' ) <EOL> def test_override_manager_method ( self ) : <EOL> serv = ExtendedService ( '<STR_LIT:test>' , <EOL> '<STR_LIT:test>' , <EOL> '<STR_LIT:test>' , <EOL> '<STR_LIT>' ) <EOL> serv . start ( ) <EOL> self . assertEqual ( serv . test_method ( ) , '<STR_LIT>' ) <EOL> class ServiceFlagsTestCase ( test . TestCase ) : <EOL> def test_service_enabled_on_create_based_on_flag ( self ) : <EOL> self . flags ( enable_new_services = True ) <EOL> host = '<STR_LIT:foo>' <EOL> binary = '<STR_LIT>' <EOL> app = service . Service . create ( host = host , binary = binary ) <EOL> app . start ( ) <EOL> app . stop ( ) <EOL> ref = db . service_get ( context . get_admin_context ( ) , app . service_id ) <EOL> db . service_destroy ( context . get_admin_context ( ) , app . service_id ) <EOL> self . assert_ ( not ref [ '<STR_LIT>' ] ) <EOL> def test_service_disabled_on_create_based_on_flag ( self ) : <EOL> self . flags ( enable_new_services = False ) <EOL> host = '<STR_LIT:foo>' <EOL> binary = '<STR_LIT>' <EOL> app = service . Service . create ( host = host , binary = binary ) <EOL> app . start ( ) <EOL> app . stop ( ) <EOL> ref = db . service_get ( context . get_admin_context ( ) , app . service_id ) <EOL> db . service_destroy ( context . get_admin_context ( ) , app . service_id ) <EOL> self . assert_ ( ref [ '<STR_LIT>' ] ) <EOL> class ServiceTestCase ( test . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( ServiceTestCase , self ) . setUp ( ) <EOL> self . mox . StubOutWithMock ( service , '<STR_LIT>' ) <EOL> def test_create ( self ) : <EOL> host = '<STR_LIT:foo>' <EOL> binary = '<STR_LIT>' <EOL> topic = '<STR_LIT>' <EOL> app = service . Service . create ( host = host , binary = binary , topic = topic ) <EOL> self . assert_ ( app ) <EOL> def test_report_state_newly_disconnected ( self ) : <EOL> host = '<STR_LIT:foo>' <EOL> binary = '<STR_LIT:bar>' <EOL> topic = '<STR_LIT:test>' <EOL> service_create = { '<STR_LIT:host>' : host , <EOL> '<STR_LIT>' : binary , <EOL> '<STR_LIT>' : topic , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> service_ref = { '<STR_LIT:host>' : host , <EOL> '<STR_LIT>' : binary , <EOL> '<STR_LIT>' : topic , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> service . db . service_get_by_args ( mox . IgnoreArg ( ) , <EOL> host , <EOL> binary ) . AndRaise ( exception . NotFound ( ) ) <EOL> service . db . service_create ( mox . IgnoreArg ( ) , <EOL> service_create ) . AndReturn ( service_ref ) <EOL> service . db . service_get ( mox . IgnoreArg ( ) , <EOL> mox . IgnoreArg ( ) ) . AndRaise ( Exception ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> serv = service . Service ( host , <EOL> binary , <EOL> topic , <EOL> '<STR_LIT>' ) <EOL> serv . start ( ) <EOL> serv . report_state ( ) <EOL> self . assert_ ( serv . model_disconnected ) <EOL> def test_report_state_newly_connected ( self ) : <EOL> host = '<STR_LIT:foo>' <EOL> binary = '<STR_LIT:bar>' <EOL> topic = '<STR_LIT:test>' <EOL> service_create = { '<STR_LIT:host>' : host , <EOL> '<STR_LIT>' : binary , <EOL> '<STR_LIT>' : topic , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> service_ref = { '<STR_LIT:host>' : host , <EOL> '<STR_LIT>' : binary , <EOL> '<STR_LIT>' : topic , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> service . db . service_get_by_args ( mox . IgnoreArg ( ) , <EOL> host , <EOL> binary ) . AndRaise ( exception . NotFound ( ) ) <EOL> service . db . service_create ( mox . IgnoreArg ( ) , <EOL> service_create ) . AndReturn ( service_ref ) <EOL> service . db . service_get ( mox . IgnoreArg ( ) , <EOL> service_ref [ '<STR_LIT:id>' ] ) . AndReturn ( service_ref ) <EOL> service . db . service_update ( mox . IgnoreArg ( ) , service_ref [ '<STR_LIT:id>' ] , <EOL> mox . ContainsKeyValue ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> self . mox . ReplayAll ( ) <EOL> serv = service . Service ( host , <EOL> binary , <EOL> topic , <EOL> '<STR_LIT>' ) <EOL> serv . start ( ) <EOL> serv . model_disconnected = True <EOL> serv . report_state ( ) <EOL> self . assert_ ( not serv . model_disconnected ) <EOL> class TestWSGIService ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestWSGIService , self ) . setUp ( ) <EOL> self . stubs . Set ( wsgi . Loader , "<STR_LIT>" , mox . MockAnything ( ) ) <EOL> def test_service_random_port ( self ) : <EOL> test_service = service . WSGIService ( "<STR_LIT>" ) <EOL> self . assertEquals ( <NUM_LIT:0> , test_service . port ) <EOL> test_service . start ( ) <EOL> self . assertNotEqual ( <NUM_LIT:0> , test_service . port ) <EOL> test_service . stop ( ) <EOL> class TestLauncher ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestLauncher , self ) . setUp ( ) <EOL> self . stubs . Set ( wsgi . Loader , "<STR_LIT>" , mox . MockAnything ( ) ) <EOL> self . service = service . WSGIService ( "<STR_LIT>" ) <EOL> def test_launch_app ( self ) : <EOL> self . assertEquals ( <NUM_LIT:0> , self . service . port ) <EOL> launcher = service . Launcher ( ) <EOL> launcher . launch_server ( self . service ) <EOL> self . assertEquals ( <NUM_LIT:0> , self . service . port ) <EOL> launcher . stop ( ) </s>
