From: Alina Quereilhac Date: Mon, 23 May 2011 23:26:36 +0000 (+0200) Subject: eliminated parameters testbed_guid in experiment controller methods when the guid... X-Git-Tag: nepi_v2~6^2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=b9a4dd2a6df034a829a0bcf5b3296722e25b64e2;p=nepi.git eliminated parameters testbed_guid in experiment controller methods when the guid is present. I might have broken pl :S. --- diff --git a/src/nepi/core/design.py b/src/nepi/core/design.py index c942d10e..a0051885 100644 --- a/src/nepi/core/design.py +++ b/src/nepi/core/design.py @@ -602,15 +602,4 @@ class ExperimentDescription(object): for testbed_description in self.testbed_descriptions: testbed_description.destroy() -# TODO: When the experiment xml is passed to the controller to execute it -# NetReferences in the xml need to be solved -# -#targets = re.findall(r"%target:(.*?)%", command) -#for target in targets: -# try: -# (family, address, port) = resolve_netref(target, AF_INET, -# self.server.experiment ) -# command = command.replace("%%target:%s%%" % target, address.address) -# except: -# continue diff --git a/src/nepi/core/execute.py b/src/nepi/core/execute.py index 3b1463a4..c7919d5a 100644 --- a/src/nepi/core/execute.py +++ b/src/nepi/core/execute.py @@ -362,14 +362,26 @@ class ExperimentController(object): def experiment_xml(self): return self._experiment_xml + @property + def guids(self): + guids = list() + for testbed_guid in self._testbeds.keys(): + _guids = self._guids_in_testbed(testbed_guid) + if _guids: + guids.extend(_guids) + return guids + def persist_experiment_xml(self): xml_path = os.path.join(self._root_dir, "experiment.xml") f = open(xml_path, "w") f.write(self._experiment_xml) f.close() - def trace(self, testbed_guid, guid, trace_id, attribute='value'): - return self._testbeds[testbed_guid].trace(guid, trace_id, attribute) + def trace(self, guid, trace_id, attribute='value'): + testbed = self._testbed_for_guid(guid) + if testbed != None: + return testbed.trace(guid, trace_id, attribute) + raise RuntimeError("No element exists with guid %d" % guid) @staticmethod def _parallel(callables): @@ -470,7 +482,10 @@ class ExperimentController(object): # Last chance to configure (parallel on all testbeds) self._parallel([testbed.do_prestart for testbed in self._testbeds.itervalues()]) - + + # After this point no new elements will be craeted. Cleaning cache for safety. + self._guids_in_testbed_cache = dict() + # start experiment (parallel start on all testbeds) self._parallel([testbed.start for testbed in self._testbeds.itervalues()]) @@ -547,27 +562,39 @@ class ExperimentController(object): self._init_testbed_controllers(recover = True) def is_finished(self, guid): - for testbed in self._testbeds.values(): - if guid in testbed.guids: - return testbed.status(guid) == STATUS_FINISHED + testbed = self._testbed_for_guid(guid) + if testbed != None: + return testbed.status(guid) == STATUS_FINISHED raise RuntimeError("No element exists with guid %d" % guid) - def set(self, testbed_guid, guid, name, value, time = TIME_NOW): - testbed = self._testbeds[testbed_guid] - testbed.set(guid, name, value, time) + def set(self, guid, name, value, time = TIME_NOW): + testbed = self._testbed_for_guid(guid) + if testbed != None: + testbed.set(guid, name, value, time) + raise RuntimeError("No element exists with guid %d" % guid) - def get(self, testbed_guid, guid, name, time = TIME_NOW): - testbed = self._testbeds[testbed_guid] - return testbed.get(guid, name, time) + def get(self, guid, name, time = TIME_NOW): + testbed = self._testbed_for_guid(guid) + if testbed != None: + return testbed.get(guid, name, time) + raise RuntimeError("No element exists with guid %d" % guid) - def get_tags(self, testbed_guid, guid): - testbed = self._testbeds[testbed_guid] - return testbed.get_tags(guid) + def get_tags(self, guid): + testbed = self._testbed_for_guid(guid) + if testbed != None: + return testbed.get_tags(guid) + raise RuntimeError("No element exists with guid %d" % guid) def shutdown(self): for testbed in self._testbeds.values(): testbed.shutdown() - + + def _testbed_for_guid(self, guid): + for testbed_guid in self._testbeds.keys(): + if guid in self._guids_in_testbed(testbed_guid): + return self._testbeds[testbed_guid] + return None + def _guids_in_testbed(self, testbed_guid): if testbed_guid not in self._testbeds: return set() diff --git a/src/nepi/util/proxy.py b/src/nepi/util/proxy.py index 3a64ecd9..8db9dd77 100644 --- a/src/nepi/util/proxy.py +++ b/src/nepi/util/proxy.py @@ -662,6 +662,12 @@ class ExperimentControllerServer(BaseServer): self._controller = ExperimentController(self._experiment_xml, root_dir = self._root_dir) + @Marshalling.handles(GUIDS) + @Marshalling.args() + @Marshalling.retval( Marshalling.pickled_data ) + def guids(self): + return self._controller.guids + @Marshalling.handles(XML) @Marshalling.args() @Marshalling.retval() @@ -669,10 +675,10 @@ class ExperimentControllerServer(BaseServer): return self._controller.experiment_xml @Marshalling.handles(TRACE) - @Marshalling.args(int, int, str, Marshalling.base64_data) + @Marshalling.args(int, str, Marshalling.base64_data) @Marshalling.retval() - def trace(self, testbed_guid, guid, trace_id, attribute): - return str(self._controller.trace(testbed_guid, guid, trace_id, attribute)) + def trace(self, guid, trace_id, attribute): + return str(self._controller.trace(guid, trace_id, attribute)) @Marshalling.handles(FINISHED) @Marshalling.args(int) @@ -681,22 +687,22 @@ class ExperimentControllerServer(BaseServer): return self._controller.is_finished(guid) @Marshalling.handles(EXPERIMENT_GET) - @Marshalling.args(int, int, Marshalling.base64_data, str) + @Marshalling.args(int, Marshalling.base64_data, str) @Marshalling.retval( Marshalling.pickled_data ) - def get(self, testbed_guid, guid, name, time): - return self._controller.get(testbed_guid, guid, name, time) + def get(self, guid, name, time): + return self._controller.get(guid, name, time) @Marshalling.handles(EXPERIMENT_SET) - @Marshalling.args(int, int, Marshalling.base64_data, Marshalling.pickled_data, str) + @Marshalling.args(int, Marshalling.base64_data, Marshalling.pickled_data, str) @Marshalling.retvoid - def set(self, testbed_guid, guid, name, value, time): - self._controller.set(testbed_guid, guid, name, value, time) + def set(self, guid, name, value, time): + self._controller.set(guid, name, value, time) @Marshalling.handles(GET_TAGS) - @Marshalling.args(int, int) + @Marshalling.args(int) @Marshalling.retval( Marshalling.pickled_data ) - def get_tags(self, testbed_guid, guid): - return self._controller.get_tags(testbed_guid, guid) + def get_tags(self, guid): + return self._controller.get_tags(guid) @Marshalling.handles(START) @Marshalling.args() diff --git a/src/nepi/util/tags.py b/src/nepi/util/tags.py new file mode 100644 index 00000000..85d39fbb --- /dev/null +++ b/src/nepi/util/tags.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +MOBILE = 0 + diff --git a/test/core/integration.py b/test/core/integration.py index ea125859..2bd0d9b7 100755 --- a/test/core/integration.py +++ b/test/core/integration.py @@ -78,8 +78,8 @@ class ExecuteTestCase(unittest.TestCase): controller = proxy.create_controller(xml, access_config) controller.start() - cross1 = controller.get(desc1.guid, iface12.guid, "cross") - cross2 = controller.get(desc2.guid, iface21.guid, "cross") + cross1 = controller.get(iface12.guid, "cross") + cross2 = controller.get(iface21.guid, "cross") self.assertTrue(cross1 == cross2 == True) controller.stop() controller.shutdown() @@ -93,14 +93,14 @@ class ExecuteTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) - self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE]) controller.stop() controller.shutdown() @@ -116,14 +116,14 @@ class ExecuteTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) - self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE]) controller.stop() controller.shutdown() @@ -141,14 +141,14 @@ class ExecuteTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) - self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE]) controller.stop() controller.shutdown() @@ -171,14 +171,14 @@ class ExecuteTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) - self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE]) controller.stop() controller.shutdown() @@ -201,14 +201,14 @@ class ExecuteTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) - self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE]) # controller dies del controller @@ -219,7 +219,7 @@ class ExecuteTestCase(unittest.TestCase): # test recovery self.assertTrue(controller.is_finished(app.guid)) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") self.assertTrue(fake_result.startswith(comp_result)) controller.stop() @@ -239,7 +239,7 @@ class ExecuteTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- @@ -274,7 +274,7 @@ class ExecuteTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- @@ -318,7 +318,7 @@ class ExecuteTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - fake_result = controller.trace(desc.guid, app.guid, "fake") + fake_result = controller.trace(app.guid, "fake") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- diff --git a/test/testbeds/netns/integration.py b/test/testbeds/netns/integration.py index d1692970..c2d494a8 100755 --- a/test/testbeds/netns/integration.py +++ b/test/testbeds/netns/integration.py @@ -54,7 +54,7 @@ class NetnsIntegrationTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - ping_result = controller.trace(netns_desc.guid, app.guid, "stdout") + ping_result = controller.trace(app.guid, "stdout") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- @@ -113,7 +113,7 @@ class NetnsIntegrationTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - ping_result = controller.trace(netns_desc.guid, app.guid, "stdout") + ping_result = controller.trace(app.guid, "stdout") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- @@ -176,7 +176,7 @@ class NetnsIntegrationTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - ping_result = controller.trace(netns_desc.guid, app.guid, "stdout") + ping_result = controller.trace(app.guid, "stdout") comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. --- 10.0.0.2 ping statistics --- diff --git a/test/testbeds/ns3/integration.py b/test/testbeds/ns3/integration.py index d4a7a4cd..4bbfc089 100755 --- a/test/testbeds/ns3/integration.py +++ b/test/testbeds/ns3/integration.py @@ -72,7 +72,7 @@ class Ns3IntegrationTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - ping_result = controller.trace(ns3_desc.guid, iface2.guid, "P2PAsciiTrace") + ping_result = controller.trace(iface2.guid, "P2PAsciiTrace") comp_result = "- 19.021 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 19 protocol 1 offset 0 flags [none] length: 84 10.0.0.2 > 10.0.0.1) ns3::Icmpv4Header (type=0, code=0) ns3::Icmpv4Echo (identifier=0, sequence=19)" if ping_result.find(comp_result) == -1: self.fail("Unexpected trace: %s" % (ping_result,)) @@ -146,7 +146,7 @@ class Ns3IntegrationTestCase(unittest.TestCase): while not controller.is_finished(app.guid): time.sleep(0.5) - ping_result = controller.trace(ns3_desc.guid, iface2.guid, "P2PAsciiTrace") + ping_result = controller.trace(iface2.guid, "P2PAsciiTrace") comp_result = "- 19.021 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 19 protocol 1 offset 0 flags [none] length: 84 10.0.0.2 > 10.0.0.1) ns3::Icmpv4Header (type=0, code=0) ns3::Icmpv4Echo (identifier=0, sequence=19)" if ping_result.find(comp_result) == -1: self.fail("Unexpected trace: %s" % (ping_result,)) diff --git a/test/testbeds/planetlab/integration.py b/test/testbeds/planetlab/integration.py index 8b143d78..2786285d 100755 --- a/test/testbeds/planetlab/integration.py +++ b/test/testbeds/planetlab/integration.py @@ -82,7 +82,7 @@ class PlanetLabIntegrationTestCase(unittest.TestCase): controller.start() while not controller.is_finished(app.guid): time.sleep(0.5) - ping_result = controller.trace(pl.guid, app.guid, "stdout") + ping_result = controller.trace(app.guid, "stdout") comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data. --- .* ping statistics ---