Swift: Honor *_domain_name parameters
The *_domain_id parmaeters should not have any default. Otherwise keystoneauth ignores the *_domain_name parameters and it requires only *_domain_id parameters are used. Closes-Bug: #1620999 Change-Id: I1f8c9184761313f9fc5fda2f257e52233e0196d1
This commit is contained in:
parent
6851cab51a
commit
6738d0b156
@ -98,11 +98,6 @@ Related options:
|
||||
"""),
|
||||
]
|
||||
|
||||
_config_defaults = {'user_domain_id': 'default',
|
||||
'user_domain_name': 'default',
|
||||
'project_domain_id': 'default',
|
||||
'project_domain_name': 'default'}
|
||||
|
||||
|
||||
class SwiftConfigParser(configparser.ConfigParser):
|
||||
|
||||
@ -121,7 +116,7 @@ class SwiftConfigParser(configparser.ConfigParser):
|
||||
return value
|
||||
|
||||
|
||||
CONFIG = SwiftConfigParser(defaults=_config_defaults)
|
||||
CONFIG = SwiftConfigParser()
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -193,15 +188,25 @@ class SwiftParams(object):
|
||||
for ref in account_references:
|
||||
reference = {}
|
||||
try:
|
||||
for param in ('auth_address',
|
||||
'user',
|
||||
'key',
|
||||
'project_domain_id',
|
||||
'project_domain_name',
|
||||
'user_domain_id',
|
||||
'user_domain_name'):
|
||||
for param in ('auth_address', 'user', 'key'):
|
||||
reference[param] = CONFIG.get(ref, param)
|
||||
|
||||
reference['project_domain_name'] = CONFIG.get(
|
||||
ref, 'project_domain_name', fallback=None)
|
||||
reference['project_domain_id'] = CONFIG.get(
|
||||
ref, 'project_domain_id', fallback=None)
|
||||
if (reference['project_domain_name'] is None and
|
||||
reference['project_domain_id'] is None):
|
||||
reference['project_domain_id'] = 'default'
|
||||
|
||||
reference['user_domain_name'] = CONFIG.get(
|
||||
ref, 'user_domain_name', fallback=None)
|
||||
reference['user_domain_id'] = CONFIG.get(
|
||||
ref, 'user_domain_id', fallback=None)
|
||||
if (reference['user_domain_name'] is None and
|
||||
reference['user_domain_id'] is None):
|
||||
reference['user_domain_id'] = 'default'
|
||||
|
||||
try:
|
||||
reference['auth_version'] = CONFIG.get(ref, 'auth_version')
|
||||
except configparser.NoOptionError:
|
||||
|
@ -16,6 +16,22 @@ user = "user3"
|
||||
key = "key3"
|
||||
auth_address = "http://example.com"
|
||||
|
||||
[ref4]
|
||||
user = user4
|
||||
key = key4
|
||||
user_domain_id = userdomainid
|
||||
project_domain_id = projdomainid
|
||||
auth_version = 3
|
||||
auth_address = "http://example.com"
|
||||
|
||||
[ref5]
|
||||
user = user5
|
||||
key = key5
|
||||
user_domain_name = userdomain
|
||||
project_domain_name = projdomain
|
||||
auth_version = 3
|
||||
auth_address = "http://example.com"
|
||||
|
||||
[store_2]
|
||||
user = tenant:user1
|
||||
key = key1
|
||||
|
@ -1462,15 +1462,72 @@ class TestStoreAuthV3(TestStoreAuthV1):
|
||||
loc = location.get_location_from_uri(uri, conf=self.conf)
|
||||
ctxt = mock.MagicMock()
|
||||
store.init_client(location=loc.store_location, context=ctxt)
|
||||
# check that keystone was initialized correctly
|
||||
tenant = None if store.auth_version == '1' else "tenant"
|
||||
username = "tenant:user1" if store.auth_version == '1' else "user1"
|
||||
mock_identity.V3Password.assert_called_once_with(
|
||||
auth_url=loc.store_location.swift_url + '/',
|
||||
username=username, password="key",
|
||||
project_name=tenant,
|
||||
project_domain_id='default', project_domain_name='default',
|
||||
user_domain_id='default', user_domain_name='default',)
|
||||
username="user1", password="key",
|
||||
project_name="tenant",
|
||||
project_domain_id='default', project_domain_name=None,
|
||||
user_domain_id='default', user_domain_name=None,)
|
||||
mock_session.Session.assert_called_once_with(
|
||||
auth=mock_identity.V3Password(), verify=True)
|
||||
mock_client.Client.assert_called_once_with(
|
||||
session=mock_session.Session())
|
||||
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_identity")
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_session")
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_client")
|
||||
def test_init_client_single_tenant_with_domain_ids(self,
|
||||
mock_client,
|
||||
mock_session,
|
||||
mock_identity):
|
||||
"""Test that keystone client was initialized correctly"""
|
||||
# initialize client
|
||||
conf = self.getConfig()
|
||||
conf['default_swift_reference'] = 'ref4'
|
||||
self.config(**conf)
|
||||
store = Store(self.conf)
|
||||
store.configure()
|
||||
uri = "swift://%s:key@auth_address/glance/%s" % (
|
||||
self.swift_store_user, FAKE_UUID)
|
||||
loc = location.get_location_from_uri(uri, conf=self.conf)
|
||||
ctxt = mock.MagicMock()
|
||||
store.init_client(location=loc.store_location, context=ctxt)
|
||||
mock_identity.V3Password.assert_called_once_with(
|
||||
auth_url=loc.store_location.swift_url + '/',
|
||||
username="user1", password="key",
|
||||
project_name="tenant",
|
||||
project_domain_id='projdomainid', project_domain_name=None,
|
||||
user_domain_id='userdomainid', user_domain_name=None,)
|
||||
mock_session.Session.assert_called_once_with(
|
||||
auth=mock_identity.V3Password(), verify=True)
|
||||
mock_client.Client.assert_called_once_with(
|
||||
session=mock_session.Session())
|
||||
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_identity")
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_session")
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_client")
|
||||
def test_init_client_single_tenant_with_domain_names(self,
|
||||
mock_client,
|
||||
mock_session,
|
||||
mock_identity):
|
||||
"""Test that keystone client was initialized correctly"""
|
||||
# initialize client
|
||||
conf = self.getConfig()
|
||||
conf['default_swift_reference'] = 'ref5'
|
||||
self.config(**conf)
|
||||
store = Store(self.conf)
|
||||
store.configure()
|
||||
uri = "swift://%s:key@auth_address/glance/%s" % (
|
||||
self.swift_store_user, FAKE_UUID)
|
||||
loc = location.get_location_from_uri(uri, conf=self.conf)
|
||||
ctxt = mock.MagicMock()
|
||||
store.init_client(location=loc.store_location, context=ctxt)
|
||||
mock_identity.V3Password.assert_called_once_with(
|
||||
auth_url=loc.store_location.swift_url + '/',
|
||||
username="user1", password="key",
|
||||
project_name="tenant",
|
||||
project_domain_id=None, project_domain_name='projdomain',
|
||||
user_domain_id=None, user_domain_name='userdomain',)
|
||||
mock_session.Session.assert_called_once_with(
|
||||
auth=mock_identity.V3Password(), verify=True)
|
||||
mock_client.Client.assert_called_once_with(
|
||||
|
@ -1459,15 +1459,72 @@ class TestStoreAuthV3(TestStoreAuthV1):
|
||||
uri, "swift1", conf=self.conf)
|
||||
ctxt = mock.MagicMock()
|
||||
store.init_client(location=loc.store_location, context=ctxt)
|
||||
# check that keystone was initialized correctly
|
||||
tenant = None if store.auth_version == '1' else "tenant"
|
||||
username = "tenant:user1" if store.auth_version == '1' else "user1"
|
||||
mock_identity.V3Password.assert_called_once_with(
|
||||
auth_url=loc.store_location.swift_url + '/',
|
||||
username=username, password="key",
|
||||
project_name=tenant,
|
||||
project_domain_id='default', project_domain_name='default',
|
||||
user_domain_id='default', user_domain_name='default',)
|
||||
username="user1", password="key",
|
||||
project_name="tenant",
|
||||
project_domain_id='default', project_domain_name=None,
|
||||
user_domain_id='default', user_domain_name=None,)
|
||||
mock_session.Session.assert_called_once_with(
|
||||
auth=mock_identity.V3Password(), verify=True)
|
||||
mock_client.Client.assert_called_once_with(
|
||||
session=mock_session.Session())
|
||||
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_identity")
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_session")
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_client")
|
||||
def test_init_client_single_tenant_with_domain_ids(self,
|
||||
mock_client,
|
||||
mock_session,
|
||||
mock_identity):
|
||||
"""Test that keystone client was initialized correctly"""
|
||||
conf = self.getConfig()
|
||||
conf['default_swift_reference'] = 'ref4'
|
||||
self.config(group="swift1", **conf)
|
||||
store = Store(self.conf, backend="swift1")
|
||||
store.configure()
|
||||
uri = "swift://%s:key@auth_address/glance/%s" % (
|
||||
self.swift_store_user, FAKE_UUID)
|
||||
loc = location.get_location_from_uri_and_backend(
|
||||
uri, "swift1", conf=self.conf)
|
||||
ctxt = mock.MagicMock()
|
||||
store.init_client(location=loc.store_location, context=ctxt)
|
||||
mock_identity.V3Password.assert_called_once_with(
|
||||
auth_url=loc.store_location.swift_url + '/',
|
||||
username="user1", password="key",
|
||||
project_name="tenant",
|
||||
project_domain_id='projdomainid', project_domain_name=None,
|
||||
user_domain_id='userdomainid', user_domain_name=None)
|
||||
mock_session.Session.assert_called_once_with(
|
||||
auth=mock_identity.V3Password(), verify=True)
|
||||
mock_client.Client.assert_called_once_with(
|
||||
session=mock_session.Session())
|
||||
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_identity")
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_session")
|
||||
@mock.patch("glance_store._drivers.swift.store.ks_client")
|
||||
def test_init_client_single_tenant_with_domain_names(self,
|
||||
mock_client,
|
||||
mock_session,
|
||||
mock_identity):
|
||||
"""Test that keystone client was initialized correctly"""
|
||||
conf = self.getConfig()
|
||||
conf['default_swift_reference'] = 'ref5'
|
||||
self.config(group="swift1", **conf)
|
||||
store = Store(self.conf, backend="swift1")
|
||||
store.configure()
|
||||
uri = "swift://%s:key@auth_address/glance/%s" % (
|
||||
self.swift_store_user, FAKE_UUID)
|
||||
loc = location.get_location_from_uri_and_backend(
|
||||
uri, "swift1", conf=self.conf)
|
||||
ctxt = mock.MagicMock()
|
||||
store.init_client(location=loc.store_location, context=ctxt)
|
||||
mock_identity.V3Password.assert_called_once_with(
|
||||
auth_url=loc.store_location.swift_url + '/',
|
||||
username="user1", password="key",
|
||||
project_name="tenant",
|
||||
project_domain_id=None, project_domain_name='projdomain',
|
||||
user_domain_id=None, user_domain_name='userdomain')
|
||||
mock_session.Session.assert_called_once_with(
|
||||
auth=mock_identity.V3Password(), verify=True)
|
||||
mock_client.Client.assert_called_once_with(
|
||||
|
@ -98,6 +98,31 @@ class TestSwiftParams(base.StoreBaseTest):
|
||||
swift_params['ref3']['auth_address']
|
||||
)
|
||||
|
||||
def test_swift_store_config_without_domain(self):
|
||||
swift_params = sutils.SwiftParams(self.conf).params
|
||||
self.assertEqual('default', swift_params['ref1']['project_domain_id'])
|
||||
self.assertIsNone(swift_params['ref1']['project_domain_name'])
|
||||
self.assertEqual('default', swift_params['ref1']['user_domain_id'])
|
||||
self.assertIsNone(swift_params['ref1']['user_domain_name'])
|
||||
|
||||
def test_swift_store_config_with_domain_ids(self):
|
||||
swift_params = sutils.SwiftParams(self.conf).params
|
||||
self.assertEqual('projdomainid',
|
||||
swift_params['ref4']['project_domain_id'])
|
||||
self.assertIsNone(swift_params['ref4']['project_domain_name'])
|
||||
self.assertEqual('userdomainid',
|
||||
swift_params['ref4']['user_domain_id'])
|
||||
self.assertIsNone(swift_params['ref4']['user_domain_name'])
|
||||
|
||||
def test_swift_store_config_with_domain_names(self):
|
||||
swift_params = sutils.SwiftParams(self.conf).params
|
||||
self.assertIsNone(swift_params['ref5']['project_domain_id'])
|
||||
self.assertEqual('projdomain',
|
||||
swift_params['ref5']['project_domain_name'])
|
||||
self.assertIsNone(swift_params['ref5']['user_domain_id'])
|
||||
self.assertEqual('userdomain',
|
||||
swift_params['ref5']['user_domain_name'])
|
||||
|
||||
|
||||
class TestSwiftConfigParser(base.StoreBaseTest):
|
||||
|
||||
|
7
releasenotes/notes/bug-1620999-8b76a0ad14826197.yaml
Normal file
7
releasenotes/notes/bug-1620999-8b76a0ad14826197.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Now the ``project_domain_name`` parameter and the ``user_domain_name``
|
||||
parameter are properly used by swift backends. Previously these two
|
||||
parameters were ignored and the ``*_domain_id`` parameters should be
|
||||
set to use a keystone domain different from the default one.
|
Loading…
x
Reference in New Issue
Block a user