X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Fcharm%2Fprometheus%2Ftests%2Ftest_pod_spec.py;h=1adbae64bb2e55f83dfcbef5ca1aac25a3ded370;hb=HEAD;hp=445d4a8e1fd9350372b27622b963f002d600c1bd;hpb=2459af695441e460e64daea40157c0fd5a78e2c3;p=osm%2Fdevops.git diff --git a/installers/charm/prometheus/tests/test_pod_spec.py b/installers/charm/prometheus/tests/test_pod_spec.py index 445d4a8e..1adbae64 100644 --- a/installers/charm/prometheus/tests/test_pod_spec.py +++ b/installers/charm/prometheus/tests/test_pod_spec.py @@ -267,18 +267,18 @@ class TestPodSpec(unittest.TestCase): { "path": "prometheus.yml", "content": ( - "global:" - " scrape_interval: 15s" - " evaluation_interval: 15s" - "alerting:" - " alertmanagers:" - " - static_configs:" - " - targets:" - "rule_files:" - "scrape_configs:" - " - job_name: 'prometheus'" - " static_configs:" - " - targets: [{}]".format(config["default_target"]) + "global:\n" + " scrape_interval: 15s\n" + " evaluation_interval: 15s\n" + "alerting:\n" + " alertmanagers:\n" + " - static_configs:\n" + " - targets:\n" + "rule_files:\n" + "scrape_configs:\n" + " - job_name: 'prometheus'\n" + " static_configs:\n" + " - targets: [{}]\n".format(config["default_target"]) ), } ], @@ -286,7 +286,6 @@ class TestPodSpec(unittest.TestCase): ] pod_envconfig = pod_spec._make_pod_files(config) - self.assertListEqual(expected_result, pod_envconfig) def test_make_readiness_probe(self) -> NoReturn: @@ -333,8 +332,6 @@ class TestPodSpec(unittest.TestCase): } expected_result = [ - "sh", - "-c", "/bin/prometheus", "--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus", @@ -350,6 +347,33 @@ class TestPodSpec(unittest.TestCase): self.assertListEqual(expected_result, pod_envconfig) + def test_make_pod_command_with_web_admin_api_enabled(self) -> NoReturn: + """Testing make pod command.""" + port = 9090 + config = { + "web_subpath": "/", + "default_target": "", + "site_url": "", + "enable_web_admin_api": True, + } + + expected_result = [ + "/bin/prometheus", + "--config.file=/etc/prometheus/prometheus.yml", + "--storage.tsdb.path=/prometheus", + "--web.console.libraries=/usr/share/prometheus/console_libraries", + "--web.console.templates=/usr/share/prometheus/consoles", + "--web.route-prefix={}".format(config.get("web_subpath")), + "--web.external-url=http://localhost:{}{}".format( + port, config.get("web_subpath") + ), + "--web.enable-admin-api", + ] + + pod_envconfig = pod_spec._make_pod_command(config, port) + + self.assertListEqual(expected_result, pod_envconfig) + def test_make_pod_spec(self) -> NoReturn: """Testing make pod spec.""" image_info = {"upstream-source": "ubuntu/prometheus:latest"} @@ -357,6 +381,7 @@ class TestPodSpec(unittest.TestCase): "web_subpath": "/", "default_target": "", "site_url": "", + "enable_web_admin_api": False, } relation_state = {} app_name = "prometheus" @@ -385,18 +410,18 @@ class TestPodSpec(unittest.TestCase): { "path": "prometheus.yml", "content": ( - "global:" - " scrape_interval: 15s" - " evaluation_interval: 15s" - "alerting:" - " alertmanagers:" - " - static_configs:" - " - targets:" - "rule_files:" - "scrape_configs:" - " - job_name: 'prometheus'" - " static_configs:" - " - targets: [{}]".format( + "global:\n" + " scrape_interval: 15s\n" + " evaluation_interval: 15s\n" + "alerting:\n" + " alertmanagers:\n" + " - static_configs:\n" + " - targets:\n" + "rule_files:\n" + "scrape_configs:\n" + " - job_name: 'prometheus'\n" + " static_configs:\n" + " - targets: [{}]\n".format( config.get("default_target") ) ), @@ -405,8 +430,6 @@ class TestPodSpec(unittest.TestCase): } ], "command": [ - "sh", - "-c", "/bin/prometheus", "--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus", @@ -456,6 +479,7 @@ class TestPodSpec(unittest.TestCase): "tls_secret_name": "prometheus", "max_file_size": 0, "ingress_whitelist_source_range": "0.0.0.0/0", + "enable_web_admin_api": False, } relation_state = {} app_name = "prometheus" @@ -484,18 +508,18 @@ class TestPodSpec(unittest.TestCase): { "path": "prometheus.yml", "content": ( - "global:" - " scrape_interval: 15s" - " evaluation_interval: 15s" - "alerting:" - " alertmanagers:" - " - static_configs:" - " - targets:" - "rule_files:" - "scrape_configs:" - " - job_name: 'prometheus'" - " static_configs:" - " - targets: [{}]".format( + "global:\n" + " scrape_interval: 15s\n" + " evaluation_interval: 15s\n" + "alerting:\n" + " alertmanagers:\n" + " - static_configs:\n" + " - targets:\n" + "rule_files:\n" + "scrape_configs:\n" + " - job_name: 'prometheus'\n" + " static_configs:\n" + " - targets: [{}]\n".format( config.get("default_target") ) ), @@ -504,8 +528,6 @@ class TestPodSpec(unittest.TestCase): } ], "command": [ - "sh", - "-c", "/bin/prometheus", "--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus", @@ -590,6 +612,7 @@ class TestPodSpec(unittest.TestCase): "web_subpath": "/", "default_target": "", "site_url": "", + "enable_web_admin_api": False, } relation_state = {} app_name = "prometheus"