From dfe26e5f814e082a3b4a416a2b26c44c33644165 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Sun, 19 Jul 2020 12:07:38 +0200 Subject: [PATCH] Remove six package usage Since py2 is no longer supported, built in methods can replace the six package usage, as been done in the neutron project. Change-Id: I435462c940e68fa48a910210e584cf139b3b9d95 --- doc/requirements.txt | 3 +-- lower-constraints.txt | 1 - requirements.txt | 1 - vmware_nsxlib/tests/unit/v3/mocks.py | 4 ++-- vmware_nsxlib/tests/unit/v3/test_cluster.py | 2 +- vmware_nsxlib/tests/unit/v3/test_security.py | 5 ++--- vmware_nsxlib/v3/client.py | 3 ++- vmware_nsxlib/v3/cluster.py | 8 +++----- vmware_nsxlib/v3/exceptions.py | 5 ----- vmware_nsxlib/v3/lib.py | 4 +--- vmware_nsxlib/v3/policy/core_defs.py | 4 +--- vmware_nsxlib/v3/policy/core_resources.py | 4 +--- vmware_nsxlib/v3/policy/lb_resources.py | 3 --- vmware_nsxlib/v3/token_provider.py | 5 +---- vmware_nsxlib/v3/trust_management.py | 4 +--- 15 files changed, 16 insertions(+), 40 deletions(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index d3c22481..4a140912 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,8 +1,7 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -sphinx!=1.6.6,!=1.6.7,>=1.6.2,<2.0.0;python_version=='2.7' # BSD -sphinx!=1.6.6,!=1.6.7,>=1.6.2;python_version>='3.4' # BSD +sphinx>=2.0.0,!=2.1.0 # BSD oslosphinx>=4.7.0 # Apache-2.0 openstackdocstheme>=1.18.1 # Apache-2.0 oslotest>=3.2.0 # Apache-2.0 diff --git a/lower-constraints.txt b/lower-constraints.txt index db9787cd..374c1ec1 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -20,7 +20,6 @@ python-subunit==1.0.0 pylint==1.7.1 reno==2.5.0 requests-mock==1.2.0 -six==1.10.0 sphinx==1.6.5 stestr==1.0.0 tempest==17.1.0 diff --git a/requirements.txt b/requirements.txt index 175d63a7..d934ad61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ decorator>=4.3.0 # BSD eventlet>=0.24.1 # MIT netaddr>=0.7.18 # BSD tenacity>=5.0.1 # Apache-2.0 -six>=1.10.0 # MIT oslo.i18n>=3.15.3 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 oslo.serialization>=2.28.1 # Apache-2.0 diff --git a/vmware_nsxlib/tests/unit/v3/mocks.py b/vmware_nsxlib/tests/unit/v3/mocks.py index 09a7519b..d39f325d 100644 --- a/vmware_nsxlib/tests/unit/v3/mocks.py +++ b/vmware_nsxlib/tests/unit/v3/mocks.py @@ -12,11 +12,11 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -import requests -import six.moves.urllib.parse as urlparse +from urllib import parse as urlparse from oslo_serialization import jsonutils from oslo_utils import uuidutils +import requests from vmware_nsxlib.v3 import nsx_constants diff --git a/vmware_nsxlib/tests/unit/v3/test_cluster.py b/vmware_nsxlib/tests/unit/v3/test_cluster.py index 3950e4ee..b3ab25be 100644 --- a/vmware_nsxlib/tests/unit/v3/test_cluster.py +++ b/vmware_nsxlib/tests/unit/v3/test_cluster.py @@ -15,11 +15,11 @@ # import unittest from unittest import mock +from urllib import parse as urlparse from requests import codes from requests import exceptions as requests_exceptions from requests import models -import six.moves.urllib.parse as urlparse from oslo_serialization import jsonutils diff --git a/vmware_nsxlib/tests/unit/v3/test_security.py b/vmware_nsxlib/tests/unit/v3/test_security.py index 485c343f..4c927992 100644 --- a/vmware_nsxlib/tests/unit/v3/test_security.py +++ b/vmware_nsxlib/tests/unit/v3/test_security.py @@ -16,7 +16,6 @@ from unittest import mock from oslo_utils import uuidutils -import six from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase from vmware_nsxlib.tests.unit.v3 import test_constants @@ -482,7 +481,7 @@ class TestNsxLibNSGroup(nsxlib_testcase.NsxClientTestCase): def test_get_nsgroup_lp_complex_expression(self): port_tags = {'app': 'foo', 'project': 'myproject'} port_exp = [self.nsxlib.ns_group.get_port_tag_expression(k, v) - for k, v in six.iteritems(port_tags)] + for k, v in port_tags.items()] complex_exp = self.nsxlib.ns_group.get_nsgroup_complex_expression( expressions=port_exp) expected_exp = {'resource_type': const.NSGROUP_COMPLEX_EXP, @@ -492,7 +491,7 @@ class TestNsxLibNSGroup(nsxlib_testcase.NsxClientTestCase): def test_get_nsgroup_ls_complex_expression(self): switch_tags = {'app': 'foo', 'project': 'myproject'} switch_exp = [self.nsxlib.ns_group.get_switch_tag_expression(k, v) - for k, v in six.iteritems(switch_tags)] + for k, v in switch_tags.items()] complex_exp = self.nsxlib.ns_group.get_nsgroup_complex_expression( expressions=switch_exp) expected_exp = {'resource_type': const.NSGROUP_COMPLEX_EXP, diff --git a/vmware_nsxlib/v3/client.py b/vmware_nsxlib/v3/client.py index 227c49e8..96031aab 100644 --- a/vmware_nsxlib/v3/client.py +++ b/vmware_nsxlib/v3/client.py @@ -15,11 +15,12 @@ # import re import time +from urllib import parse as urlparse from oslo_log import log from oslo_serialization import jsonutils import requests -import six.moves.urllib.parse as urlparse + from vmware_nsxlib._i18n import _ from vmware_nsxlib.v3 import exceptions from vmware_nsxlib.v3 import utils diff --git a/vmware_nsxlib/v3/cluster.py b/vmware_nsxlib/v3/cluster.py index 2f969e14..37f15f70 100644 --- a/vmware_nsxlib/v3/cluster.py +++ b/vmware_nsxlib/v3/cluster.py @@ -23,6 +23,8 @@ import itertools import logging import re import time +from urllib import parse as urlparse +import urllib3 import eventlet from eventlet import greenpool @@ -32,9 +34,6 @@ from oslo_log import log from oslo_service import loopingcall import requests from requests import adapters -import six -import six.moves.urllib.parse as urlparse -import urllib3 from vmware_nsxlib._i18n import _ from vmware_nsxlib.v3 import client as nsx_client @@ -53,8 +52,7 @@ logging.getLogger( urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) -@six.add_metaclass(abc.ABCMeta) -class AbstractHTTPProvider(object): +class AbstractHTTPProvider(object, metaclass=abc.ABCMeta): """Interface for providers of HTTP connections. which are responsible for creating and validating connections diff --git a/vmware_nsxlib/v3/exceptions.py b/vmware_nsxlib/v3/exceptions.py index 70aab1ca..8b66751e 100644 --- a/vmware_nsxlib/v3/exceptions.py +++ b/vmware_nsxlib/v3/exceptions.py @@ -15,7 +15,6 @@ # from oslo_utils import excutils -import six from vmware_nsxlib._i18n import _ @@ -40,10 +39,6 @@ class NsxLibException(Exception): # at least get the core message out if something happened super(NsxLibException, self).__init__(self.message) - if six.PY2: - def __unicode__(self): - return unicode(self.msg) if six.PY2 else self.msg # noqa - def __str__(self): return self.msg diff --git a/vmware_nsxlib/v3/lib.py b/vmware_nsxlib/v3/lib.py index 33877ced..d4a6cb97 100644 --- a/vmware_nsxlib/v3/lib.py +++ b/vmware_nsxlib/v3/lib.py @@ -17,7 +17,6 @@ import abc from distutils import version from oslo_log import log -import six from vmware_nsxlib._i18n import _ from vmware_nsxlib.v3 import client @@ -29,8 +28,7 @@ from vmware_nsxlib.v3 import utils LOG = log.getLogger(__name__) -@six.add_metaclass(abc.ABCMeta) -class NsxLibBase(object): +class NsxLibBase(object, metaclass=abc.ABCMeta): def __init__(self, nsxlib_config): self.nsx_version = None diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 783ce9b5..b8f17328 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -18,7 +18,6 @@ import abc from distutils import version from oslo_log import log as logging -import six from vmware_nsxlib.v3 import exceptions from vmware_nsxlib.v3 import nsx_constants @@ -70,8 +69,7 @@ TIER1_LOCALE_SERVICES_PATH_PATTERN = (TIER1S_PATH_PATTERN + "%s/locale-services/") -@six.add_metaclass(abc.ABCMeta) -class ResourceDef(object): +class ResourceDef(object, metaclass=abc.ABCMeta): def __init__(self, nsx_version=None, **kwargs): self.attrs = kwargs diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 8c7c36d9..0084aaa7 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -22,7 +22,6 @@ import decorator import eventlet from oslo_log import log as logging from oslo_utils import uuidutils -import six from vmware_nsxlib._i18n import _ from vmware_nsxlib.v3 import exceptions @@ -56,8 +55,7 @@ def check_allowed_passthrough(f, *args, **kwargs): return f(*args, **kwargs) -@six.add_metaclass(abc.ABCMeta) -class NsxPolicyResourceBase(object): +class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta): """Abstract class for NSX policy resources declaring the basic apis each policy resource should support, diff --git a/vmware_nsxlib/v3/policy/lb_resources.py b/vmware_nsxlib/v3/policy/lb_resources.py index 6b44f9f4..5b99a2f3 100644 --- a/vmware_nsxlib/v3/policy/lb_resources.py +++ b/vmware_nsxlib/v3/policy/lb_resources.py @@ -14,11 +14,9 @@ # under the License. # -import abc import copy from oslo_log import log as logging -import six from vmware_nsxlib._i18n import _ from vmware_nsxlib.v3 import exceptions as nsxlib_exc @@ -1080,7 +1078,6 @@ class NsxPolicyLoadBalancerVirtualServerAPI(NsxPolicyResourceBase): sleep=sleep, max_attempts=max_attempts) -@six.add_metaclass(abc.ABCMeta) class NsxPolicyLBMonitorProfileBase(NsxPolicyResourceBase): """NSX Policy LB monitor profile""" diff --git a/vmware_nsxlib/v3/token_provider.py b/vmware_nsxlib/v3/token_provider.py index cfe9e918..e4ba4fea 100644 --- a/vmware_nsxlib/v3/token_provider.py +++ b/vmware_nsxlib/v3/token_provider.py @@ -15,13 +15,10 @@ import abc -import six - # NOTE: Consider inheriting from an abstract TokenProvider class to share # interface with XSRF token -@six.add_metaclass(abc.ABCMeta) -class AbstractJWTProvider(object): +class AbstractJWTProvider(object, metaclass=abc.ABCMeta): """Interface for providers of JSON Web Tokens(JWT) Responsible to provide the token value and refresh it once expired, diff --git a/vmware_nsxlib/v3/trust_management.py b/vmware_nsxlib/v3/trust_management.py index c7495cb8..2f1a5a7e 100644 --- a/vmware_nsxlib/v3/trust_management.py +++ b/vmware_nsxlib/v3/trust_management.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - from vmware_nsxlib.v3 import exceptions as nsxlib_exc from vmware_nsxlib.v3 import utils @@ -98,7 +96,7 @@ class NsxLibTrustManagement(utils.NsxLibApiBase): def find_cert_and_identity(self, name, cert_pem): certs = self.get_certs() - if not isinstance(cert_pem, six.text_type): + if not isinstance(cert_pem, str): cert_pem = cert_pem.decode('ascii') cert_ids = [cert['id'] for cert in certs