Merge "Raise exc when using multi-tenant and swift+config"

This commit is contained in:
Jenkins 2016-12-19 19:58:29 +00:00 committed by Gerrit Code Review
commit 6982b3c2e5
4 changed files with 50 additions and 2 deletions

View File

@ -294,12 +294,16 @@ in tenant specific Swift accounts. If this is disabled, Glance stores all
images in its own account. More details multi-tenant store can be found at images in its own account. More details multi-tenant store can be found at
https://wiki.openstack.org/wiki/GlanceSwiftTenantSpecificStorage https://wiki.openstack.org/wiki/GlanceSwiftTenantSpecificStorage
NOTE: If using multi-tenant swift store, please make sure
that you do not set a swift configuration file with the
'swift_store_config_file' option.
Possible values: Possible values:
* True * True
* False * False
Related options: Related options:
* None * swift_store_config_file
""")), """)),
cfg.IntOpt('swift_store_multiple_containers_seed', cfg.IntOpt('swift_store_multiple_containers_seed',
@ -697,6 +701,19 @@ class StoreLocation(location.StoreLocation):
def Store(conf): def Store(conf):
# NOTE(dharinic): Multi-tenant store cannot work with swift config
if conf.glance_store.swift_store_multi_tenant:
if (conf.glance_store.default_store == 'swift+config' or
sutils.is_multiple_swift_store_accounts_enabled(conf)):
msg = _("Swift multi-tenant store cannot be configured to "
"work with swift+config. The options "
"'swift_store_multi_tenant' and "
"'swift_store_config_file' are mutually exclusive. "
"If you inted 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.")
raise exceptions.BadStoreConfiguration(store_name="swift",
reason=msg)
try: try:
conf.register_opts(_SWIFT_OPTS + sutils.swift_opts, conf.register_opts(_SWIFT_OPTS + sutils.swift_opts,
group='glance_store') group='glance_store')

View File

@ -87,12 +87,15 @@ and customized Swift referencing is disabled. Configuring this
option is highly recommended while using Swift storage backend for option is highly recommended while using Swift storage backend for
image storage as it avoids storage of credentials in the database. image storage as it avoids storage of credentials in the database.
NOTE: Please do not configure this option if you have set
``swift_store_multi_tenant`` to ``True``.
Possible values: Possible values:
* String value representing an absolute path on the glance-api * String value representing an absolute path on the glance-api
node node
Related options: Related options:
* None * swift_store_multi_tenant
""")), """)),
] ]

View File

@ -258,12 +258,26 @@ class SwiftTests(object):
"""Test that single tenant uris work with multi tenant on.""" """Test that single tenant uris work with multi tenant on."""
uri = ("swift://%s:key@auth_address/glance/%s" % uri = ("swift://%s:key@auth_address/glance/%s" %
(self.swift_store_user, FAKE_UUID)) (self.swift_store_user, FAKE_UUID))
self.config(swift_store_config_file=None)
self.config(swift_store_multi_tenant=True) self.config(swift_store_multi_tenant=True)
# NOTE(markwash): ensure the image is found # NOTE(markwash): ensure the image is found
ctxt = mock.MagicMock() ctxt = mock.MagicMock()
size = backend.get_size_from_backend(uri, context=ctxt) size = backend.get_size_from_backend(uri, context=ctxt)
self.assertEqual(5120, size) self.assertEqual(5120, size)
def test_multi_tenant_with_swift_config(self):
"""
Test that Glance does not start when a config file is set on
multi-tenant mode
"""
schemes = ['swift', 'swift+config']
for s in schemes:
self.config(default_store=s,
swift_store_config_file='not/none',
swift_store_multi_tenant=True)
self.assertRaises(exceptions.BadStoreConfiguration,
Store, self.conf)
def test_get(self): def test_get(self):
"""Test a "normal" retrieval of an image in chunks.""" """Test a "normal" retrieval of an image in chunks."""
uri = "swift://%s:key@auth_address/glance/%s" % ( uri = "swift://%s:key@auth_address/glance/%s" % (
@ -1097,6 +1111,7 @@ class SwiftTests(object):
""" """
Test that we can set a public read acl. Test that we can set a public read acl.
""" """
self.config(swift_store_config_file=None)
self.config(swift_store_multi_tenant=True) self.config(swift_store_multi_tenant=True)
store = Store(self.conf) store = Store(self.conf)
store.configure() store.configure()
@ -1112,6 +1127,7 @@ class SwiftTests(object):
""" """
Test that we can set read acl for tenants. Test that we can set read acl for tenants.
""" """
self.config(swift_store_config_file=None)
self.config(swift_store_multi_tenant=True) self.config(swift_store_multi_tenant=True)
store = Store(self.conf) store = Store(self.conf)
store.configure() store.configure()
@ -1129,6 +1145,7 @@ class SwiftTests(object):
""" """
Test that we can set write acl for tenants. Test that we can set write acl for tenants.
""" """
self.config(swift_store_config_file=None)
self.config(swift_store_multi_tenant=True) self.config(swift_store_multi_tenant=True)
store = Store(self.conf) store = Store(self.conf)
store.configure() store.configure()
@ -1147,6 +1164,7 @@ class SwiftTests(object):
def test_get_connection_manager_multi_tenant(self, manager_class): def test_get_connection_manager_multi_tenant(self, manager_class):
manager = mock.MagicMock() manager = mock.MagicMock()
manager_class.return_value = manager manager_class.return_value = manager
self.config(swift_store_config_file=None)
self.config(swift_store_multi_tenant=True) self.config(swift_store_multi_tenant=True)
store = Store(self.conf) store = Store(self.conf)
store.configure() store.configure()
@ -1177,6 +1195,7 @@ class SwiftTests(object):
mock_identity): mock_identity):
"""Test that keystone client was initialized correctly""" """Test that keystone client was initialized correctly"""
# initialize store and connection parameters # initialize store and connection parameters
self.config(swift_store_config_file=None)
self.config(swift_store_multi_tenant=True) self.config(swift_store_multi_tenant=True)
store = Store(self.conf) store = Store(self.conf)
store.configure() store.configure()

View File

@ -0,0 +1,9 @@
---
upgrade:
- If using Swift in the multi-tenant mode for storing
images in Glance, please note that the configuration
options ``swift_store_multi_tenant`` and
``swift_store_config_file`` are now mutually exclusive
and cannot be configured together. If you intend to
use multi-tenant store, please make sure that you have
not set a swift configuration file.