From bfbe7a8c9a8b830619c532381f30681c563f6ad9 Mon Sep 17 00:00:00 2001 From: adrianvillin Date: Tue, 5 Dec 2023 11:47:00 +0100 Subject: tests: Added a simple prom(etheus exporter) plugin test Type: test Change-Id: Ibceabc411f09d80cc23be6f2e7c8abd56d4c4ac2 Signed-off-by: adrianvillin --- test/asf/test_prom.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/asf/test_prom.py diff --git a/test/asf/test_prom.py b/test/asf/test_prom.py new file mode 100644 index 00000000000..3f8fb4c7a44 --- /dev/null +++ b/test/asf/test_prom.py @@ -0,0 +1,58 @@ +from config import config +from asfframework import VppAsfTestCase, VppTestRunner +import unittest +import subprocess +from vpp_qemu_utils import ( + create_host_interface, + delete_host_interfaces, + create_namespace, + delete_namespace, +) + + +@unittest.skipIf( + "http_static" in config.excluded_plugins, "Exclude HTTP Static Server plugin tests" +) +@unittest.skipIf("prom" in config.excluded_plugins, "Exclude Prometheus plugin tests") +@unittest.skipIf(config.skip_netns_tests, "netns not available or disabled from cli") +class TestProm(VppAsfTestCase): + """Prometheus plugin test""" + + @classmethod + def setUpClass(cls): + super(TestProm, cls).setUpClass() + + create_namespace("HttpStaticProm") + create_host_interface("vppHost", "vppOut", "HttpStaticProm", "10.10.1.1/24") + + cls.vapi.cli("create host-interface name vppOut") + cls.vapi.cli("set int state host-vppOut up") + cls.vapi.cli("set int ip address host-vppOut 10.10.1.2/24") + + @classmethod + def tearDownClass(cls): + delete_namespace(["HttpStaticProm"]) + delete_host_interfaces("vppHost") + super(TestProm, cls).tearDownClass() + + def test_prom(self): + """Enable HTTP Static server and prometheus exporter, get stats""" + self.vapi.cli("http static server uri tcp://0.0.0.0/80 url-handlers") + self.vapi.cli("prom enable") + + process = subprocess.run( + [ + "ip", + "netns", + "exec", + "HttpStaticProm", + "curl", + f"10.10.1.2/stats.prom", + ], + capture_output=True, + ) + self.assertIn(b"TYPE", process.stdout) + + +if __name__ == "__main__": + unittest.main(testRunner=VppTestRunner) -- cgit 1.2.3-korg