adrianvillin | bfbe7a8 | 2023-12-05 11:47:00 +0100 | [diff] [blame] | 1 | from config import config |
| 2 | from asfframework import VppAsfTestCase, VppTestRunner |
| 3 | import unittest |
| 4 | import subprocess |
| 5 | from 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") |
| 18 | class 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") |
| 42 | |
| 43 | process = subprocess.run( |
| 44 | [ |
| 45 | "ip", |
| 46 | "netns", |
| 47 | "exec", |
| 48 | "HttpStaticProm", |
| 49 | "curl", |
| 50 | f"10.10.1.2/stats.prom", |
| 51 | ], |
| 52 | capture_output=True, |
| 53 | ) |
| 54 | self.assertIn(b"TYPE", process.stdout) |
| 55 | |
| 56 | |
| 57 | if __name__ == "__main__": |
| 58 | unittest.main(testRunner=VppTestRunner) |