diff --git a/glance/api/v2/discovery.py b/glance/api/v2/discovery.py index 0a259950e7..ce76d1d4fb 100644 --- a/glance/api/v2/discovery.py +++ b/glance/api/v2/discovery.py @@ -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 } diff --git a/glance/tests/unit/v2/test_discovery_stores.py b/glance/tests/unit/v2/test_discovery_stores.py index 4e08a29780..60e0b8e6c8 100644 --- a/glance/tests/unit/v2/test_discovery_stores.py +++ b/glance/tests/unit/v2/test_discovery_stores.py @@ -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']])