diff options
author | Zuul <zuul@review.opendev.org> | 2023-05-04 15:44:01 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-05-04 15:44:01 +0000 |
commit | 03283b672da6671153387f90452991307d1d765f (patch) | |
tree | 4e27e9f323e56a8d6607923fe1b54c1b901bd732 | |
parent | bc9375e68c0d8fcf7f4386daca8b046aa9395cb2 (diff) | |
parent | 4e5b90a4d200316492dff2c00ff0fe530f9025f8 (diff) | |
download | glance_store-03283b672da6671153387f90452991307d1d765f.tar.gz |
Merge "Swift: Honor *_domain_name parameters" into stable/yoga
-rw-r--r-- | glance_store/_drivers/swift/utils.py | 33 | ||||
-rw-r--r-- | glance_store/tests/etc/glance-swift.conf | 16 | ||||
-rw-r--r-- | glance_store/tests/unit/test_swift_store.py | 71 | ||||
-rw-r--r-- | glance_store/tests/unit/test_swift_store_multibackend.py | 71 | ||||
-rw-r--r-- | glance_store/tests/unit/test_swift_store_utils.py | 25 | ||||
-rw-r--r-- | releasenotes/notes/bug-1620999-8b76a0ad14826197.yaml | 7 |
6 files changed, 195 insertions, 28 deletions
diff --git a/glance_store/_drivers/swift/utils.py b/glance_store/_drivers/swift/utils.py index 7285ba1..015d5d3 100644 --- a/glance_store/_drivers/swift/utils.py +++ b/glance_store/_drivers/swift/utils.py @@ -99,11 +99,6 @@ Related options: """), ] -_config_defaults = {'user_domain_id': 'default', - 'user_domain_name': 'default', - 'project_domain_id': 'default', - 'project_domain_name': 'default'} - if sys.version_info >= (3, 2): parser_class = configparser.ConfigParser else: @@ -128,9 +123,9 @@ class SwiftConfigParser(parser_class): if sys.version_info >= (3,): - CONFIG = SwiftConfigParser(defaults=_config_defaults) + CONFIG = SwiftConfigParser() else: - CONFIG = parser_class(defaults=_config_defaults) + CONFIG = parser_class() LOG = logging.getLogger(__name__) @@ -202,15 +197,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: diff --git a/glance_store/tests/etc/glance-swift.conf b/glance_store/tests/etc/glance-swift.conf index 916d676..47f53f3 100644 --- a/glance_store/tests/etc/glance-swift.conf +++ b/glance_store/tests/etc/glance-swift.conf @@ -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 diff --git a/glance_store/tests/unit/test_swift_store.py b/glance_store/tests/unit/test_swift_store.py index 7364923..5d18ebc 100644 --- a/glance_store/tests/unit/test_swift_store.py +++ b/glance_store/tests/unit/test_swift_store.py @@ -1464,15 +1464,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( diff --git a/glance_store/tests/unit/test_swift_store_multibackend.py b/glance_store/tests/unit/test_swift_store_multibackend.py index dba5bda..b91f32f 100644 --- a/glance_store/tests/unit/test_swift_store_multibackend.py +++ b/glance_store/tests/unit/test_swift_store_multibackend.py @@ -1461,15 +1461,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( diff --git a/glance_store/tests/unit/test_swift_store_utils.py b/glance_store/tests/unit/test_swift_store_utils.py index 94079ae..b7b25f7 100644 --- a/glance_store/tests/unit/test_swift_store_utils.py +++ b/glance_store/tests/unit/test_swift_store_utils.py @@ -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): diff --git a/releasenotes/notes/bug-1620999-8b76a0ad14826197.yaml b/releasenotes/notes/bug-1620999-8b76a0ad14826197.yaml new file mode 100644 index 0000000..7f5ae6e --- /dev/null +++ b/releasenotes/notes/bug-1620999-8b76a0ad14826197.yaml @@ -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. |