Skip to content

Commit

Permalink
Accept 'valid_interfaces' in client setup
Browse files Browse the repository at this point in the history
The consumer of ironicclient may be deriving their get_client kwargs
from config inherited from ksa, where the 'interface' option has been
deprecated in favor of 'valid_interfaces'. To accomodate this, we accept
'valid_interfaces' as a kwarg, giving it precedence over 'interface'.
However, we still accept 'interface', as the consumer may be deriving
kwargs from a non-conf source (such as an already-created ksa Adapter
where 'valid_interfaces' has already been translated to 'interfaces'.

Co-Authored-By: guang-yee <guang.yee@suse.com>

Change-Id: I3b6fa53005f143d34f03bb1ed71c0aa04b7fce7b
  • Loading branch information
Eric Fried authored and kaifeng committed Mar 7, 2019
1 parent aa2c7fc commit ae1743d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ironicclient/client.py
Expand Up @@ -101,9 +101,11 @@ def get_client(api_version, auth_type=None, os_ironic_api_version=None,
**session_opts)

# Make sure we also pass the endpoint interface to the HTTP client.
# NOTE(gyee): we are supposed to be using valid_interfaces as interface
# is deprecated.
interface = kwargs.get('interface')
# NOTE(gyee/efried): 'interface' in ksa config is deprecated in favor of
# 'valid_interfaces'. So, since the caller may be deriving kwargs from
# conf, accept 'valid_interfaces' first. But keep support for 'interface',
# in case the caller is deriving kwargs from, say, an existing Adapter.
interface = kwargs.get('valid_interfaces', kwargs.get('interface'))

endpoint = kwargs.get('endpoint')
if not endpoint:
Expand Down
30 changes: 30 additions & 0 deletions ironicclient/tests/unit/test_client.py
Expand Up @@ -164,6 +164,36 @@ def test_get_client_and_interface(self):
self._test_get_client(warn_mock_call_count=4,
expected_interface='internal', **kwargs)

def test_get_client_and_valid_interfaces(self):
kwargs = {
'os_project_name': 'PROJECT_NAME',
'os_username': 'USERNAME',
'os_password': 'PASSWORD',
'os_auth_url': 'http://localhost:35357/v2.0',
'os_auth_token': '',
'os_service_type': '',
'valid_interfaces': ['internal', 'public']
}
self._test_get_client(warn_mock_call_count=4,
expected_interface=['internal', 'public'],
**kwargs)

def test_get_client_and_interface_and_valid_interfaces(self):
"""Ensure 'valid_interfaces' takes precedence over 'interface'."""
kwargs = {
'os_project_name': 'PROJECT_NAME',
'os_username': 'USERNAME',
'os_password': 'PASSWORD',
'os_auth_url': 'http://localhost:35357/v2.0',
'os_auth_token': '',
'os_service_type': '',
'interface': ['ignored'],
'valid_interfaces': ['internal', 'public']
}
self._test_get_client(warn_mock_call_count=4,
expected_interface=['internal', 'public'],
**kwargs)

def test_get_client_with_region_no_auth_token(self):
kwargs = {
'os_project_name': 'PROJECT_NAME',
Expand Down
11 changes: 11 additions & 0 deletions releasenotes/notes/accept-valid_interfaces-3b8f5e3e362e04cd.yaml
@@ -0,0 +1,11 @@
---
features:
- |
The consumer of ironicclient may be deriving their ``get_client`` kwargs
from config inherited from ksa, where the ``interface`` option has been
deprecated in favor of ``valid_interfaces``. To accomodate this, we now
accept ``valid_interfaces`` as a kwarg, giving it precedence over
``interface``. However, we still accept ``interface``, as the consumer may
be deriving kwargs from a non-conf source (such as an already-created ksa
Adapter where ``valid_interfaces`` has already been translated to
``interfaces``.

0 comments on commit ae1743d

Please sign in to comment.