Browse Source

Deprecate v1.1 and remove v3

Module novaclient.v1_1 is already deprecated, so it's time to stop using it
inside novaclient.

Since support of v3 nova is undocumented feature, which uses v2
implementation, we can remove code related to it.

Also, this patch removes redundant check for compute api version != 1.0.

Change-Id: I06b349f704d5ae2c592d8d286da268870f2a69e9
tags/2.25.0
Andrey Kurilin 4 years ago
parent
commit
61ef35fe79

+ 26
- 11
novaclient/client.py View File

@@ -24,8 +24,10 @@ import copy
24 24
 import functools
25 25
 import hashlib
26 26
 import logging
27
+import pkgutil
27 28
 import re
28 29
 import socket
30
+import warnings
29 31
 
30 32
 from keystoneclient import adapter
31 33
 from oslo_utils import importutils
@@ -41,11 +43,15 @@ except ImportError:
41 43
 from six.moves.urllib import parse
42 44
 
43 45
 from novaclient import exceptions
44
-from novaclient.i18n import _
46
+from novaclient.i18n import _, _LW
45 47
 from novaclient import service_catalog
46 48
 from novaclient import utils
47 49
 
48 50
 
51
+# key is a deprecated version and value is an alternative version.
52
+DEPRECATED_VERSIONS = {"1.1": "2"}
53
+
54
+
49 55
 class TCPKeepAliveAdapter(adapters.HTTPAdapter):
50 56
     """The custom adapter used to set TCP Keep-Alive on all connections."""
51 57
     def init_poolmanager(self, *args, **kwargs):
@@ -712,21 +718,30 @@ def _construct_http_client(username=None, password=None, project_id=None,
712 718
 
713 719
 
714 720
 def get_client_class(version):
715
-    version_map = {
716
-        '1.1': 'novaclient.v2.client.Client',
717
-        '2': 'novaclient.v2.client.Client',
718
-        '3': 'novaclient.v2.client.Client',
719
-    }
721
+    version = str(version)
722
+    if version in DEPRECATED_VERSIONS:
723
+        warnings.warn(_LW(
724
+            "Version %(deprecated_version)s is deprecated, using "
725
+            "alternative version %(alternative)s instead.") %
726
+            {"deprecated_version": version,
727
+             "alternative": DEPRECATED_VERSIONS[version]})
728
+        version = DEPRECATED_VERSIONS[version]
720 729
     try:
721
-        client_path = version_map[str(version)]
722
-    except (KeyError, ValueError):
730
+        return importutils.import_class(
731
+            "novaclient.v%s.client.Client" % version)
732
+    except ImportError:
733
+        # NOTE(andreykurilin): available clients version should not be
734
+        # hardcoded, so let's discover them.
735
+        matcher = re.compile(r"v[0-9_]*$")
736
+        submodules = pkgutil.iter_modules(['novaclient'])
737
+        available_versions = [
738
+            name[1:].replace("_", ".") for loader, name, ispkg in submodules
739
+            if matcher.search(name)]
723 740
         msg = _("Invalid client version '%(version)s'. must be one of: "
724 741
                 "%(keys)s") % {'version': version,
725
-                               'keys': ', '.join(version_map.keys())}
742
+                               'keys': ', '.join(available_versions)}
726 743
         raise exceptions.UnsupportedVersion(msg)
727 744
 
728
-    return importutils.import_class(client_path)
729
-
730 745
 
731 746
 def Client(version, *args, **kwargs):
732 747
     client_class = get_client_class(version)

+ 8
- 48
novaclient/shell.py View File

@@ -58,13 +58,7 @@ from novaclient.v2 import shell as shell_v2
58 58
 
59 59
 DEFAULT_OS_COMPUTE_API_VERSION = "2"
60 60
 DEFAULT_NOVA_ENDPOINT_TYPE = 'publicURL'
61
-# NOTE(cyeoh): Having the service type dependent on the API version
62
-# is pretty ugly, but we have to do this because traditionally the
63
-# catalog entry for compute points directly to the V2 API rather than
64
-# the root, and then doing version discovery.
65
-DEFAULT_NOVA_SERVICE_TYPE_MAP = {'1.1': 'compute',
66
-                                 '2': 'compute',
67
-                                 '3': 'computev3'}
61
+DEFAULT_NOVA_SERVICE_TYPE = "compute"
68 62
 
69 63
 logger = logging.getLogger(__name__)
70 64
 
@@ -414,7 +408,7 @@ class OpenStackComputeShell(object):
414 408
             metavar='<compute-api-ver>',
415 409
             default=cliutils.env('OS_COMPUTE_API_VERSION',
416 410
                                  default=DEFAULT_OS_COMPUTE_API_VERSION),
417
-            help=_('Accepts 1.1 or 3, '
411
+            help=_('Accepts number of API version, '
418 412
                    'defaults to env[OS_COMPUTE_API_VERSION].'))
419 413
         parser.add_argument(
420 414
             '--os_compute_api_version',
@@ -490,9 +484,9 @@ class OpenStackComputeShell(object):
490 484
     def _discover_via_contrib_path(self, version):
491 485
         module_path = os.path.dirname(os.path.abspath(__file__))
492 486
         version_str = "v%s" % version.replace('.', '_')
493
-        # NOTE(akurilin): v1.1, v2 and v3 have one implementation, so
494
-        # we should discover contrib modules in one place.
495
-        if version_str in ["v1_1", "v3"]:
487
+        # NOTE(andreykurilin): v1.1 uses implementation of v2, so we should
488
+        # discover contrib modules in novaclient.v2 dir.
489
+        if version_str == "v1_1":
496 490
             version_str = "v2"
497 491
         ext_path = os.path.join(module_path, version_str, 'contrib')
498 492
         ext_glob = os.path.join(ext_path, "*.py")
@@ -656,15 +650,8 @@ class OpenStackComputeShell(object):
656 650
             endpoint_type += 'URL'
657 651
 
658 652
         if not service_type:
659
-            os_compute_api_version = (options.os_compute_api_version or
660
-                                      DEFAULT_OS_COMPUTE_API_VERSION)
661
-            try:
662
-                service_type = DEFAULT_NOVA_SERVICE_TYPE_MAP[
663
-                    os_compute_api_version]
664
-            except KeyError:
665
-                service_type = DEFAULT_NOVA_SERVICE_TYPE_MAP[
666
-                    DEFAULT_OS_COMPUTE_API_VERSION]
667
-            service_type = cliutils.get_service_type(args.func) or service_type
653
+            service_type = (cliutils.get_service_type(args.func) or
654
+                            DEFAULT_NOVA_SERVICE_TYPE)
668 655
 
669 656
         # If we have an auth token but no management_url, we must auth anyway.
670 657
         # Expired tokens are handled by client.py:_cs_request
@@ -734,8 +721,7 @@ class OpenStackComputeShell(object):
734 721
                         project_domain_id=args.os_project_domain_id,
735 722
                         project_domain_name=args.os_project_domain_name)
736 723
 
737
-        if (options.os_compute_api_version and
738
-                options.os_compute_api_version != '1.0'):
724
+        if options.os_compute_api_version:
739 725
             if not any([args.os_tenant_id, args.os_tenant_name,
740 726
                         args.os_project_id, args.os_project_name]):
741 727
                 raise exc.CommandError(_("You must provide a project name or"
@@ -806,32 +792,6 @@ class OpenStackComputeShell(object):
806 792
         except exc.AuthorizationFailure:
807 793
             raise exc.CommandError(_("Unable to authorize user"))
808 794
 
809
-        if options.os_compute_api_version == "3" and service_type != 'image':
810
-            # NOTE(cyeoh): create an image based client because the
811
-            # images api is no longer proxied by the V3 API and we
812
-            # sometimes need to be able to look up images information
813
-            # via glance when connected to the nova api.
814
-            image_service_type = 'image'
815
-            # NOTE(hdd): the password is needed again because creating a new
816
-            # Client without specifying bypass_url will force authentication.
817
-            # We can't reuse self.cs's bypass_url, because that's the URL for
818
-            # the nova service; we need to get glance's URL for this Client
819
-            if not os_password:
820
-                os_password = helper.password
821
-            self.cs.image_cs = client.Client(
822
-                options.os_compute_api_version, os_username,
823
-                os_password, os_tenant_name, tenant_id=os_tenant_id,
824
-                auth_url=os_auth_url, insecure=insecure,
825
-                region_name=os_region_name, endpoint_type=endpoint_type,
826
-                extensions=self.extensions, service_type=image_service_type,
827
-                service_name=service_name, auth_system=os_auth_system,
828
-                auth_plugin=auth_plugin,
829
-                volume_service_name=volume_service_name,
830
-                timings=args.timings, bypass_url=bypass_url,
831
-                os_cache=os_cache, http_log_debug=options.debug,
832
-                session=keystone_session, auth=keystone_auth,
833
-                cacert=cacert, timeout=timeout)
834
-
835 795
         args.func(self.cs, args)
836 796
 
837 797
         if args.timings:

+ 0
- 4
novaclient/tests/unit/test_client.py View File

@@ -161,10 +161,6 @@ class ClientTest(utils.TestCase):
161 161
         self._check_version_url('http://foo.com/nova/v2/%s',
162 162
                                 'http://foo.com/nova/')
163 163
 
164
-    def test_get_client_class_v3(self):
165
-        output = novaclient.client.get_client_class('3')
166
-        self.assertEqual(output, novaclient.v2.client.Client)
167
-
168 164
     def test_get_client_class_v2(self):
169 165
         output = novaclient.client.get_client_class('2')
170 166
         self.assertEqual(output, novaclient.v2.client.Client)

+ 0
- 4
novaclient/tests/unit/test_shell.py View File

@@ -342,10 +342,6 @@ class ShellTest(utils.TestCase):
342 342
     def test_v2_service_type(self, mock_client):
343 343
         self._test_service_type('2', 'compute', mock_client)
344 344
 
345
-    @mock.patch('novaclient.client.Client')
346
-    def test_v3_service_type(self, mock_client):
347
-        self._test_service_type('3', 'computev3', mock_client)
348
-
349 345
     @mock.patch('novaclient.client.Client')
350 346
     def test_v_unknown_service_type(self, mock_client):
351 347
         self._test_service_type('unknown', 'compute', mock_client)

+ 0
- 11
novaclient/tests/unit/v2/test_shell.py View File

@@ -2374,17 +2374,6 @@ class ShellTestV11(ShellTest):
2374 2374
     }
2375 2375
 
2376 2376
 
2377
-class ShellTestV3(ShellTest):
2378
-    FAKE_ENV = {
2379
-        'NOVA_USERNAME': 'username',
2380
-        'NOVA_PASSWORD': 'password',
2381
-        'NOVA_PROJECT_ID': 'project_id',
2382
-        'OS_COMPUTE_API_VERSION': '3',
2383
-        'NOVA_URL': 'http://no.where',
2384
-        'OS_AUTH_URL': 'http://no.where/v2.0',
2385
-    }
2386
-
2387
-
2388 2377
 class ShellWithSessionClientTest(ShellTest):
2389 2378
 
2390 2379
     def setUp(self):

Loading…
Cancel
Save