From c7eeecf3751a0d3bbd3e0d700e2ee233ee4c73bb Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 8 Oct 2021 10:07:24 -0700 Subject: [PATCH] [pytest]: Check for duplicate intfs (#1949) 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 --- tests/conftest.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 485f0a0a8bfe..a5e6dbd04666 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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