From 199da4e739c5181bb69e3d3239db03e0961806b9 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Mon, 4 Jun 2018 17:31:04 +0200 Subject: [PATCH] Update tests to use Juju storage Due to changes to the ceph-osd charm, it is suggested to use Juju storage for testing. Change-Id: Icd1b53d8672271a5350b630f14f20bbd3b6c8740 Related-Bug: #1698154 --- hooks/charmhelpers/core/hookenv.py | 7 +++++++ tests/basic_deployment.py | 9 +++------ tests/charmhelpers/contrib/amulet/deployment.py | 6 ++++-- tests/charmhelpers/contrib/openstack/amulet/utils.py | 12 +++++++----- tests/charmhelpers/core/hookenv.py | 7 +++++++ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/hooks/charmhelpers/core/hookenv.py b/hooks/charmhelpers/core/hookenv.py index 627d8f7..ed7af39 100644 --- a/hooks/charmhelpers/core/hookenv.py +++ b/hooks/charmhelpers/core/hookenv.py @@ -972,6 +972,13 @@ def application_version_set(version): log("Application Version: {}".format(version)) +@translate_exc(from_exc=OSError, to_exc=NotImplementedError) +def goal_state(): + """Juju goal state values""" + cmd = ['goal-state', '--format=json'] + return json.loads(subprocess.check_output(cmd).decode('UTF-8')) + + @translate_exc(from_exc=OSError, to_exc=NotImplementedError) def is_leader(): """Does the current unit hold the juju leadership diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py index 1ea9a8d..ec34532 100644 --- a/tests/basic_deployment.py +++ b/tests/basic_deployment.py @@ -47,7 +47,8 @@ class CephBasicDeployment(OpenStackAmuletDeployment): """ this_service = {'name': 'ceph-proxy'} other_services = [{'name': 'ceph-mon', 'units': 3}, - {'name': 'ceph-osd', 'units': 3}, + {'name': 'ceph-osd', 'units': 3, + 'storage': {'osd-devices': 'cinder,10G'}}, {'name': 'ceph-radosgw'}] super(CephBasicDeployment, self)._add_services(this_service, other_services) @@ -64,16 +65,12 @@ class CephBasicDeployment(OpenStackAmuletDeployment): ceph_config = { 'monitor-count': '3', 'auth-supported': 'none', - 'fsid': '6547bd3e-1397-11e2-82e5-53567c8d32dc', - 'monitor-secret': 'AQCXrnZQwI7KGBAAiPofmKEXKxu5bUzoYLVkbQ==', } # Include a non-existent device as osd-devices is a whitelist, # and this will catch cases where proposals attempt to change that. ceph_osd_config = { - 'osd-reformat': True, - 'ephemeral-unmount': '/mnt', - 'osd-devices': '/dev/vdb /srv/ceph /dev/test-non-existent' + 'osd-devices': '/srv/ceph /dev/test-non-existent' } proxy_config = { diff --git a/tests/charmhelpers/contrib/amulet/deployment.py b/tests/charmhelpers/contrib/amulet/deployment.py index 9c65518..d21d01d 100644 --- a/tests/charmhelpers/contrib/amulet/deployment.py +++ b/tests/charmhelpers/contrib/amulet/deployment.py @@ -50,7 +50,8 @@ class AmuletDeployment(object): this_service['units'] = 1 self.d.add(this_service['name'], units=this_service['units'], - constraints=this_service.get('constraints')) + constraints=this_service.get('constraints'), + storage=this_service.get('storage')) for svc in other_services: if 'location' in svc: @@ -64,7 +65,8 @@ class AmuletDeployment(object): svc['units'] = 1 self.d.add(svc['name'], charm=branch_location, units=svc['units'], - constraints=svc.get('constraints')) + constraints=svc.get('constraints'), + storage=svc.get('storage')) def _add_relations(self, relations): """Add all of the relations for the services.""" diff --git a/tests/charmhelpers/contrib/openstack/amulet/utils.py b/tests/charmhelpers/contrib/openstack/amulet/utils.py index 84e87f5..d43038b 100644 --- a/tests/charmhelpers/contrib/openstack/amulet/utils.py +++ b/tests/charmhelpers/contrib/openstack/amulet/utils.py @@ -40,6 +40,7 @@ import novaclient import pika import swiftclient +from charmhelpers.core.decorators import retry_on_exception from charmhelpers.contrib.amulet.utils import ( AmuletUtils ) @@ -423,6 +424,7 @@ class OpenStackAmuletUtils(AmuletUtils): self.log.debug('Checking if tenant exists ({})...'.format(tenant)) return tenant in [t.name for t in keystone.tenants.list()] + @retry_on_exception(num_retries=5, base_delay=1) def keystone_wait_for_propagation(self, sentry_relation_pairs, api_version): """Iterate over list of sentry and relation tuples and verify that @@ -542,7 +544,7 @@ class OpenStackAmuletUtils(AmuletUtils): return ep def get_default_keystone_session(self, keystone_sentry, - openstack_release=None): + openstack_release=None, api_version=2): """Return a keystone session object and client object assuming standard default settings @@ -557,12 +559,12 @@ class OpenStackAmuletUtils(AmuletUtils): eyc """ self.log.debug('Authenticating keystone admin...') - api_version = 2 - client_class = keystone_client.Client # 11 => xenial_queens - if openstack_release and openstack_release >= 11: - api_version = 3 + if api_version == 3 or (openstack_release and openstack_release >= 11): client_class = keystone_client_v3.Client + api_version = 3 + else: + client_class = keystone_client.Client keystone_ip = keystone_sentry.info['public-address'] session, auth = self.get_keystone_session( keystone_ip, diff --git a/tests/charmhelpers/core/hookenv.py b/tests/charmhelpers/core/hookenv.py index 627d8f7..ed7af39 100644 --- a/tests/charmhelpers/core/hookenv.py +++ b/tests/charmhelpers/core/hookenv.py @@ -972,6 +972,13 @@ def application_version_set(version): log("Application Version: {}".format(version)) +@translate_exc(from_exc=OSError, to_exc=NotImplementedError) +def goal_state(): + """Juju goal state values""" + cmd = ['goal-state', '--format=json'] + return json.loads(subprocess.check_output(cmd).decode('UTF-8')) + + @translate_exc(from_exc=OSError, to_exc=NotImplementedError) def is_leader(): """Does the current unit hold the juju leadership