summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Fried <openstack@fried.cc>2019-03-06 11:07:28 -0600
committerKaifeng Wang <kaifeng.w@gmail.com>2019-03-07 02:39:44 +0000
commitae1743d2c194c690c4d4629e51e860b5f5b84252 (patch)
tree109d9c0c279db422e8b3b64fc76e681a2d04a0e1
parentaa2c7fc9ac0b9c094db0f09bb3b75a09fa92063f (diff)
downloadpython-ironicclient-ae1743d2c194c690c4d4629e51e860b5f5b84252.tar.gz
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
-rw-r--r--ironicclient/client.py8
-rw-r--r--ironicclient/tests/unit/test_client.py30
-rw-r--r--releasenotes/notes/accept-valid_interfaces-3b8f5e3e362e04cd.yaml11
3 files changed, 46 insertions, 3 deletions
diff --git a/ironicclient/client.py b/ironicclient/client.py
index 83b0e14..66fd6d0 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 7d10701..20f68a2 100644
--- a/ironicclient/tests/unit/test_client.py
+++ b/ironicclient/tests/unit/test_client.py
@@ -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',
diff --git a/releasenotes/notes/accept-valid_interfaces-3b8f5e3e362e04cd.yaml b/releasenotes/notes/accept-valid_interfaces-3b8f5e3e362e04cd.yaml
new file mode 100644
index 0000000..adadfbd
--- /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``.