From 438e40db3683307e35944b5a41b2e9895093135d Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 9 May 2024 17:51:02 +0100 Subject: [PATCH] Remove python-novaclient There are a few remnants left here but this is trivial to clean up now. Change-Id: I517d906796338e64a31afa08b9ee6909b08e0115 Signed-off-by: Stephen Finucane --- openstackclient/compute/client.py | 103 ++---------------- openstackclient/compute/v2/hypervisor.py | 7 +- openstackclient/compute/v2/service.py | 2 +- openstackclient/image/client.py | 8 +- .../tests/functional/common/test_module.py | 2 +- .../tests/unit/compute/v2/fakes.py | 9 -- .../tests/unit/compute/v2/test_hypervisor.py | 4 +- .../tests/unit/compute/v2/test_server.py | 3 - requirements.txt | 1 - 9 files changed, 19 insertions(+), 120 deletions(-) diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py index 157e0dddc4..23979ec7f3 100644 --- a/openstackclient/compute/client.py +++ b/openstackclient/compute/client.py @@ -15,76 +15,28 @@ import logging -from osc_lib import exceptions from osc_lib import utils from openstackclient.i18n import _ - LOG = logging.getLogger(__name__) DEFAULT_API_VERSION = '2.1' API_VERSION_OPTION = 'os_compute_api_version' API_NAME = 'compute' API_VERSIONS = { - "2": "novaclient.client", - "2.1": "novaclient.client", + '2': 'openstack.connection.Connection', + '2.1': 'openstack.connection.Connection', } -COMPUTE_API_VERSIONS = { - '2': 'openstackclient.api.compute_v2.APIv2', -} - -# Save the microversion if in use -_compute_api_version = None - def make_client(instance): """Returns a compute service client.""" - - # Defer client import until we actually need them - from novaclient import client as nova_client - - if _compute_api_version is not None: - version = _compute_api_version - else: - version = instance._api_version[API_NAME] - from novaclient import api_versions - - # convert to APIVersion object - version = api_versions.get_api_version(version) - - if version.is_latest(): - import novaclient - - # NOTE(RuiChen): executing version discovery make sense, but that need - # an initialized REST client, it's not available now, - # fallback to use the max version of novaclient side. - version = novaclient.API_MAX_VERSION - - # Set client http_log_debug to True if verbosity level is high enough - http_log_debug = utils.get_effective_log_level() <= logging.DEBUG - - extensions = [ - ext - for ext in nova_client.discover_extensions(version) - if ext.name == "list_extensions" - ] - - # Remember interface only if it is set - kwargs = utils.build_kwargs_dict('endpoint_type', instance.interface) - - client = nova_client.Client( - version, - session=instance.session, - extensions=extensions, - http_log_debug=http_log_debug, - timings=instance.timing, - region_name=instance.region_name, - **kwargs + LOG.debug( + 'Compute client initialized using OpenStack SDK: %s', + instance.sdk_connection.compute, ) - - return client + return instance.sdk_connection.compute def build_option_parser(parser): @@ -93,48 +45,7 @@ def build_option_parser(parser): '--os-compute-api-version', metavar='', default=utils.env('OS_COMPUTE_API_VERSION'), - help=_( - "Compute API version, default=%s " "(Env: OS_COMPUTE_API_VERSION)" - ) + help=_("Compute API version, default=%s (Env: OS_COMPUTE_API_VERSION)") % DEFAULT_API_VERSION, ) return parser - - -def check_api_version(check_version): - """Validate version supplied by user - - Returns: - - * True if version is OK - * False if the version has not been checked and the previous plugin - check should be performed - * throws an exception if the version is no good - - TODO(dtroyer): make the exception thrown a version-related one - """ - - # Defer client imports until we actually need them - import novaclient - from novaclient import api_versions - - global _compute_api_version - - # Copy some logic from novaclient 3.3.0 for basic version detection - # NOTE(dtroyer): This is only enough to resume operations using API - # version 2.0 or any valid version supplied by the user. - _compute_api_version = api_versions.get_api_version(check_version) - - # Bypass X.latest format microversion - if not _compute_api_version.is_latest(): - if _compute_api_version > api_versions.APIVersion("2.0"): - if not _compute_api_version.matches( - novaclient.API_MIN_VERSION, - novaclient.API_MAX_VERSION, - ): - msg = _("versions supported by client: %(min)s - %(max)s") % { - "min": novaclient.API_MIN_VERSION.get_string(), - "max": novaclient.API_MAX_VERSION.get_string(), - } - raise exceptions.CommandError(msg) - return True diff --git a/openstackclient/compute/v2/hypervisor.py b/openstackclient/compute/v2/hypervisor.py index a118913b62..fffeb35216 100644 --- a/openstackclient/compute/v2/hypervisor.py +++ b/openstackclient/compute/v2/hypervisor.py @@ -18,7 +18,7 @@ import json import re -from novaclient import exceptions as nova_exceptions +from openstack import exceptions as sdk_exceptions from openstack import utils as sdk_utils from osc_lib.cli import format_columns from osc_lib.command import command @@ -223,8 +223,9 @@ class ShowHypervisor(command.ShowOne): hypervisor['uptime'] = m.group(2) hypervisor['users'] = m.group(3) hypervisor['load_average'] = m.group(4) - except nova_exceptions.HTTPNotImplemented: - pass + except sdk_exceptions.HttpException as exc: + if exc.status_code != 501: + raise hypervisor['service_id'] = service_details['id'] hypervisor['service_host'] = service_details['host'] diff --git a/openstackclient/compute/v2/service.py b/openstackclient/compute/v2/service.py index d6e522d03f..b96386e033 100644 --- a/openstackclient/compute/v2/service.py +++ b/openstackclient/compute/v2/service.py @@ -198,7 +198,7 @@ class SetService(command.Command): :param host: the name of the compute service host :param binary: the compute service binary, e.g. nova-compute - :returns: novaclient.v2.services.Service dict-like object + :returns: The service. :raises: CommandError if no or multiple results were found """ services = list(compute_client.services(host=host, binary=binary)) diff --git a/openstackclient/image/client.py b/openstackclient/image/client.py index a3da099ad1..d5ee52b35e 100644 --- a/openstackclient/image/client.py +++ b/openstackclient/image/client.py @@ -19,19 +19,19 @@ from osc_lib import utils from openstackclient.i18n import _ - LOG = logging.getLogger(__name__) DEFAULT_API_VERSION = '2' API_VERSION_OPTION = 'os_image_api_version' -API_NAME = "image" +API_NAME = 'image' API_VERSIONS = { - "1": "openstack.connection.Connection", - "2": "openstack.connection.Connection", + '1': 'openstack.connection.Connection', + '2': 'openstack.connection.Connection', } def make_client(instance): + """Returns an image service client.""" LOG.debug( 'Image client initialized using OpenStack SDK: %s', instance.sdk_connection.image, diff --git a/openstackclient/tests/functional/common/test_module.py b/openstackclient/tests/functional/common/test_module.py index 0cb3739180..1506683499 100644 --- a/openstackclient/tests/functional/common/test_module.py +++ b/openstackclient/tests/functional/common/test_module.py @@ -18,7 +18,7 @@ from openstackclient.tests.functional import base class ModuleTest(base.TestCase): """Functional tests for openstackclient module list output.""" - CLIENTS = ['openstackclient', 'keystoneclient', 'novaclient', 'openstack'] + CLIENTS = ['openstackclient', 'keystoneclient', 'openstack'] LIBS = ['osc_lib', 'keystoneauth1'] diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py index 1e1bc40751..d021c5d760 100644 --- a/openstackclient/tests/unit/compute/v2/fakes.py +++ b/openstackclient/tests/unit/compute/v2/fakes.py @@ -20,7 +20,6 @@ from unittest import mock import uuid from keystoneauth1 import discover -from novaclient import api_versions from openstack.compute.v2 import _proxy from openstack.compute.v2 import aggregate as _aggregate from openstack.compute.v2 import availability_zone as _availability_zone @@ -105,12 +104,6 @@ class FakeClientMixin: def setUp(self): super().setUp() - self.app.client_manager.compute = FakeComputev2Client( - endpoint=fakes.AUTH_URL, - token=fakes.AUTH_TOKEN, - ) - self.compute_client = self.app.client_manager.compute - # TODO(stephenfin): Rename to 'compute_client' once all commands are # migrated to SDK self.app.client_manager.sdk_connection.compute = mock.Mock( @@ -130,8 +123,6 @@ class FakeClientMixin: """ assert re.match(r'2.\d+', version) - self.compute_client.api_version = api_versions.APIVersion(version) - self.compute_sdk_client.default_microversion = version self.compute_sdk_client.get_endpoint_data.return_value = ( discover.EndpointData( diff --git a/openstackclient/tests/unit/compute/v2/test_hypervisor.py b/openstackclient/tests/unit/compute/v2/test_hypervisor.py index ba3d58e8d1..2c226f0046 100644 --- a/openstackclient/tests/unit/compute/v2/test_hypervisor.py +++ b/openstackclient/tests/unit/compute/v2/test_hypervisor.py @@ -14,7 +14,7 @@ import json -from novaclient import exceptions as nova_exceptions +from openstack import exceptions as sdk_exceptions from osc_lib.cli import format_columns from osc_lib import exceptions @@ -484,7 +484,7 @@ class TestHypervisorShow(compute_fakes.TestComputev2): parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.compute_sdk_client.get_hypervisor_uptime.side_effect = ( - nova_exceptions.HTTPNotImplemented(501) + sdk_exceptions.HttpException(http_status=501) ) # In base command class ShowOne in cliff, abstract method take_action() diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index c96e0fada1..a116ff3c35 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -5452,9 +5452,6 @@ class TestServerListV273(_TestServerList): {"href": "http://fake/v2.1/", "rel": "self"}, {"href": "http://fake", "rel": "bookmark"}, ], - # We need to pass networks as {} because its defined as a property - # of the novaclient Server class which gives {} by default. If not - # it will fail at formatting the networks info later on. "networks": {}, } fake_server = compute_fakes.fakes.FakeResource( diff --git a/requirements.txt b/requirements.txt index 341525ea76..3c494d9811 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,6 @@ openstacksdk>=3.3.0 # Apache-2.0 osc-lib>=2.3.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 python-keystoneclient>=3.22.0 # Apache-2.0 -python-novaclient>=18.1.0 # Apache-2.0 python-cinderclient>=3.3.0 # Apache-2.0 requests>=2.14.2 # Apache-2.0 stevedore>=2.0.1 # Apache-2.0