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
This commit is contained in:
Dmitry Tantsur 2016-02-11 16:28:15 +01:00
parent 61d0b85ed6
commit f56bf0c8c2
3 changed files with 34 additions and 28 deletions

View File

@ -79,14 +79,9 @@ OBJECT_NAME_PREFIX = 'inspector_data'
class SwiftAPI(object): class SwiftAPI(object):
"""API for communicating with Swift.""" """API for communicating with Swift."""
def __init__(self, def __init__(self, user=None, tenant_name=None, key=None,
user=CONF.swift.username, auth_url=None, auth_version=None,
tenant_name=CONF.swift.tenant_name, service_type=None, endpoint_type=None):
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):
"""Constructor for creating a SwiftAPI object. """Constructor for creating a SwiftAPI object.
:param user: the name of the user for Swift account :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 key: the 'password' or key to authenticate with
:param auth_url: the url for authentication :param auth_url: the url for authentication
:param auth_version: the version of api to use 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, self.connection = swift_client.Connection(
'user': user, retries=CONF.swift.max_retries,
'tenant_name': tenant_name, user=user or CONF.swift.username,
'key': key, tenant_name=tenant_name or CONF.swift.tenant_name,
'authurl': auth_url, key=key or CONF.swift.password,
'auth_version': auth_version, authurl=auth_url or CONF.swift.os_auth_url,
'os_options': {'service_type': service_type, auth_version=auth_version or CONF.swift.os_auth_version,
'endpoint_type': endpoint_type}} os_options={
'service_type': service_type or CONF.swift.os_service_type,
self.connection = swift_client.Connection(**params) 'endpoint_type': endpoint_type or CONF.swift.os_endpoint_type
}
)
def create_object(self, object, data, container=CONF.swift.container, def create_object(self, object, data, container=CONF.swift.container,
headers=None): headers=None):
@ -168,11 +167,7 @@ def store_introspection_data(data, uuid):
:param uuid: UUID of the Ironic node that the data came from :param uuid: UUID of the Ironic node that the data came from
:returns: name of the Swift object that the data is stored in :returns: name of the Swift object that the data is stored in
""" """
swift_api = SwiftAPI(user=CONF.swift.username, swift_api = SwiftAPI()
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_object_name = '%s-%s' % (OBJECT_NAME_PREFIX, uuid) swift_object_name = '%s-%s' % (OBJECT_NAME_PREFIX, uuid)
swift_api.create_object(swift_object_name, json.dumps(data)) swift_api.create_object(swift_object_name, json.dumps(data))
return swift_object_name 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 :param uuid: UUID of the Ironic node that the data came from
:returns: Swift object with the introspection data :returns: Swift object with the introspection data
""" """
swift_api = SwiftAPI(user=CONF.swift.username, swift_api = SwiftAPI()
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_object_name = '%s-%s' % (OBJECT_NAME_PREFIX, uuid) swift_object_name = '%s-%s' % (OBJECT_NAME_PREFIX, uuid)
return swift_api.get_object(swift_object_name) return swift_api.get_object(swift_object_name)

View File

@ -89,6 +89,18 @@ class SwiftTestCase(BaseTest):
'endpoint_type': 'internalURL'}} 'endpoint_type': 'internalURL'}}
connection_mock.assert_called_once_with(**params) 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): def test_create_object(self, connection_mock):
swiftapi = swift.SwiftAPI(user=CONF.swift.username, swiftapi = swift.SwiftAPI(user=CONF.swift.username,
tenant_name=CONF.swift.tenant_name, tenant_name=CONF.swift.tenant_name,

View File

@ -0,0 +1,3 @@
---
fixes:
- Fixed extra_hardware plugin connection to Swift.