Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / tasks / mgr / test_dashboard.py
1
2
3 from mgr_test_case import MgrTestCase
4
5 import logging
6 import requests
7
8
9 log = logging.getLogger(__name__)
10
11
12 class TestDashboard(MgrTestCase):
13     MGRS_REQUIRED = 3
14
15     def test_standby(self):
16         self._assign_ports("dashboard", "server_port")
17         self._load_module("dashboard")
18
19         original_active = self.mgr_cluster.get_active_id()
20
21         original_uri = self._get_uri("dashboard")
22         log.info("Originally running at {0}".format(original_uri))
23
24         self.mgr_cluster.mgr_fail(original_active)
25
26         failed_over_uri = self._get_uri("dashboard")
27         log.info("After failover running at {0}".format(original_uri))
28
29         self.assertNotEqual(original_uri, failed_over_uri)
30
31         # The original active daemon should have come back up as a standby
32         # and be doing redirects to the new active daemon
33         r = requests.get(original_uri, allow_redirects=False)
34         self.assertEqual(r.status_code, 303)
35         self.assertEqual(r.headers['Location'], failed_over_uri)
36
37     def test_urls(self):
38         self._assign_ports("dashboard", "server_port")
39         self._load_module("dashboard")
40
41         base_uri = self._get_uri("dashboard")
42
43         # This is a very simple smoke test to check that the dashboard can
44         # give us a 200 response to requests.  We're not testing that
45         # the content is correct or even renders!
46
47         urls = [
48             "/health",
49             "/servers",
50             "/osd/",
51             "/osd/perf/0",
52             "/rbd_mirroring",
53             "/rbd_iscsi"
54         ]
55
56         failures = []
57
58         for url in urls:
59             r = requests.get(base_uri + url, allow_redirects=False)
60             if r.status_code >= 300 and r.status_code < 400:
61                 log.error("Unexpected redirect to: {0} (from {1})".format(
62                     r.headers['Location'], base_uri))
63             if r.status_code != 200:
64                 failures.append(url)
65
66             log.info("{0}: {1} ({2} bytes)".format(
67                 url, r.status_code, len(r.content)
68             ))
69
70         self.assertListEqual(failures, [])