diff options
author | Sander Vrijders <sander.vrijders@ugent.be> | 2018-06-04 11:43:02 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2018-06-04 14:20:18 +0200 |
commit | 7636de071e69948da2b6bbbc3dc6055d3cac04cc (patch) | |
tree | b2e565773585e96bf9925c9d1c17dbd7d44579ec | |
parent | ebdd8624528275311396f90e08632c550cb64a71 (diff) | |
download | rumba-7636de071e69948da2b6bbbc3dc6055d3cac04cc.tar.gz rumba-7636de071e69948da2b6bbbc3dc6055d3cac04cc.zip |
testbeds: Fix bad interface name in docker testbed
Linux has length limits for the name of an interface. This adds an
additional check to ensure the name is never too long. It also adds
more debug logs which are handy to see the progress of swap-in and
out.
-rw-r--r-- | rumba/testbeds/dockertb.py | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/rumba/testbeds/dockertb.py b/rumba/testbeds/dockertb.py index 5dcbb16..f58ab92 100644 --- a/rumba/testbeds/dockertb.py +++ b/rumba/testbeds/dockertb.py @@ -82,23 +82,29 @@ class Testbed(mod.Testbed): # Pull image if self.pull_image: - docker_client.images.pull(self.base_image_repo, - self.base_image_tag) + logger.info("Fetching image...") + docker_client.images.pull(self.base_image_repo, + self.base_image_tag) docker_client.images.get("%s:%s" % (self.base_image_repo, self.base_image_tag)) + logger.info("Starting nodes...") + # Start all nodes for node in experiment.nodes: + logger.debug('Starting node %s', node.name) self.running_containers[node.name] = docker_client.containers.run( self.base_image, command=node.startup_command, name='node-' + node.name, detach=True, network="none", privileged=True, devices=["/dev/fuse"]) - logger.info("Nodes starting") + cmd = 'sudo mkdir /var/run/netns' + + logger.debug('executing >> %s', cmd) if not os.path.exists("/var/run/netns"): - subprocess.check_call('sudo mkdir /var/run/netns'.split()) + subprocess.check_call(cmd.split()) for shim in experiment.dif_ordering: if not isinstance(shim, mod.ShimEthDIF): @@ -114,9 +120,12 @@ class Testbed(mod.Testbed): self.active_bridges.add(shim.name) + logger.debug('executing >> %s', cmd) + subprocess.check_call(cmd.split()) if not self.use_ovs: + logger.debug('executing >> %s', cmd) cmd = 'sudo ip link set dev %(shim)s up' % {'shim': shim.name} subprocess.check_call(cmd.split()) for node in experiment.nodes: @@ -133,17 +142,27 @@ class Testbed(mod.Testbed): pid = state["Pid"] - subprocess.check_call(('sudo ln -s /proc/%(pid)i/ns/net ' - '/var/run/netns/%(pid)i' % {'pid': pid}).split()) + cmd = ('sudo ln -s /proc/%(pid)i/ns/net ' + '/var/run/netns/%(pid)i' % {'pid': pid}) + + logger.debug('executing >> %s', cmd) + + subprocess.check_call(cmd.split()) for ipcp in node.ipcps: if isinstance(ipcp, mod.ShimEthIPCP): if ipcp.ifname is None: - ipcp.ifname = "eth%i" % node.ipcps.index(ipcp) + ipcp.ifname = "e%i" % node.ipcps.index(ipcp) + + # Linux has a limit on the length of interface names + node_name = node.name[0:11] cmd = ('sudo ip link add %(node)s.%(ifname)s type veth ' 'peer name _%(node)s.%(ifname)s'\ - % {'node': node.name, 'ifname': ipcp.ifname}) + % {'node': node_name, 'ifname': ipcp.ifname}) + + logger.debug('executing >> %s', cmd) + subprocess.check_call(cmd.split()) cmd = "" @@ -154,27 +173,33 @@ class Testbed(mod.Testbed): cmd += ('sudo ip link set %(node)s.%(ifname)s master ' '%(dif)s') - cmd = (cmd % {'node': node.name, + cmd = (cmd % {'node': node_name, 'ifname': ipcp.ifname, 'dif': ipcp.dif.name}) + logger.debug('executing >> %s', cmd) + subprocess.check_call(cmd.split()) cmd = ('sudo ip link set _%(node)s.%(ifname)s ' 'netns %(pid)i ' 'name %(ifname)s' - % {'node': node.name, + % {'node': node_name, 'pid': pid, 'ifname': ipcp.ifname}) + + logger.debug('executing >> %s', cmd) subprocess.check_call(cmd.split()) cmd = ('sudo ip link set dev %(node)s.%(ifname)s up' - % {'node': node.name, 'ifname': ipcp.ifname}) + % {'node': node_name, 'ifname': ipcp.ifname}) + logger.debug('executing >> %s', cmd) subprocess.check_call(cmd.split()) cmd = ('sudo ip netns exec %(pid)i ip link set dev ' '%(ifname)s up' % {'pid': pid, 'ifname': ipcp.ifname}) + logger.debug('executing >> %s', cmd) subprocess.check_call(cmd.split()) self.active_ipcps.add(ipcp) @@ -183,10 +208,12 @@ class Testbed(mod.Testbed): def _swap_out(self, experiment): for name, container in self.running_containers.items(): + logger.debug('Stopping node %s' % name) container.remove(force=True) for shim in experiment.dif_ordering: - if isinstance(shim, mod.ShimEthDIF) and shim.name in self.active_bridges: + if isinstance(shim, mod.ShimEthDIF) \ + and shim.name in self.active_bridges: cmd = "" if self.use_ovs: cmd += 'sudo ovs-vsctl del-br %(shim)s' @@ -194,6 +221,8 @@ class Testbed(mod.Testbed): cmd += 'sudo ip link del %(shim)s' cmd = cmd % {'shim': shim.name} + logger.debug('executing >> %s', cmd) + subprocess.check_call(cmd.split()) self.active_bridges.remove(shim.name) @@ -201,8 +230,14 @@ class Testbed(mod.Testbed): for name, container in self.running_containers.items(): pid = container.attrs["State"]["Pid"] - cmd = 'sudo rm /var/run/netns/%(pid)i' % {'pid': pid} - subprocess.check_call(cmd.split()) + if pid == 0: + continue + + path = '/var/run/netns/%d' % pid + if os.path.islink(path): + cmd = 'sudo rm '+ path + logger.debug('executing >> %s', cmd) + subprocess.check_call(cmd.split()) self.running_containers = {} |