def test_find_labs(self, voodoo_log): global_config = gen.load('test/unit/voodoo/gen/sample.yml') core_server = gen.CoordAddress('core_machine', 'core_server1', 'core') locator = gen.Locator(global_config, core_server) self.assertFalse(voodoo_log.called) laboratories = locator.find_by_type('laboratory') self.assertTrue(voodoo_log.called) self.assertEquals(len(laboratories), 5) t = gen.CoordAddress.translate self.assertTrue(t('laboratory:laboratory@accessible_machine') in laboratories) self.assertTrue(t('laboratory3:core_server1@core_machine') in laboratories) self.assertTrue(t('laboratory1:laboratory1@core_machine') in laboratories) self.assertTrue(t('laboratory2:laboratory2@core_machine') in laboratories) con1 = locator.get_connection(t('laboratory:laboratory@accessible_machine')) self.assertDictEquals(con1, {'type' : 'http', 'host' : '192.168.0.2', 'port' : 12345, 'path' : '' }) con2 = locator.get_connection(t('laboratory3:core_server1@core_machine')) self.assertDictEquals(con2, {'type' : 'direct', 'address' : 'laboratory3:core_server1@core_machine'}) con3 = locator.get_connection(t('laboratory1:laboratory1@core_machine')) self.assertDictEquals(con3, {'type' : 'http', 'host' : '127.0.0.1', 'port' : 10003, 'path' : '' }) con4 = locator.get_connection(t('laboratory2:laboratory2@core_machine')) self.assertDictEquals(con4, {'type' : 'xmlrpc', 'host' : '127.0.0.1', 'port' : 10004, 'path' : '' })
def test_load(self): result = gen.load('test/unit/voodoo/gen/sample.yml') machine = result['core_machine'] config_files = ['test/unit/voodoo/gen/core_machine/machine_config.py', 'test/unit/voodoo/gen/core_machine/machine_config.py'] self.assertEquals(machine.config_files, config_files) self.assertEquals(machine.host, '192.168.0.1') self.assertEquals(machine.runner, 'run.py') core_server1 = machine['core_server1'] core_component = core_server1['core'] self.assertEquals(core_component.config_values['core_facade_port'], 10000) self.assertEquals(core_component.component_type, 'core') self.assertEquals(core_component.component_class, parser.CORE_CLASS) self.assertEquals(len(core_component.protocols), 0) laboratory1 = machine['laboratory1'] lab_component1 = laboratory1['laboratory1'] self.assertEquals(lab_component1.config_files, ['test/unit/voodoo/gen/core_machine/laboratory1/laboratory1/server_config.py']) self.assertEquals(lab_component1.component_type, 'laboratory') self.assertEquals(lab_component1.component_class, parser.LAB_CLASS) self.assertEquals(lab_component1.protocols.port, 10003) self.assertEquals(lab_component1.protocols['http'], {}) self.assertEquals(lab_component1.protocols['xmlrpc'], {}) lab_address1 = gen.CoordAddress('core_machine', 'laboratory1', 'laboratory1') lab_address2 = gen.CoordAddress('core_machine', 'laboratory2', 'laboratory2') lab_component1_obtained = result[lab_address1] lab_component2_obtained = result[lab_address2] self.assertEquals(lab_component1_obtained, lab_component1) self.assertNotEquals(lab_component2_obtained, lab_component1)