Merge remote-tracking branch 'origin/master'

This commit is contained in:
Aurelien Lourot
2020-05-06 11:26:07 +02:00
4 changed files with 82 additions and 12 deletions

View File

@@ -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')

View File

@@ -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()

View File

@@ -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,

View File

@@ -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
"""