1 from config import config
2 from asfframework import VppTestCase, VppTestRunner
6 from vpp_qemu_utils import (
8 delete_host_interfaces,
16 "http_static" in config.excluded_plugins, "Exclude HTTP Static Server plugin tests"
18 class TestHttpStaticVapi(VppTestCase):
19 """enable the http static server [VAPI]"""
23 super(TestHttpStaticVapi, cls).setUpClass()
24 # 2 temp files to improve coverage of http_cache.c
25 cls.temp = tempfile.NamedTemporaryFile()
26 cls.temp.write(b"Hello world")
28 cls.temp2 = tempfile.NamedTemporaryFile()
29 cls.temp2.write(b"Hello world2")
31 if not can_create_namespaces():
32 raise Exception("Unable to create namespace")
33 create_namespace("HttpStatic")
35 create_host_interface("vppHost", "vppOut", "HttpStatic", "10.10.1.1/24")
36 cls.vapi.cli("create host-interface name vppOut")
37 cls.vapi.cli("set int state host-vppOut up")
38 cls.vapi.cli("set int ip address host-vppOut 10.10.1.2/24")
41 def tearDownClass(cls):
42 delete_namespace(["HttpStatic"])
43 delete_host_interfaces("vppHost")
46 super(TestHttpStaticVapi, cls).tearDownClass()
48 def test_http_static_vapi(self):
49 self.vapi.http_static_enable(
51 uri="tcp://0.0.0.0/80",
53 # move file pointer to the beginning
55 process = subprocess.run(
62 f"10.10.1.2/{self.temp.name[5:]}",
66 self.assertIn(b"Hello world", process.stdout)
69 process = subprocess.run(
76 f"10.10.1.2/{self.temp2.name[5:]}",
80 self.assertIn(b"Hello world2", process.stdout)
84 "http_static" in config.excluded_plugins, "Exclude HTTP Static Server plugin tests"
86 class TestHttpStaticCli(VppTestCase):
87 """enable the static http server [CLI]"""
91 super(TestHttpStaticCli, cls).setUpClass()
92 # 2 temp files to improve coverage of http_cache.c
93 cls.temp = tempfile.NamedTemporaryFile()
94 cls.temp.write(b"Hello world")
96 cls.temp2 = tempfile.NamedTemporaryFile()
97 cls.temp2.write(b"Hello world2")
99 if not can_create_namespaces("vpp_chk_4212_2"):
100 raise Exception("Unable to create namespace")
101 create_namespace("HttpStatic2")
103 create_host_interface("vppHost2", "vppOut2", "HttpStatic2", "10.10.1.1/24")
104 cls.vapi.cli("create host-interface name vppOut2")
105 cls.vapi.cli("set int state host-vppOut2 up")
106 cls.vapi.cli("set int ip address host-vppOut2 10.10.1.2/24")
109 def tearDownClass(cls):
110 delete_namespace(["HttpStatic2"])
111 delete_host_interfaces("vppHost2")
114 super(TestHttpStaticCli, cls).tearDownClass()
116 def test_http_static_cli(self):
118 "http static server www-root /tmp uri tcp://0.0.0.0/80 cache-size 2m"
120 # move file pointer to the beginning
122 process = subprocess.run(
129 f"10.10.1.2/{self.temp.name[5:]}",
133 self.assertIn(b"Hello world", process.stdout)
136 process = subprocess.run(
143 f"10.10.1.2/{self.temp2.name[5:]}",
147 self.assertIn(b"Hello world2", process.stdout)
149 self.vapi.cli("show http static server cache")
150 self.vapi.cli("clear http static cache")
151 self.vapi.cli("show http static server sessions")
154 if __name__ == "__main__":
155 unittest.main(testRunner=VppTestRunner)