tests: Added a simple prom(etheus exporter) plugin test 58/40058/5
authoradrianvillin <avillin@cisco.com>
Tue, 5 Dec 2023 10:47:00 +0000 (11:47 +0100)
committerDave Wallace <dwallacelf@gmail.com>
Tue, 9 Apr 2024 16:17:29 +0000 (16:17 +0000)
Type: test

Change-Id: Ibceabc411f09d80cc23be6f2e7c8abd56d4c4ac2
Signed-off-by: adrianvillin <avillin@cisco.com>
test/asf/test_prom.py [new file with mode: 0644]

diff --git a/test/asf/test_prom.py b/test/asf/test_prom.py
new file mode 100644 (file)
index 0000000..3f8fb4c
--- /dev/null
@@ -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)