From 07da644b2ba6a2371cf7ef5249e196f18a3b8823 Mon Sep 17 00:00:00 2001 From: Jorge Merlino Date: Wed, 20 Mar 2024 15:27:01 -0300 Subject: [PATCH] Add parameters to cinder backend configuration Add configuration parameters cinder_store_user_name, cinder_store_password, cinder_store_project_name and cinder_store_auth_address to cinder volume type backend configuration. This avoids a glance_store bug that prevents glance-api from starting. Closes-Bug: #2052726 Change-Id: I4b6ca32ed426f77a326711c2457046dbda594e77 --- hooks/glance_contexts.py | 13 +++++++++++++ unit_tests/test_glance_contexts.py | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hooks/glance_contexts.py b/hooks/glance_contexts.py index 1fe24e41..65d36836 100644 --- a/hooks/glance_contexts.py +++ b/hooks/glance_contexts.py @@ -33,6 +33,7 @@ from charmhelpers.contrib.openstack.context import ( ApacheSSLContext as SSLContext, BindHostContext, VolumeAPIContext, + IdentityServiceContext, ) from charmhelpers.contrib.hahelpers.cluster import ( @@ -367,6 +368,7 @@ class MultiBackendContext(OSContextGenerator): # backend cinder_volume_type should be left blank so that glance # creates volume in cinder without specifying any volume type. if cinder_volume_types: + keystone_ctx = IdentityServiceContext()() for volume_type in volume_types: ctxt['enabled_backend_configs'][volume_type] = { 'cinder_volume_type': volume_type, @@ -374,6 +376,17 @@ class MultiBackendContext(OSContextGenerator): 'cinder_state_transition_timeout': config( 'cinder-state-transition-timeout'), } + if keystone_ctx: + ctxt['enabled_backend_configs'][volume_type].update({ + 'cinder_store_user_name': keystone_ctx.get( + 'admin_user'), + 'cinder_store_password': keystone_ctx.get( + 'admin_password'), + 'cinder_store_project_name': keystone_ctx.get( + 'admin_tenant_name'), + 'cinder_store_auth_address': keystone_ctx.get( + 'keystone_authtoken').get('auth_url'), + }) else: # default cinder volume type cinder ctxt['enabled_backend_configs']['cinder'] = { diff --git a/unit_tests/test_glance_contexts.py b/unit_tests/test_glance_contexts.py index e4749d43..82d65ab7 100644 --- a/unit_tests/test_glance_contexts.py +++ b/unit_tests/test_glance_contexts.py @@ -389,7 +389,9 @@ class TestGlanceContexts(CharmTestCase): 'default_store_backend': 'cinder', }) - def test_multi_backend_with_cinder_volume_types_defined(self): + @patch('charmhelpers.contrib.openstack.' + 'context.IdentityServiceContext.__call__') + def test_multi_backend_with_cinder_volume_types_defined(self, keystone): # return relation_ids only for cinder but not for swift def _relation_ids(*args, **kwargs): if args[0] == 'cinder-volume-service': @@ -399,6 +401,12 @@ class TestGlanceContexts(CharmTestCase): self.maxDiff = None self.relation_ids.side_effect = _relation_ids + keystone.return_value = { + 'admin_user': 'user', + 'admin_password': 'password', + 'admin_tenant_name': 'services', + 'keystone_authtoken': {'auth_url': 'http://10.0.0.1:35357/v3'}, + } self.is_relation_made.return_value = False data_dir = '/some/data/dir' conf_dict = { @@ -420,6 +428,11 @@ class TestGlanceContexts(CharmTestCase): 'cinder_volume_type': 'volume-type-test', 'cinder_http_retries': 3, 'cinder_state_transition_timeout': 30, + 'cinder_store_user_name': 'user', + 'cinder_store_password': 'password', + 'cinder_store_project_name': 'services', + 'cinder_store_auth_address': + 'http://10.0.0.1:35357/v3', } }, 'enabled_backends': 'local:file, volume-type-test:cinder',