1 from config import config
2 from asfframework import VppAsfTestCase, VppTestRunner
6 from vpp_qemu_utils import (
8 delete_host_interfaces,
15 "http_static" in config.excluded_plugins, "Exclude HTTP Static Server plugin tests"
17 @unittest.skipIf(config.skip_netns_tests, "netns not available or disabled from cli")
18 class TestHttpStaticVapi(VppAsfTestCase):
19 """enable the http static server and send requests [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")
32 create_namespace("HttpStatic")
34 cls.logger.warning("Unable to create a namespace, retrying.")
35 delete_namespace("HttpStatic")
36 create_namespace("HttpStatic")
38 create_host_interface("vppHost", "vppOut", "HttpStatic", "10.10.1.1/24")
40 cls.vapi.cli("create host-interface name vppOut")
41 cls.vapi.cli("set int state host-vppOut up")
42 cls.vapi.cli("set int ip address host-vppOut 10.10.1.2/24")
45 def tearDownClass(cls):
46 delete_namespace("HttpStatic")
47 delete_host_interfaces("vppHost")
50 super(TestHttpStaticVapi, cls).tearDownClass()
52 def test_http_static_vapi(self):
53 self.vapi.http_static_enable(
55 uri="tcp://0.0.0.0/80",
57 # move file pointer to the beginning
59 process = subprocess.run(
66 f"10.10.1.2/{self.temp.name[5:]}",
70 self.assertIn(b"Hello world", process.stdout)
73 process = subprocess.run(
80 f"10.10.1.2/{self.temp2.name[5:]}",
84 self.assertIn(b"Hello world2", process.stdout)
88 "http_static" in config.excluded_plugins, "Exclude HTTP Static Server plugin tests"
90 @unittest.skipIf(config.skip_netns_tests, "netns not available or disabled from cli")
91 class TestHttpStaticCli(VppAsfTestCase):
92 """enable the static http server and send requests [CLI]"""
96 super(TestHttpStaticCli, cls).setUpClass()
97 # 2 temp files to improve coverage of http_cache.c
98 cls.temp = tempfile.NamedTemporaryFile()
99 cls.temp.write(b"Hello world")
101 cls.temp2 = tempfile.NamedTemporaryFile()
102 cls.temp2.write(b"Hello world2")
105 create_namespace("HttpStatic2")
107 cls.logger.warning("Unable to create namespace, retrying.")
108 delete_namespace("HttpStatic2")
109 create_namespace("HttpStatic2")
111 create_host_interface("vppHost2", "vppOut2", "HttpStatic2", "10.10.1.1/24")
113 cls.vapi.cli("create host-interface name vppOut2")
114 cls.vapi.cli("set int state host-vppOut2 up")
115 cls.vapi.cli("set int ip address host-vppOut2 10.10.1.2/24")
118 def tearDownClass(cls):
119 delete_namespace("HttpStatic2")
120 delete_host_interfaces("vppHost2")
123 super(TestHttpStaticCli, cls).tearDownClass()
125 def test_http_static_cli(self):
127 "http static server www-root /tmp uri tcp://0.0.0.0/80 cache-size 2m"
129 # move file pointer to the beginning
131 process = subprocess.run(
138 f"10.10.1.2/{self.temp.name[5:]}",
142 self.assertIn(b"Hello world", process.stdout)
145 process = subprocess.run(
152 f"10.10.1.2/{self.temp2.name[5:]}",
156 self.assertIn(b"Hello world2", process.stdout)
158 self.vapi.cli("show http static server cache")
159 self.vapi.cli("clear http static cache")
160 self.vapi.cli("show http static server sessions")
163 if __name__ == "__main__":
164 unittest.main(testRunner=VppTestRunner)