2016-06-14 09:46:10 -05:00
|
|
|
# Copyright 2012-2013 OpenStack Foundation
|
2013-06-30 23:01:17 -04:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
|
2015-05-01 17:37:38 -05:00
|
|
|
import copy
|
2016-04-05 17:57:55 +02:00
|
|
|
import fixtures
|
2013-06-30 23:01:17 -04:00
|
|
|
import mock
|
|
|
|
import os
|
2015-07-13 22:59:15 -04:00
|
|
|
import testtools
|
2013-06-30 23:01:17 -04:00
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
from osc_lib import shell
|
|
|
|
from osc_lib.tests import utils
|
2013-06-30 23:01:17 -04:00
|
|
|
|
|
|
|
|
2013-12-09 20:01:04 -05:00
|
|
|
DEFAULT_AUTH_URL = "http://127.0.0.1:5000/v2.0/"
|
2013-07-29 11:11:11 -05:00
|
|
|
DEFAULT_PROJECT_ID = "xxxx-yyyy-zzzz"
|
|
|
|
DEFAULT_PROJECT_NAME = "project"
|
2013-12-09 20:01:04 -05:00
|
|
|
DEFAULT_DOMAIN_ID = "aaaa-bbbb-cccc"
|
2015-04-29 22:59:02 -05:00
|
|
|
DEFAULT_DOMAIN_NAME = "default"
|
2013-12-09 20:01:04 -05:00
|
|
|
DEFAULT_USER_DOMAIN_ID = "aaaa-bbbb-cccc"
|
|
|
|
DEFAULT_USER_DOMAIN_NAME = "domain"
|
|
|
|
DEFAULT_PROJECT_DOMAIN_ID = "aaaa-bbbb-cccc"
|
|
|
|
DEFAULT_PROJECT_DOMAIN_NAME = "domain"
|
|
|
|
DEFAULT_USERNAME = "username"
|
|
|
|
DEFAULT_PASSWORD = "password"
|
2015-04-29 22:59:02 -05:00
|
|
|
|
|
|
|
DEFAULT_CLOUD = "altocumulus"
|
2013-06-30 23:01:17 -04:00
|
|
|
DEFAULT_REGION_NAME = "ZZ9_Plural_Z_Alpha"
|
2013-12-09 20:01:04 -05:00
|
|
|
DEFAULT_TOKEN = "token"
|
2013-06-30 23:01:17 -04:00
|
|
|
DEFAULT_SERVICE_URL = "http://127.0.0.1:8771/v3.0/"
|
2014-07-18 19:18:25 +02:00
|
|
|
DEFAULT_AUTH_PLUGIN = "v2password"
|
2015-07-04 09:32:16 -06:00
|
|
|
DEFAULT_INTERFACE = "internal"
|
2014-07-18 19:18:25 +02:00
|
|
|
|
2015-05-08 13:14:15 -06:00
|
|
|
DEFAULT_COMPUTE_API_VERSION = ""
|
|
|
|
DEFAULT_IDENTITY_API_VERSION = ""
|
|
|
|
DEFAULT_IMAGE_API_VERSION = ""
|
|
|
|
DEFAULT_VOLUME_API_VERSION = ""
|
|
|
|
DEFAULT_NETWORK_API_VERSION = ""
|
|
|
|
|
|
|
|
LIB_COMPUTE_API_VERSION = ""
|
|
|
|
LIB_IDENTITY_API_VERSION = ""
|
|
|
|
LIB_IMAGE_API_VERSION = ""
|
|
|
|
LIB_VOLUME_API_VERSION = ""
|
|
|
|
LIB_NETWORK_API_VERSION = ""
|
2013-06-30 23:01:17 -04:00
|
|
|
|
2015-05-01 17:37:38 -05:00
|
|
|
CLOUD_1 = {
|
|
|
|
'clouds': {
|
|
|
|
'scc': {
|
|
|
|
'auth': {
|
|
|
|
'auth_url': DEFAULT_AUTH_URL,
|
|
|
|
'project_name': DEFAULT_PROJECT_NAME,
|
|
|
|
'username': 'zaphod',
|
|
|
|
},
|
2016-05-12 15:35:53 -05:00
|
|
|
'region_name': 'occ-cloud,krikkit',
|
2015-05-01 17:37:38 -05:00
|
|
|
'donut': 'glazed',
|
2015-07-04 09:32:16 -06:00
|
|
|
'interface': 'public',
|
2015-05-01 17:37:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CLOUD_2 = {
|
|
|
|
'clouds': {
|
|
|
|
'megacloud': {
|
|
|
|
'cloud': 'megadodo',
|
|
|
|
'auth': {
|
|
|
|
'project_name': 'heart-o-gold',
|
|
|
|
'username': 'zaphod',
|
|
|
|
},
|
2015-12-23 12:48:45 -06:00
|
|
|
'region_name': 'occ-cloud,krikkit,occ-env',
|
2015-05-29 20:39:24 +09:00
|
|
|
'log_file': '/tmp/test_log_file',
|
|
|
|
'log_level': 'debug',
|
2016-04-01 23:42:27 +02:00
|
|
|
'cert': 'mycert',
|
|
|
|
'key': 'mickey',
|
2015-05-01 17:37:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PUBLIC_1 = {
|
|
|
|
'public-clouds': {
|
|
|
|
'megadodo': {
|
|
|
|
'auth': {
|
|
|
|
'auth_url': DEFAULT_AUTH_URL,
|
|
|
|
'project_name': DEFAULT_PROJECT_NAME,
|
|
|
|
},
|
|
|
|
'region_name': 'occ-public',
|
|
|
|
'donut': 'cake',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-30 23:01:17 -04:00
|
|
|
|
2015-04-29 22:59:02 -05:00
|
|
|
# The option table values is a tuple of (<value>, <test-opt>, <test-env>)
|
|
|
|
# where <value> is the test value to use, <test-opt> is True if this option
|
|
|
|
# should be tested as a CLI option and <test-env> is True of this option
|
|
|
|
# should be tested as an environment variable.
|
|
|
|
|
|
|
|
# Global options that should be parsed before shell.initialize_app() is called
|
|
|
|
global_options = {
|
|
|
|
'--os-cloud': (DEFAULT_CLOUD, True, True),
|
|
|
|
'--os-region-name': (DEFAULT_REGION_NAME, True, True),
|
|
|
|
'--os-default-domain': (DEFAULT_DOMAIN_NAME, True, True),
|
|
|
|
'--os-cacert': ('/dev/null', True, True),
|
|
|
|
'--timing': (True, True, False),
|
2016-04-18 14:39:21 -05:00
|
|
|
'--os-profile': ('SECRET_KEY', True, False),
|
2015-07-04 09:32:16 -06:00
|
|
|
'--os-interface': (DEFAULT_INTERFACE, True, True)
|
2015-04-29 22:59:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def opt2attr(opt):
|
|
|
|
if opt.startswith('--os-'):
|
|
|
|
attr = opt[5:]
|
|
|
|
elif opt.startswith('--'):
|
|
|
|
attr = opt[2:]
|
|
|
|
else:
|
|
|
|
attr = opt
|
|
|
|
return attr.lower().replace('-', '_')
|
|
|
|
|
|
|
|
|
|
|
|
def opt2env(opt):
|
|
|
|
return opt[2:].upper().replace('-', '_')
|
|
|
|
|
|
|
|
|
2013-06-30 23:01:17 -04:00
|
|
|
def make_shell():
|
|
|
|
"""Create a new command shell and mock out some bits."""
|
|
|
|
_shell = shell.OpenStackShell()
|
|
|
|
_shell.command_manager = mock.Mock()
|
2016-05-12 15:35:53 -05:00
|
|
|
_shell.cloud = mock.Mock()
|
2013-06-30 23:01:17 -04:00
|
|
|
|
|
|
|
return _shell
|
|
|
|
|
|
|
|
|
|
|
|
def fake_execute(shell, cmd):
|
|
|
|
"""Pretend to execute shell commands."""
|
|
|
|
return shell.run(cmd.split())
|
|
|
|
|
|
|
|
|
2016-04-05 17:57:55 +02:00
|
|
|
class EnvFixture(fixtures.Fixture):
|
|
|
|
"""Environment Fixture.
|
|
|
|
|
|
|
|
This fixture replaces os.environ with provided env or an empty env.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, env=None):
|
|
|
|
self.new_env = env or {}
|
|
|
|
|
|
|
|
def _setUp(self):
|
|
|
|
self.orig_env, os.environ = os.environ, self.new_env
|
|
|
|
self.addCleanup(self.revert)
|
|
|
|
|
|
|
|
def revert(self):
|
|
|
|
os.environ = self.orig_env
|
|
|
|
|
|
|
|
|
2013-06-30 23:01:17 -04:00
|
|
|
class TestShell(utils.TestCase):
|
2016-02-23 10:38:58 -06:00
|
|
|
|
2013-06-30 23:01:17 -04:00
|
|
|
def setUp(self):
|
|
|
|
super(TestShell, self).setUp()
|
2016-05-12 15:35:53 -05:00
|
|
|
patch = "osc_lib.shell.OpenStackShell.run_subcommand"
|
2013-06-30 23:01:17 -04:00
|
|
|
self.cmd_patch = mock.patch(patch)
|
|
|
|
self.cmd_save = self.cmd_patch.start()
|
2016-04-05 17:57:55 +02:00
|
|
|
self.addCleanup(self.cmd_patch.stop)
|
2013-06-30 23:01:17 -04:00
|
|
|
self.app = mock.Mock("Test Shell")
|
|
|
|
|
|
|
|
|
|
|
|
class TestShellHelp(TestShell):
|
|
|
|
"""Test the deferred help flag"""
|
2016-02-23 10:38:58 -06:00
|
|
|
|
2013-06-30 23:01:17 -04:00
|
|
|
def setUp(self):
|
|
|
|
super(TestShellHelp, self).setUp()
|
2016-04-05 17:57:55 +02:00
|
|
|
self.useFixture(EnvFixture())
|
2013-06-30 23:01:17 -04:00
|
|
|
|
2015-07-13 22:59:15 -04:00
|
|
|
@testtools.skip("skip until bug 1444983 is resolved")
|
2013-06-30 23:01:17 -04:00
|
|
|
def test_help_options(self):
|
|
|
|
flag = "-h list server"
|
|
|
|
kwargs = {
|
|
|
|
"deferred_help": True,
|
|
|
|
}
|
2016-05-12 15:35:53 -05:00
|
|
|
with mock.patch(
|
|
|
|
"osc_lib.shell.OpenStackShell.initialize_app",
|
|
|
|
self.app,
|
|
|
|
):
|
2013-06-30 23:01:17 -04:00
|
|
|
_shell, _cmd = make_shell(), flag
|
|
|
|
fake_execute(_shell, _cmd)
|
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual(
|
|
|
|
kwargs["deferred_help"],
|
|
|
|
_shell.options.deferred_help,
|
|
|
|
)
|
2013-06-30 23:01:17 -04:00
|
|
|
|
|
|
|
|
2015-04-29 22:59:02 -05:00
|
|
|
class TestShellOptions(TestShell):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test the option handling by argparse and os_client_config
|
|
|
|
|
|
|
|
This covers getting the CLI options through the initial processing
|
|
|
|
and validates the arguments to initialize_app() and occ_get_one()
|
|
|
|
"""
|
2016-02-23 10:38:58 -06:00
|
|
|
|
2013-06-30 23:01:17 -04:00
|
|
|
def setUp(self):
|
2015-04-29 22:59:02 -05:00
|
|
|
super(TestShellOptions, self).setUp()
|
2016-04-05 17:57:55 +02:00
|
|
|
self.useFixture(EnvFixture())
|
2013-06-30 23:01:17 -04:00
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
def _assert_initialize_app_arg(self, cmd_options, default_args):
|
|
|
|
"""Check the args passed to initialize_app()
|
|
|
|
|
|
|
|
The argv argument to initialize_app() is the remainder from parsing
|
|
|
|
global options declared in both cliff.app and
|
|
|
|
osc_lib.OpenStackShell build_option_parser(). Any global
|
|
|
|
options passed on the command line should not be in argv but in
|
|
|
|
_shell.options.
|
|
|
|
"""
|
|
|
|
|
|
|
|
with mock.patch(
|
|
|
|
"osc_lib.shell.OpenStackShell.initialize_app",
|
|
|
|
self.app,
|
|
|
|
):
|
|
|
|
_shell, _cmd = make_shell(), cmd_options + " module list"
|
|
|
|
fake_execute(_shell, _cmd)
|
|
|
|
|
|
|
|
self.app.assert_called_with(["module", "list"])
|
|
|
|
for k in default_args.keys():
|
|
|
|
self.assertEqual(
|
|
|
|
default_args[k],
|
|
|
|
vars(_shell.options)[k],
|
|
|
|
"%s does not match" % k,
|
|
|
|
)
|
|
|
|
|
|
|
|
def _assert_cloud_config_arg(self, cmd_options, default_args):
|
|
|
|
"""Check the args passed to cloud_config.get_one_cloud()
|
|
|
|
|
|
|
|
The argparse argument to get_one_cloud() is an argparse.Namespace
|
|
|
|
object that contains all of the options processed to this point in
|
|
|
|
initialize_app().
|
|
|
|
"""
|
|
|
|
|
|
|
|
cloud = mock.Mock(name="cloudy")
|
|
|
|
cloud.config = {}
|
|
|
|
self.occ_get_one = mock.Mock(return_value=cloud)
|
|
|
|
with mock.patch(
|
|
|
|
"os_client_config.config.OpenStackConfig.get_one_cloud",
|
|
|
|
self.occ_get_one,
|
|
|
|
):
|
|
|
|
_shell, _cmd = make_shell(), cmd_options + " module list"
|
|
|
|
fake_execute(_shell, _cmd)
|
|
|
|
|
|
|
|
self.app.assert_called_with(["module", "list"])
|
|
|
|
opts = self.occ_get_one.call_args[1]['argparse']
|
|
|
|
for k in default_args.keys():
|
|
|
|
self.assertEqual(
|
|
|
|
default_args[k],
|
|
|
|
vars(opts)[k],
|
|
|
|
"%s does not match" % k,
|
|
|
|
)
|
|
|
|
|
2015-04-29 22:59:02 -05:00
|
|
|
def _test_options_init_app(self, test_opts):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test options on the command line"""
|
2015-04-29 22:59:02 -05:00
|
|
|
for opt in test_opts.keys():
|
|
|
|
if not test_opts[opt][1]:
|
|
|
|
continue
|
|
|
|
key = opt2attr(opt)
|
2016-02-22 16:20:30 -06:00
|
|
|
if isinstance(test_opts[opt][0], str):
|
2015-04-29 22:59:02 -05:00
|
|
|
cmd = opt + " " + test_opts[opt][0]
|
|
|
|
else:
|
|
|
|
cmd = opt
|
|
|
|
kwargs = {
|
|
|
|
key: test_opts[opt][0],
|
|
|
|
}
|
|
|
|
self._assert_initialize_app_arg(cmd, kwargs)
|
|
|
|
|
|
|
|
def _test_env_init_app(self, test_opts):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test options in the environment"""
|
2015-04-29 22:59:02 -05:00
|
|
|
for opt in test_opts.keys():
|
|
|
|
if not test_opts[opt][2]:
|
|
|
|
continue
|
|
|
|
key = opt2attr(opt)
|
|
|
|
kwargs = {
|
|
|
|
key: test_opts[opt][0],
|
|
|
|
}
|
|
|
|
env = {
|
|
|
|
opt2env(opt): test_opts[opt][0],
|
|
|
|
}
|
|
|
|
os.environ = env.copy()
|
|
|
|
self._assert_initialize_app_arg("", kwargs)
|
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
def _test_options_get_one_cloud(self, test_opts):
|
|
|
|
"""Test options sent "to os_client_config"""
|
|
|
|
for opt in test_opts.keys():
|
|
|
|
if not test_opts[opt][1]:
|
|
|
|
continue
|
|
|
|
key = opt2attr(opt)
|
|
|
|
if isinstance(test_opts[opt][0], str):
|
|
|
|
cmd = opt + " " + test_opts[opt][0]
|
|
|
|
else:
|
|
|
|
cmd = opt
|
|
|
|
kwargs = {
|
|
|
|
key: test_opts[opt][0],
|
|
|
|
}
|
|
|
|
self._assert_cloud_config_arg(cmd, kwargs)
|
|
|
|
|
2015-04-29 22:59:02 -05:00
|
|
|
def _test_env_get_one_cloud(self, test_opts):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test environment options sent "to os_client_config"""
|
2015-04-29 22:59:02 -05:00
|
|
|
for opt in test_opts.keys():
|
|
|
|
if not test_opts[opt][2]:
|
|
|
|
continue
|
|
|
|
key = opt2attr(opt)
|
|
|
|
kwargs = {
|
|
|
|
key: test_opts[opt][0],
|
|
|
|
}
|
|
|
|
env = {
|
|
|
|
opt2env(opt): test_opts[opt][0],
|
|
|
|
}
|
|
|
|
os.environ = env.copy()
|
|
|
|
self._assert_cloud_config_arg("", kwargs)
|
2014-06-30 19:12:27 +02:00
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
def test_no_options(self):
|
2015-04-29 22:59:02 -05:00
|
|
|
os.environ = {}
|
|
|
|
self._assert_initialize_app_arg("", {})
|
|
|
|
self._assert_cloud_config_arg("", {})
|
2013-06-30 23:01:17 -04:00
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
def test_global_options(self):
|
|
|
|
self._test_options_init_app(global_options)
|
|
|
|
self._test_options_get_one_cloud(global_options)
|
|
|
|
|
|
|
|
def test_global_env(self):
|
|
|
|
self._test_env_init_app(global_options)
|
|
|
|
self._test_env_get_one_cloud(global_options)
|
|
|
|
|
2013-06-30 23:01:17 -04:00
|
|
|
|
|
|
|
class TestShellCli(TestShell):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test handling of specific global options
|
|
|
|
|
|
|
|
_shell.options is the parsed command line from argparse
|
|
|
|
_shell.client_manager.* are the values actually used
|
|
|
|
|
|
|
|
"""
|
2016-02-23 10:38:58 -06:00
|
|
|
|
2013-06-30 23:01:17 -04:00
|
|
|
def setUp(self):
|
|
|
|
super(TestShellCli, self).setUp()
|
2016-05-12 15:35:53 -05:00
|
|
|
env = {}
|
2016-04-05 17:57:55 +02:00
|
|
|
self.useFixture(EnvFixture(env.copy()))
|
2013-06-30 23:01:17 -04:00
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
def test_shell_args_tls_options(self):
|
|
|
|
"""Test the TLS verify and CA cert file options"""
|
2015-05-01 12:25:58 -05:00
|
|
|
_shell = make_shell()
|
|
|
|
|
|
|
|
# Default
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "module list")
|
2015-05-01 12:25:58 -05:00
|
|
|
self.assertIsNone(_shell.options.verify)
|
|
|
|
self.assertIsNone(_shell.options.insecure)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertIsNone(_shell.options.cacert)
|
|
|
|
self.assertTrue(_shell.client_manager.verify)
|
|
|
|
self.assertIsNone(_shell.client_manager.cacert)
|
2015-05-01 12:25:58 -05:00
|
|
|
|
|
|
|
# --verify
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "--verify module list")
|
2015-05-01 12:25:58 -05:00
|
|
|
self.assertTrue(_shell.options.verify)
|
|
|
|
self.assertIsNone(_shell.options.insecure)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertIsNone(_shell.options.cacert)
|
|
|
|
self.assertTrue(_shell.client_manager.verify)
|
|
|
|
self.assertIsNone(_shell.client_manager.cacert)
|
2015-05-01 12:25:58 -05:00
|
|
|
|
|
|
|
# --insecure
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "--insecure module list")
|
2015-05-01 12:25:58 -05:00
|
|
|
self.assertIsNone(_shell.options.verify)
|
|
|
|
self.assertTrue(_shell.options.insecure)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertIsNone(_shell.options.cacert)
|
|
|
|
self.assertFalse(_shell.client_manager.verify)
|
|
|
|
self.assertIsNone(_shell.client_manager.cacert)
|
2015-05-01 12:25:58 -05:00
|
|
|
|
|
|
|
# --os-cacert
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "--os-cacert foo module list")
|
2015-05-01 12:25:58 -05:00
|
|
|
self.assertIsNone(_shell.options.verify)
|
|
|
|
self.assertIsNone(_shell.options.insecure)
|
2015-04-29 22:59:02 -05:00
|
|
|
self.assertEqual('foo', _shell.options.cacert)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual('foo', _shell.client_manager.verify)
|
|
|
|
self.assertEqual('foo', _shell.client_manager.cacert)
|
2015-05-01 12:25:58 -05:00
|
|
|
|
|
|
|
# --os-cacert and --verify
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "--os-cacert foo --verify module list")
|
2015-05-01 12:25:58 -05:00
|
|
|
self.assertTrue(_shell.options.verify)
|
|
|
|
self.assertIsNone(_shell.options.insecure)
|
2015-04-29 22:59:02 -05:00
|
|
|
self.assertEqual('foo', _shell.options.cacert)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual('foo', _shell.client_manager.verify)
|
|
|
|
self.assertEqual('foo', _shell.client_manager.cacert)
|
2015-05-01 12:25:58 -05:00
|
|
|
|
|
|
|
# --os-cacert and --insecure
|
2015-06-04 09:20:29 -05:00
|
|
|
# NOTE(dtroyer): Per bug https://bugs.launchpad.net/bugs/1447784
|
|
|
|
# in this combination --insecure now overrides any
|
|
|
|
# --os-cacert setting, where before --insecure
|
|
|
|
# was ignored if --os-cacert was set.
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "--os-cacert foo --insecure module list")
|
2015-05-01 12:25:58 -05:00
|
|
|
self.assertIsNone(_shell.options.verify)
|
|
|
|
self.assertTrue(_shell.options.insecure)
|
2015-04-29 22:59:02 -05:00
|
|
|
self.assertEqual('foo', _shell.options.cacert)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertFalse(_shell.client_manager.verify)
|
|
|
|
self.assertIsNone(_shell.client_manager.cacert)
|
2015-05-01 12:25:58 -05:00
|
|
|
|
2016-04-01 23:42:27 +02:00
|
|
|
def test_shell_args_cert_options(self):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test client cert options"""
|
2016-04-01 23:42:27 +02:00
|
|
|
_shell = make_shell()
|
|
|
|
|
|
|
|
# Default
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "module list")
|
2016-04-01 23:42:27 +02:00
|
|
|
self.assertEqual('', _shell.options.cert)
|
|
|
|
self.assertEqual('', _shell.options.key)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertIsNone(_shell.client_manager.cert)
|
2016-04-01 23:42:27 +02:00
|
|
|
|
|
|
|
# --os-cert
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "--os-cert mycert module list")
|
2016-04-01 23:42:27 +02:00
|
|
|
self.assertEqual('mycert', _shell.options.cert)
|
|
|
|
self.assertEqual('', _shell.options.key)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual('mycert', _shell.client_manager.cert)
|
2016-04-01 23:42:27 +02:00
|
|
|
|
|
|
|
# --os-key
|
2016-05-12 15:35:53 -05:00
|
|
|
fake_execute(_shell, "--os-key mickey module list")
|
2016-04-01 23:42:27 +02:00
|
|
|
self.assertEqual('', _shell.options.cert)
|
|
|
|
self.assertEqual('mickey', _shell.options.key)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertIsNone(_shell.client_manager.cert)
|
2016-04-01 23:42:27 +02:00
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
# --os-cert and --os-key
|
|
|
|
fake_execute(_shell, "--os-cert mycert --os-key mickey module list")
|
|
|
|
self.assertEqual('mycert', _shell.options.cert)
|
|
|
|
self.assertEqual('mickey', _shell.options.key)
|
|
|
|
self.assertEqual(('mycert', 'mickey'), _shell.client_manager.cert)
|
2015-05-01 17:37:38 -05:00
|
|
|
|
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
|
|
|
|
def test_shell_args_cloud_no_vendor(self, config_mock):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test cloud config options without the vendor file"""
|
2015-05-28 11:01:13 -06:00
|
|
|
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_1))
|
2015-05-01 17:37:38 -05:00
|
|
|
_shell = make_shell()
|
|
|
|
|
|
|
|
fake_execute(
|
|
|
|
_shell,
|
2016-05-12 15:35:53 -05:00
|
|
|
"--os-cloud scc module list",
|
2015-05-01 17:37:38 -05:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'scc',
|
|
|
|
_shell.cloud.name,
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
DEFAULT_AUTH_URL,
|
|
|
|
_shell.cloud.config['auth']['auth_url'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
DEFAULT_PROJECT_NAME,
|
|
|
|
_shell.cloud.config['auth']['project_name'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'zaphod',
|
|
|
|
_shell.cloud.config['auth']['username'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'occ-cloud',
|
|
|
|
_shell.cloud.config['region_name'],
|
|
|
|
)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual(
|
|
|
|
'occ-cloud',
|
|
|
|
_shell.client_manager.region_name,
|
|
|
|
)
|
2015-05-01 17:37:38 -05:00
|
|
|
self.assertEqual(
|
|
|
|
'glazed',
|
|
|
|
_shell.cloud.config['donut'],
|
|
|
|
)
|
2015-05-22 16:22:35 -07:00
|
|
|
self.assertEqual(
|
|
|
|
'public',
|
2015-07-04 09:32:16 -06:00
|
|
|
_shell.cloud.config['interface'],
|
2015-05-22 16:22:35 -07:00
|
|
|
)
|
2015-05-01 17:37:38 -05:00
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertIsNone(_shell.cloud.config['cert'])
|
|
|
|
self.assertIsNone(_shell.cloud.config['key'])
|
|
|
|
self.assertIsNone(_shell.client_manager.cert)
|
|
|
|
|
2015-05-01 17:37:38 -05:00
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
|
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
|
2015-08-10 12:33:28 -06:00
|
|
|
def test_shell_args_cloud_public(self, config_mock, public_mock):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test cloud config options with the vendor file"""
|
2015-05-28 11:01:13 -06:00
|
|
|
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
|
|
|
|
public_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
|
2015-05-01 17:37:38 -05:00
|
|
|
_shell = make_shell()
|
|
|
|
|
|
|
|
fake_execute(
|
|
|
|
_shell,
|
2016-05-12 15:35:53 -05:00
|
|
|
"--os-cloud megacloud module list",
|
2015-05-01 17:37:38 -05:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'megacloud',
|
|
|
|
_shell.cloud.name,
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds-public.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
DEFAULT_AUTH_URL,
|
|
|
|
_shell.cloud.config['auth']['auth_url'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'cake',
|
|
|
|
_shell.cloud.config['donut'],
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
'heart-o-gold',
|
|
|
|
_shell.cloud.config['auth']['project_name'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'zaphod',
|
|
|
|
_shell.cloud.config['auth']['username'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'occ-cloud',
|
|
|
|
_shell.cloud.config['region_name'],
|
|
|
|
)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual(
|
|
|
|
'occ-cloud',
|
|
|
|
_shell.client_manager.region_name,
|
|
|
|
)
|
2015-05-01 17:37:38 -05:00
|
|
|
|
2016-04-01 23:42:27 +02:00
|
|
|
self.assertEqual('mycert', _shell.cloud.config['cert'])
|
|
|
|
self.assertEqual('mickey', _shell.cloud.config['key'])
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual(('mycert', 'mickey'), _shell.client_manager.cert)
|
2016-04-01 23:42:27 +02:00
|
|
|
|
2015-05-01 17:37:38 -05:00
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
|
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
|
2015-08-10 12:33:28 -06:00
|
|
|
def test_shell_args_precedence(self, config_mock, vendor_mock):
|
2015-05-28 11:01:13 -06:00
|
|
|
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
|
|
|
|
vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
|
2015-05-01 17:37:38 -05:00
|
|
|
_shell = make_shell()
|
|
|
|
|
|
|
|
# Test command option overriding config file value
|
|
|
|
fake_execute(
|
|
|
|
_shell,
|
2016-05-12 15:35:53 -05:00
|
|
|
"--os-cloud megacloud --os-region-name krikkit module list",
|
2015-05-01 17:37:38 -05:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'megacloud',
|
|
|
|
_shell.cloud.name,
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds-public.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
DEFAULT_AUTH_URL,
|
|
|
|
_shell.cloud.config['auth']['auth_url'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'cake',
|
|
|
|
_shell.cloud.config['donut'],
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
'heart-o-gold',
|
|
|
|
_shell.cloud.config['auth']['project_name'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'zaphod',
|
|
|
|
_shell.cloud.config['auth']['username'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'krikkit',
|
|
|
|
_shell.cloud.config['region_name'],
|
|
|
|
)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual(
|
|
|
|
'krikkit',
|
|
|
|
_shell.client_manager.region_name,
|
|
|
|
)
|
2015-05-01 17:37:38 -05:00
|
|
|
|
|
|
|
|
2016-05-12 15:35:53 -05:00
|
|
|
class TestShellCliPrecedence(TestShell):
|
|
|
|
"""Test option precedencr order"""
|
2016-02-23 10:38:58 -06:00
|
|
|
|
2015-05-01 17:37:38 -05:00
|
|
|
def setUp(self):
|
2016-05-12 15:35:53 -05:00
|
|
|
super(TestShellCliPrecedence, self).setUp()
|
2015-05-01 17:37:38 -05:00
|
|
|
env = {
|
2016-05-12 15:35:53 -05:00
|
|
|
'OS_CLOUD': 'megacloud',
|
2015-05-01 17:37:38 -05:00
|
|
|
'OS_REGION_NAME': 'occ-env',
|
|
|
|
}
|
2016-04-05 17:57:55 +02:00
|
|
|
self.useFixture(EnvFixture(env.copy()))
|
2015-05-01 17:37:38 -05:00
|
|
|
|
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
|
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
|
2015-08-10 12:33:28 -06:00
|
|
|
def test_shell_args_precedence_1(self, config_mock, vendor_mock):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test environment overriding occ"""
|
2015-05-28 11:01:13 -06:00
|
|
|
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
|
|
|
|
vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
|
2015-05-01 17:37:38 -05:00
|
|
|
_shell = make_shell()
|
|
|
|
|
|
|
|
# Test env var
|
|
|
|
fake_execute(
|
|
|
|
_shell,
|
2016-05-12 15:35:53 -05:00
|
|
|
"module list",
|
2015-05-01 17:37:38 -05:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'megacloud',
|
|
|
|
_shell.cloud.name,
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds-public.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
DEFAULT_AUTH_URL,
|
|
|
|
_shell.cloud.config['auth']['auth_url'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'cake',
|
|
|
|
_shell.cloud.config['donut'],
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
'heart-o-gold',
|
|
|
|
_shell.cloud.config['auth']['project_name'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'zaphod',
|
|
|
|
_shell.cloud.config['auth']['username'],
|
|
|
|
)
|
2016-05-12 15:35:53 -05:00
|
|
|
|
|
|
|
# These come from the environment
|
2015-05-01 17:37:38 -05:00
|
|
|
self.assertEqual(
|
|
|
|
'occ-env',
|
|
|
|
_shell.cloud.config['region_name'],
|
|
|
|
)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual(
|
|
|
|
'occ-env',
|
|
|
|
_shell.client_manager.region_name,
|
|
|
|
)
|
2015-05-01 17:37:38 -05:00
|
|
|
|
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
|
|
|
|
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
|
2015-08-10 12:33:28 -06:00
|
|
|
def test_shell_args_precedence_2(self, config_mock, vendor_mock):
|
2016-05-12 15:35:53 -05:00
|
|
|
"""Test command line overriding environment and occ"""
|
2015-05-28 11:01:13 -06:00
|
|
|
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
|
|
|
|
vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
|
2015-05-01 17:37:38 -05:00
|
|
|
_shell = make_shell()
|
|
|
|
|
|
|
|
# Test command option overriding config file value
|
|
|
|
fake_execute(
|
|
|
|
_shell,
|
2016-05-12 15:35:53 -05:00
|
|
|
"--os-region-name krikkit list user",
|
2015-05-01 17:37:38 -05:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'megacloud',
|
|
|
|
_shell.cloud.name,
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds-public.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
DEFAULT_AUTH_URL,
|
|
|
|
_shell.cloud.config['auth']['auth_url'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'cake',
|
|
|
|
_shell.cloud.config['donut'],
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
'heart-o-gold',
|
|
|
|
_shell.cloud.config['auth']['project_name'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'zaphod',
|
|
|
|
_shell.cloud.config['auth']['username'],
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from the command line
|
|
|
|
self.assertEqual(
|
|
|
|
'krikkit',
|
|
|
|
_shell.cloud.config['region_name'],
|
|
|
|
)
|
2016-05-12 15:35:53 -05:00
|
|
|
self.assertEqual(
|
|
|
|
'krikkit',
|
|
|
|
_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")
|
|
|
|
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))
|
|
|
|
vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
|
|
|
|
_shell = make_shell()
|
|
|
|
|
|
|
|
# Test command option overriding config file value
|
|
|
|
fake_execute(
|
|
|
|
_shell,
|
|
|
|
"--os-cloud scc --os-region-name krikkit list user",
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'scc',
|
|
|
|
_shell.cloud.name,
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds-public.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
DEFAULT_AUTH_URL,
|
|
|
|
_shell.cloud.config['auth']['auth_url'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'glazed',
|
|
|
|
_shell.cloud.config['donut'],
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from clouds.yaml
|
|
|
|
self.assertEqual(
|
|
|
|
DEFAULT_PROJECT_NAME,
|
|
|
|
_shell.cloud.config['auth']['project_name'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'zaphod',
|
|
|
|
_shell.cloud.config['auth']['username'],
|
|
|
|
)
|
|
|
|
|
|
|
|
# These come from the command line
|
|
|
|
self.assertEqual(
|
|
|
|
'krikkit',
|
|
|
|
_shell.cloud.config['region_name'],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'krikkit',
|
|
|
|
_shell.client_manager.region_name,
|
|
|
|
)
|