clean up potential conflict veth before creating new one in create_ns
authorYonghong Song <yhs@plumgrid.com>
Tue, 11 Aug 2015 00:33:24 +0000 (17:33 -0700)
committerYonghong Song <yhs@plumgrid.com>
Tue, 11 Aug 2015 00:36:35 +0000 (17:36 -0700)
Signed-off-by: Yonghong Song <yhs@plumgrid.com>
examples/distributed_bridge/main.py
examples/simulation.py

index 939b3c3..9e135f3 100755 (executable)
@@ -54,7 +54,7 @@ try:
     for p in sim.processes: p.communicate(b"\n")
 except:
     if "sim" in locals():
-        for p in sim.processes: p.kill(); p.wait()
+        for p in sim.processes: p.kill(); p.wait(); p.release()
 finally:
     if "br-fabric" in ipdb.interfaces: ipdb.interfaces["br-fabric"].remove().commit()
     if "sim" in locals(): sim.release()
index 269ad3f..9e2e677 100644 (file)
@@ -1,3 +1,4 @@
+import os
 import subprocess
 import pyroute2
 from pyroute2 import IPRoute, NetNS, IPDB, NSPopen
@@ -46,6 +47,9 @@ class Simulation(object):
                 # move half of veth into namespace
                 v.net_ns_fd = ns_ipdb.nl.netns
         else:
+            # delete the potentially leaf-over veth interfaces
+            subprocess.call(["ip", "link", "del", "%sa" % ifc_base_name],
+                            stderr=open(os.devnull, 'w'))
             try:
                 out_ifc = self.ipdb.create(ifname="%sa" % ifc_base_name, kind="veth",
                                            peer="%sb" % ifc_base_name).commit()