From 5993f3f2c586c67a261c510324254dcc5879b8c4 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Wed, 11 Aug 2021 13:00:56 +0000 Subject: [PATCH 1/2] Dashboard test updates Verify CA now that bug is fix released *1. Check logging in to the dashbaord works Use a random username for tests so a test reruns work. *1 https://bugs.launchpad.net/cloud-archive/+bug/1933410 --- .../charm_tests/ceph/dashboard/tests.py | 61 +++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/dashboard/tests.py b/zaza/openstack/charm_tests/ceph/dashboard/tests.py index 1727699..1b5e46d 100644 --- a/zaza/openstack/charm_tests/ceph/dashboard/tests.py +++ b/zaza/openstack/charm_tests/ceph/dashboard/tests.py @@ -15,7 +15,9 @@ """Encapsulating `ceph-dashboard` testing.""" import collections +import json import requests +import uuid import zaza import zaza.openstack.charm_tests.test_utils as test_utils @@ -36,13 +38,27 @@ class CephDashboardTest(test_utils.BaseCharmTest): cls.local_ca_cert = openstack_utils.get_remote_ca_cert_file( cls.application_name) + def get_master_dashboard_url(self): + """Get the url of the dashboard servicing requests. + + Only one unit serves requests at any one time, the other units + redirect to that unit. + + :returns: URL of dashboard on unit + :rtype: Union[str, None] + """ + units = zaza.model.get_units(self.application_name) + for unit in units: + r = requests.get( + 'https://{}:8443'.format(unit.public_address), + verify=self.local_ca_cert, + allow_redirects=False) + if r.status_code == requests.codes.ok: + return 'https://{}:8443'.format(unit.public_address) + def test_dashboard_units(self): """Check dashboard units are configured correctly.""" - # XXX: Switch to using CA for verification when - # https://bugs.launchpad.net/cloud-archive/+bug/1933410 - # is fix released. - # verify = self.local_ca_cert - verify = False + verify = self.local_ca_cert units = zaza.model.get_units(self.application_name) rcs = collections.defaultdict(list) for unit in units: @@ -72,12 +88,45 @@ class CephDashboardTest(test_utils.BaseCharmTest): 'role': role}) return action + def get_random_username(self): + """Generate a username to use in tests. + + :returns: Username + :rtype: str + """ + return "zazauser-{}".format(uuid.uuid1()) + def test_create_user(self): """Test create user action.""" - test_user = 'marvin' + test_user = self.get_random_username() action = self.create_user(test_user) self.assertEqual(action.status, "completed") self.assertTrue(action.data['results']['password']) action = self.create_user(test_user) # Action should fail as the user already exists self.assertEqual(action.status, "failed") + + def access_dashboard(self, dashboard_url): + """Test logging via a dashboard url. + + :param dashboard_url: Base url to use to login to + :type dashboard_url: str + """ + user = self.get_random_username() + action = self.create_user(username=user) + self.assertEqual(action.status, "completed") + password = action.data['results']['password'] + path = "api/auth" + headers = {'Content-type': 'application/json'} + payload = {"username": user, "password": password} + verify = self.local_ca_cert + r = requests.post( + "{}/{}".format(dashboard_url, path), + data=json.dumps(payload), + headers=headers, + verify=verify) + self.assertEqual(r.status_code, requests.codes.created) + + def test_access_dashboard(self): + """Test logging in to the dashboard.""" + self.access_dashboard(self.get_master_dashboard_url()) From 36d85aece547e037bdd4eca36af7519187fc6406 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Wed, 8 Sep 2021 13:34:30 +0000 Subject: [PATCH 2/2] Pacific requires client to set accepted api version --- zaza/openstack/charm_tests/ceph/dashboard/tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/ceph/dashboard/tests.py b/zaza/openstack/charm_tests/ceph/dashboard/tests.py index 1b5e46d..9c6eae7 100644 --- a/zaza/openstack/charm_tests/ceph/dashboard/tests.py +++ b/zaza/openstack/charm_tests/ceph/dashboard/tests.py @@ -117,7 +117,9 @@ class CephDashboardTest(test_utils.BaseCharmTest): self.assertEqual(action.status, "completed") password = action.data['results']['password'] path = "api/auth" - headers = {'Content-type': 'application/json'} + headers = { + 'Content-type': 'application/json', + 'Accept': 'application/vnd.ceph.api.v1.0'} payload = {"username": user, "password": password} verify = self.local_ca_cert r = requests.post(