Merge "Fix 500 if multi-tenant swift is used"

This commit is contained in:
Zuul 2024-07-11 22:55:27 +00:00 committed by Gerrit Code Review
commit f87f202bad
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']])