Netref fixes - oh goodie
authorClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Fri, 22 Apr 2011 16:03:49 +0000 (18:03 +0200)
committerClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Fri, 22 Apr 2011 16:03:49 +0000 (18:03 +0200)
src/nepi/core/execute.py
src/nepi/testbeds/planetlab/execute.py
test/testbeds/planetlab/execute.py
test/testbeds/planetlab/integration.py

index add0909..bc8df21 100644 (file)
@@ -486,9 +486,11 @@ class ExperimentController(object):
                                     if component not in COMPONENT_GETTERS:
                                         raise ValueError, "Malformed netref: %r - unknown component" % (expr,)
                                     else:
-                                        value = COMPONENT_GETTERS[component](
+                                        ref_value = COMPONENT_GETTERS[component](
                                             ref_testbed, ref_guid, component_index, attribute)
-                                        if value: 
+                                        if ref_value:
+                                            testbed.set(TIME_NOW, guid, name, 
+                                                value.replace(match.group(), ref_value))
                                             break
                                 else:
                                     # couldn't find value
index 857b2a4..b0918c5 100644 (file)
@@ -113,6 +113,8 @@ class TestbedController(testbed_impl.TestbedController):
             return None
 
     def get_address(self, guid, index, attribute='Address'):
+        index = int(index)
+        
         # try the real stuff
         iface = self._elements.get(guid)
         if iface and index == 0:
@@ -125,7 +127,7 @@ class TestbedController(testbed_impl.TestbedController):
         
         # if all else fails, query box
         try:
-            return self.box_get_address(guid, int(index), attribute)
+            return self.box_get_address(guid, index, attribute)
         except KeyError, AttributeError:
             return None
 
index f7da57f..2eb91cd 100755 (executable)
@@ -49,7 +49,7 @@ class PlanetLabExecuteTestCase(unittest.TestCase):
         instance.defer_connect(4, "inet", 6, "devs")
         instance.defer_connect(5, "inet", 6, "devs")
         instance.defer_create(7, "Application")
-        instance.defer_create_set(7, "command", "ping -qc1 {#GUID-5.addr[0].[Address]#}")
+        instance.defer_create_set(7, "command", "ping -qc1 {#[GUID-5].addr[0].[Address]#}")
         instance.defer_add_trace(7, "stdout")
         instance.defer_connect(7, "node", 2, "apps")
 
@@ -61,7 +61,7 @@ class PlanetLabExecuteTestCase(unittest.TestCase):
         # Manually replace netref
         instance.set(TIME_NOW, 7, "command",
             instance.get(TIME_NOW, 7, "command")
-                .replace("{#GUID-5.addr[0].[Address]#}", 
+                .replace("{#[GUID-5].addr[0].[Address]#}", 
                     instance.get_address(5, 0, "Address") )
         )
 
index 692bebc..05c4bd3 100755 (executable)
@@ -11,6 +11,7 @@ import tempfile
 import test_util
 import time
 import unittest
+import re
 
 class PlanetLabIntegrationTestCase(unittest.TestCase):
     def setUp(self):
@@ -19,6 +20,61 @@ class PlanetLabIntegrationTestCase(unittest.TestCase):
     def tearDown(self):
         shutil.rmtree(self.root_dir)
 
+    def make_experiment_desc(self):
+        testbed_id = "planetlab"
+        testbed_version = "01"
+        slicename = "inria_nepi12"
+        pl_user, pl_pwd = test_util.pl_auth()
+
+        exp_desc = ExperimentDescription()
+        pl_provider = FactoriesProvider(testbed_id, testbed_version)
+        pl_desc = exp_desc.add_testbed_description(pl_provider)
+        pl_desc.set_attribute_value("homeDirectory", self.root_dir)
+        pl_desc.set_attribute_value("slice", slicename)
+        pl_desc.set_attribute_value("sliceSSHKey", "/user/%s/home/.ssh/id_rsa_planetlab" % (getpass.getuser(),))
+        pl_desc.set_attribute_value("authUser", pl_user)
+        pl_desc.set_attribute_value("authPass", pl_pwd)
+        
+        return pl_desc, exp_desc
+
+    @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
+    def test_simple(self):
+        pl, exp = self.make_experiment_desc()
+        
+        node1 = pl.create("Node")
+        node2 = pl.create("Node")
+        node1.set_attribute_value("hostname", "onelab11.pl.sophia.inria.fr")
+        node2.set_attribute_value("hostname", "onelab10.pl.sophia.inria.fr")
+        iface1 = pl.create("NodeInterface")
+        iface2 = pl.create("NodeInterface")
+        iface2.set_attribute_value("label", "node2iface")
+        inet = pl.create("Internet")
+        node1.connector("devs").connect(iface1.connector("node"))
+        node2.connector("devs").connect(iface2.connector("node"))
+        iface1.connector("inet").connect(inet.connector("devs"))
+        iface2.connector("inet").connect(inet.connector("devs"))
+        app = pl.create("Application")
+        app.set_attribute_value("command", "ping -qc1 {#[node2iface].addr[0].[Address]#}")
+        app.enable_trace("stdout")
+        app.connector("node").connect(node1.connector("apps"))
+
+        xml = exp.to_xml()
+
+        controller = ExperimentController(xml, self.root_dir)
+        controller.start()
+        while not controller.is_finished(app.guid):
+            time.sleep(0.5)
+        ping_result = controller.trace(pl.guid, app.guid, "stdout")
+        comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
+
+--- .* ping statistics ---
+1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
+"""
+        self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
+            "Unexpected trace:\n" + ping_result)
+        controller.stop()
+        controller.shutdown()
+
 if __name__ == '__main__':
     unittest.main()