]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/mgr/test_prometheus.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / qa / tasks / mgr / test_prometheus.py
CommitLineData
11fdf7f2
TL
1import json
2import logging
3import requests
4
f67539c2 5from .mgr_test_case import MgrTestCase
11fdf7f2
TL
6
7log = logging.getLogger(__name__)
8
9
10class TestPrometheus(MgrTestCase):
11 MGRS_REQUIRED = 3
12
13 def setUp(self):
9f95a23c 14 super(TestPrometheus, self).setUp()
11fdf7f2
TL
15 self.setup_mgrs()
16
17 def test_file_sd_command(self):
18 self._assign_ports("prometheus", "server_port")
19 self._load_module("prometheus")
20
21 result = json.loads(self.mgr_cluster.mon_manager.raw_cluster_cmd(
22 "prometheus", "file_sd_config"))
23 mgr_map = self.mgr_cluster.get_mgr_map()
24 self.assertEqual(len(result[0]['targets']), len(mgr_map['standbys']) + 1)
25
26
27
28 def test_standby(self):
29 self._assign_ports("prometheus", "server_port")
30 self._load_module("prometheus")
31
32 original_active = self.mgr_cluster.get_active_id()
33
34 original_uri = self._get_uri("prometheus")
35 log.info("Originally running at {0}".format(original_uri))
36
37 self.mgr_cluster.mgr_fail(original_active)
38
39 failed_over_uri = self._get_uri("prometheus")
40 log.info("After failover running at {0}".format(failed_over_uri))
41
42 self.assertNotEqual(original_uri, failed_over_uri)
43
44 # The original active daemon should have come back up as a standby
45 # and serve some html under "/" and an empty answer under /metrics
46 r = requests.get(original_uri, allow_redirects=False)
47 self.assertEqual(r.status_code, 200)
48 r = requests.get(original_uri + "metrics", allow_redirects=False)
49 self.assertEqual(r.status_code, 200)
50 self.assertEqual(r.headers["content-type"], "text/plain;charset=utf-8")
cd265ab1 51 self.assertEqual(r.headers["server"], "Ceph-Prometheus")
11fdf7f2
TL
52
53 def test_urls(self):
54 self._assign_ports("prometheus", "server_port")
55 self._load_module("prometheus")
56
57 base_uri = self._get_uri("prometheus")
58
59 # This is a very simple smoke test to check that the module can
60 # give us a 200 response to requests. We're not testing that
61 # the content is correct or even renders!
62
63 urls = [
64 "/",
65 "/metrics"
66 ]
67
68 failures = []
69
70 for url in urls:
71 r = requests.get(base_uri + url, allow_redirects=False)
72 if r.status_code != 200:
73 failures.append(url)
74
75 log.info("{0}: {1} ({2} bytes)".format(
76 url, r.status_code, len(r.content)
77 ))
78
79 self.assertListEqual(failures, [])