summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-08-22 19:12:23 +0000
committerGerrit Code Review <review@openstack.org>2022-08-22 19:12:23 +0000
commitd8cc723490115de282456637736c2a83adabb355 (patch)
tree6108b2745c744c26d3cffec022b2ff0fa0734279
parentbefcca345b233cae28cd320f20592aaab3fa289a (diff)
parent6738d0b156fc1caae0604eb7bd8f05a6ed1c2d68 (diff)
downloadglance_store-d8cc723490115de282456637736c2a83adabb355.tar.gz
Merge "Swift: Honor *_domain_name parameters"
-rw-r--r--glance_store/_drivers/swift/utils.py31
-rw-r--r--glance_store/tests/etc/glance-swift.conf16
-rw-r--r--glance_store/tests/unit/test_swift_store.py71
-rw-r--r--glance_store/tests/unit/test_swift_store_multibackend.py71
-rw-r--r--glance_store/tests/unit/test_swift_store_utils.py25
-rw-r--r--releasenotes/notes/bug-1620999-8b76a0ad14826197.yaml7
6 files changed, 194 insertions, 27 deletions
diff --git a/glance_store/_drivers/swift/utils.py b/glance_store/_drivers/swift/utils.py
index da034b4..812ef2f 100644
--- a/glance_store/_drivers/swift/utils.py
+++ b/glance_store/_drivers/swift/utils.py
@@ -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:
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 eb57138..2c21752 100644
--- a/glance_store/tests/unit/test_swift_store.py
+++ b/glance_store/tests/unit/test_swift_store.py
@@ -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(
diff --git a/glance_store/tests/unit/test_swift_store_multibackend.py b/glance_store/tests/unit/test_swift_store_multibackend.py
index 10b5c46..d8bfcf7 100644
--- a/glance_store/tests/unit/test_swift_store_multibackend.py
+++ b/glance_store/tests/unit/test_swift_store_multibackend.py
@@ -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(
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.