def test_xmlrpc_create_client(self): message2 = self.message2 cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) xmlrpc_server_class = ServerSkel.factory(cfg_manager, Protocols.XMLRPC, self.methods) class XmlRpcServerClass(xmlrpc_server_class): def do_say_hello(self, msg): return msg + message2 xmlrpc_server_instance = XmlRpcServerClass(XMLRPC=('', self.port)) xmlrpc_server_instance.start() xmlrpc_addr = XMLRPCAddress.Address(self.host + ':' + str(self.port) + '@NetworkA') xmlrpc_client = xmlrpc_addr.create_client(self.methods) self.assertEquals(xmlrpc_client.say_hello(self.message1), self.message1 + message2) xmlrpc_server_instance.stop() xmlrpc_addr = XMLRPCAddress.Address(self.host + ':' + str(self.port) + '@NetworkA')
def test_soap_create_client(self): message2 = self.message2 cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) soap_server_class = ServerSkel.factory(cfg_manager, Protocols.SOAP, self.methods) class SoapServerClass(soap_server_class): def do_say_hello(self, msg): return msg + message2 soap_server_instance = SoapServerClass(SOAP=('', self.port)) soap_server_instance.start() soap_addr = SOAPAddress.Address(self.host + ':' + str(self.port) + '@NetworkA') soap_client = soap_addr.create_client(self.methods) self.assertEquals(soap_client.say_hello(self.message1), self.message1 + message2) soap_server_instance.stop() soap_addr = SOAPAddress.Address(self.host + ':' + str(self.port) + '@NetworkA')
def setUp(self): cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) self.fake_client = FakeClient() self.fake_locator = FakeLocator((self.fake_client, )) locator = EasyLocator.EasyLocator( CoordAddress.CoordAddress('mach', 'inst', 'serv'), self.fake_locator) self.experiment_instance_id = ExperimentInstanceId( "exp_inst", "exp_name", "exp_cat") self.experiment_coord_address = CoordAddress.CoordAddress.translate_address( 'myserver:myinstance@mymachine') cfg_manager._set_value( 'laboratory_assigned_experiments', { 'exp_inst:exp_name@exp_cat': { 'coord_address': 'myserver1:myinstance@mymachine', 'checkers': ( ('WebcamIsUpAndRunningHandler', ("https://...", )), ('HostIsUpAndRunningHandler', ("hostname", 80), {}), ) } }) self.lab = LaboratoryServer.LaboratoryServer(None, locator, cfg_manager)
def setUp(self): self.mocker = mocker.Mocker() self.lab_mock = self.mocker.mock() self.locator = FakeLocator(lab=self.lab_mock) self.db = FakeDatabase() self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.cfg_manager._set_value( COORDINATOR_LABORATORY_SERVERS, { 'server:laboratoryserver@labmachine': { 'inst1|ud-dummy|Dummy experiments': 'res_inst@res_type' } }) self.commands_store = TemporalInformationStore.CommandsTemporalInformationStore( ) self.coordinator = coordinator_create(SQLALCHEMY, self.locator, self.cfg_manager, ConfirmerClass=FakeConfirmer) self.coordinator._clean() self.coordinator.add_experiment_instance_id( "server:laboratoryserver@labmachine", ExperimentInstanceId('inst', 'ud-dummy', 'Dummy experiments'), Resource("res_type", "res_inst")) self.processor = UserProcessor.UserProcessor( self.locator, {'db_session_id': ValidDatabaseSessionId('my_db_session_id')}, self.cfg_manager, self.coordinator, self.db, self.commands_store)
def setUp(self): self.configurationManager = ConfigurationManager.ConfigurationManager() self.configurationManager.append_module(configuration) self.configurationManager._set_value(configuration_doc.FACADE_TIMEOUT, 0.01) time.sleep(0.01 * 5) self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_ZSI_PORT, 10123) self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_ZSI_SERVICE_NAME, '/weblab/login/soap/') self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_ZSI_LISTEN, '') self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_JSON_PORT, 10124) self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_JSON_LISTEN, '') self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_XMLRPC_PORT, 10125) self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_XMLRPC_LISTEN, '')
def test_exceptions(self): methods = ["method1", "method2"] msg1 = "hello" msg2 = " world" exc_msg = "Haw haw! (with Nelson's voice)" cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) class Ser( gens.ServerSkel.factory(cfg_manager, Protocols.XMLRPC, methods)): def do_method1(self, arg): return arg + msg2 def do_method2(self): raise ArithmeticError(exc_msg) server = Ser(XMLRPC=('', PORT)) server.start() # Avoid debug info client = gens.ClientSkel.factory(Protocols.XMLRPC, methods)('localhost', PORT) self.assertEquals(client.method1(msg1), msg1 + msg2) self.assertRaises(Exceptions.UnknownFaultType, client.method2)
def setUp(self): self.configurationManager = ConfigurationManager.ConfigurationManager( ) self.configurationManager.append_module(configuration) self.configurationManager._set_value( configuration_doc.FACADE_TIMEOUT, 0.001) self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_ZSI_PORT, 10223) self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_ZSI_SERVICE_NAME, '/weblab/soap/') self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_ZSI_LISTEN, '') self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_JSON_PORT, 10224) self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_JSON_LISTEN, '') self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_XMLRPC_PORT, 10225) self.configurationManager._set_value( LoginFacadeServer.LOGIN_FACADE_XMLRPC_LISTEN, '') self.mock_server = MockLogin() self.rfs = LoginFacadeServer.LoginRemoteFacadeServer( self.mock_server, self.configurationManager)
def setUp(self): self.maxDiff = 2000 def _find_server(server_type, name): return self.ups self._find_server_backup = methods._find_server methods._find_server = _find_server self.locator = FakeLocator() self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.cfg_manager._set_value(COORDINATOR_LABORATORY_SERVERS, { 'server:laboratoryserver@labmachine' : { 'inst|ud-dummy|Dummy experiments' : 'res_inst@res_type' } }) # With this one we clean everything before creating the UPS self.coordinator = coordinator_create(SQLALCHEMY, self.locator, self.cfg_manager, ConfirmerClass = ConfirmerMock) self.coordinator._clean() self.coord_address = CoordAddress.CoordAddress.translate_address( "server0:instance0@machine0" ) self.ups = UserProcessingServer.UserProcessingServer( self.coord_address, self.locator, self.cfg_manager ) self.ups._coordinator.stop() self.ups._coordinator = self.coordinator self.coordinator.add_experiment_instance_id("server:laboratoryserver@labmachine", ExperimentInstanceId('inst','ud-dummy','Dummy experiments'), Resource("res_type", "res_inst"))
def test_fail(self): initial_store = TemporalInformationStore.InitialTemporalInformationStore( ) finished_store = TemporalInformationStore.FinishTemporalInformationStore( ) commands_store = TemporalInformationStore.CommandsTemporalInformationStore( ) completed_store = TemporalInformationStore.CompletedInformationStore() cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration) fake = FakeTemporalInformationRetriever(cfg_manager, initial_store, finished_store, commands_store, completed_store, None) fake.start() try: initial_time = time.time() while not hasattr(fake, 'failures') or fake.failures < 1: time.sleep(0.01) if time.time() - initial_time > 5: raise AssertionError( "Too long time passed waiting for failures to increase" ) finally: fake.stop() fake.join(1) self.assertFalse(fake.isAlive())
def test_redis_zombies(self): cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) cfg_manager._set_value( configuration_doc.SESSION_MANAGER_DEFAULT_TIMEOUT, 1) server = SessionManager.SessionManager(cfg_manager, SessionType.redis, "0") try: server.create_session() sessions = server.list_sessions() self.assertEquals(1, len(sessions)) time.sleep(1) server.gateway._lock(redis.Redis(), 'foobar') # In redis 2.4, we can not establish a timeout lower than 1 second. So # we basically wait 1 second and few time more to confirm that it has # been removed. for _ in xrange(10): server.delete_expired_sessions() sessions = server.list_sessions() if len(sessions) == 0: break time.sleep(0.2) self.assertEquals(0, len(sessions)) finally: server.clear()
def setUp(self): self.coord_address = CoordAddress.CoordAddress.translate_address( "server0:instance0@machine0" ) self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.cfg_manager._set_value(CoordinationConfigurationParser.COORDINATOR_LABORATORY_SERVERS, { 'server:laboratoryserver@labmachine' : { 'inst|ud-dummy|Dummy experiments' : 'dummy1@dummy boards' } } ) self.mocker = mocker.Mocker() self.lab_mock = self.mocker.mock() self.locator = FakeLocator(self.lab_mock) # Clean the database coordinator = coordinator_create(SQLALCHEMY, self.locator, self.cfg_manager) coordinator._clean() coordinator.stop() # External server generation self.ups = WrappedUPS( self.coord_address, self.locator, self.cfg_manager ) self.ups._db_manager._gateway._delete_all_uses()
def setUp(self): cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) cfg_manager._set_value( configuration_doc.SESSION_MEMORY_GATEWAY_SERIALIZE, True) self.memory_server1 = SessionManager.SessionManager( cfg_manager, SessionType.Memory, "foo") self.memory_server2 = SessionManager.SessionManager( cfg_manager, SessionType.Memory, "bar") self.sqlalchemy_server1 = SessionManager.SessionManager( cfg_manager, SessionType.sqlalchemy, "foo") self.sqlalchemy_server2 = SessionManager.SessionManager( cfg_manager, SessionType.sqlalchemy, "bar") if REDIS_AVAILABLE: self.redis_server1 = SessionManager.SessionManager( cfg_manager, SessionType.redis, "0") self.redis_server2 = SessionManager.SessionManager( cfg_manager, SessionType.redis, "1") else: global ERROR_MESSAGE_SHOWN if not ERROR_MESSAGE_SHOWN: print( "redis not available. Skipping redis sessions related tests", file=sys.stderr) ERROR_MESSAGE_SHOWN = True self.memory_server1.clear() self.memory_server2.clear() self.sqlalchemy_server1.clear() self.sqlalchemy_server2.clear() if REDIS_AVAILABLE: self.redis_server1.clear() self.redis_server2.clear()
def setUp(self): self.configurationManager = ConfigurationManager.ConfigurationManager() self.configurationManager.append_module(configuration) self.configurationManager._set_value(configuration_doc.FACADE_TIMEOUT, 0.01) time.sleep(0.01 * 5) self.configurationManager._set_value( UserProcessingFacadeServer.USER_PROCESSING_FACADE_ZSI_PORT, 10223) self.configurationManager._set_value( UserProcessingFacadeServer.USER_PROCESSING_FACADE_ZSI_SERVICE_NAME, '/weblab/soap/') self.configurationManager._set_value( UserProcessingFacadeServer.USER_PROCESSING_FACADE_ZSI_LISTEN, '') self.configurationManager._set_value( UserProcessingFacadeServer.USER_PROCESSING_FACADE_JSON_PORT, 10224) self.configurationManager._set_value( UserProcessingFacadeServer.USER_PROCESSING_FACADE_JSON_LISTEN, '') self.configurationManager._set_value( UserProcessingFacadeServer.USER_PROCESSING_FACADE_XMLRPC_PORT, 10225) self.configurationManager._set_value( UserProcessingFacadeServer.USER_PROCESSING_FACADE_XMLRPC_LISTEN, '')
def test_get_values(self): module_name = self._create_module() confManager = ConfigurationManager.ConfigurationManager() the_module_name = path.basename(module_name)[:-3] # .py the_module = __import__(the_module_name) confManager.append_modules((the_module, )) # # Without a provided default value # self.assertRaises(ConfigurationErrors.KeysNotFoundError, confManager.get_values, 'this.does.not.exist', 'this.neither') values = confManager.get_values('mynumber', 'mystr') self.assertEquals(values.mynumber, 5) self.assertEquals(values.mystr, "hello world") # # With a provided default value # # 1st way: As a known key in the source code values = confManager.get_values(not_found='expected_value') self.assertEquals('expected_value', values.not_found) # 2nd way: As an unknown key in the source code values = confManager.get_values(**{"not_found": 'expected_value'}) self.assertEquals('expected_value', getattr(values, "not_found")) os.remove(module_name) os.remove(module_name + 'c')
def setUp(self): self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.fake_client = FakeClient() self.fake_locator = FakeLocator(self.fake_client) self.locator = self.fake_locator self.experiment_instance_id = ExperimentInstanceId( "exp_inst", "exp_name", "exp_cat") self.experiment_instance_id_old = ExperimentInstanceId( "exp_inst", "exp_name", "exp_cat2") self.experiment_coord_address = CoordAddress.translate( 'myserver:myinstance@mymachine') self.cfg_manager._set_value( 'laboratory_assigned_experiments', { 'exp_inst:exp_name@exp_cat': { 'coord_address': 'myserver:myinstance@mymachine', 'checkers': ( ('WebcamIsUpAndRunningHandler', ("https://...", )), ('HostIsUpAndRunningHandler', ("hostname", 80), {}), ) }, 'exp_inst:exp_name@exp_cat2': { 'coord_address': 'myserver:myinstance@mymachine', 'checkers': ( ('WebcamIsUpAndRunningHandler', ("https://...", )), ('HostIsUpAndRunningHandler', ("hostname", 80), {}), ), }, }) self._create_lab()
def setUp(self): self.cfg_manager= ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.locker = WrappedFastDbLock(self.cfg_manager, "mypool") _remove_sessions(self.cfg_manager)
def setUp(self): self._cfg_manager = ConfigurationManager.ConfigurationManager() self._cfg_manager.append_module(configuration_module) self.ANY_COORD_ADDR = CoordAddress.translate( 'myserver:myprocess@mymachine') self._clean_up_files_stored_dir()
def setUp(self): self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.locator = FakeLocator(FakeClient()) self.experiment_instance_id = ExperimentInstanceId( "exp_inst", "exp_name", "exp_cat")
def setUp(self): self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.pool = redis.ConnectionPool() redis_maker = lambda: redis.Redis(connection_pool=self.pool) self.resources_manager = ResourcesManager.ResourcesManager(redis_maker) self.resources_manager._clean()
def real_test(): cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) notifier = AdminNotifier.AdminNotifier(cfg_manager) notifier.notify('message') print "Verify in your e-mail address :-D"
def setUp(self): coord_address = CoordAddress.translate( "server0:instance0@machine0") self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.core_server = UserProcessingServer(coord_address, None, self.cfg_manager)
def setUp(self): self.cfg_manager= ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) def func(): self.cfg_manager.get_value("db_driver") self.runner = stress_util.MainRunner(func, "ConfigurationManager")
def test_simple_path(self): module_name = self._create_module() confManager = ConfigurationManager.ConfigurationManager() confManager.append_paths((module_name, )) self.assertEquals(confManager.get_value('mynumber'), 5) self.assertEquals(confManager.get_value('mystr'), "hello world") os.remove(module_name)
def setUp(self): self.compiler = FakeCompiler() self.launcher = FakeLauncher() self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.experiment = WrappedUdGpibExperiment(None, None, self.cfg_manager, self.compiler, self.launcher)
def setUp(self): self._cfg_manager = ConfigurationManager.ConfigurationManager() self._cfg_manager.append_module(configuration_module) self.RESERVATION_ID = "my_reservation_id" self.RESERVATION_SESS_ID = SessionId.SessionId(self.RESERVATION_ID) self.LAB_SESS_ID = "my_lab_sess_id" self.ANY_COORD_ADDR = CoordAddress.CoordAddress.translate_address( 'myserver:myprocess@mymachine') self.LAB_COORD_ADDR = self.ANY_COORD_ADDR
def setUp(self): self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.locator = EasyLocator.EasyLocator( CoordAddress.CoordAddress('mach', 'inst', 'serv'), FakeLocator((FakeClient(), ))) self.experiment_instance_id = ExperimentInstanceId( "exp_inst", "exp_name", "exp_cat")
def test_get_server(self): cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) cfg_manager._set_value( configuration_doc.SESSION_MEMORY_GATEWAY_SERIALIZE, True) map = create_coordinator_map() coord_server = CoordinatorServer.CoordinatorServer(cfg_manager, map) self.assertRaises(CoordinatorServerErrors.SessionNotFoundError, coord_server.do_get_server, "p0wn3d") my_address = map['machine0']['instance0']['server0'].address # What if there are problems serializing? self.assertRaises(CoordinatorServerErrors.CouldNotCreateSessionError, coord_server.do_new_query, threading.Lock(), SampleServerType.Login, None) # Ok, let's create a good one. Actually, let's do it three times for i in range(3): sess_id = coord_server.do_new_query(my_address.address, SampleServerType.Login, None) cur_address = coord_server.do_get_server(sess_id) self.assertEquals(True, isinstance(cur_address, DirectAddress.Address)) self.assertEquals(cur_address.machine_id, 'machine0') self.assertEquals(cur_address.instance_id, 'instance0') self.assertEquals(cur_address.server_id, 'server1') cur_address = coord_server.do_get_server(sess_id) self.assertEquals(True, isinstance(cur_address, SOAPAddress.Address)) self.assertEquals(cur_address.ip_address, '127.0.0.1') self.assertEquals(cur_address.net_name, 'NETWORK') self.assertEquals(cur_address.port, 9026) cur_address = coord_server.do_get_server(sess_id) self.assertEquals(True, isinstance(cur_address, SOAPAddress.Address)) self.assertEquals(cur_address.ip_address, '127.0.0.1') self.assertEquals(cur_address.net_name, 'NETWORK') self.assertEquals(cur_address.port, 9027) cur_address = coord_server.do_get_server(sess_id) self.assertEquals(True, isinstance(cur_address, SOAPAddress.Address)) self.assertEquals(cur_address.ip_address, '127.0.0.1') self.assertEquals(cur_address.net_name, 'NETWORK') self.assertEquals(cur_address.port, 9028) # There are no more servers! self.assertRaises(CoordinatorServerErrors.NoServerFoundError, coord_server.do_get_server, sess_id)
def setUp(self): self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.session_manager = SessionManager.SessionManager( self.cfg_manager, SessionType.Memory, "foo") def func(): self.session_manager.create_session() self.runner = stress_util.MainRunner(func, "SessionManager")
def test_simple_module(self): module_name = self._create_module() confManager = ConfigurationManager.ConfigurationManager() the_module_name = path.basename(module_name)[:-3] # .py the_module = __import__(the_module_name) confManager.append_modules((the_module, )) self.assertEquals(confManager.get_value('mynumber'), 5) self.assertEquals(confManager.get_value('mystr'), "hello world") os.remove(module_name) os.remove(module_name + 'c')
def setUp(self): cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration) self.dbmanager = DatabaseGateway(cfg_manager) self.dbmanager._delete_all_uses() session = self.dbmanager.Session() try: student1 = self.dbmanager._get_user(session, 'student1') finally: session.close() self.initial_store = TemporalInformationStore.InitialTemporalInformationStore( ) self.finished_store = TemporalInformationStore.FinishTemporalInformationStore( ) self.commands_store = TemporalInformationStore.CommandsTemporalInformationStore( ) self.completed_store = TemporalInformationStore.CompletedInformationStore( ) self.retriever = TemporalInformationRetriever.TemporalInformationRetriever( cfg_manager, self.initial_store, self.finished_store, self.commands_store, self.completed_store, self.dbmanager) self.retriever.timeout = 0.001 # Be quicker instead of waiting for half a second self.initial_time = self.end_time = datetime.datetime.now() self.initial_timestamp = self.end_timestamp = time.time() request_info = { 'username': '******', 'role': 'student', 'permission_scope': 'user', 'permission_id': student1.id } exp_id = ExperimentId('ud-dummy', 'Dummy Experiments') self.entry1 = TemporalInformationStore.InitialInformationEntry( RESERVATION1, exp_id, coord_addr('ser:inst@mach'), DATA1, self.initial_time, self.end_time, request_info.copy(), DATA_REQUEST1) self.entry2 = TemporalInformationStore.InitialInformationEntry( RESERVATION2, exp_id, coord_addr('ser:inst@mach'), DATA2, self.initial_time, self.end_time, request_info.copy(), DATA_REQUEST2) self.entry3 = TemporalInformationStore.InitialInformationEntry( RESERVATION3, exp_id, coord_addr('ser:inst@mach'), DATA3, self.initial_time, self.end_time, request_info.copy(), DATA_REQUEST3) self.entry4 = TemporalInformationStore.InitialInformationEntry( RESERVATION4, exp_id, coord_addr('ser:inst@mach'), DATA4, self.initial_time, self.end_time, request_info.copy(), DATA_REQUEST3)