Use converged SDK insead of os-client-config

Sanity-check the o-c-c move to OpenStackSDK

Depends-on: I8d035cfd1afc1cad01ceac7cd643568e94897e27
Change-Id: Ia111f127fbdceac2afe20fd9d1fe032145cdd72c
This commit is contained in:
Dean Troyer 2017-11-07 00:09:59 -06:00
parent e65c2aa93f
commit 86129e6f88
7 changed files with 109 additions and 21 deletions

View File

@ -15,8 +15,16 @@
import logging
from os_client_config import config
from os_client_config import exceptions as occ_exceptions
try:
from openstack.config import exceptions as occ_exceptions
except ImportError:
from os_client_config import exceptions as occ_exceptions
try:
from openstack.config import loader as config
except ImportError:
from os_client_config import config
from oslo_utils import strutils
import six

View File

@ -19,6 +19,7 @@ import copy
import logging
import sys
from openstack import connection
from oslo_utils import strutils
import six
@ -27,6 +28,13 @@ from osc_lib import exceptions
from osc_lib import session as osc_session
from osc_lib import version
# 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.config import loader as config # noqa
profile = None
except ImportError:
from openstack import profile
LOG = logging.getLogger(__name__)
@ -209,6 +217,15 @@ class ClientManager(object):
app_version=self._app_version,
additional_user_agent=[('osc-lib', version.version_string)],
)
# Create a common default SDK Connection object if it is the newer
# non-Profile style.
if profile is None:
self.sdk_connection = connection.Connection(
config=self._cli_options,
session=self.session,
)
self._auth_setup_completed = True
def validate_scope(self):

View File

@ -22,7 +22,14 @@ from keystoneauth1.identity import generic as generic_plugin
from keystoneauth1.identity.v3 import k2k
from keystoneauth1 import loading
from keystoneauth1 import token_endpoint
from os_client_config import cloud_config
try:
from openstack.config import cloud_config
_occ_in_sdk = True
except ImportError:
from os_client_config import cloud_config
_occ_in_sdk = False
from openstack import connection
from osc_lib.api import auth
from osc_lib import clientmanager
@ -377,3 +384,19 @@ class TestClientManager(utils.TestClientManager):
self.assertEqual(client_manager.auth._sp_id, fakes.SERVICE_PROVIDER_ID)
self.assertEqual(client_manager.auth.project_id, fakes.PROJECT_ID)
self.assertTrue(client_manager._auth_setup_completed)
class TestClientManagerSDK(utils.TestClientManager):
def test_client_manager_connection(self):
client_manager = self._make_clientmanager(
auth_required=True,
)
if _occ_in_sdk:
self.assertIsInstance(
client_manager.sdk_connection,
connection.Connection,
)
else:
self.assertIsNone(getattr(client_manager, 'sdk_connection', None))

View File

@ -22,6 +22,16 @@ import testtools
from osc_lib import shell
from osc_lib.tests import utils
# 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 loader as config # noqa
except ImportError:
# Fall back to os-client-config
CONFIG_MOCK_BASE = "os_client_config.config"
DEFAULT_AUTH_URL = "http://127.0.0.1:5000/v2.0/"
DEFAULT_PROJECT_ID = "xxxx-yyyy-zzzz"
@ -174,7 +184,7 @@ class TestShellHelp(utils.TestShell):
class TestShellOptions(utils.TestShell):
"""Test the option handling by argparse and os_client_config
"""Test the option handling by argparse and openstack.config.loader
This covers getting the CLI options through the initial processing
and validates the arguments to initialize_app() and occ_get_one()
@ -312,7 +322,7 @@ class TestShellCli(utils.TestShell):
self.assertEqual('mickey', _shell.options.key)
self.assertEqual(('mycert', 'mickey'), _shell.client_manager.cert)
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file")
def test_shell_args_cloud_no_vendor(self, config_mock):
"""Test cloud config options without the vendor file"""
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_1))
@ -361,8 +371,8 @@ class TestShellCli(utils.TestShell):
self.assertIsNone(_shell.cloud.config['key'])
self.assertIsNone(_shell.client_manager.cert)
@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_cloud_public(self, config_mock, public_mock):
"""Test cloud config options with the vendor file"""
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
@ -410,8 +420,8 @@ class TestShellCli(utils.TestShell):
self.assertEqual('mickey', _shell.cloud.config['key'])
self.assertEqual(('mycert', 'mickey'), _shell.client_manager.cert)
@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(self, config_mock, vendor_mock):
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
@ -467,8 +477,8 @@ class TestShellCliPrecedence(utils.TestShell):
}
self.useFixture(utils.EnvFixture(env.copy()))
@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):
"""Test environment overriding occ"""
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
@ -515,8 +525,8 @@ class TestShellCliPrecedence(utils.TestShell):
_shell.client_manager.region_name,
)
@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):
"""Test command line overriding environment and occ"""
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
@ -563,8 +573,8 @@ class TestShellCliPrecedence(utils.TestShell):
_shell.client_manager.region_name,
)
@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_3(self, config_mock, vendor_mock):
"""Test command line overriding environment and occ"""
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_1))

View File

@ -22,7 +22,14 @@ import os
from cliff import columns as cliff_columns
import fixtures
from keystoneauth1 import loading
from os_client_config import cloud_config
try:
from openstack.config import cloud_config
from openstack.config import defaults
except ImportError:
from os_client_config import cloud_config
from os_client_config import defaults
from oslo_utils import importutils
from requests_mock.contrib import fixture
import testtools
@ -31,6 +38,16 @@ from osc_lib import clientmanager
from osc_lib import shell
from osc_lib.tests import fakes
# 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 loader as config # noqa
except ImportError:
# Fall back to os-client-config
CONFIG_MOCK_BASE = "os_client_config.config"
def fake_execute(shell, cmd):
"""Pretend to execute shell commands."""
@ -246,12 +263,14 @@ class TestClientManager(TestCase):
if auth_args is not None:
auth_dict = auth_args
cli_options = {
cli_options = defaults.get_defaults()
cli_options.update({
'auth_type': auth_plugin_name,
'auth': auth_dict,
'interface': fakes.INTERFACE,
'region_name': fakes.REGION_NAME,
}
# 'workflow_api_version': '2',
})
if config_args is not None:
cli_options.update(config_args)
@ -330,7 +349,7 @@ class TestShell(TestCase):
cloud.config = {}
self.occ_get_one = mock.Mock(return_value=cloud)
with mock.patch(
"os_client_config.config.OpenStackConfig.get_one_cloud",
CONFIG_MOCK_BASE + ".OpenStackConfig.get_one_cloud",
self.occ_get_one,
):
_shell = make_shell(shell_class=self.shell_class)
@ -377,7 +396,7 @@ class TestShell(TestCase):
self._assert_initialize_app_arg("", kwargs)
def _test_options_get_one_cloud(self, test_opts):
"""Test options sent "to os_client_config"""
"""Test options sent "to openstack.config"""
for opt in test_opts.keys():
if not test_opts[opt][1]:
continue
@ -392,7 +411,7 @@ class TestShell(TestCase):
self._assert_cloud_config_arg(cmd, kwargs)
def _test_env_get_one_cloud(self, test_opts):
"""Test environment options sent "to os_client_config"""
"""Test environment options sent "to openstack.config"""
for opt in test_opts.keys():
if not test_opts[opt][2]:
continue

View File

@ -7,6 +7,7 @@ six>=1.10.0 # MIT
Babel!=2.4.0,>=2.3.4 # BSD
cliff!=2.9.0,>=2.8.0 # Apache-2.0
keystoneauth1>=3.2.0 # Apache-2.0
openstacksdk>=0.9.19 # Apache-2.0
os-client-config>=1.28.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0
oslo.utils>=3.31.0 # Apache-2.0

10
tox.ini
View File

@ -17,6 +17,16 @@ deps =
commands = ostestr {posargs}
whitelist_externals = ostestr
[testenv:unit-tips]
commands =
pip install -q -e "git+file://{toxinidir}/../cliff#egg=cliff"
pip install -q -e "git+file://{toxinidir}/../keystoneauth#egg=keystoneauth"
pip install -q -e "git+file://{toxinidir}/../os-client-config#egg=os_client_config"
pip install -q -e "git+file://{toxinidir}/../python-openstacksdk#egg=openstacksdk"
pip freeze
ostestr {posargs}
whitelist_externals = ostestr
[testenv:pep8]
commands = flake8