From 2a58c7b8bcf19b3661b5f1854615cd3651f3e951 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Thu, 11 Feb 2021 08:21:42 +0200 Subject: [PATCH] Fix hacking requirements to support py27 in train And fix some related pep8 issues Change-Id: If90431416b0cc7ac48e7bc251aa8f64efbf45d1d --- test-requirements.txt | 3 ++- vmware_nsx/plugins/common_v3/plugin.py | 6 ++--- vmware_nsx/plugins/nsx_p/plugin.py | 10 ++++---- vmware_nsx/plugins/nsx_p/utils.py | 1 + .../lbaas/nsx_p/implementation/lb_utils.py | 1 + .../nsx_p/implementation/listener_mgr.py | 5 ++-- .../admin/plugins/nsxp/resources/migration.py | 1 + .../admin/plugins/nsxp/resources/utils.py | 1 + .../plugins/nsxv3/resources/migration.py | 23 +++++++++++-------- .../unit/services/lbaas/test_nsxp_driver.py | 1 + 10 files changed, 32 insertions(+), 20 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 4dd43b73c7..bc279bcf23 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,8 @@ # 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. -hacking>=1.1.0 # Apache-2.0 +hacking>=1.1.0,<1.2.0 # Apache-2.0 + coverage!=4.4,>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD flake8>=2.6.0 diff --git a/vmware_nsx/plugins/common_v3/plugin.py b/vmware_nsx/plugins/common_v3/plugin.py index c8e4495b10..0c3430524b 100644 --- a/vmware_nsx/plugins/common_v3/plugin.py +++ b/vmware_nsx/plugins/common_v3/plugin.py @@ -2840,9 +2840,9 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, tags=tags, name=name, attachment_type=nsxlib_consts.ATTACHMENT_MDPROXY) except nsx_lib_exc.ResourceNotFound: - err_msg = (_('Logical switch %s or MD proxy %s do ' - 'not exist') % (nsx_net_id, - az._native_md_proxy_uuid)) + err_msg = (_('Logical switch %(net)s or MD proxy %(md)s do ' + 'not exist') % {'net': nsx_net_id, + 'md': az._native_md_proxy_uuid}) LOG.error(err_msg) raise nsx_exc.NsxPluginException(err_msg=err_msg) diff --git a/vmware_nsx/plugins/nsx_p/plugin.py b/vmware_nsx/plugins/nsx_p/plugin.py index 43f8c7791a..c6a8a50752 100644 --- a/vmware_nsx/plugins/nsx_p/plugin.py +++ b/vmware_nsx/plugins/nsx_p/plugin.py @@ -1400,13 +1400,15 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): gw_ip = netaddr.IPAddress(raw_gw_ip) cidr = netaddr.IPNetwork(raw_cidr) if gw_ip.version != cidr.version: - err_msg = (_("Subnet gateway ip version %s does not match subnet " - "cidr %s") % (gw_ip.version, raw_cidr)) + err_msg = (_("Subnet gateway ip version %(ver)s does not match " + "subnet cidr %(cidr)s") % + {'ver': gw_ip.version, 'cidr': raw_cidr}) raise n_exc.InvalidInput(error_message=err_msg) if gw_ip not in cidr: - err_msg = (_("Subnet gateway ip %s does not belong to subnet " - "cidr %s") % (raw_gw_ip, raw_cidr)) + err_msg = (_("Subnet gateway ip %(ip)s does not belong to subnet " + "cidr %(cidr)s") % + {'ip': raw_gw_ip, 'cidr': raw_cidr}) raise n_exc.InvalidInput(error_message=err_msg) if gw_ip.version == const.IP_VERSION_6: diff --git a/vmware_nsx/plugins/nsx_p/utils.py b/vmware_nsx/plugins/nsx_p/utils.py index 1cf0c9e58f..8552a311c1 100644 --- a/vmware_nsx/plugins/nsx_p/utils.py +++ b/vmware_nsx/plugins/nsx_p/utils.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. + def get_edge_cluster_tzs(nsxpolicy, nsxlib, ec_uuid): ec_nodes = nsxpolicy.edge_cluster.get_edge_node_nsx_ids(ec_uuid) ec_tzs = [] diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py b/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py index 086b1326bb..e617997a49 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py @@ -14,6 +14,7 @@ # under the License. import functools + import netaddr from neutron_lib import exceptions as n_exc diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py b/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py index 09a7249d68..bef2caa5ca 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py @@ -158,8 +158,9 @@ class EdgeListenerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): pool_id = p_utils.path_to_id(vs.get('pool_path', '')) if pool_id == def_pool_id: completor(success=False) - msg = (_('Default pool %s is already used by another ' - 'listener %s') % (def_pool_id, vs.get('id'))) + msg = (_("Default pool %(pool)s is already used by " + "another listener %(listener)s") % + {'pool': def_pool_id, 'listener': vs.get('id')}) raise n_exc.BadRequest(resource='lbaas-pool', msg=msg) lb_common.validate_session_persistence( diff --git a/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py b/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py index b5099c2964..f28a4048be 100644 --- a/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py +++ b/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py @@ -13,6 +13,7 @@ # under the License. import copy + import netaddr from neutron_lib.callbacks import registry diff --git a/vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py b/vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py index c7334aca14..935e207bb7 100644 --- a/vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py +++ b/vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py @@ -13,6 +13,7 @@ # under the License. import logging + from oslo_config import cfg from neutron.db import l3_dvr_db # noqa diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py index cf82bda98c..169a8af8d4 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py @@ -16,6 +16,7 @@ import copy import time import logging + import paramiko import tenacity @@ -164,8 +165,8 @@ def change_migration_service_status(start=True, nsxlib=None): try: get_migration_status_with_retry(nsxlib) except Exception: - raise Exception("The migration service did not get up after %s " - "retries" % SERVICE_UP_RETRIES) + raise Exception(_("The migration service did not get up after %s " + "retries") % SERVICE_UP_RETRIES) elapsed_time = time.time() - start_time LOG.info("The service is up (waited %s seconds)", elapsed_time) @@ -204,8 +205,8 @@ def verify_component_status(nsxlib, component_number): # Success that indicates resource migration is already done return COMPONENT_STATUS_ALREADY_MIGRATED # bad state. abort, mark as fail, and go to next request - raise Exception("The migration server returned with FAILURE status. " - "Details: %s", status) + raise Exception(_("The migration server returned with FAILURE status. " + "Details: %s"), status) # Success return COMPONENT_STATUS_OK @@ -298,11 +299,12 @@ def get_resource_migration_data(nsxlib_resource, neutron_id_tags, # Make sure not to migrate multiple resources to the same policy-id if policy_id: if policy_id in policy_ids: - msg = (_("Cannot migrate %s %s to policy-id %s: Another %s " + msg = (_("Cannot migrate %(res)s %(name)s to policy-id " + "%(id)s: Another %(res)s " "has the same designated policy-id. One of those is " "probably a neutron orphaned. Please delete it and " - "try migration again.") % (printable_name, - name_and_id, policy_id, printable_name)) + "try migration again.") % {'res': printable_name, + 'name': name_and_id, 'id': policy_id}) raise Exception(msg) policy_ids.append(policy_id) @@ -319,7 +321,7 @@ def get_resource_migration_data(nsxlib_resource, neutron_id_tags, def migrate_objects(nsxlib, data, use_admin=False): if not ensure_migration_state_ready(nsxlib): - raise Exception("The migration server is not ready") + raise Exception(_("The migration server is not ready")) migration_body = {"migration_data": [data]} @@ -395,8 +397,9 @@ def migrate_resource(nsxlib, resource_type, entries, addition_size = 1 + len(entries[index].get('linked_ids', [])) if addition_size > limit: # Unsupported size of resource - raise Exception("%s size is over the allowed limit of " - "%s" % (resource_type, limit)) + raise Exception(_("%(res)s size is over the allowed limit " + "of %(lim)s") % {'res': resource_type, + 'lim': limit}) if counter + addition_size > limit: # Migrate what was accumulated so far migrate_objects(nsxlib, diff --git a/vmware_nsx/tests/unit/services/lbaas/test_nsxp_driver.py b/vmware_nsx/tests/unit/services/lbaas/test_nsxp_driver.py index 86353c7a32..8c14c926b4 100644 --- a/vmware_nsx/tests/unit/services/lbaas/test_nsxp_driver.py +++ b/vmware_nsx/tests/unit/services/lbaas/test_nsxp_driver.py @@ -14,6 +14,7 @@ # limitations under the License. import copy + import mock from neutron.tests import base