2 # -*- coding: utf-8 -*-
5 from nepi.core.design import ExperimentDescription, FactoriesProvider
6 from nepi.core.execute import ExperimentController
7 from nepi.util import proxy
17 class PlanetLabIntegrationTestCase(unittest.TestCase):
18 testbed_id = "planetlab"
19 slicename = "inria_nepi"
20 plchost = "nepiplc.pl.sophia.inria.fr"
22 host1 = "nepi1.pl.sophia.inria.fr"
23 host2 = "nepi2.pl.sophia.inria.fr"
24 host3 = "nepi3.pl.sophia.inria.fr"
25 host4 = "nepi5.pl.sophia.inria.fr"
28 self.root_dir = tempfile.mkdtemp()
33 shutil.rmtree(self.root_dir)
37 shutil.rmtree(self.root_dir)
39 def make_experiment_desc(self):
40 testbed_id = self.testbed_id
41 slicename = self.slicename
42 plchost = self.plchost
43 pl_ssh_key = os.environ.get(
45 "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'],) )
46 pl_user, pl_pwd = test_util.pl_auth()
48 exp_desc = ExperimentDescription()
49 pl_provider = FactoriesProvider(testbed_id)
50 pl_desc = exp_desc.add_testbed_description(pl_provider)
51 pl_desc.set_attribute_value("homeDirectory", self.root_dir)
52 pl_desc.set_attribute_value("slice", slicename)
53 pl_desc.set_attribute_value("sliceSSHKey", pl_ssh_key)
54 pl_desc.set_attribute_value("authUser", pl_user)
55 pl_desc.set_attribute_value("authPass", pl_pwd)
56 pl_desc.set_attribute_value("plcHost", plchost)
58 return pl_desc, exp_desc
60 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
61 def test_simple(self):
62 pl, exp = self.make_experiment_desc()
64 node1 = pl.create("Node")
65 node2 = pl.create("Node")
66 node1.set_attribute_value("hostname", self.host1)
67 node2.set_attribute_value("hostname", self.host2)
68 iface1 = pl.create("NodeInterface")
69 iface2 = pl.create("NodeInterface")
70 iface2.set_attribute_value("label", "node2iface")
71 inet = pl.create("Internet")
72 node1.connector("devs").connect(iface1.connector("node"))
73 node2.connector("devs").connect(iface2.connector("node"))
74 iface1.connector("inet").connect(inet.connector("devs"))
75 iface2.connector("inet").connect(inet.connector("devs"))
76 app = pl.create("Application")
77 app.set_attribute_value("command", "ping -qc1 {#[node2iface].addr[0].[Address]#}")
78 app.enable_trace("stdout")
79 app.connector("node").connect(node1.connector("apps"))
83 controller = ExperimentController(xml, self.root_dir)
86 while not controller.is_finished(app.guid):
88 ping_result = controller.trace(app.guid, "stdout")
89 comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
91 --- .* ping statistics ---
92 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
94 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
95 "Unexpected trace:\n" + ping_result)
102 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
103 def test_spanning_deployment(self):
104 pl, exp = self.make_experiment_desc()
106 from nepi.testbeds import planetlab as plpackage
108 nodes = [ pl.create("Node") for i in xrange(4) ]
109 ifaces = [ pl.create("NodeInterface") for node in nodes ]
110 inet = pl.create("Internet")
111 for node, iface in zip(nodes,ifaces):
112 node.connector("devs").connect(iface.connector("node"))
113 iface.connector("inet").connect(inet.connector("devs"))
117 app = pl.create("Application")
118 app.set_attribute_value("command", "./consts")
119 app.set_attribute_value("buildDepends", "gcc")
120 app.set_attribute_value("build", "gcc ${SOURCES}/consts.c -o consts")
121 app.set_attribute_value("install", "cp consts ${SOURCES}/consts")
122 app.set_attribute_value("sources", os.path.join(
123 os.path.dirname(plpackage.__file__),'scripts','consts.c'))
124 app.enable_trace("stdout")
125 app.enable_trace("stderr")
126 app.enable_trace("buildlog")
127 node.connector("apps").connect(app.connector("node"))
131 r""".*ETH_P_ALL = 0x[0-9a-fA-F]{8}
132 ETH_P_IP = 0x[0-9a-fA-F]{8}
133 TUNGETIFF = 0x[0-9a-fA-F]{8}
134 TUNSETIFF = 0x[0-9a-fA-F]{8}
135 IFF_NO_PI = 0x[0-9a-fA-F]{8}
136 IFF_TAP = 0x[0-9a-fA-F]{8}
137 IFF_TUN = 0x[0-9a-fA-F]{8}
138 IFF_VNET_HDR = 0x[0-9a-fA-F]{8}
139 TUN_PKT_STRIP = 0x[0-9a-fA-F]{8}
140 IFHWADDRLEN = 0x[0-9a-fA-F]{8}
141 IFNAMSIZ = 0x[0-9a-fA-F]{8}
142 IFREQ_SZ = 0x[0-9a-fA-F]{8}
143 FIONREAD = 0x[0-9a-fA-F]{8}.*
146 comp_build = r".*(Identity added|gcc).*"
150 controller = ExperimentController(xml, self.root_dir)
153 while not all(controller.is_finished(app.guid) for app in apps):
157 app_result = controller.trace(app.guid, "stdout") or ""
158 self.assertTrue(re.match(comp_result, app_result, re.MULTILINE),
159 "Unexpected trace:\n" + app_result)
161 build_result = controller.trace(app.guid, "buildlog") or ""
162 self.assertTrue(re.match(comp_build, build_result, re.MULTILINE | re.DOTALL),
163 "Unexpected trace:\n" + build_result)
167 controller.shutdown()
170 if __name__ == '__main__':