From 740bc2060f4e1d267aaa5c265b68b3e46221ba38 Mon Sep 17 00:00:00 2001 From: Dmitrii Shcherbakov Date: Mon, 4 May 2020 20:45:55 +0300 Subject: [PATCH 1/2] Pass arguments BaseCharmTest.setUpClass Not doing so triggers an incorrect behavior leading to functional test failures as the application name is not set correctly. https://github.com/openstack-charmers/zaza-openstack-tests/issues/256 https://review.opendev.org/#/c/712980/1 --- unit_tests/charm_tests/test_utils.py | 32 ++++++++++++++++++++++++ zaza/openstack/charm_tests/test_utils.py | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 unit_tests/charm_tests/test_utils.py diff --git a/unit_tests/charm_tests/test_utils.py b/unit_tests/charm_tests/test_utils.py new file mode 100644 index 0000000..280e2e2 --- /dev/null +++ b/unit_tests/charm_tests/test_utils.py @@ -0,0 +1,32 @@ +# Copyright 2020 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import zaza.openstack.charm_tests.test_utils as test_utils + +from unittest.mock import patch + + +class TestOpenStackBaseTest(unittest.TestCase): + + @patch.object(test_utils.openstack_utils, 'get_cacert') + @patch.object(test_utils.openstack_utils, 'get_overcloud_keystone_session') + @patch.object(test_utils.BaseCharmTest, 'setUpClass') + def test_setUpClass(self, _setUpClass, _get_ovcks, _get_cacert): + + class MyTestClass(test_utils.OpenStackBaseTest): + model_name = 'deadbeef' + + MyTestClass.setUpClass('foo', 'bar') + _setUpClass.assert_called_with('foo', 'bar') diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index ae431c1..bcb5aff 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -427,7 +427,7 @@ class OpenStackBaseTest(BaseCharmTest): @classmethod def setUpClass(cls, application_name=None, model_alias=None): """Run setup for test class to create common resources.""" - super(OpenStackBaseTest, cls).setUpClass() + super(OpenStackBaseTest, cls).setUpClass(application_name, model_alias) cls.keystone_session = openstack_utils.get_overcloud_keystone_session( model_name=cls.model_name) cls.cacert = openstack_utils.get_cacert() From db0fff648040f4f08ba6a76f039f968c29302e73 Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 5 May 2020 12:28:09 +0100 Subject: [PATCH 2/2] triliovault: Check restore completes Ensure that the oneclick restore process completes as part of the snapshot test case. Drop use of api_version in get_domain_id utility. --- zaza/openstack/charm_tests/trilio/tests.py | 56 ++++++++++++++++++---- zaza/openstack/utilities/openstack.py | 4 +- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/zaza/openstack/charm_tests/trilio/tests.py b/zaza/openstack/charm_tests/trilio/tests.py index e7595a5..99ef3e0 100644 --- a/zaza/openstack/charm_tests/trilio/tests.py +++ b/zaza/openstack/charm_tests/trilio/tests.py @@ -102,13 +102,26 @@ class WorkloadmgrCLIHelper(object): "{snapshot_id} " ) + RESTORE_LIST_CMD = ( + "openstack {auth_args} workloadmgr restore list " + "--snapshot_id {snapshot_id} " + "-f value -c ID" + ) + + RESTORE_STATUS_CMD = ( + "openstack {auth_args} workloadmgr restore show " + "-f value -c status {resource_id}" + ) + def __init__(self, keystone_client): """Initialise helper. :param keystone_client: keystone client :type keystone_client: keystoneclient.v3 """ - self.trilio_wlm_unit = zaza_model.get_first_unit_name("trilio-wlm") + self.trilio_wlm_unit = zaza_model.get_first_unit_name( + "trilio-wlm" + ) self.auth_args = self._auth_arguments(keystone_client) @classmethod @@ -147,7 +160,8 @@ class WorkloadmgrCLIHelper(object): for os_key in _required_keys: params.append( "--{}={}".format( - os_key.lower().replace("_", "-"), overcloud_auth[os_key] + os_key.lower().replace("_", "-"), + overcloud_auth[os_key], ) ) return " ".join(params) @@ -170,7 +184,7 @@ class WorkloadmgrCLIHelper(object): ).strip() retryer = tenacity.Retrying( - wait=tenacity.wait_exponential(multiplier=1, max=60), + wait=tenacity.wait_exponential(multiplier=1, max=30), stop=tenacity.stop_after_delay(180), reraise=True, ) @@ -211,7 +225,7 @@ class WorkloadmgrCLIHelper(object): ).strip() retryer = tenacity.Retrying( - wait=tenacity.wait_exponential(multiplier=1, max=60), + wait=tenacity.wait_exponential(multiplier=1, max=30), stop=tenacity.stop_after_delay(720), reraise=True, ) @@ -241,9 +255,31 @@ class WorkloadmgrCLIHelper(object): timeout=180, fatal=True, ) + restore_id = juju_utils.remote_run( + self.trilio_wlm_unit, + remote_cmd=self.RESTORE_LIST_CMD.format( + auth_args=self.auth_args, snapshot_id=snapshot_id + ), + timeout=180, + fatal=True, + ).strip() - # TODO validate restore but currently failing with 4.0 - # pre-release + retryer = tenacity.Retrying( + wait=tenacity.wait_exponential(multiplier=1, max=30), + stop=tenacity.stop_after_delay(720), + reraise=True, + ) + + retryer( + _resource_reaches_status, + self.trilio_wlm_unit, + self.auth_args, + self.RESTORE_STATUS_CMD, + restore_id, + "available", + ) + + return restore_id class TrilioBaseTest(test_utils.OpenStackBaseTest): @@ -310,7 +346,9 @@ class TrilioBaseTest(test_utils.OpenStackBaseTest): ) # Trilio need direct access to ceph - OMG - openstack_utils.attach_volume(self.nova_client, volume.id, instance.id) + openstack_utils.attach_volume( + self.nova_client, volume.id, instance.id + ) workloadmgrcli = WorkloadmgrCLIHelper(self.keystone_client) @@ -333,7 +371,9 @@ class TrilioBaseTest(test_utils.OpenStackBaseTest): ) # NOTE: Trilio leaves a snapshot in place - # drop before volume deletion. - for volume_snapshot in self.cinder_client.volume_snapshots.list(): + for ( + volume_snapshot + ) in self.cinder_client.volume_snapshots.list(): openstack_utils.delete_resource( self.cinder_client.volume_snapshots, volume_snapshot.id, diff --git a/zaza/openstack/utilities/openstack.py b/zaza/openstack/utilities/openstack.py index 3e72faf..55f8d1b 100644 --- a/zaza/openstack/utilities/openstack.py +++ b/zaza/openstack/utilities/openstack.py @@ -487,15 +487,13 @@ def get_project_id(ks_client, project_name, api_version=2, domain_name=None): return None -def get_domain_id(ks_client, domain_name, api_version=2): +def get_domain_id(ks_client, domain_name): """Return domain ID. :param ks_client: Authenticated keystoneclient :type ks_client: keystoneclient.v3.Client object :param domain_name: Name of the domain :type domain_name: string - :param api_version: API version number - :type api_version: int :returns: Domain ID :rtype: string or None """