From ca4fb9b1cfe2693771e6b0d346d5923db66696e8 Mon Sep 17 00:00:00 2001 From: Jacek Tomasiak Date: Thu, 15 Mar 2018 11:59:07 +0100 Subject: [PATCH] Allow Swift endpoint override Swiftclient uses public endpoint by default. Ironic uses the base URL from Swift connection to build TempURLs for generated images. Some drivers (e.g. iLO) use those TempURLs to mount images as vmedia. With public URLs it will fail if the BMC doesn't have access to the public network. This change introduces an option to explicitly set the endpoint URL used for Swift. This is a stable-only change as the problem is fixed by refactoring changes in later releases. This is the only version where Ironic uses public Swift endpoints and there is no option to override this. Change-Id: I639a421fa06fff7ab07b8eab557531b8f36c5ed9 Closes-Bug: #1755164 Related-Bug: #1699547 --- ironic/common/swift.py | 5 +++++ ironic/conf/swift.py | 3 +++ ironic/tests/unit/common/test_swift.py | 11 +++++++++++ .../swift-endpoint-override-4151d2fbb159950d.yaml | 8 ++++++++ 4 files changed, 27 insertions(+) create mode 100644 releasenotes/notes/swift-endpoint-override-4151d2fbb159950d.yaml diff --git a/ironic/common/swift.py b/ironic/common/swift.py index 8168870eef..4f1488ca59 100644 --- a/ironic/common/swift.py +++ b/ironic/common/swift.py @@ -55,6 +55,11 @@ class SwiftAPI(object): # with swift is initialized. Since v3.2.0 swiftclient supports # instantiating the API client from keystoneauth session. params = {'session': _get_swift_session()} + + if CONF.swift.endpoint_override: + params['os_options'] = { + 'object_storage_url': CONF.swift.endpoint_override} + self.connection = swift_client.Connection(**params) def create_object(self, container, obj, filename, diff --git a/ironic/conf/swift.py b/ironic/conf/swift.py index 66a0b1f5c9..6e1a287b06 100644 --- a/ironic/conf/swift.py +++ b/ironic/conf/swift.py @@ -20,6 +20,9 @@ from ironic.common.i18n import _ from ironic.conf import auth opts = [ + cfg.StrOpt('endpoint_override', + help=_('Always use this endpoint URL for requests to Swift. ' + 'It also controls base URL used for image TempURLs.')), cfg.IntOpt('swift_max_retries', default=2, help=_('Maximum number of times to retry a Swift request, ' diff --git a/ironic/tests/unit/common/test_swift.py b/ironic/tests/unit/common/test_swift.py index f9b07e4baa..f5d3dd3640 100644 --- a/ironic/tests/unit/common/test_swift.py +++ b/ironic/tests/unit/common/test_swift.py @@ -47,6 +47,17 @@ class SwiftTestCase(base.TestCase): connection_mock.assert_called_once_with( session=keystone_mock.return_value) + def test___init___endpoint(self, connection_mock, keystone_mock): + """Check if client is properly initialized with endpoint override""" + + CONF.swift.endpoint_override = 'dummy_override_url' + + swift.SwiftAPI() + connection_mock.assert_called_once_with( + session=keystone_mock.return_value, + os_options={'object_storage_url': 'dummy_override_url'} + ) + def test___init___radosgw(self, connection_mock, swift_session_mock): """Check if client is properly initialized with radosgw""" diff --git a/releasenotes/notes/swift-endpoint-override-4151d2fbb159950d.yaml b/releasenotes/notes/swift-endpoint-override-4151d2fbb159950d.yaml new file mode 100644 index 0000000000..79013e424b --- /dev/null +++ b/releasenotes/notes/swift-endpoint-override-4151d2fbb159950d.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - Adds ``[swift]/endpoint_override`` option to explicitly set the endpoint + URL used for Swift. Ironic uses the Swift connection URL as a base for + generation of some TempURLs. Added parameter enables operators to fix + the problem when image is attached (via TempURL) as vmedia (e.g. in iLO + driver) and BMC doesn't have connectivity to public network. + By default this parameter is not set for backward compatibility.