Accept 'valid_interfaces' in client setup

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
This commit is contained in:
Eric Fried 2019-03-06 11:07:28 -06:00 committed by Kaifeng Wang
parent aa2c7fc9ac
commit ae1743d2c1
3 changed files with 46 additions and 3 deletions

View File

@ -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:

View File

@ -164,6 +164,36 @@ class ClientTest(utils.BaseTestCase):
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',

View File

@ -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``.