aboutsummaryrefslogtreecommitdiffstats
path: root/test/asf/test_http_static.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/asf/test_http_static.py')
-rw-r--r--test/asf/test_http_static.py84
1 files changed, 55 insertions, 29 deletions
diff --git a/test/asf/test_http_static.py b/test/asf/test_http_static.py
index 701bfe783ea..368826f75d4 100644
--- a/test/asf/test_http_static.py
+++ b/test/asf/test_http_static.py
@@ -1,13 +1,14 @@
from config import config
-from asfframework import VppAsfTestCase, VppTestRunner
+from asfframework import VppAsfTestCase, VppTestRunner, get_testcase_dirname
import unittest
import subprocess
import tempfile
+import os
from vpp_qemu_utils import (
create_host_interface,
- delete_host_interfaces,
+ delete_all_host_interfaces,
create_namespace,
- delete_namespace,
+ delete_all_namespaces,
)
@@ -28,23 +29,36 @@ class TestHttpStaticVapi(VppAsfTestCase):
cls.temp2 = tempfile.NamedTemporaryFile()
cls.temp2.write(b"Hello world2")
+ cls.ns_history_name = (
+ f"{config.tmp_dir}/{get_testcase_dirname(cls.__name__)}/history_ns.txt"
+ )
+ cls.if_history_name = (
+ f"{config.tmp_dir}/{get_testcase_dirname(cls.__name__)}/history_if.txt"
+ )
+
try:
- create_namespace("HttpStatic")
- except Exception:
- cls.logger.warning("Unable to create a namespace, retrying.")
- delete_namespace("HttpStatic")
- create_namespace("HttpStatic")
+ # CleanUp
+ delete_all_namespaces(cls.ns_history_name)
+ delete_all_host_interfaces(cls.if_history_name)
- create_host_interface("vppHost", "vppOut", "HttpStatic", "10.10.1.1/24")
+ cls.ns_name = create_namespace(cls.ns_history_name)
+ cls.host_if_name, cls.vpp_if_name = create_host_interface(
+ cls.if_history_name, cls.ns_name, "10.10.1.1/24"
+ )
- cls.vapi.cli("create host-interface name vppOut")
- cls.vapi.cli("set int state host-vppOut up")
- cls.vapi.cli("set int ip address host-vppOut 10.10.1.2/24")
+ except Exception as e:
+ cls.logger.warning(f"Unable to complete setup: {e}")
+ raise unittest.SkipTest("Skipping tests due to setup failure.")
+
+ cls.vapi.cli(f"create host-interface name {cls.vpp_if_name}")
+ cls.vapi.cli(f"set int state host-{cls.vpp_if_name} up")
+ cls.vapi.cli(f"set int ip address host-{cls.vpp_if_name} 10.10.1.2/24")
@classmethod
def tearDownClass(cls):
- delete_namespace("HttpStatic")
- delete_host_interfaces("vppHost")
+ delete_all_namespaces(cls.ns_history_name)
+ delete_all_host_interfaces(cls.if_history_name)
+
cls.temp.close()
cls.temp2.close()
super(TestHttpStaticVapi, cls).tearDownClass()
@@ -61,7 +75,7 @@ class TestHttpStaticVapi(VppAsfTestCase):
"ip",
"netns",
"exec",
- "HttpStatic",
+ self.ns_name,
"curl",
"-v",
f"10.10.1.2/{self.temp.name[5:]}",
@@ -77,7 +91,7 @@ class TestHttpStaticVapi(VppAsfTestCase):
"ip",
"netns",
"exec",
- "HttpStatic",
+ self.ns_name,
"curl",
f"10.10.1.2/{self.temp2.name[5:]}",
],
@@ -103,23 +117,35 @@ class TestHttpStaticCli(VppAsfTestCase):
cls.temp2 = tempfile.NamedTemporaryFile()
cls.temp2.write(b"Hello world2")
+ cls.ns_history_name = (
+ f"{config.tmp_dir}/{get_testcase_dirname(cls.__name__)}/history_ns.txt"
+ )
+ cls.if_history_name = (
+ f"{config.tmp_dir}/{get_testcase_dirname(cls.__name__)}/history_if.txt"
+ )
+
try:
- create_namespace("HttpStatic2")
- except Exception:
- cls.logger.warning("Unable to create namespace, retrying.")
- delete_namespace("HttpStatic2")
- create_namespace("HttpStatic2")
+ delete_all_namespaces(cls.ns_history_name)
+ delete_all_host_interfaces(cls.if_history_name)
- create_host_interface("vppHost2", "vppOut2", "HttpStatic2", "10.10.1.1/24")
+ cls.ns_name = create_namespace(cls.ns_history_name)
+ cls.host_if_name, cls.vpp_if_name = create_host_interface(
+ cls.if_history_name, cls.ns_name, "10.10.1.1/24"
+ )
- cls.vapi.cli("create host-interface name vppOut2")
- cls.vapi.cli("set int state host-vppOut2 up")
- cls.vapi.cli("set int ip address host-vppOut2 10.10.1.2/24")
+ except Exception as e:
+ cls.logger.warning(f"Unable to complete setup: {e}")
+ raise unittest.SkipTest("Skipping tests due to setup failure.")
+
+ cls.vapi.cli(f"create host-interface name {cls.vpp_if_name}")
+ cls.vapi.cli(f"set int state host-{cls.vpp_if_name} up")
+ cls.vapi.cli(f"set int ip address host-{cls.vpp_if_name} 10.10.1.2/24")
@classmethod
def tearDownClass(cls):
- delete_namespace("HttpStatic2")
- delete_host_interfaces("vppHost2")
+ delete_all_namespaces(cls.ns_history_name)
+ delete_all_host_interfaces(cls.if_history_name)
+
cls.temp.close()
cls.temp2.close()
super(TestHttpStaticCli, cls).tearDownClass()
@@ -135,7 +161,7 @@ class TestHttpStaticCli(VppAsfTestCase):
"ip",
"netns",
"exec",
- "HttpStatic2",
+ self.ns_name,
"curl",
f"10.10.1.2/{self.temp.name[5:]}",
],
@@ -149,7 +175,7 @@ class TestHttpStaticCli(VppAsfTestCase):
"ip",
"netns",
"exec",
- "HttpStatic2",
+ self.ns_name,
"curl",
f"10.10.1.2/{self.temp2.name[5:]}",
],