summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Yourtchenko <ayourtch@gmail.com>2023-06-20 14:52:08 +0000
committerAndrew Yourtchenko <ayourtch@gmail.com>2023-06-21 17:20:03 +0000
commit9ba6dcf558eeb876f863e13e6250c13341a2a3f0 (patch)
tree8893de8cf1372b814518c3cf091ac91509e81e15
parent4aeba3776244efe5fbf8de894b6af13a9220762c (diff)
tests: do not run qemu interface tests if the environment does not allow it
cdf73b973181ff4c67147900408216e37bae897a has added the qemu tests as part of the default test run, which results in "make test" failure in more restricted environments which do not allow the namespace creation. Add a config flag to skip those tests, and skip them if the namespace creation fails. Type: test Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com> Change-Id: Ie631f7fb2a80864f77c79619eba4a43712e950e5
-rw-r--r--test/config.py10
-rw-r--r--test/test_vm_vpp_interfaces.py5
-rw-r--r--test/vpp_qemu_utils.py26
3 files changed, 39 insertions, 2 deletions
diff --git a/test/config.py b/test/config.py
index 578cc40fa2a..5d2ef1dab4f 100644
--- a/test/config.py
+++ b/test/config.py
@@ -2,6 +2,7 @@ import argparse
import os
import psutil
import time
+from vpp_qemu_utils import can_create_namespaces
def positive_int_or_default(default):
@@ -191,6 +192,11 @@ parser.add_argument(
)
parser.add_argument("--extended", action="store_true", help="run extended tests")
+parser.add_argument(
+ "--skip-netns-tests",
+ action="store_true",
+ help="skip tests involving netns operations",
+)
parser.add_argument(
"--sanity", action="store_true", help="perform sanity vpp run before running tests"
@@ -444,6 +450,10 @@ elif config.max_vpp_cpus > 0:
else:
max_vpp_cpus = num_cpus
+if not config.skip_netns_tests:
+ if not can_create_namespaces():
+ config.skip_netns_tests = True
+
if __name__ == "__main__":
print("Provided arguments:")
for i in config.__dict__:
diff --git a/test/test_vm_vpp_interfaces.py b/test/test_vm_vpp_interfaces.py
index f87a48aef37..6866c24d228 100644
--- a/test/test_vm_vpp_interfaces.py
+++ b/test/test_vm_vpp_interfaces.py
@@ -63,6 +63,9 @@ layer3 = test_config["L3"]
def create_test(test_name, test, ip_version, mtu):
"""Create and return a unittest method for a test."""
+ @unittest.skipIf(
+ config.skip_netns_tests, "netns not available or disabled from cli"
+ )
def test_func(self):
self.logger.debug(f"Starting unittest:{test_name}")
self.setUpTestToplogy(test=test, ip_version=ip_version)
@@ -97,6 +100,8 @@ def create_test(test_name, test, ip_version, mtu):
def generate_vpp_interface_tests():
"""Generate unittests for testing vpp interfaces."""
+ if config.skip_netns_tests:
+ print("Skipping netns tests")
for test in tests:
for ip_version in test_config["ip_versions"]:
for mtu in test_config["mtus"]:
diff --git a/test/vpp_qemu_utils.py b/test/vpp_qemu_utils.py
index 5c433201650..cb1a0dd9f4c 100644
--- a/test/vpp_qemu_utils.py
+++ b/test/vpp_qemu_utils.py
@@ -6,6 +6,22 @@ import subprocess
import sys
+def can_create_namespaces():
+ """Check if the environment allows creating the namespaces"""
+
+ try:
+ namespace = "vpp_chk_4212"
+ result = subprocess.run(["ip", "netns", "add", namespace], capture_output=True)
+ if result.returncode != 0:
+ return False
+ result = subprocess.run(["ip", "netns", "del", namespace], capture_output=True)
+ if result.returncode != 0:
+ return False
+ return True
+ except:
+ return False
+
+
def create_namespace(ns):
"""create one or more namespaces.
@@ -18,7 +34,9 @@ def create_namespace(ns):
namespaces = ns
try:
for namespace in namespaces:
- subprocess.run(["ip", "netns", "add", namespace])
+ result = subprocess.run(["ip", "netns", "add", namespace])
+ if result.returncode != 0:
+ raise Exception(f"Error while creating namespace {namespace}")
except subprocess.CalledProcessError as e:
raise Exception("Error creating namespace:", e.output)
@@ -207,7 +225,11 @@ def delete_namespace(namespaces):
"""
try:
for namespace in namespaces:
- subprocess.run(["ip", "netns", "del", namespace], capture_output=True)
+ result = subprocess.run(
+ ["ip", "netns", "del", namespace], capture_output=True
+ )
+ if result.returncode != 0:
+ raise Exception(f"Error while deleting namespace {namespace}")
except subprocess.CalledProcessError as e:
raise Exception("Error deleting namespace:", e.output)