Fix 500 if multi-tenant swift is used

1. store-info --details and image-create apis fail with 500 if
   swift configuration file is set in g-api.conf when muti-tenant
   swift store is used. Fixed this by excluding the unregistered
   conf parameter and added log warning.
2. Also, store-info --details fails with AttributeError, when
   multitenant is enabled for swift store since it doesn not set
   the container value during store configuration.
   Fixed this by returing `None` incase of multitenant swift store.

Closes-Bug: #2061947
Change-Id: I6cbd11fd0ee5758169a2e0e9961660edb844e65f
This commit is contained in:
Pranali Deore
2024-05-22 09:51:59 +00:00
parent dfbfdad77f
commit 06c727cfb3
2 changed files with 38 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ from glance.api.v2 import policy as api_policy
from glance.common import exception
from glance.common import wsgi
import glance.db
from glance.i18n import _
from glance.i18n import _, _LW
from glance.quota import keystone as ks_quota
CONF = cfg.CONF
@@ -64,6 +64,21 @@ class InfoController(object):
continue
stores = {}
if enabled_backends[backend] == 'swift':
conf_file = getattr(CONF, backend).swift_store_config_file
multitenant = getattr(CONF, backend).swift_store_multi_tenant
if multitenant and conf_file:
msg = ("The config options 'swift_store_multi_tenant' "
"and 'swift_store_config_file' are mutually "
"exclusive. If you intend to use multi-tenant "
"swift store, please make sure that you have "
"not set a swift configuration file with the "
"'swift_store_config_file' option. "
"Excluding `%s:%s` store details from the "
"response as it's not configured correctly."
% (backend, enabled_backends[backend]))
LOG.warning(_LW(msg))
continue
stores['id'] = backend
description = getattr(CONF, backend).store_description
if description:
@@ -103,7 +118,7 @@ class InfoController(object):
@staticmethod
def _get_swift_properties(store_detail):
return {
'container': store_detail.container,
'container': getattr(store_detail, 'container', None),
'large_object_size': store_detail.large_object_size,
'large_object_chunk_size': store_detail.large_object_chunk_size
}

View File

@@ -12,6 +12,7 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import glance_store
from oslo_config import cfg
import webob.exc
@@ -128,3 +129,23 @@ class TestInfoControllers(base.MultiStoreClearingUnitTest):
self.assertRaises(webob.exc.HTTPForbidden,
self.controller.get_stores_detail,
req)
def test_swift_multitenant_and_conf_file_enabled(self):
self.config(enabled_backends={'fast-rbd': 'rbd', 'test': 'swift'})
glance_store.register_store_opts(CONF)
self.config(default_backend='fast-rbd',
group='glance_store')
self.config(rbd_store_chunk_size=8688388, rbd_store_pool='images',
rbd_thin_provisioning=False, group='fast-rbd')
self.config(swift_store_container='glance',
swift_store_large_object_size=524288000,
swift_store_large_object_chunk_size=204800000,
swift_store_config_file='fake-file.conf',
swift_store_multi_tenant=True,
group='test')
glance_store.create_multi_stores(CONF)
req = unit_test_utils.get_fake_request(roles=['admin'])
output = self.controller.get_stores_detail(req)
self.assertNotEqual(len(CONF.enabled_backends), len(output['stores']))
self.assertNotIn('test',
[store.get('id') for store in output['stores']])