Make remaining tests pass

* clientmanager had a stray identity_client import
* auth_plugin did not make the transition to osc-lib so remove
  those tests
* test_shell had tests for auth handling that belongs with auth
  plugin handling
This commit is contained in:
Dean Troyer 2016-05-10 08:04:51 -05:00
parent 641ae6bccb
commit 99fddaccdc
3 changed files with 8 additions and 245 deletions

View File

@ -27,7 +27,6 @@ import six
from openstackclient.api import auth from openstackclient.api import auth
from openstackclient.common import exceptions from openstackclient.common import exceptions
from openstackclient.common import session as osc_session from openstackclient.common import session as osc_session
from openstackclient.identity import client as identity_client
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -63,8 +62,6 @@ class ClientManager(object):
# A simple incrementing version for the plugin to know what is available # A simple incrementing version for the plugin to know what is available
PLUGIN_INTERFACE_VERSION = "2" PLUGIN_INTERFACE_VERSION = "2"
identity = ClientCache(identity_client.make_client)
def __getattr__(self, name): def __getattr__(self, name):
# this is for the auth-related parameters. # this is for the auth-related parameters.
if name in ['_' + o.replace('-', '_') if name in ['_' + o.replace('-', '_')
@ -316,11 +313,11 @@ def build_plugin_option_parser(parser):
return parser return parser
# Get list of base plugin modules # # Get list of base plugin modules
PLUGIN_MODULES = get_plugin_modules( # PLUGIN_MODULES = get_plugin_modules(
'openstack.cli.base', # 'openstack.cli.base',
) # )
# Append list of external plugin modules # # Append list of external plugin modules
PLUGIN_MODULES.extend(get_plugin_modules( # PLUGIN_MODULES.extend(get_plugin_modules(
'openstack.cli.extension', # 'openstack.cli.extension',
)) # ))

View File

@ -21,7 +21,6 @@ from keystoneclient.auth.identity import v2 as auth_v2
from keystoneclient import service_catalog from keystoneclient import service_catalog
from openstackclient.api import auth from openstackclient.api import auth
from openstackclient.api import auth_plugin
from openstackclient.common import clientmanager from openstackclient.common import clientmanager
from openstackclient.common import exceptions as exc from openstackclient.common import exceptions as exc
from openstackclient.tests import fakes from openstackclient.tests import fakes
@ -100,38 +99,6 @@ class TestClientManager(utils.TestCase):
url=fakes.AUTH_URL, url=fakes.AUTH_URL,
verb='GET') verb='GET')
def test_client_manager_token_endpoint(self):
client_manager = clientmanager.ClientManager(
cli_options=FakeOptions(
auth_type='token_endpoint',
auth=dict(
token=fakes.AUTH_TOKEN,
url=fakes.AUTH_URL,
),
),
api_version=API_VERSION,
verify=True
)
client_manager.setup_auth()
client_manager.auth_ref
self.assertEqual(
fakes.AUTH_URL,
client_manager._url,
)
self.assertEqual(
fakes.AUTH_TOKEN,
client_manager.auth.get_token(None),
)
self.assertIsInstance(
client_manager.auth,
auth_plugin.TokenEndpoint,
)
self.assertFalse(client_manager._insecure)
self.assertTrue(client_manager._verify)
self.assertTrue(client_manager.is_network_endpoint_enabled())
def test_client_manager_token(self): def test_client_manager_token(self):
client_manager = clientmanager.ClientManager( client_manager = clientmanager.ClientManager(
@ -328,7 +295,6 @@ class TestClientManager(utils.TestCase):
token=fakes.AUTH_TOKEN, token=fakes.AUTH_TOKEN,
), ),
) )
self._select_auth_plugin(params, 'XXX', 'token_endpoint')
# test password auth # test password auth
params = dict( params = dict(
auth=dict( auth=dict(

View File

@ -116,26 +116,6 @@ global_options = {
'--os-interface': (DEFAULT_INTERFACE, True, True) '--os-interface': (DEFAULT_INTERFACE, True, True)
} }
auth_options = {
'--os-auth-url': (DEFAULT_AUTH_URL, True, True),
'--os-project-id': (DEFAULT_PROJECT_ID, True, True),
'--os-project-name': (DEFAULT_PROJECT_NAME, True, True),
'--os-domain-id': (DEFAULT_DOMAIN_ID, True, True),
'--os-domain-name': (DEFAULT_DOMAIN_NAME, True, True),
'--os-user-domain-id': (DEFAULT_USER_DOMAIN_ID, True, True),
'--os-user-domain-name': (DEFAULT_USER_DOMAIN_NAME, True, True),
'--os-project-domain-id': (DEFAULT_PROJECT_DOMAIN_ID, True, True),
'--os-project-domain-name': (DEFAULT_PROJECT_DOMAIN_NAME, True, True),
'--os-username': (DEFAULT_USERNAME, True, True),
'--os-password': (DEFAULT_PASSWORD, True, True),
'--os-region-name': (DEFAULT_REGION_NAME, True, True),
'--os-trust-id': ("1234", True, True),
'--os-auth-type': ("v2password", True, True),
'--os-token': (DEFAULT_TOKEN, True, True),
'--os-url': (DEFAULT_SERVICE_URL, True, True),
'--os-interface': (DEFAULT_INTERFACE, True, True),
}
def opt2attr(opt): def opt2attr(opt):
if opt.startswith('--os-'): if opt.startswith('--os-'):
@ -216,68 +196,6 @@ class TestShell(utils.TestCase):
"%s does not match" % 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 + " list project"
fake_execute(_shell, _cmd)
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,
)
def _assert_token_auth(self, cmd_options, default_args):
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
self.app):
_shell, _cmd = make_shell(), cmd_options + " list role"
fake_execute(_shell, _cmd)
self.app.assert_called_with(["list", "role"])
self.assertEqual(
default_args.get("token", ''),
_shell.options.token,
"token"
)
self.assertEqual(
default_args.get("auth_url", ''),
_shell.options.auth_url,
"auth_url"
)
def _assert_token_endpoint_auth(self, cmd_options, default_args):
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
self.app):
_shell, _cmd = make_shell(), cmd_options + " list role"
fake_execute(_shell, _cmd)
self.app.assert_called_with(["list", "role"])
self.assertEqual(
default_args.get("token", ''),
_shell.options.token,
"token",
)
self.assertEqual(
default_args.get("url", ''),
_shell.options.url,
"url",
)
def _assert_cli(self, cmd_options, default_args): def _assert_cli(self, cmd_options, default_args):
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app", with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
self.app): self.app):
@ -339,20 +257,6 @@ class TestShellOptions(TestShell):
} }
self._assert_initialize_app_arg(cmd, kwargs) self._assert_initialize_app_arg(cmd, kwargs)
def _test_options_get_one_cloud(self, test_opts):
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)
def _test_env_init_app(self, test_opts): def _test_env_init_app(self, test_opts):
for opt in test_opts.keys(): for opt in test_opts.keys():
if not test_opts[opt][2]: if not test_opts[opt][2]:
@ -386,110 +290,6 @@ class TestShellOptions(TestShell):
self._assert_initialize_app_arg("", {}) self._assert_initialize_app_arg("", {})
self._assert_cloud_config_arg("", {}) self._assert_cloud_config_arg("", {})
def test_global_options(self):
self._test_options_init_app(global_options)
self._test_options_get_one_cloud(global_options)
def test_auth_options(self):
self._test_options_init_app(auth_options)
self._test_options_get_one_cloud(auth_options)
def test_global_env(self):
self._test_env_init_app(global_options)
self._test_env_get_one_cloud(global_options)
def test_auth_env(self):
self._test_env_init_app(auth_options)
self._test_env_get_one_cloud(auth_options)
class TestShellTokenAuthEnv(TestShell):
def setUp(self):
super(TestShellTokenAuthEnv, self).setUp()
env = {
"OS_TOKEN": DEFAULT_TOKEN,
"OS_AUTH_URL": DEFAULT_AUTH_URL,
}
self.useFixture(EnvFixture(env.copy()))
def test_env(self):
flag = ""
kwargs = {
"token": DEFAULT_TOKEN,
"auth_url": DEFAULT_AUTH_URL,
}
self._assert_token_auth(flag, kwargs)
def test_only_token(self):
flag = "--os-token xyzpdq"
kwargs = {
"token": "xyzpdq",
"auth_url": DEFAULT_AUTH_URL,
}
self._assert_token_auth(flag, kwargs)
def test_only_auth_url(self):
flag = "--os-auth-url http://cloud.local:555"
kwargs = {
"token": DEFAULT_TOKEN,
"auth_url": "http://cloud.local:555",
}
self._assert_token_auth(flag, kwargs)
def test_empty_auth(self):
os.environ = {}
flag = ""
kwargs = {
"token": '',
"auth_url": '',
}
self._assert_token_auth(flag, kwargs)
class TestShellTokenEndpointAuthEnv(TestShell):
def setUp(self):
super(TestShellTokenEndpointAuthEnv, self).setUp()
env = {
"OS_TOKEN": DEFAULT_TOKEN,
"OS_URL": DEFAULT_SERVICE_URL,
}
self.useFixture(EnvFixture(env.copy()))
def test_env(self):
flag = ""
kwargs = {
"token": DEFAULT_TOKEN,
"url": DEFAULT_SERVICE_URL,
}
self._assert_token_auth(flag, kwargs)
def test_only_token(self):
flag = "--os-token xyzpdq"
kwargs = {
"token": "xyzpdq",
"url": DEFAULT_SERVICE_URL,
}
self._assert_token_auth(flag, kwargs)
def test_only_url(self):
flag = "--os-url http://cloud.local:555"
kwargs = {
"token": DEFAULT_TOKEN,
"url": "http://cloud.local:555",
}
self._assert_token_auth(flag, kwargs)
def test_empty_auth(self):
os.environ = {}
flag = ""
kwargs = {
"token": '',
"url": '',
}
self._assert_token_auth(flag, kwargs)
class TestShellCli(TestShell): class TestShellCli(TestShell):