Skip to content

Commit 1d914dd

Browse files
author
Dean Troyer
committed
Fix SDK Connection creation alternative to Profile
Do a dummy import to determine which SDK is installed (Pre/post merge). This solves the DevStack error "Cloud defaults was not found" in -tips jobs. Depends-On: Ia111f127fbdceac2afe20fd9d1fe032145cdd72c Change-Id: I60c2d418dd5a393eee2cc2a5c2fdebfffdabf2d3
1 parent 396cde3 commit 1d914dd

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

openstackclient/network/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414
import logging
1515

1616
from openstack import connection
17+
18+
19+
# NOTE(dtroyer): Attempt an import to detect if the SDK installed is new
20+
# enough to not use Profile. If so, use that.
1721
try:
18-
from openstack import profile
19-
except ImportError:
22+
from openstack.config import loader as config # noqa
2023
profile = None
24+
except ImportError:
25+
from openstack import profile
2126
from osc_lib import utils
2227

2328
from openstackclient.i18n import _
@@ -39,7 +44,7 @@ def make_client(instance):
3944
if profile is None:
4045
# New SDK
4146
conn = connection.Connection(
42-
cloud_config=instance._cli_options,
47+
config=instance._cli_options,
4348
session=instance.session)
4449
else:
4550
prof = profile.Profile()

openstackclient/tests/unit/integ/cli/test_shell.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
from openstackclient.tests.unit.integ import base as test_base
2020
from openstackclient.tests.unit import test_shell
2121

22+
# NOTE(dtroyer): Attempt the import to detect if the SDK installed is new
23+
# enough to contain the os_client_config code. If so, use
24+
# that path for mocks.
25+
CONFIG_MOCK_BASE = "openstack.config.loader"
26+
try:
27+
from openstack.config import defaults # noqa
28+
except ImportError:
29+
# Fall back to os-client-config
30+
CONFIG_MOCK_BASE = "os_client_config.config"
31+
2232

2333
class TestIntegShellCliV2(test_base.TestInteg):
2434

@@ -389,8 +399,8 @@ def setUp(self):
389399
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
390400
= test_base.V3_AUTH_URL
391401

392-
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
393-
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
402+
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file")
403+
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file")
394404
def test_shell_args_precedence_1(self, config_mock, vendor_mock):
395405
"""Precedence run 1
396406
@@ -405,6 +415,7 @@ def vendor_mock_return():
405415
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
406416
vendor_mock.side_effect = vendor_mock_return
407417

418+
print("CONFIG_MOCK_BASE=%s" % CONFIG_MOCK_BASE)
408419
_shell = shell.OpenStackShell()
409420
_shell.run(
410421
"--os-password qaz configuration show".split(),
@@ -458,8 +469,8 @@ def vendor_mock_return():
458469
# +env, +cli, +occ
459470
# see test_shell_args_precedence_2()
460471

461-
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
462-
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
472+
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file")
473+
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file")
463474
def test_shell_args_precedence_2(self, config_mock, vendor_mock):
464475
"""Precedence run 2
465476
@@ -474,6 +485,7 @@ def vendor_mock_return():
474485
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
475486
vendor_mock.side_effect = vendor_mock_return
476487

488+
print("CONFIG_MOCK_BASE=%s" % CONFIG_MOCK_BASE)
477489
_shell = shell.OpenStackShell()
478490
_shell.run(
479491
"--os-username zarquon --os-password qaz "

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ commands =
6161
pip install -q -U -e "git+file://{toxinidir}/../keystoneauth#egg=keystoneauth"
6262
pip install -q -U -e "git+file://{toxinidir}/../osc-lib#egg=osc_lib"
6363
pip install -q -U -e "git+file://{toxinidir}/../os-client-config#egg=os_client_config"
64-
pip install -q -U -e "git+file://{toxinidir}/../python-openstacksdk#egg=openstacksdk"
64+
pip install -q -e "git+file://{toxinidir}/../python-openstacksdk#egg=openstacksdk"
6565
pip freeze
6666
ostestr {posargs}
6767
whitelist_externals = ostestr

0 commit comments

Comments
 (0)