2 # -*- coding: utf-8 -*-
5 from nepi.util.constants import STATUS_FINISHED, TIME_NOW
6 from nepi.testbeds import planetlab
15 class PlanetLabExecuteTestCase(unittest.TestCase):
17 self.root_dir = tempfile.mkdtemp()
20 shutil.rmtree(self.root_dir)
22 def make_instance(self):
23 testbed_version = "01"
24 instance = planetlab.TestbedController(testbed_version)
25 slicename = "inria_nepi12"
26 pl_user, pl_pwd = test_util.pl_auth()
28 instance.defer_configure("homeDirectory", self.root_dir)
29 instance.defer_configure("slice", slicename)
30 instance.defer_configure("sliceSSHKey", "/user/%s/home/.ssh/id_rsa_planetlab" % (getpass.getuser(),))
31 instance.defer_configure("authUser", pl_user)
32 instance.defer_configure("authPass", pl_pwd)
36 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
37 def test_simple(self):
38 instance = self.make_instance()
40 instance.defer_create(2, "Node")
41 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
42 instance.defer_create(3, "Node")
43 instance.defer_create_set(3, "hostname", "onelab10.pl.sophia.inria.fr")
44 instance.defer_create(4, "NodeInterface")
45 instance.defer_connect(2, "devs", 4, "node")
46 instance.defer_create(5, "NodeInterface")
47 instance.defer_connect(3, "devs", 5, "node")
48 instance.defer_create(6, "Internet")
49 instance.defer_connect(4, "inet", 6, "devs")
50 instance.defer_connect(5, "inet", 6, "devs")
51 instance.defer_create(7, "Application")
52 instance.defer_create_set(7, "command", "ping -qc1 {#[GUID-5].addr[0].[Address]#}")
53 instance.defer_add_trace(7, "stdout")
54 instance.defer_connect(7, "node", 2, "apps")
59 instance.do_preconfigure()
61 # Manually replace netref
62 instance.set(TIME_NOW, 7, "command",
63 instance.get(TIME_NOW, 7, "command")
64 .replace("{#[GUID-5].addr[0].[Address]#}",
65 instance.get_address(5, 0, "Address") )
68 instance.do_configure()
71 while instance.status(7) != STATUS_FINISHED:
73 ping_result = instance.trace(7, "stdout") or ""
74 comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
76 --- .* ping statistics ---
77 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
79 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
80 "Unexpected trace:\n" + ping_result)
84 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
85 def test_depends(self):
86 instance = self.make_instance()
88 instance.defer_create(2, "Node")
89 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
90 instance.defer_create(3, "NodeInterface")
91 instance.defer_connect(2, "devs", 3, "node")
92 instance.defer_create(4, "Internet")
93 instance.defer_connect(3, "inet", 4, "devs")
94 instance.defer_create(5, "Application")
95 instance.defer_create_set(5, "command", "gfortran --version")
96 instance.defer_create_set(5, "depends", "gcc-gfortran")
97 instance.defer_add_trace(5, "stdout")
98 instance.defer_connect(5, "node", 2, "apps")
102 instance.do_connect()
103 instance.do_preconfigure()
104 instance.do_configure()
107 while instance.status(5) != STATUS_FINISHED:
109 ping_result = instance.trace(5, "stdout") or ""
110 comp_result = r".*GNU Fortran \(GCC\).*"
111 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
112 "Unexpected trace:\n" + ping_result)
116 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
117 def test_build(self):
118 instance = self.make_instance()
120 instance.defer_create(2, "Node")
121 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
122 instance.defer_create(3, "NodeInterface")
123 instance.defer_connect(2, "devs", 3, "node")
124 instance.defer_create(4, "Internet")
125 instance.defer_connect(3, "inet", 4, "devs")
126 instance.defer_create(10, "Application")
127 instance.defer_create_set(10, "command", "./consts")
128 instance.defer_create_set(10, "buildDepends", "gcc")
129 instance.defer_create_set(10, "build", "gcc ${SOURCES}/consts.c -o consts")
130 instance.defer_create_set(10, "install", "cp consts ${SOURCES}/consts")
131 instance.defer_create_set(10, "sources", os.path.join(os.path.dirname(planetlab.__file__),'scripts','consts.c'))
132 instance.defer_add_trace(10, "stdout")
133 instance.defer_connect(10, "node", 2, "apps")
137 instance.do_connect()
138 instance.do_preconfigure()
139 instance.do_configure()
142 while instance.status(10) != STATUS_FINISHED:
144 ping_result = instance.trace(10, "stdout") or ""
146 r""".*ETH_P_ALL = 0x[0-9a-fA-F]{8}
147 ETH_P_IP = 0x[0-9a-fA-F]{8}
148 TUNSETIFF = 0x[0-9a-fA-F]{8}
149 IFF_NO_PI = 0x[0-9a-fA-F]{8}
150 IFF_TAP = 0x[0-9a-fA-F]{8}
151 IFF_TUN = 0x[0-9a-fA-F]{8}
152 IFF_VNET_HDR = 0x[0-9a-fA-F]{8}
153 TUN_PKT_STRIP = 0x[0-9a-fA-F]{8}
154 IFHWADDRLEN = 0x[0-9a-fA-F]{8}
155 IFNAMSIZ = 0x[0-9a-fA-F]{8}
156 IFREQ_SZ = 0x[0-9a-fA-F]{8}
157 FIONREAD = 0x[0-9a-fA-F]{8}.*
159 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
160 "Unexpected trace:\n" + ping_result)
165 if __name__ == '__main__':