From 2633ec06072a12a5c913055e8758c86fea81b11b Mon Sep 17 00:00:00 2001 From: Boden R Date: Tue, 19 Jun 2018 11:25:53 -0600 Subject: [PATCH] make python 3 the default for tox.ini This patch is part of the community goals to enable python 3 first, and only use python 2 when explict. To do so, this patch: - Makes python 3 the default env for non py27 tox targets. - Adds a py3-dev target for running py3 locally. - Refactors the pip install commands for stable dependency install into their own target and refs them where needed. - Updates the code to pass pep8 in python 3. - Bumps the version of pylint to 1.7.1 to address some py3 issues in earlier versions. As part of this effort we should also look into making python 3 the default for our VMware NSX 3rd party CI jobs. Change-Id: Ibaa3e9d717f32ffb6479346163c14d4be7df50cf --- lower-constraints.txt | 2 +- test-requirements.txt | 2 +- tox.ini | 70 +++++++++---------- vmware_nsx/common/utils.py | 2 + vmware_nsx/nsxlib/mh/versioning.py | 1 + .../nsx_v/vshield/common/VcnsApiClient.py | 4 +- vmware_nsx/services/ipam/nsx_tvd/driver.py | 2 +- vmware_nsx/shell/nsx_instance_if_migrate.py | 36 +++++----- 8 files changed, 61 insertions(+), 58 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 6aba6ee59b..e1dd85b0fa 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -103,7 +103,7 @@ pycparser==2.18 pyflakes==0.8.1 Pygments==2.2.0 pyinotify==0.9.6 -pylint==1.4.5 +pylint==1.7.1 pyparsing==2.1.0 pyperclip==1.5.27 python-dateutil==2.5.3 diff --git a/test-requirements.txt b/test-requirements.txt index 9bd7b5ad33..fca95ee8ab 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -21,6 +21,6 @@ testscenarios>=0.4 # Apache-2.0/BSD WebTest>=2.0.27 # MIT bandit>=1.1.0 # Apache-2.0 tempest>=17.1.0 # Apache-2.0 -pylint==1.4.5 # GPLv2 +pylint==1.7.1 # GPLv2 python-openstackclient>=3.12.0 # Apache-2.0 requests-mock>=1.2.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 0467e8489a..ba841f6918 100644 --- a/tox.ini +++ b/tox.ini @@ -23,8 +23,23 @@ commands = setenv = OS_TEST_TIMEOUT=180 commands = false +[testenv:dev] +# run locally (not in the gate) using editable mode +# https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs +# note that order is important to ensure dependencies don't override +commands = + pip install -q -e "git+https://git.openstack.org/openstack/networking-l2gw#egg=networking_l2gw" + pip install -q -e "git+https://git.openstack.org/openstack/networking-sfc#egg=networking_sfc" + pip install -q -e "git+https://git.openstack.org/openstack/neutron-lbaas#egg=neutron_lbaas" + pip install -q -e "git+https://git.openstack.org/openstack/neutron-fwaas#egg=neutron_fwaas" + pip install -q -e "git+https://git.openstack.org/openstack/neutron-dynamic-routing#egg=neutron_dynamic_routing" + pip install -q -e "git+https://git.openstack.org/openstack/neutron-vpnaas#egg=neutron_vpnaas" + pip install -q -e "git+https://git.openstack.org/openstack/vmware-nsxlib#egg=vmware_nsxlib" + pip install -q -e "git+https://git.openstack.org/openstack/neutron#egg=neutron" + + [testenv:functional] -basepython = python2.7 +basepython = python3 setenv = {[testenv]setenv} {[testenv:common]setenv} OS_TEST_PATH=./vmware_nsx/tests/functional @@ -34,7 +49,7 @@ deps = -r{toxinidir}/vmware_nsx/tests/functional/requirements.txt [testenv:dsvm-functional] -basepython = python2.7 +basepython = python3 setenv = OS_SUDO_TESTING=1 OS_FAIL_ON_MISSING_DEPS=1 OS_TEST_TIMEOUT=180 @@ -49,6 +64,7 @@ commands = sitepackages = True [testenv:releasenotes] +basepython = python3 deps = -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -r{toxinidir}/doc/requirements.txt commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html @@ -57,24 +73,24 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen setenv = OS_FAIL_ON_MISSING_DEPS=1 [testenv:py27-dev] -# run py27 locally (not in the gate) using editable mode -# https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs -# note that order is important to ensure dependencies don't override commands = - pip install -q -e "git+https://git.openstack.org/openstack/networking-l2gw#egg=networking_l2gw" - pip install -q -e "git+https://git.openstack.org/openstack/networking-sfc#egg=networking_sfc" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-lbaas#egg=neutron_lbaas" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-fwaas#egg=neutron_fwaas" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-dynamic-routing#egg=neutron_dynamic_routing" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-vpnaas#egg=neutron_vpnaas" - pip install -q -e "git+https://git.openstack.org/openstack/vmware-nsxlib#egg=vmware_nsxlib" - pip install -q -e "git+https://git.openstack.org/openstack/neutron#egg=neutron" + {[testenv:dev]commands} + pip freeze + stestr run {posargs} +whitelist_externals = + stestr + +[testenv:py3-dev] +basepython = python3 +commands = + {[testenv:dev]commands} pip freeze stestr run {posargs} whitelist_externals = stestr [testenv:pep8] +basepython = python3 commands = # If it is easier to add a check via a shell script, consider adding it in this file sh ./tools/misc-sanity-checks.sh @@ -88,18 +104,9 @@ whitelist_externals = bash [testenv:pep8-dev] -# run pep8 locally (not in the gate) using editable mode -# https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs -# note that order is important to ensure dependencies don't override +basepython = python3 commands = - pip install -q -e "git+https://git.openstack.org/openstack/networking-l2gw#egg=networking_l2gw" - pip install -q -e "git+https://git.openstack.org/openstack/networking-sfc#egg=networking_sfc" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-lbaas#egg=neutron_lbaas" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-fwaas#egg=neutron_fwaas" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-dynamic-routing#egg=neutron_dynamic_routing" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-vpnaas#egg=neutron_vpnaas" - pip install -q -e "git+https://git.openstack.org/openstack/vmware-nsxlib#egg=vmware_nsxlib" - pip install -q -e "git+https://git.openstack.org/openstack/neutron#egg=neutron" + {[testenv:dev]commands} pip freeze # If it is easier to add a check via a shell script, consider adding it in this file sh ./tools/misc-sanity-checks.sh @@ -115,15 +122,13 @@ whitelist_externals = commands = bandit -r vmware_nsx -n 5 -ll [testenv:cover] -basepython = python2.7 +basepython = python3 commands = python setup.py testr --coverage --testr-args='{posargs}' coverage report -[testenv:venv] -commands = {posargs} - [testenv:docs] +basepython = python3 deps = -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -r{toxinidir}/doc/requirements.txt commands = sphinx-build -b html doc/source doc/build/html @@ -170,14 +175,7 @@ deps = [testenv:lower-constraints-dev] basepython = python3 commands = - pip install -q -e "git+https://git.openstack.org/openstack/networking-l2gw#egg=networking_l2gw" - pip install -q -e "git+https://git.openstack.org/openstack/networking-sfc#egg=networking_sfc" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-lbaas#egg=neutron_lbaas" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-fwaas#egg=neutron_fwaas" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-dynamic-routing#egg=neutron_dynamic_routing" - pip install -q -e "git+https://git.openstack.org/openstack/neutron-vpnaas#egg=neutron_vpnaas" - pip install -q -e "git+https://git.openstack.org/openstack/vmware-nsxlib#egg=vmware_nsxlib" - pip install -q -e "git+https://git.openstack.org/openstack/neutron#egg=neutron" + {[testenv:dev]commands} pip freeze stestr run {posargs} deps = diff --git a/vmware_nsx/common/utils.py b/vmware_nsx/common/utils.py index 9531b1bbb7..560719a313 100644 --- a/vmware_nsx/common/utils.py +++ b/vmware_nsx/common/utils.py @@ -161,7 +161,9 @@ def _log_before_retry(func, trial_number): def _get_args_from_frame(frames, frame_num): if len(frames) > frame_num and frames[frame_num] and frames[frame_num][0]: + # pylint: disable=deprecated-method argvalues = inspect.getargvalues(frames[frame_num][0]) + # pylint: disable=deprecated-method formated_args = inspect.formatargvalues(*argvalues) # remove the first 'self' arg from the log as it adds no information formated_args = re.sub(r'\(self=.*?, ', "(", formated_args) diff --git a/vmware_nsx/nsxlib/mh/versioning.py b/vmware_nsx/nsxlib/mh/versioning.py index 1fda3da470..aec9c1a329 100644 --- a/vmware_nsx/nsxlib/mh/versioning.py +++ b/vmware_nsx/nsxlib/mh/versioning.py @@ -34,6 +34,7 @@ def versioned(func_table): cluster.api_client.get_version()) func = get_function_by_version(func_table, func_name, v) func_kwargs = kwargs + # pylint: disable=deprecated-method arg_spec = inspect.getargspec(func) if not arg_spec.keywords and not arg_spec.varargs: # drop args unknown to function from func_args diff --git a/vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py b/vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py index b118f53afb..2d95623357 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py +++ b/vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py @@ -88,7 +88,9 @@ class VcnsApiHelper(object): def __init__(self, address, user, password, format='json', ca_file=None, insecure=True, timeout=None): - self.authToken = base64.encodestring(six.b("%s:%s" % (user, password))) + # pylint: disable=deprecated-method + encode_fn = base64.encodestring if six.PY2 else base64.encodebytes + self.authToken = encode_fn(six.b("%s:%s" % (user, password))) self.user = user self.passwd = password self.address = address diff --git a/vmware_nsx/services/ipam/nsx_tvd/driver.py b/vmware_nsx/services/ipam/nsx_tvd/driver.py index 5efeaf1feb..cb20cdab05 100644 --- a/vmware_nsx/services/ipam/nsx_tvd/driver.py +++ b/vmware_nsx/services/ipam/nsx_tvd/driver.py @@ -64,7 +64,7 @@ class NsxTvdIpamDriver(subnet_alloc.SubnetAllocator, "support for IPAM", {'project': project, 'plugin': plugin_type}) raise ipam_exc.IpamValueInvalid( - msg="IPAM driver not found") + message="IPAM driver not found") return self.drivers[plugin_type] def allocate_subnet(self, subnet_request): diff --git a/vmware_nsx/shell/nsx_instance_if_migrate.py b/vmware_nsx/shell/nsx_instance_if_migrate.py index c34c26f50a..94aeb00f73 100644 --- a/vmware_nsx/shell/nsx_instance_if_migrate.py +++ b/vmware_nsx/shell/nsx_instance_if_migrate.py @@ -31,24 +31,24 @@ LOG = logging.getLogger(__name__) def usage(): - print ("python nsx_instance_if_migrate.py --username= " - "--password= --project= " - "--auth-url= " - "[--project-domain-id=] " - "[--user-domain-id=] " - "[--machine-type=] " - "[--nsx-bridge=]\n\n" - "Convert libvirt interface definitions on a KVM host, to NSX " - "managed vSwitch definitions\n\n" - " username: Admin user's username\n" - " password: Admin user's password\n" - " keystone auth URL: URL to keystone's authentication service\n" - " project domain: Keystone project domain\n" - " user domain: Keystone user domain\n" - " migrated machine type: Overwrites libvirt's machine type\n" - " log file: Output log of the command execution\n" - " NSX managed vSwitch: vSwitch on host, managed by NSX\n\n") + print("python nsx_instance_if_migrate.py --username= " + "--password= --project= " + "--auth-url= " + "[--project-domain-id=] " + "[--user-domain-id=] " + "[--machine-type=] " + "[--nsx-bridge=]\n\n" + "Convert libvirt interface definitions on a KVM host, to NSX " + "managed vSwitch definitions\n\n" + " username: Admin user's username\n" + " password: Admin user's password\n" + " keystone auth URL: URL to keystone's authentication service\n" + " project domain: Keystone project domain\n" + " user domain: Keystone user domain\n" + " migrated machine type: Overwrites libvirt's machine type\n" + " log file: Output log of the command execution\n" + " NSX managed vSwitch: vSwitch on host, managed by NSX\n\n") sys.exit()