def test_cmp(self): machine_id = 'a' instance_id = 'b' server_id = 'c' coordAddress1 = CoordAddress.CoordAddress(machine_id, instance_id, server_id) coordAddress2 = CoordAddress.CoordAddress(machine_id + '.', instance_id, server_id) coordAddress3 = CoordAddress.CoordAddress(machine_id, instance_id + '.', server_id) coordAddress4 = CoordAddress.CoordAddress(machine_id, instance_id, server_id + '.') addr1 = DirectAddress.from_coord_address(coordAddress1) addr2 = DirectAddress.from_coord_address(coordAddress1) addr3 = DirectAddress.from_coord_address(coordAddress2) addr4 = DirectAddress.from_coord_address(coordAddress3) addr5 = DirectAddress.from_coord_address(coordAddress4) self.assertEquals(addr1, addr2) self.assertNotEquals(addr1, addr3) self.assertNotEquals(addr1, addr4) self.assertNotEquals(addr1, addr5)
def setUp(self): self.locator_mocker = mocker.Mocker() self.locator = self.locator_mocker.mock() self.coord_addr = CoordAddress.CoordAddress('server:instance@machine') self.coord_addr2 = CoordAddress.CoordAddress( 'server2:instance@machine') self.easy_locator = EasyLocator.EasyLocator(self.coord_addr, self.locator)
def test_coord_machine(self): map = CoordInfo.CoordinationMap() #Creators map.add_new_machine('machine') map.add_new_instance('machine','instance') map.add_new_server( 'machine', 'instance', 'server1', ServerType.Login, () ) #Basic __getitem__ machine = map['machine'] instance = machine['instance'] server1 = instance['server1'] #parents self.assertEquals(machine.parent, map) self.assertEquals(instance.parent, machine) self.assertEquals(server1.parent, instance) #addresses machine_address = CoordAddress.CoordAddress( 'machine' ) instance_address = CoordAddress.CoordAddress( 'machine', 'instance' ) server_address = CoordAddress.CoordAddress( 'machine', 'instance', 'server1' ) self.assertEquals(machine.address, machine_address) self.assertEquals(instance.address, instance_address) self.assertEquals(server1.address, server_address) # machine's __getitem__ self.assertEquals(machine[server_address],server1) self.assertEquals(machine['instance'],instance) self.assertEquals( machine[server_address.get_instance_address()], instance ) # instance's __getitem__ self.assertEquals(instance['server1'],server1) self.assertEquals(instance[server_address],server1)
def generate_locator(self): coordinator_server_address = DirectAddress.Address( 'WL_MACHINE1', 'WL_SERVER1', 'coordinator1' ) server_type_handler = ServerTypeHandler.ServerTypeHandler( ServerType, { ServerType.Coordinator : voodoo_exported_methods.coordinator, ServerType.Login : weblab_exported_methods.Login, ServerType.UserProcessing : weblab_exported_methods.UserProcessing, ServerType.Proxy : weblab_exported_methods.Proxy, ServerType.Laboratory : weblab_exported_methods.Laboratory, ServerType.Translator : weblab_exported_methods.Translator, ServerType.Experiment : weblab_exported_methods.Experiment } ) locator = ServerLocator.ServerLocator( coordinator_server_address, server_type_handler ) easy_locator = EasyLocator.EasyLocator( CoordAddress.CoordAddress('WL_MACHINE1','WL_SERVER1','coordinator1'), locator ) return easy_locator
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 test_version_change(self): address = CoordAddress.CoordAddress('machine_id') self.assertRaises(CoordVersionErrors.CoordVersionNotAnActionError, CoordVersion.CoordVersionChange, address, 'NEW2') self.assertRaises(CoordVersionErrors.CoordVersionNotAnAddressError, CoordVersion.CoordVersionChange, 'machine_id', CoordVersion.ChangeActions.NEW)
def _create_server(self, global_config, machine_name, instance_name, server_name, locator, cfg_manager): server_config = global_config.machines[machine_name].instances[ instance_name].servers[server_name] protocols = [ getattr(Protocols, protocol.name) for protocol in server_config.protocols ] generated_server = ServerSkel.factory(cfg_manager, protocols, server_config.methods) class RealServer(server_config.implementation, generated_server): def __init__(self, coord_address, locator, cfg_manager, *args, **kargs): server_config.implementation.__init__(self, coord_address, locator, cfg_manager, *args, **kargs) RealServer.__name__ = 'Server of %s' % server_config.implementation coord_address = CoordAddress.CoordAddress(machine_name, instance_name, server_name) protocol_args = {} for protocol in server_config.protocols: if isinstance(protocol.name, unicode): protocol_name = str(protocol.name) else: protocol_name = protocol.name protocol_args[protocol_name] = protocol.filled_creation[1] real_server = RealServer(coord_address, locator, cfg_manager, **protocol_args) real_server.start() return real_server
def __init__(self, server_type, server_name, parent_instance, accesses, restrictions=()): """ CoordServer(server_type,server_name[, parent_instance[,accesses]]) -> CoordServer * server_type is a member of an enumerator listing the types of server * server_name is the name of the server * parent_instance is a member of CoordInstance, and can be later * accesses is a sequence of instances of Access * restrictions is a sequence of restrictions. For instance, a server for FPGAs, etc. modified with the "parent" property. """ object.__init__(self) # Server information self._server_type = server_type self._status = False self._accesses_lock = lock.RWLock() self._accesses_read_lock = self._accesses_lock.read_lock() self._accesses_write_lock = self._accesses_lock.write_lock() self._version = 0 self._accesses = list(accesses) self._restrictions = list(restrictions) # Addressing information self._name = server_name self._parent = parent_instance self._address = CoordAddress.CoordAddress(self._parent.parent.name, self._parent.name, self._name)
def _return_reserved(self): self.lab_mock.reserve_experiment( ExperimentInstanceId('inst', 'ud-dummy', 'Dummy experiments'), "{}", mocker.ANY) self.mocker.result((SessionId.SessionId('my_lab_session_id'), 'ok', 'servexp:inst@mach')) self.lab_mock.resolve_experiment_address('my_lab_session_id') self.mocker.result(CoordAddress.CoordAddress("exp", "inst", "mach")) self.mocker.count(1, 2)
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 _fake_simple_lab_response(self): self.lab_mock.reserve_experiment( ExperimentInstanceId('inst', 'ud-dummy', 'Dummy experiments'), "{}", mocker.ANY) self.mocker.result((SessionId.SessionId('my_lab_session_id'), 'ok', 'servexp:inst@mach')) self.lab_mock.resolve_experiment_address('my_lab_session_id') self.mocker.result(CoordAddress.CoordAddress("exp", "inst", "mach")) self.lab_mock.should_experiment_finish( SessionId.SessionId('my_lab_session_id')) self.mocker.result(0) self.mocker.replay()
def test_from_coord_address(self): machine_id = 'a' instance_id = 'b' server_id = 'c' coordAddress = CoordAddress.CoordAddress(machine_id, instance_id, server_id) addr = DirectAddress.from_coord_address(coordAddress) self.assertEquals(addr.machine_id, machine_id) self.assertEquals(addr.instance_id, instance_id) self.assertEquals(addr.server_id, server_id)
def __init__(self, machine_id, parent_map): object.__init__(self) # A machine is a set of CoordInstances self._instances_lock = lock.RWLock() self._instances_read_lock = self._instances_lock.read_lock() self._instances_write_lock = self._instances_lock.write_lock() self._instances = {} self._version = 0 # Addressing information self.name = machine_id self.parent = parent_map self.address = CoordAddress.CoordAddress(machine_id, '', '')
def __init__(self, instance_name, parent_machine): object.__init__(self) # An instance is a set of CoordServers self._servers_lock = lock.RWLock() self._servers_read_lock = self._servers_lock.read_lock() self._servers_write_lock = self._servers_lock.write_lock() self._servers = {} self._version = 0 # Addressing information self.name = instance_name self._parent = parent_machine self._address = CoordAddress.CoordAddress(self._parent.name, self.name, '')
def test_coord_address(self): machine = 'machine_example' instance = 'instance_example' server = 'server_example' coordAddress = CoordAddress.CoordAddress(machine, instance, server) self.assertEqual(machine, coordAddress.machine_id) self.assertEqual(instance, coordAddress.instance_id) self.assertEqual(server, coordAddress.server_id) coordAddress2 = CoordAddress.CoordAddress.translate_address( coordAddress.address) self.assertEqual(coordAddress, coordAddress2) self.assertRaises(CoordErrors.CoordInvalidAddressName, CoordAddress.CoordAddress.translate_address, 'whatever')
def create_usage(gateway, reservation_id = 'my_reservation_id'): session = gateway.Session() student1 = gateway._get_user(session, 'student1') initial_usage = ExperimentUsage() initial_usage.start_date = time.time() initial_usage.end_date = time.time() initial_usage.from_ip = "130.206.138.16" initial_usage.experiment_id = ExperimentId("ud-dummy","Dummy experiments") initial_usage.coord_address = CoordAddress.CoordAddress("machine1","instance1","server1") #.translate_address("server1:instance1@machine1") initial_usage.reservation_id = reservation_id file1 = FileSent( 'path/to/file1', '{sha}12345', time.time() ) file2 = FileSent( 'path/to/file2', '{sha}123456', time.time(), Command.Command('response'), time.time(), file_info = 'program' ) command1 = CommandSent( Command.Command("your command1"), time.time() ) command2 = CommandSent( Command.Command("your command2"), time.time(), Command.Command("your response2"), time.time() ) initial_usage.append_command(command1) initial_usage.append_command(command2) initial_usage.append_file(file1) initial_usage.append_file(file2) initial_usage.request_info = {'facebook' : False} gateway.store_experiment_usage(student1.login, initial_usage) return student1, initial_usage, command1, command2, file1, file2
def _generate_easy_locator(self, global_config, machine_name, instance_name, server_name): coordinator_server_address = DirectAddress.Address( machine_name, instance_name, self._generate_coordinator_server_name(machine_name, instance_name)) server_type, map = self._generate_map_server_type2methods( global_config) server_type_handler = ServerTypeHandler.ServerTypeHandler( server_type, map) locator = ServerLocator.ServerLocator(coordinator_server_address, server_type_handler) server_coord_address = CoordAddress.CoordAddress( machine_name, instance_name, server_name) easy_locator = EasyLocator.EasyLocator(server_coord_address, locator) return easy_locator
def test_update_command(self): session = self.gateway.Session() student1 = self.gateway._get_user(session, 'student1') RESERVATION_ID1 = 'my_reservation_id1' usage1 = ExperimentUsage() usage1.start_date = time.time() usage1.end_date = time.time() usage1.from_ip = "130.206.138.16" usage1.experiment_id = ExperimentId("ud-dummy","Dummy experiments") usage1.coord_address = CoordAddress.CoordAddress("machine1","instance1","server1") #.translate_address("server1:instance1@machine1") usage1.reservation_id = RESERVATION_ID1 usage1.request_info = {'facebook' : False} self.gateway.store_experiment_usage(student1.login, usage1) usages = self.gateway.list_usages_per_user(student1.login) self.assertEquals(1, len(usages)) full_usage = self.gateway.retrieve_usage(usages[0].experiment_use_id) self.assertEquals(0, len(full_usage.commands)) command1 = CommandSent( Command.Command("your command"), time.time() ) command_id = self.gateway.append_command( RESERVATION_ID1, command1 ) full_usage = self.gateway.retrieve_usage(usages[0].experiment_use_id) self.assertEquals("your command", full_usage.commands[0].command.commandstring) self.assertEquals(Command.NullCommand(), full_usage.commands[0].response) self.gateway.update_command(command_id, Command.Command("the response"), time.time()) full_usage = self.gateway.retrieve_usage(usages[0].experiment_use_id) self.assertEquals("your command", full_usage.commands[0].command.commandstring) self.assertEquals("the response", full_usage.commands[0].response.commandstring)
def _generate_address_of_sublevel(self, address, name): return CoordAddress.CoordAddress( address.machine_id, name )
</coordinations> <creation> <parameter name="address" value="" /> <parameter name="port" value="8095" /> </creation> </protocol> </protocols> </server> """ SERVER_VALID_TYPE = "test.unit.voodoo.gen.loader.ServerType::Login" SERVER_VALID_METHODS = "test.unit.voodoo.gen.loader.APItype1::methods" SERVER_VALID_IMPLEMENTATION = "test.unit.voodoo.gen.loader.ServerSample.Server" SERVER_ADDRESS = CoordAddress.CoordAddress('NAME_OF_MACHINE1', 'NAME_OF_INSTANCE1', 'NAME_OF_SERVER1') INSTANCE_ADDRESS = CoordAddress.CoordAddress('NAME_OF_MACHINE1', 'NAME_OF_INSTANCE1') MACHINE_ADDRESS = CoordAddress.CoordAddress('NAME_OF_MACHINE1') class ServerParserTestCase(unittest.TestCase): def setUp(self): self.server_parser = ConfigurationParser.ServerParser() def test_address_is_none(self): self.assertRaises( LoaderErrors.InvalidConfigurationError, self.server_parser.parse, SERVER_PATH,
def test_update_file(self): session = self.gateway.Session() student1 = self.gateway._get_user(session, 'student1') RESERVATION_ID1 = 'my_reservation_id1' RESERVATION_ID2 = 'my_reservation_id2' usage1 = ExperimentUsage() usage1.start_date = time.time() usage1.end_date = time.time() usage1.from_ip = "130.206.138.16" usage1.experiment_id = ExperimentId("ud-dummy","Dummy experiments") usage1.coord_address = CoordAddress.CoordAddress("machine1","instance1","server1") #.translate_address("server1:instance1@machine1") usage1.reservation_id = RESERVATION_ID1 usage1.request_info = {'facebook' : False} usage2 = ExperimentUsage() usage2.start_date = time.time() usage2.end_date = time.time() usage2.from_ip = "130.206.138.17" usage2.experiment_id = ExperimentId("ud-dummy","Dummy experiments") usage2.coord_address = CoordAddress.CoordAddress("machine1","instance1","server1") #.translate_address("server1:instance1@machine1") usage2.reservation_id = RESERVATION_ID2 usage2.request_info = {'facebook' : False} self.gateway.store_experiment_usage(student1.login, usage1) self.gateway.store_experiment_usage(student1.login, usage2) file_sent1 = FileSent( 'path/to/file2', '{sha}123456', time.time(), file_info = 'program' ) usages = self.gateway.list_usages_per_user(student1.login) self.assertEquals(2, len(usages)) full_usage1 = self.gateway.retrieve_usage(usages[0].experiment_use_id) full_usage2 = self.gateway.retrieve_usage(usages[1].experiment_use_id) self.assertEquals(0, len(full_usage1.commands)) self.assertEquals(0, len(full_usage2.commands)) self.assertEquals(0, len(full_usage1.sent_files)) self.assertEquals(0, len(full_usage2.sent_files)) file_sent_id = self.gateway.append_file(RESERVATION_ID1, file_sent1) full_usage1 = self.gateway.retrieve_usage(usages[0].experiment_use_id) full_usage2 = self.gateway.retrieve_usage(usages[1].experiment_use_id) self.assertEquals(0, len(full_usage1.commands)) self.assertEquals(0, len(full_usage2.commands)) self.assertEquals(1, len(full_usage1.sent_files)) self.assertEquals(0, len(full_usage2.sent_files)) self.assertEquals(None, full_usage1.sent_files[0].response.commandstring) self.gateway.update_file(file_sent_id, Command.Command("response"), time.time()) full_usage1 = self.gateway.retrieve_usage(usages[0].experiment_use_id) full_usage2 = self.gateway.retrieve_usage(usages[1].experiment_use_id) self.assertEquals(0, len(full_usage1.commands)) self.assertEquals(0, len(full_usage2.commands)) self.assertEquals(1, len(full_usage1.sent_files)) self.assertEquals(0, len(full_usage2.sent_files)) self.assertEquals("response", full_usage1.sent_files[0].response.commandstring)
def test_finish_experiment_usage(self): session = self.gateway.Session() student1 = self.gateway._get_user(session, 'student1') RESERVATION_ID1 = 'my_reservation_id1' RESERVATION_ID2 = 'my_reservation_id2' usage1 = ExperimentUsage() usage1.start_date = time.time() usage1.from_ip = "130.206.138.16" usage1.experiment_id = ExperimentId("ud-dummy","Dummy experiments") usage1.coord_address = CoordAddress.CoordAddress("machine1","instance1","server1") #.translate_address("server1:instance1@machine1") usage1.reservation_id = RESERVATION_ID1 command1 = CommandSent( Command.Command("your command1"), time.time(), Command.Command("your response1"), time.time() ) usage1.append_command(command1) usage1.request_info = {'facebook' : False} usage2 = ExperimentUsage() usage2.start_date = time.time() usage2.from_ip = "130.206.138.17" usage2.experiment_id = ExperimentId("ud-dummy","Dummy experiments") usage2.coord_address = CoordAddress.CoordAddress("machine1","instance1","server1") #.translate_address("server1:instance1@machine1") usage2.reservation_id = RESERVATION_ID2 command2 = CommandSent( Command.Command("your command2"), time.time(), Command.Command("your response2"), time.time() ) usage2.append_command(command2) usage2.request_info = {'facebook' : False} self.gateway.store_experiment_usage(student1.login, usage1) self.gateway.store_experiment_usage(student1.login, usage2) finishing_command = CommandSent( Command.Command("@@@finish@@@"), time.time(), Command.Command("finish"), time.time() ) usages = self.gateway.list_usages_per_user(student1.login) self.assertEquals(2, len(usages)) full_usage1 = self.gateway.retrieve_usage(usages[0].experiment_use_id) full_usage2 = self.gateway.retrieve_usage(usages[1].experiment_use_id) self.assertEquals(None, full_usage1.end_date) self.assertEquals(None, full_usage2.end_date) self.assertEquals(1, len(full_usage1.commands)) self.assertEquals(1, len(full_usage2.commands)) result = self.gateway.finish_experiment_usage(RESERVATION_ID1, time.time(), finishing_command) self.assertTrue(result) full_usage1 = self.gateway.retrieve_usage(usages[0].experiment_use_id) full_usage2 = self.gateway.retrieve_usage(usages[1].experiment_use_id) self.assertNotEqual(None, full_usage1.end_date) self.assertEquals(None, full_usage2.end_date) self.assertEquals(2, len(full_usage1.commands)) self.assertEquals(1, len(full_usage2.commands)) self.assertEquals("@@@finish@@@", full_usage1.commands[1].command.commandstring) self.assertEquals("finish", full_usage1.commands[1].response.commandstring)
def _store_two_reservations(self): # # Two users: student2, that started before "any" but finished after "any", and "any" then. Both use # the same experiment. # reservation_id1 = SessionId.SessionId(u'5') initial_usage1 = ExperimentUsage() initial_usage1.start_date = time.time() initial_usage1.end_date = time.time() initial_usage1.from_ip = u"130.206.138.16" initial_usage1.experiment_id = ExperimentId(u"ud-dummy",u"Dummy experiments") initial_usage1.coord_address = CoordAddress.CoordAddress(u"machine1",u"instance1",u"server1") #.translate_address("server1:instance1@machine1") initial_usage1.reservation_id = reservation_id1.id valid_file_path = os.path.relpath(os.sep.join(('test','__init__.py'))) file1 = FileSent( valid_file_path, u'{sha}12345', time.time()) file2 = FileSent( valid_file_path, u'{sha}123456', time.time(), Command(u'response'), time.time(), file_info = u'program') command1 = CommandSent( Command(u"your command1"), time.time()) command2 = CommandSent( Command(u"your command2"), time.time(), Command(u"your response2"), time.time()) initial_usage1.append_command(command1) initial_usage1.append_command(command2) initial_usage1.append_file(file1) initial_usage1.append_file(file2) reservation_id2 = SessionId.SessionId(u'6') initial_usage2 = ExperimentUsage() initial_usage2.start_date = time.time() initial_usage2.end_date = time.time() initial_usage2.from_ip = u"130.206.138.16" initial_usage2.experiment_id = ExperimentId(u"ud-dummy",u"Dummy experiments") initial_usage2.coord_address = CoordAddress.CoordAddress(u"machine1",u"instance1",u"server1") #.translate_address("server1:instance1@machine1") initial_usage2.reservation_id = reservation_id2.id file1 = FileSent( valid_file_path, u'{sha}12345', time.time()) file2 = FileSent( valid_file_path, u'{sha}123456', time.time(), Command(u'response'), time.time(), file_info = u'program') command1 = CommandSent( Command(u"your command1"), time.time()) command2 = CommandSent( Command(u"your command2"), time.time(), Command(u"your response2"), time.time()) initial_usage2.append_command(command1) initial_usage2.append_command(command2) initial_usage2.append_file(file1) initial_usage2.append_file(file2) self.ups._db_manager._gateway.store_experiment_usage('student1', initial_usage1) self.ups._db_manager._gateway.store_experiment_usage('student2', initial_usage2) return (reservation_id1, reservation_id2), (initial_usage1, initial_usage2)
def _generate_address_of_sublevel(self, address, name): return CoordAddress.CoordAddress( name )