Merge pull request #24 from lolwww/master

Add cinder-backup-swift functional tests
This commit is contained in:
Frode Nordahl
2019-06-30 10:12:03 +02:00
committed by GitHub
4 changed files with 219 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
# Copyright 2018 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.
"""Collection of code for setting up and testing cinder-backup-swift."""

View File

@@ -0,0 +1,48 @@
# Copyright 2018 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.
"""Code for configuring cinder-backup-swift."""
import zaza.model as zaza_model
import zaza.openstack.charm_tests.test_utils
def configure_cinder_backup():
"""Configure cinder-backup-swift."""
keystone_ip = zaza_model.get_app_ips(
'swift-keystone')[0]
swift_ip = zaza_model.get_app_ips(
'swift-proxy')[0]
auth_ver = (zaza_model.get_application_config('swift-keystone')
.get('preferred-api-version').get('value'))
if auth_ver == 2:
auth_url = 'http://{}:5000/v2.0'.format(keystone_ip)
endpoint_url = 'http://{}:8080/v1/AUTH_'.format(swift_ip)
else:
auth_url = 'http://{}:5000/v3'.format(keystone_ip)
endpoint_url = 'http://{}:8080/v1/AUTH'.format(swift_ip)
cinder_backup_swift_conf = {
'endpoint-url': endpoint_url,
'auth-url': auth_url
}
juju_service = 'cinder-backup-swift'
zaza_model.set_application_config(juju_service, cinder_backup_swift_conf)
zaza_model.wait_for_agent_status()
zaza_model.wait_for_application_states()
_singleton = zaza.openstack.charm_tests.test_utils.OpenStackBaseTest()
_singleton.setUpClass()
with _singleton.config_change(cinder_backup_swift_conf,
cinder_backup_swift_conf):
# wait for configuration to be applied then return
pass

View File

@@ -0,0 +1,63 @@
#!/usr/bin/env python3
# Copyright 2018 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.
"""Encapsulate cinder-backup testing."""
import logging
import zaza.openstack.utilities.openstack as openstack_utils
import zaza.openstack.charm_tests.test_utils as test_utils
class CinderBackupSwiftTest(test_utils.OpenStackBaseTest):
"""Encapsulate cinder-backup tests."""
@classmethod
def setUpClass(cls):
"""Run class setup for running cinder tests."""
super(CinderBackupSwiftTest, cls).setUpClass()
cls.cinder_client = openstack_utils.get_cinder_session_client(
cls.keystone_session)
def test_cinder_volume_backup_create_delete(self):
"""Create volume backup and then delete it."""
# Create volume
logging.info('Creating volume')
size = 1
volume = openstack_utils.create_volume(
self.cinder_client,
size)
# Create volume backup
logging.info('Creating volume backup')
volume_backup = openstack_utils.create_volume_backup(
self.cinder_client,
volume.id)
# Check if backup was created via Swift
record = openstack_utils.get_volume_backup_metadata(
self.cinder_client,
volume_backup.id
)
swift_driver = 'cinder.backup.drivers.swift.SwiftBackupDriver'
assert record['backup_service'] == swift_driver
# Delete volume backup
logging.info('Deleting volume backup')
openstack_utils.delete_volume_backup(
self.cinder_client,
volume_backup.id)
logging.info('Deleting volume')
openstack_utils.delete_volume(self.cinder_client, volume.id)

View File

@@ -1690,6 +1690,29 @@ def delete_image(glance, img_id):
delete_resource(glance.images, img_id, msg="glance image")
def delete_volume(cinder, vol_id):
"""Delete the given volume from cinder.
:param cinder: Authenticated cinderclient
:type cinder: cinderclient.Client
:param vol_id: unique name or id for the openstack resource
:type vol_id: str
"""
delete_resource(cinder.volumes, vol_id, msg="deleting cinder volume")
def delete_volume_backup(cinder, vol_backup_id):
"""Delete the given volume from cinder.
:param cinder: Authenticated cinderclient
:type cinder: cinderclient.Client
:param vol_backup_id: unique name or id for the openstack resource
:type vol_backup_id: str
"""
delete_resource(cinder.backups, vol_backup_id,
msg="deleting cinder volume backup")
def upload_image_to_glance(glance, local_path, image_name, disk_format='qcow2',
visibility='public', container_format='bare'):
"""Upload the given image to glance and apply the given label.
@@ -1769,6 +1792,76 @@ def create_image(glance, image_url, image_name, image_cache_dir=None, tags=[]):
return image
def create_volume(cinder, size, name=None, image=None):
"""Create cinder volume.
:param cinder: Authenticated cinderclient
:type cinder: cinder.Client
:param size: Size of the volume
:type size: int
:param name: display name for new volume
:type name: Option[str, None]
:param image: Image to download to volume.
:type image: Option[str, None]
:returns: cinder volume pointer
:rtype: cinderclient.common.utils.RequestIdProxy
"""
logging.debug('Creating volume')
# Create volume
volume = cinder.volumes.create(
size=size,
name=name,
imageRef=image)
resource_reaches_status(
cinder.volumes,
volume.id,
expected_status='available',
msg='Volume status wait')
return volume
def create_volume_backup(cinder, volume_id, name=None):
"""Create cinder volume backup.
:param cinder: Authenticated cinderclient
:type cinder: cinder.Client
:param volume_id: the source volume's id for backup
:type volume_id: str
:param name: display name for new volume backup
:type name: Option[str, None]
:returns: cinder volume backup pointer
:rtype: cinderclient.common.utils.RequestIdProxy
"""
logging.debug('Creating volume backup')
# Create volume backup
volume_backup = cinder.backups.create(
volume_id,
name=name)
resource_reaches_status(
cinder.backups,
volume_backup.id,
expected_status='available',
msg='Volume status wait')
return volume_backup
def get_volume_backup_metadata(cinder, backup_id):
"""Get cinder volume backup record.
:param cinder: Authenticated cinderclient
:type cinder: cinder.Client
:param backup_id: the source backup id
"""
logging.debug('Request volume backup record')
# Request volume backup record
volume_backup_record = cinder.backups.export_record(
backup_id)
return volume_backup_record
def create_ssh_key(nova_client, keypair_name, replace=False):
"""Create ssh key.