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") |
Matus Fabian | f95c4d8 | 2024-07-24 15:47:31 +0200 | [diff] [blame] | 42 | self.sleep(1, "wait for min-scrape-interval to expire") |
adrianvillin | bfbe7a8 | 2023-12-05 11:47:00 +0100 | [diff] [blame] | 43 | |
| 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 | |
| 58 | if __name__ == "__main__": |
| 59 | unittest.main(testRunner=VppTestRunner) |