Skip to content

Commit

Permalink
[pytest]: Check for duplicate intfs (#1949)
Browse files Browse the repository at this point in the history
When creating virtual servers, before a network interface into the DVS network namespace, check if that interface name is already used in the DVS namespace. If it is, delete it before moving the new interface.

Signed-off-by: Lawrence Lee <lawlee@microsoft.com>
  • Loading branch information
theasianpianist authored Oct 8, 2021
1 parent 1bacd10 commit c7eeecf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ def __init__(self, ctn_name: str, pid: int, i: int):
f"ip netns exec {self.nsname} ip link add {self.nsname[0:12]}"
f" type veth peer name {self.pifname}"
)

# ensure self.pifname is not already an interface in the DVS net namespace
rc, _ = subprocess.getstatusoutput(f"nsenter -t {pid} -n ip link show | grep '{self.pifname}@'")
if not rc:
ensure_system(f"nsenter -t {pid} -n ip link delete {self.pifname}")

ensure_system(f"ip netns exec {self.nsname} ip link set {self.pifname} netns {pid}")

# bring up link in the virtual server
Expand Down

0 comments on commit c7eeecf

Please sign in to comment.