diff --git a/openstackclient/network/client.py b/openstackclient/network/client.py index 3566bfe52..6f74303d0 100644 --- a/openstackclient/network/client.py +++ b/openstackclient/network/client.py @@ -14,10 +14,15 @@ import logging from openstack import connection + + +# NOTE(dtroyer): Attempt an import to detect if the SDK installed is new +# enough to not use Profile. If so, use that. try: - from openstack import profile -except ImportError: + from openstack.config import loader as config # noqa profile = None +except ImportError: + from openstack import profile from osc_lib import utils from openstackclient.i18n import _ @@ -39,7 +44,7 @@ def make_client(instance): if profile is None: # New SDK conn = connection.Connection( - cloud_config=instance._cli_options, + config=instance._cli_options, session=instance.session) else: prof = profile.Profile() diff --git a/openstackclient/tests/unit/integ/cli/test_shell.py b/openstackclient/tests/unit/integ/cli/test_shell.py index 78663fbcd..70303be39 100644 --- a/openstackclient/tests/unit/integ/cli/test_shell.py +++ b/openstackclient/tests/unit/integ/cli/test_shell.py @@ -19,6 +19,16 @@ from openstackclient import shell from openstackclient.tests.unit.integ import base as test_base from openstackclient.tests.unit import test_shell +# NOTE(dtroyer): Attempt the import to detect if the SDK installed is new +# enough to contain the os_client_config code. If so, use +# that path for mocks. +CONFIG_MOCK_BASE = "openstack.config.loader" +try: + from openstack.config import defaults # noqa +except ImportError: + # Fall back to os-client-config + CONFIG_MOCK_BASE = "os_client_config.config" + class TestIntegShellCliV2(test_base.TestInteg): @@ -389,8 +399,8 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg): test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \ = test_base.V3_AUTH_URL - @mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file") - @mock.patch("os_client_config.config.OpenStackConfig._load_config_file") + @mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file") + @mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file") def test_shell_args_precedence_1(self, config_mock, vendor_mock): """Precedence run 1 @@ -405,6 +415,7 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg): return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1)) vendor_mock.side_effect = vendor_mock_return + print("CONFIG_MOCK_BASE=%s" % CONFIG_MOCK_BASE) _shell = shell.OpenStackShell() _shell.run( "--os-password qaz configuration show".split(), @@ -458,8 +469,8 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg): # +env, +cli, +occ # see test_shell_args_precedence_2() - @mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file") - @mock.patch("os_client_config.config.OpenStackConfig._load_config_file") + @mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file") + @mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file") def test_shell_args_precedence_2(self, config_mock, vendor_mock): """Precedence run 2 @@ -474,6 +485,7 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg): return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1)) vendor_mock.side_effect = vendor_mock_return + print("CONFIG_MOCK_BASE=%s" % CONFIG_MOCK_BASE) _shell = shell.OpenStackShell() _shell.run( "--os-username zarquon --os-password qaz " diff --git a/tox.ini b/tox.ini index 26c643c82..8ce7ce8c9 100644 --- a/tox.ini +++ b/tox.ini @@ -61,7 +61,7 @@ commands = pip install -q -U -e "git+file://{toxinidir}/../keystoneauth#egg=keystoneauth" pip install -q -U -e "git+file://{toxinidir}/../osc-lib#egg=osc_lib" pip install -q -U -e "git+file://{toxinidir}/../os-client-config#egg=os_client_config" - pip install -q -U -e "git+file://{toxinidir}/../python-openstacksdk#egg=openstacksdk" + pip install -q -e "git+file://{toxinidir}/../python-openstacksdk#egg=openstacksdk" pip freeze ostestr {posargs} whitelist_externals = ostestr