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
This commit is contained in:
@@ -14,10 +14,15 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from openstack import connection
|
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:
|
try:
|
||||||
from openstack import profile
|
from openstack.config import loader as config # noqa
|
||||||
except ImportError:
|
|
||||||
profile = None
|
profile = None
|
||||||
|
except ImportError:
|
||||||
|
from openstack import profile
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
|
||||||
from openstackclient.i18n import _
|
from openstackclient.i18n import _
|
||||||
@@ -39,7 +44,7 @@ def make_client(instance):
|
|||||||
if profile is None:
|
if profile is None:
|
||||||
# New SDK
|
# New SDK
|
||||||
conn = connection.Connection(
|
conn = connection.Connection(
|
||||||
cloud_config=instance._cli_options,
|
config=instance._cli_options,
|
||||||
session=instance.session)
|
session=instance.session)
|
||||||
else:
|
else:
|
||||||
prof = profile.Profile()
|
prof = profile.Profile()
|
||||||
|
|||||||
@@ -19,6 +19,16 @@ from openstackclient import shell
|
|||||||
from openstackclient.tests.unit.integ import base as test_base
|
from openstackclient.tests.unit.integ import base as test_base
|
||||||
from openstackclient.tests.unit import test_shell
|
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):
|
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_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
|
||||||
= test_base.V3_AUTH_URL
|
= test_base.V3_AUTH_URL
|
||||||
|
|
||||||
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
|
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file")
|
||||||
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
|
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file")
|
||||||
def test_shell_args_precedence_1(self, config_mock, vendor_mock):
|
def test_shell_args_precedence_1(self, config_mock, vendor_mock):
|
||||||
"""Precedence run 1
|
"""Precedence run 1
|
||||||
|
|
||||||
@@ -405,6 +415,7 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
|
|||||||
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
|
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
|
||||||
vendor_mock.side_effect = vendor_mock_return
|
vendor_mock.side_effect = vendor_mock_return
|
||||||
|
|
||||||
|
print("CONFIG_MOCK_BASE=%s" % CONFIG_MOCK_BASE)
|
||||||
_shell = shell.OpenStackShell()
|
_shell = shell.OpenStackShell()
|
||||||
_shell.run(
|
_shell.run(
|
||||||
"--os-password qaz configuration show".split(),
|
"--os-password qaz configuration show".split(),
|
||||||
@@ -458,8 +469,8 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
|
|||||||
# +env, +cli, +occ
|
# +env, +cli, +occ
|
||||||
# see test_shell_args_precedence_2()
|
# see test_shell_args_precedence_2()
|
||||||
|
|
||||||
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
|
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file")
|
||||||
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
|
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file")
|
||||||
def test_shell_args_precedence_2(self, config_mock, vendor_mock):
|
def test_shell_args_precedence_2(self, config_mock, vendor_mock):
|
||||||
"""Precedence run 2
|
"""Precedence run 2
|
||||||
|
|
||||||
@@ -474,6 +485,7 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
|
|||||||
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
|
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
|
||||||
vendor_mock.side_effect = vendor_mock_return
|
vendor_mock.side_effect = vendor_mock_return
|
||||||
|
|
||||||
|
print("CONFIG_MOCK_BASE=%s" % CONFIG_MOCK_BASE)
|
||||||
_shell = shell.OpenStackShell()
|
_shell = shell.OpenStackShell()
|
||||||
_shell.run(
|
_shell.run(
|
||||||
"--os-username zarquon --os-password qaz "
|
"--os-username zarquon --os-password qaz "
|
||||||
|
|||||||
2
tox.ini
2
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}/../keystoneauth#egg=keystoneauth"
|
||||||
pip install -q -U -e "git+file://{toxinidir}/../osc-lib#egg=osc_lib"
|
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}/../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
|
pip freeze
|
||||||
ostestr {posargs}
|
ostestr {posargs}
|
||||||
whitelist_externals = ostestr
|
whitelist_externals = ostestr
|
||||||
|
|||||||
Reference in New Issue
Block a user