diff options
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/common/client_config.py | 68 | ||||
| -rw-r--r-- | openstackclient/common/quota.py | 36 | ||||
| -rw-r--r-- | openstackclient/compute/v2/console.py | 13 | ||||
| -rw-r--r-- | openstackclient/network/client.py | 5 | ||||
| -rw-r--r-- | openstackclient/network/v2/floating_ip.py | 4 | ||||
| -rw-r--r-- | openstackclient/tests/unit/compute/v2/test_console.py | 28 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/fakes.py | 4 |
7 files changed, 25 insertions, 133 deletions
diff --git a/openstackclient/common/client_config.py b/openstackclient/common/client_config.py index 5e139596..a22dd0cb 100644 --- a/openstackclient/common/client_config.py +++ b/openstackclient/common/client_config.py @@ -13,7 +13,6 @@ """OpenStackConfig subclass for argument compatibility""" -from os_client_config import exceptions as occ_exceptions from osc_lib.cli import client_config @@ -70,70 +69,3 @@ class OSC_Config(client_config.OSC_Config): config = self._validate_auth(config, loader) auth_plugin = loader.load_from_options(**config['auth']) return auth_plugin - - # TODO(dtroyer): Remove _validate_auth_ksc when it is in osc-lib 1.3.0 - def _validate_auth_ksc(self, config, cloud, fixed_argparse=None): - """Old compatibility hack for OSC, no longer needed/wanted""" - return config - - # TODO(dtroyer): Remove _validate_auth when it is in osc-lib 1.3.0 - def _validate_auth(self, config, loader, fixed_argparse=None): - """Validate auth plugin arguments""" - # May throw a keystoneauth1.exceptions.NoMatchingPlugin - - plugin_options = loader.get_options() - - msgs = [] - prompt_options = [] - for p_opt in plugin_options: - # if it's in config, win, move it and kill it from config dict - # if it's in config.auth but not in config we're good - # deprecated loses to current - # provided beats default, deprecated or not - winning_value = self._find_winning_auth_value(p_opt, config) - if not winning_value: - winning_value = self._find_winning_auth_value( - p_opt, config['auth']) - - # if the plugin tells us that this value is required - # then error if it's doesn't exist now - if not winning_value and p_opt.required: - msgs.append( - 'Missing value {auth_key}' - ' required for auth plugin {plugin}'.format( - auth_key=p_opt.name, plugin=config.get('auth_type'), - ) - ) - - # Clean up after ourselves - for opt in [p_opt.name] + [o.name for o in p_opt.deprecated]: - opt = opt.replace('-', '_') - config.pop(opt, None) - config['auth'].pop(opt, None) - - if winning_value: - # Prefer the plugin configuration dest value if the value's key - # is marked as depreciated. - if p_opt.dest is None: - config['auth'][p_opt.name.replace('-', '_')] = ( - winning_value) - else: - config['auth'][p_opt.dest] = winning_value - - # See if this needs a prompting - if ( - 'prompt' in vars(p_opt) and - p_opt.prompt is not None and - p_opt.dest not in config['auth'] and - self._pw_callback is not None - ): - # Defer these until we know all required opts are present - prompt_options.append(p_opt) - - if msgs: - raise occ_exceptions.OpenStackConfigException('\n'.join(msgs)) - else: - for p_opt in prompt_options: - config['auth'][p_opt.dest] = self._pw_callback(p_opt.prompt) - - return config diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index fa6c5765..afc6195f 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -18,8 +18,6 @@ import itertools import sys -from openstack import exceptions as sdk_exceptions -from openstack.network.v2 import quota as _quota from osc_lib.command import command from osc_lib import utils import six @@ -253,39 +251,7 @@ class ShowQuota(command.ShowOne): project = self._get_project(parsed_args) client = self.app.client_manager.network if parsed_args.default: - # TODO(dtroyer): Remove the top of this if block once the - # fixed SDK QuotaDefault class is the minimum - # required version. This is expected to be - # SDK release 0.9.13 - if hasattr(_quota.QuotaDefault, 'project'): - # hack 0.9.11+ - quotadef_obj = client._get_resource( - _quota.QuotaDefault, - project, - ) - quotadef_obj.base_path = quotadef_obj.base_path % { - 'project': project, - } - try: - network_quota = quotadef_obj.get( - client.session, - requires_id=False, - ) - except sdk_exceptions.NotFoundException as e: - raise sdk_exceptions.ResourceNotFound( - message="No %s found for %s" % - (_quota.QuotaDefault.__name__, project), - details=e.details, - response=e.response, - request_id=e.request_id, - url=e.url, - method=e.method, - http_status=e.http_status, - cause=e.cause, - ) - # end hack-around - else: - network_quota = client.get_quota_default(project) + network_quota = client.get_quota_default(project) else: network_quota = client.get_quota(project) return network_quota diff --git a/openstackclient/compute/v2/console.py b/openstackclient/compute/v2/console.py index 358df501..25f92108 100644 --- a/openstackclient/compute/v2/console.py +++ b/openstackclient/compute/v2/console.py @@ -126,18 +126,7 @@ class ShowConsoleURL(command.ShowOne): parsed_args.server, ) - data = None - if parsed_args.url_type in ['novnc', 'xvpvnc']: - data = server.get_vnc_console(parsed_args.url_type) - if parsed_args.url_type in ['spice-html5']: - data = server.get_spice_console(parsed_args.url_type) - if parsed_args.url_type in ['rdp-html5']: - data = server.get_rdp_console(parsed_args.url_type) - if parsed_args.url_type in ['serial']: - data = server.get_serial_console(parsed_args.url_type) - if parsed_args.url_type in ['webmks']: - data = server.get_mks_console() - + data = server.get_console_url(parsed_args.url_type) if not data: return ({}, {}) diff --git a/openstackclient/network/client.py b/openstackclient/network/client.py index c562058d..9525b947 100644 --- a/openstackclient/network/client.py +++ b/openstackclient/network/client.py @@ -44,6 +44,11 @@ def make_client(instance): LOG.debug('Connection: %s', conn) LOG.debug('Network client initialized using OpenStack SDK: %s', conn.network) + + # NOTE(dtroyer): Horrible ugly hack since we don't actually save + # the connection anywhere yet, so stash it in the + # instance directly from here for other uses + instance.sdk_connection = conn return conn.network diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index 980c41c7..41b208aa 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -241,7 +241,7 @@ class DeleteFloatingIP(common.NetworkAndComputeDelete): def take_action_network(self, client, parsed_args): (obj, self.ip_cache) = _find_floating_ip( - client.session, + self.app.client_manager.sdk_connection.session, self.ip_cache, self.r, ignore_missing=False, @@ -472,7 +472,7 @@ class ShowFloatingIP(common.NetworkAndComputeShowOne): def take_action_network(self, client, parsed_args): (obj, self.ip_cache) = _find_floating_ip( - client.session, + self.app.client_manager.sdk_connection.session, [], parsed_args.floating_ip, ignore_missing=False, diff --git a/openstackclient/tests/unit/compute/v2/test_console.py b/openstackclient/tests/unit/compute/v2/test_console.py index d53d241e..3c708aae 100644 --- a/openstackclient/tests/unit/compute/v2/test_console.py +++ b/openstackclient/tests/unit/compute/v2/test_console.py @@ -35,11 +35,7 @@ class TestConsoleUrlShow(TestConsole): 'protocol': 'fake_protocol', 'type': 'fake_type'}} methods = { - 'get_vnc_console': fake_console_data, - 'get_spice_console': fake_console_data, - 'get_serial_console': fake_console_data, - 'get_rdp_console': fake_console_data, - 'get_mks_console': fake_console_data, + 'get_console_url': fake_console_data } self.fake_server = compute_fakes.FakeServer.create_one_server( methods=methods) @@ -68,7 +64,7 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_vnc_console.assert_called_once_with('novnc') + self.fake_server.get_console_url.assert_called_once_with('novnc') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -83,7 +79,7 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_vnc_console.assert_called_once_with('novnc') + self.fake_server.get_console_url.assert_called_once_with('novnc') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -98,7 +94,7 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_vnc_console.assert_called_once_with('xvpvnc') + self.fake_server.get_console_url.assert_called_once_with('xvpvnc') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -113,14 +109,14 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_spice_console.assert_called_once_with( + self.fake_server.get_console_url.assert_called_once_with( 'spice-html5') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) def test_console_url_show_compatible(self): methods = { - 'get_vnc_console': {'console': {'url': 'http://localhost', + 'get_console_url': {'console': {'url': 'http://localhost', 'type': 'fake_type'}}, } old_fake_server = compute_fakes.FakeServer.create_one_server( @@ -130,8 +126,8 @@ class TestConsoleUrlShow(TestConsole): 'url', ) old_data = ( - methods['get_vnc_console']['console']['type'], - methods['get_vnc_console']['console']['url'] + methods['get_console_url']['console']['type'], + methods['get_console_url']['console']['url'] ) arglist = [ 'foo_vm', @@ -144,7 +140,7 @@ class TestConsoleUrlShow(TestConsole): with mock.patch.object(self.servers_mock, 'get', return_value=old_fake_server): columns, data = self.cmd.take_action(parsed_args) - old_fake_server.get_vnc_console.assert_called_once_with('novnc') + old_fake_server.get_console_url.assert_called_once_with('novnc') self.assertEqual(old_columns, columns) self.assertEqual(old_data, data) @@ -159,7 +155,7 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_rdp_console.assert_called_once_with( + self.fake_server.get_console_url.assert_called_once_with( 'rdp-html5') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -175,7 +171,7 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_serial_console.assert_called_once_with( + self.fake_server.get_console_url.assert_called_once_with( 'serial') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) @@ -191,6 +187,6 @@ class TestConsoleUrlShow(TestConsole): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.fake_server.get_mks_console.assert_called_once_with() + self.fake_server.get_console_url.assert_called_once_with('webmks') self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index 4b266efb..dcecbeee 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -71,6 +71,10 @@ class TestNetworkV2(utils.TestCommand): token=fakes.AUTH_TOKEN, ) + self.app.client_manager.sdk_connection = mock.Mock() + self.app.client_manager.sdk_connection.network = \ + self.app.client_manager.network + self.app.client_manager.identity = ( identity_fakes_v3.FakeIdentityv3Client( endpoint=fakes.AUTH_URL, |
