From f56bf0c8c214c499b17f84f75bb3870ab1c18873 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 11 Feb 2016 16:28:15 +0100 Subject: [PATCH] Do not set Swift parameters defaults in keyword arguments The configuration values are not initialized at the moment of import, so it has no effect. The only reason we didn't hit it is due to helper functions overriding the arguments. But extra_hardware plugin does not work. Change-Id: If23bbdc4162589707cd63e6446a92036436b7f2a Closes-Bug: #1544613 --- ironic_inspector/common/swift.py | 47 ++++++++----------- ironic_inspector/test/test_swift.py | 12 +++++ ...extra-hardware-swift-aeebf299b9605bb0.yaml | 3 ++ 3 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 releasenotes/notes/extra-hardware-swift-aeebf299b9605bb0.yaml diff --git a/ironic_inspector/common/swift.py b/ironic_inspector/common/swift.py index bf323b8c6..c89e6cbb8 100644 --- a/ironic_inspector/common/swift.py +++ b/ironic_inspector/common/swift.py @@ -79,14 +79,9 @@ OBJECT_NAME_PREFIX = 'inspector_data' class SwiftAPI(object): """API for communicating with Swift.""" - def __init__(self, - user=CONF.swift.username, - tenant_name=CONF.swift.tenant_name, - key=CONF.swift.password, - auth_url=CONF.swift.os_auth_url, - auth_version=CONF.swift.os_auth_version, - service_type=CONF.swift.os_service_type, - endpoint_type=CONF.swift.os_endpoint_type): + def __init__(self, user=None, tenant_name=None, key=None, + auth_url=None, auth_version=None, + service_type=None, endpoint_type=None): """Constructor for creating a SwiftAPI object. :param user: the name of the user for Swift account @@ -94,17 +89,21 @@ class SwiftAPI(object): :param key: the 'password' or key to authenticate with :param auth_url: the url for authentication :param auth_version: the version of api to use for authentication + :param service_type: service type in the service catalog + :param endpoint_type: service endpoint type """ - params = {'retries': CONF.swift.max_retries, - 'user': user, - 'tenant_name': tenant_name, - 'key': key, - 'authurl': auth_url, - 'auth_version': auth_version, - 'os_options': {'service_type': service_type, - 'endpoint_type': endpoint_type}} - - self.connection = swift_client.Connection(**params) + self.connection = swift_client.Connection( + retries=CONF.swift.max_retries, + user=user or CONF.swift.username, + tenant_name=tenant_name or CONF.swift.tenant_name, + key=key or CONF.swift.password, + authurl=auth_url or CONF.swift.os_auth_url, + auth_version=auth_version or CONF.swift.os_auth_version, + os_options={ + 'service_type': service_type or CONF.swift.os_service_type, + 'endpoint_type': endpoint_type or CONF.swift.os_endpoint_type + } + ) def create_object(self, object, data, container=CONF.swift.container, headers=None): @@ -168,11 +167,7 @@ def store_introspection_data(data, uuid): :param uuid: UUID of the Ironic node that the data came from :returns: name of the Swift object that the data is stored in """ - swift_api = SwiftAPI(user=CONF.swift.username, - tenant_name=CONF.swift.tenant_name, - key=CONF.swift.password, - auth_url=CONF.swift.os_auth_url, - auth_version=CONF.swift.os_auth_version) + swift_api = SwiftAPI() swift_object_name = '%s-%s' % (OBJECT_NAME_PREFIX, uuid) swift_api.create_object(swift_object_name, json.dumps(data)) return swift_object_name @@ -184,10 +179,6 @@ def get_introspection_data(uuid): :param uuid: UUID of the Ironic node that the data came from :returns: Swift object with the introspection data """ - swift_api = SwiftAPI(user=CONF.swift.username, - tenant_name=CONF.swift.tenant_name, - key=CONF.swift.password, - auth_url=CONF.swift.os_auth_url, - auth_version=CONF.swift.os_auth_version) + swift_api = SwiftAPI() swift_object_name = '%s-%s' % (OBJECT_NAME_PREFIX, uuid) return swift_api.get_object(swift_object_name) diff --git a/ironic_inspector/test/test_swift.py b/ironic_inspector/test/test_swift.py index a0f29bdf5..567a3b9dd 100644 --- a/ironic_inspector/test/test_swift.py +++ b/ironic_inspector/test/test_swift.py @@ -89,6 +89,18 @@ class SwiftTestCase(BaseTest): 'endpoint_type': 'internalURL'}} connection_mock.assert_called_once_with(**params) + def test___init__defaults(self, connection_mock): + swift.SwiftAPI() + params = {'retries': 2, + 'user': 'swift', + 'tenant_name': 'tenant', + 'key': 'password', + 'authurl': 'http://authurl/v2.0', + 'auth_version': '2', + 'os_options': {'service_type': 'object-store', + 'endpoint_type': 'internalURL'}} + connection_mock.assert_called_once_with(**params) + def test_create_object(self, connection_mock): swiftapi = swift.SwiftAPI(user=CONF.swift.username, tenant_name=CONF.swift.tenant_name, diff --git a/releasenotes/notes/extra-hardware-swift-aeebf299b9605bb0.yaml b/releasenotes/notes/extra-hardware-swift-aeebf299b9605bb0.yaml new file mode 100644 index 000000000..af2b34561 --- /dev/null +++ b/releasenotes/notes/extra-hardware-swift-aeebf299b9605bb0.yaml @@ -0,0 +1,3 @@ +--- +fixes: + - Fixed extra_hardware plugin connection to Swift.