From 88c5b86c62dbaef9e3b2a73bf08b6c21075e12a3 Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Mon, 28 Jul 2014 14:07:03 +0200 Subject: [PATCH] Fixing UdpTunnel unit tests for PlanetLab --- src/nepi/resources/linux/udptunnel.py | 3 +- src/nepi/resources/planetlab/node.py | 1 - .../planetlab/scripts/pl-vif-create.py | 3 ++ src/nepi/resources/planetlab/tap.py | 26 ++++++---- test/lib/test_utils.py | 36 +++++++++++-- test/resources/planetlab/udptunnel.py | 50 ++++++++++++------- 6 files changed, 83 insertions(+), 36 deletions(-) diff --git a/src/nepi/resources/linux/udptunnel.py b/src/nepi/resources/linux/udptunnel.py index 29089fd0..01f6898b 100644 --- a/src/nepi/resources/linux/udptunnel.py +++ b/src/nepi/resources/linux/udptunnel.py @@ -34,7 +34,6 @@ class UdpTunnel(LinuxApplication): _help = "Constructs a tunnel between two Linux endpoints using a UDP connection " _backend = "linux" - @classmethod def _register_attributes(cls): cipher = Attribute("cipher", @@ -225,7 +224,7 @@ class UdpTunnel(LinuxApplication): (out2, err2), proc2 = self.endpoint2.node.kill(self._pid2, self._ppid2, sudo = True) - if err1 or err2 or proc1.poll() or proc2.poll(): + if (proc1.poll() and err1) or (proc2.poll() and err2): # check if execution errors occurred msg = " Failed to STOP tunnel" self.error(msg, err1, err2) diff --git a/src/nepi/resources/planetlab/node.py b/src/nepi/resources/planetlab/node.py index 7f07d057..d8a4edaf 100644 --- a/src/nepi/resources/planetlab/node.py +++ b/src/nepi/resources/planetlab/node.py @@ -172,7 +172,6 @@ class PlanetlabNode(LinuxNode): default = False, flags = Flags.Global) - cls._register_attribute(ip) cls._register_attribute(pl_url) cls._register_attribute(pl_ptn) diff --git a/src/nepi/resources/planetlab/scripts/pl-vif-create.py b/src/nepi/resources/planetlab/scripts/pl-vif-create.py index 998ed53b..b1ef4f35 100644 --- a/src/nepi/resources/planetlab/scripts/pl-vif-create.py +++ b/src/nepi/resources/planetlab/scripts/pl-vif-create.py @@ -75,6 +75,9 @@ def stop_action(): return "STOP-ACK" def passfd_action(fd, args): + """ Sends the file descriptor associated to the TAP device + to another process through a unix socket. + """ address = args.pop(0) print address sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) diff --git a/src/nepi/resources/planetlab/tap.py b/src/nepi/resources/planetlab/tap.py index 6d1be501..2acc3f43 100644 --- a/src/nepi/resources/planetlab/tap.py +++ b/src/nepi/resources/planetlab/tap.py @@ -27,7 +27,7 @@ from nepi.util.timefuncs import tnow, tdiffsec import os import time -# TODO: - routes!!! +# TODO: # - CREATE GRE - PlanetlabGRE - it only needs to set the gre and remote # properties when configuring the vif_up @@ -137,19 +137,21 @@ class PlanetlabTap(LinuxApplication): def upload_start_command(self): # Overwrite file every time. - # The stop.sh has the path to the socket, wich should change + # The start.sh has the path to the socket, wich should change # on every experiment run. super(PlanetlabTap, self).upload_start_command(overwrite = True) # We want to make sure the device is up and running - # before the deploy finishes (so things will be ready - # before other stuff starts running). - # Run the command as a bash script in background, - # in the host ( but wait until the command has - # finished to continue ) + # before the deploy finishes, so we execute now the + # start script. We run it in background, because the + # TAP will live for as long as the process that + # created it is running, and wait until the TAP + # is created. self._run_in_background() - # Retrive if_name + # After creating the TAP, the pl-vif-create.py script + # will write the name of the TAP to a file. We wait until + # we can read the interface name from the file. if_name = self.wait_if_name() self.set("deviceName", if_name) @@ -228,11 +230,17 @@ class PlanetlabTap(LinuxApplication): """ Waits until the if_name file for the command is generated, and returns the if_name for the device """ if_name = None - delay = 1.0 + delay = 0.5 for i in xrange(20): (out, err), proc = self.node.check_output(self.run_home, "if_name") + if proc.poll() > 0: + (out, err), proc = self.node.check_errors(self.run_home) + + if err.strip(): + raise RuntimeError, err + if out: if_name = out.strip() break diff --git a/test/lib/test_utils.py b/test/lib/test_utils.py index 958cfc0a..ed9be121 100644 --- a/test/lib/test_utils.py +++ b/test/lib/test_utils.py @@ -30,9 +30,12 @@ class DummyEC(object): def create_node(hostname, username = None, identity = None): ec = DummyEC() node = LinuxNode(ec, 1) + node.set("hostname", hostname) + if username: node.set("username", username) + if identity: node.set("identity", identity) @@ -44,18 +47,18 @@ def create_node(hostname, username = None, identity = None): def skipIfNotAlive(func): name = func.__name__ def wrapped(*args, **kwargs): - host = args[1] - if host != "localhost": - user = None + hostname = args[1] + if hostname != "localhost": + username = None identity = None if len(args) >= 3: - user = args[2] + username = args[2] if len(args) >= 4: identity = args[3] - node, ec = create_node(host, user, identity) + node, ec = create_node(hostname, username, identity) if not node.is_alive(): print "*** WARNING: Skipping test %s: Node %s is not alive\n" % ( @@ -71,6 +74,7 @@ def skipIfAnyNotAlive(func): def wrapped(*args, **kwargs): argss = list(args) argss.pop(0) + for i in xrange(len(argss)/2): username = argss[i*2] hostname = argss[i*2+1] @@ -85,6 +89,28 @@ def skipIfAnyNotAlive(func): return wrapped +def skipIfAnyNotAliveWithIdentity(func): + name = func.__name__ + def wrapped(*args, **kwargs): + argss = list(args) + argss.pop(0) + for i in xrange(len(argss)/3): + username = argss[i*3] + hostname = argss[i*3+1] + identity = argss[i*3+2] + + node, ec = create_node(hostname, username, identity) + + if not node.is_alive(): + print "*** WARNING: Skipping test %s: Node %s is not alive\n" % ( + name, node.get("hostname")) + return + + return func(*args, **kwargs) + + return wrapped + + def skipInteractive(func): name = func.__name__ def wrapped(*args, **kwargs): diff --git a/test/resources/planetlab/udptunnel.py b/test/resources/planetlab/udptunnel.py index 3a73cab2..9dd7d5b4 100755 --- a/test/resources/planetlab/udptunnel.py +++ b/test/resources/planetlab/udptunnel.py @@ -20,7 +20,7 @@ from nepi.execution.ec import ExperimentController -from test_utils import skipIfAnyNotAlive +from test_utils import skipIfAnyNotAliveWithIdentity import os import time @@ -28,36 +28,44 @@ import unittest class UdpTunnelTestCase(unittest.TestCase): def setUp(self): - self.host1 = "nepi2.pl.sophia.inria.fr" - self.host2 = "nepi5.pl.sophia.inria.fr" + #self.host1 = "nepi2.pl.sophia.inria.fr" + #self.host2 = "nepi5.pl.sophia.inria.fr" + self.host1 = "planetlab1.informatik.uni-erlangen.de" + self.host2 = "planetlab1.informatik.uni-goettingen.de" self.user = "inria_nepi" + self.identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME']) + #self.netblock = "192.168.1" + self.netblock = "192.168.3" - @skipIfAnyNotAlive - def t_tap_udp_tunnel(self, user1, host1, user2, host2): + @skipIfAnyNotAliveWithIdentity + def t_tap_udp_tunnel(self, user1, host1, identity1, user2, host2, + identity2): ec = ExperimentController(exp_id = "test-tap-udp-tunnel") node1 = ec.register_resource("PlanetlabNode") ec.set(node1, "hostname", host1) ec.set(node1, "username", user1) + ec.set(node1, "identity", identity1) ec.set(node1, "cleanHome", True) ec.set(node1, "cleanProcesses", True) tap1 = ec.register_resource("PlanetlabTap") - ec.set(tap1, "ip4", "192.168.1.1") - ec.set(tap1, "pointopoint", "192.168.1.2") + ec.set(tap1, "ip4", "%s.1" % self.netblock) + ec.set(tap1, "pointopoint", "%s.2" % self.netblock) ec.set(tap1, "prefix4", 24) ec.register_connection(tap1, node1) node2 = ec.register_resource("PlanetlabNode") ec.set(node2, "hostname", host2) ec.set(node2, "username", user2) + ec.set(node2, "identity", identity2) ec.set(node2, "cleanHome", True) ec.set(node2, "cleanProcesses", True) tap2 = ec.register_resource("PlanetlabTap") - ec.set(tap2, "ip4", "192.168.1.2") - ec.set(tap2, "pointopoint", "192.168.1.1") + ec.set(tap2, "ip4", "%s.2" % self.netblock) + ec.set(tap2, "pointopoint", "%s.1" % self.netblock) ec.set(tap2, "prefix4", 24) ec.register_connection(tap2, node2) @@ -66,7 +74,7 @@ class UdpTunnelTestCase(unittest.TestCase): ec.register_connection(tap2, udptun) app = ec.register_resource("LinuxApplication") - cmd = "ping -c3 192.168.1.2" + cmd = "ping -c3 %s.2" % self.netblock ec.set(app, "command", cmd) ec.register_connection(app, node1) @@ -86,32 +94,34 @@ class UdpTunnelTestCase(unittest.TestCase): ec.shutdown() - @skipIfAnyNotAlive - def t_tun_udp_tunnel(self, user1, host1, user2, host2): + @skipIfAnyNotAliveWithIdentity + def t_tun_udp_tunnel(self, user1, host1, identity1, user2, host2, identity2): ec = ExperimentController(exp_id = "test-tap-udp-tunnel") node1 = ec.register_resource("PlanetlabNode") ec.set(node1, "hostname", host1) ec.set(node1, "username", user1) + ec.set(node1, "identity", identity1) ec.set(node1, "cleanHome", True) ec.set(node1, "cleanProcesses", True) tun1 = ec.register_resource("PlanetlabTun") - ec.set(tun1, "ip4", "192.168.1.1") - ec.set(tun1, "pointopoint", "192.168.1.2") + ec.set(tun1, "ip4", "%s.1" % self.netblock) + ec.set(tun1, "pointopoint", "%s.2" % self.netblock) ec.set(tun1, "prefix4", 24) ec.register_connection(tun1, node1) node2 = ec.register_resource("PlanetlabNode") ec.set(node2, "hostname", host2) ec.set(node2, "username", user2) + ec.set(node2, "identity", identity2) ec.set(node2, "cleanHome", True) ec.set(node2, "cleanProcesses", True) tun2 = ec.register_resource("PlanetlabTun") - ec.set(tun2, "ip4", "192.168.1.2") - ec.set(tun2, "pointopoint", "192.168.1.1") + ec.set(tun2, "ip4", "%s.2" % self.netblock) + ec.set(tun2, "pointopoint", "%s.1" % self.netblock ) ec.set(tun2, "prefix4", 24) ec.register_connection(tun2, node2) @@ -120,7 +130,7 @@ class UdpTunnelTestCase(unittest.TestCase): ec.register_connection(tun2, udptun) app = ec.register_resource("LinuxApplication") - cmd = "ping -c3 192.168.1.2" + cmd = "ping -c3 %s.2" % self.netblock ec.set(app, "command", cmd) ec.register_connection(app, node1) @@ -141,10 +151,12 @@ class UdpTunnelTestCase(unittest.TestCase): ec.shutdown() def test_tap_udp_tunnel(self): - self.t_tap_udp_tunnel(self.user, self.host1, self.user, self.host2) + self.t_tap_udp_tunnel(self.user, self.host1, self.identity, + self.user, self.host2, self.identity) def test_tun_udp_tunnel(self): - self.t_tun_udp_tunnel(self.user, self.host1, self.user, self.host2) + self.t_tun_udp_tunnel(self.user, self.host1, self.identity, + self.user, self.host2, self.identity) if __name__ == '__main__': unittest.main() -- 2.43.0