From ae1743d2c194c690c4d4629e51e860b5f5b84252 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Wed, 6 Mar 2019 11:07:28 -0600 Subject: [PATCH] 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 Change-Id: I3b6fa53005f143d34f03bb1ed71c0aa04b7fce7b --- ironicclient/client.py | 8 +++-- ironicclient/tests/unit/test_client.py | 30 +++++++++++++++++++ ...ept-valid_interfaces-3b8f5e3e362e04cd.yaml | 11 +++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/accept-valid_interfaces-3b8f5e3e362e04cd.yaml diff --git a/ironicclient/client.py b/ironicclient/client.py index 83b0e148a..66fd6d09d 100644 --- a/ironicclient/client.py +++ b/ironicclient/client.py @@ -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: diff --git a/ironicclient/tests/unit/test_client.py b/ironicclient/tests/unit/test_client.py index 7d10701f4..20f68a2c1 100644 --- a/ironicclient/tests/unit/test_client.py +++ b/ironicclient/tests/unit/test_client.py @@ -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', diff --git a/releasenotes/notes/accept-valid_interfaces-3b8f5e3e362e04cd.yaml b/releasenotes/notes/accept-valid_interfaces-3b8f5e3e362e04cd.yaml new file mode 100644 index 000000000..adadfbd56 --- /dev/null +++ b/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``.