blob: f536fd19d34835f4fd9686c32d74d35a57f066c4 [file] [log] [blame]
adrianvillinbfbe7a82023-12-05 11:47:00 +01001from config import config
2from asfframework import VppAsfTestCase, VppTestRunner
3import unittest
4import subprocess
5from vpp_qemu_utils import (
6 create_host_interface,
7 delete_host_interfaces,
8 create_namespace,
9 delete_namespace,
10)
11
12
13@unittest.skipIf(
14 "http_static" in config.excluded_plugins, "Exclude HTTP Static Server plugin tests"
15)
16@unittest.skipIf("prom" in config.excluded_plugins, "Exclude Prometheus plugin tests")
17@unittest.skipIf(config.skip_netns_tests, "netns not available or disabled from cli")
18class TestProm(VppAsfTestCase):
19 """Prometheus plugin test"""
20
21 @classmethod
22 def setUpClass(cls):
23 super(TestProm, cls).setUpClass()
24
25 create_namespace("HttpStaticProm")
26 create_host_interface("vppHost", "vppOut", "HttpStaticProm", "10.10.1.1/24")
27
28 cls.vapi.cli("create host-interface name vppOut")
29 cls.vapi.cli("set int state host-vppOut up")
30 cls.vapi.cli("set int ip address host-vppOut 10.10.1.2/24")
31
32 @classmethod
33 def tearDownClass(cls):
34 delete_namespace(["HttpStaticProm"])
35 delete_host_interfaces("vppHost")
36 super(TestProm, cls).tearDownClass()
37
38 def test_prom(self):
39 """Enable HTTP Static server and prometheus exporter, get stats"""
40 self.vapi.cli("http static server uri tcp://0.0.0.0/80 url-handlers")
41 self.vapi.cli("prom enable")
Matus Fabianf95c4d82024-07-24 15:47:31 +020042 self.sleep(1, "wait for min-scrape-interval to expire")
adrianvillinbfbe7a82023-12-05 11:47:00 +010043
44 process = subprocess.run(
45 [
46 "ip",
47 "netns",
48 "exec",
49 "HttpStaticProm",
50 "curl",
51 f"10.10.1.2/stats.prom",
52 ],
53 capture_output=True,
54 )
55 self.assertIn(b"TYPE", process.stdout)
56
57
58if __name__ == "__main__":
59 unittest.main(testRunner=VppTestRunner)