summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-02-03 17:17:34 +0000
committerGerrit Code Review <review@openstack.org>2022-02-03 17:17:34 +0000
commitc019dc442979e53f08117220036c49f7d6457494 (patch)
tree96b189b9fd211fda778a56733a48ddbb97f0ca16
parentf20e3b7378c31caf134ecf9306821e3fb483a72d (diff)
parentcde42678b9aafdc3475457f716a7f3af17ae6995 (diff)
downloadironic-c019dc442979e53f08117220036c49f7d6457494.tar.gz
Merge "Make account prefix of Swift confgurable"
-rw-r--r--ironic/common/glance_service/image_service.py9
-rw-r--r--ironic/conf/glance.py5
-rw-r--r--ironic/tests/unit/common/test_glance_service.py56
-rw-r--r--releasenotes/notes/swift_account_prefix-dbc9e68890bff47c.yaml6
4 files changed, 74 insertions, 2 deletions
diff --git a/ironic/common/glance_service/image_service.py b/ironic/common/glance_service/image_service.py
index 66ac693f8..0a32eaf0a 100644
--- a/ironic/common/glance_service/image_service.py
+++ b/ironic/common/glance_service/image_service.py
@@ -303,15 +303,20 @@ class GlanceImageService(object):
'but it was not found in the service catalog. You must '
'provide "swift_endpoint_url" as a config option.'))
+ swift_account_prefix = CONF.glance.swift_account_prefix
+ if swift_account_prefix and not swift_account_prefix.endswith('_'):
+ swift_account_prefix = '%s_' % swift_account_prefix
+
# Strip /v1/AUTH_%(tenant_id)s, if present
- endpoint_url = re.sub('/v1/AUTH_[^/]+/?$', '', endpoint_url)
+ endpoint_url = re.sub('/v1/%s[^/]+/?$' % swift_account_prefix, '',
+ endpoint_url)
key = CONF.glance.swift_temp_url_key
account = CONF.glance.swift_account
if not account:
swift_session = swift.get_swift_session()
auth_ref = swift_session.auth.get_auth_ref(swift_session)
- account = 'AUTH_%s' % auth_ref.project_id
+ account = '%s%s' % (swift_account_prefix, auth_ref.project_id)
if not key:
swift_api = swift.SwiftAPI()
diff --git a/ironic/conf/glance.py b/ironic/conf/glance.py
index c83fa92e1..a3286b1eb 100644
--- a/ironic/conf/glance.py
+++ b/ironic/conf/glance.py
@@ -91,6 +91,11 @@ opts = [
'section). Swift temporary URL format: '
'"endpoint_url/api_version/account/container/object_id"')),
cfg.StrOpt(
+ 'swift_account_prefix',
+ default='AUTH',
+ help=_('The prefix added to the project uuid to determine the swift '
+ 'account.')),
+ cfg.StrOpt(
'swift_container',
default='glance',
help=_('The Swift container Glance is configured to store its '
diff --git a/ironic/tests/unit/common/test_glance_service.py b/ironic/tests/unit/common/test_glance_service.py
index 09f64a00f..6be0fccd9 100644
--- a/ironic/tests/unit/common/test_glance_service.py
+++ b/ironic/tests/unit/common/test_glance_service.py
@@ -605,6 +605,62 @@ class TestGlanceSwiftTempURL(base.TestCase):
method='GET')
swift_mock.assert_called_once_with()
+ @mock.patch('ironic.common.swift.get_swift_session', autospec=True)
+ @mock.patch('swiftclient.utils.generate_temp_url', autospec=True)
+ def test_swift_temp_url_account_detected_with_prefix(self, tempurl_mock,
+ swift_mock):
+ self.config(swift_account=None, group='glance')
+ self.config(swift_account_prefix='SWIFTPREFIX', group='glance')
+
+ path = ('/v1/SWIFTPREFIX_42/glance'
+ '/757274c4-2856-4bd2-bb20-9a4a231e187b')
+ tempurl_mock.return_value = (
+ path + '?temp_url_sig=hmacsig&temp_url_expires=1400001200')
+ auth_ref = swift_mock.return_value.auth.get_auth_ref.return_value
+ auth_ref.project_id = '42'
+
+ self.service._validate_temp_url_config = mock.Mock()
+
+ temp_url = self.service.swift_temp_url(image_info=self.fake_image)
+
+ self.assertEqual(CONF.glance.swift_endpoint_url
+ + tempurl_mock.return_value,
+ temp_url)
+ tempurl_mock.assert_called_with(
+ path=path,
+ seconds=CONF.glance.swift_temp_url_duration,
+ key=CONF.glance.swift_temp_url_key,
+ method='GET')
+ swift_mock.assert_called_once_with()
+
+ @mock.patch('ironic.common.swift.get_swift_session', autospec=True)
+ @mock.patch('swiftclient.utils.generate_temp_url', autospec=True)
+ def test_swift_temp_url_account_detected_with_prefix_underscore(
+ self, tempurl_mock, swift_mock):
+ self.config(swift_account=None, group='glance')
+ self.config(swift_account_prefix='SWIFTPREFIX_', group='glance')
+
+ path = ('/v1/SWIFTPREFIX_42/glance'
+ '/757274c4-2856-4bd2-bb20-9a4a231e187b')
+ tempurl_mock.return_value = (
+ path + '?temp_url_sig=hmacsig&temp_url_expires=1400001200')
+ auth_ref = swift_mock.return_value.auth.get_auth_ref.return_value
+ auth_ref.project_id = '42'
+
+ self.service._validate_temp_url_config = mock.Mock()
+
+ temp_url = self.service.swift_temp_url(image_info=self.fake_image)
+
+ self.assertEqual(CONF.glance.swift_endpoint_url
+ + tempurl_mock.return_value,
+ temp_url)
+ tempurl_mock.assert_called_with(
+ path=path,
+ seconds=CONF.glance.swift_temp_url_duration,
+ key=CONF.glance.swift_temp_url_key,
+ method='GET')
+ swift_mock.assert_called_once_with()
+
@mock.patch('ironic.common.swift.SwiftAPI', autospec=True)
@mock.patch('swiftclient.utils.generate_temp_url', autospec=True)
def test_swift_temp_url_key_detected(self, tempurl_mock, swift_mock):
diff --git a/releasenotes/notes/swift_account_prefix-dbc9e68890bff47c.yaml b/releasenotes/notes/swift_account_prefix-dbc9e68890bff47c.yaml
new file mode 100644
index 000000000..c0a458f7d
--- /dev/null
+++ b/releasenotes/notes/swift_account_prefix-dbc9e68890bff47c.yaml
@@ -0,0 +1,6 @@
+---
+features:
+ - |
+ The new ``[glance] swift_account_prefix`` parameter has been added. This
+ parameter be set according to the ``reseller_prefix`` parameter in
+ ``proxy-server.conf`` of Swift.