diff --git a/zaza/openstack/charm_tests/cinder_backup_swift/__init__.py b/zaza/openstack/charm_tests/cinder_backup_swift/__init__.py new file mode 100644 index 0000000..3d7e48c --- /dev/null +++ b/zaza/openstack/charm_tests/cinder_backup_swift/__init__.py @@ -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.""" diff --git a/zaza/openstack/charm_tests/cinder_backup_swift/setup.py b/zaza/openstack/charm_tests/cinder_backup_swift/setup.py new file mode 100644 index 0000000..d71b39d --- /dev/null +++ b/zaza/openstack/charm_tests/cinder_backup_swift/setup.py @@ -0,0 +1,51 @@ +# 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 time + + +def basic_setup(): + """Run setup for testing cinder-backup-swift. + + Cinder backup setup for testing cinder-backup is currently part of + cinder-backup functional tests. + Volume backup setup for other tests to use should go here. + """ + + +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_application_states() + time.sleep(300) diff --git a/zaza/openstack/charm_tests/cinder_backup_swift/tests.py b/zaza/openstack/charm_tests/cinder_backup_swift/tests.py new file mode 100644 index 0000000..2fb1f36 --- /dev/null +++ b/zaza/openstack/charm_tests/cinder_backup_swift/tests.py @@ -0,0 +1,54 @@ +#!/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 an 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) + # Delete volume backup + logging.info('Deleting volume backup') + openstack_utils.delete_resource( + self.cinder_client, + volume_backup.id) + logging.info('Deleting volume') + openstack_utils.delete_resource(self.cinder_client, volume.id) diff --git a/zaza/openstack/utilities/openstack.py b/zaza/openstack/utilities/openstack.py index bc2b441..f128b05 100644 --- a/zaza/openstack/utilities/openstack.py +++ b/zaza/openstack/utilities/openstack.py @@ -1769,6 +1769,63 @@ 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') + if not size: + raise Exception("Size for volume not specified") + # 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') + if not volume_id: + raise Exception("volume_id not specified") + # 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 create_ssh_key(nova_client, keypair_name, replace=False): """Create ssh key.