update bandit, hacking and flake8 requirements

This patch bumps the hacking, bandit and flake8 requirements to match
suit with similar work (ex [1]). It also updates the code to fix a few
new pep8 errors as well as adds a local tox target for
requirements-check-dev.

[1] https://review.opendev.org/#/c/658245/

Change-Id: I6caeb52dc1a5842338ec989a742ae5989608e0da
This commit is contained in:
Boden R 2019-05-30 13:09:17 -06:00
parent 2d68de6ce4
commit 5362c65416
26 changed files with 313 additions and 291 deletions

View File

@ -175,7 +175,7 @@ class NSXClient(object):
self.cleanup_tier1_nat_rules(rtr['id'])
try:
self.nsxpolicy.tier1.delete_locale_service(rtr['id'])
except exceptions.ManagerError as e:
except exceptions.ManagerError:
# Not always exists
pass
try:

View File

@ -253,7 +253,7 @@ class VSMClient(object):
# Query all firewall sections
response = self.get()
# Get layer3 sections related to security group
if response.status_code is 200:
if response.status_code == 200:
l3_sections = response.json()['layer3Sections']['layer3Sections']
# do not delete the default section, or sections created by the
# service composer
@ -289,7 +289,7 @@ class VSMClient(object):
self.__set_endpoint("/services/securitygroup/scope/globalroot-0")
# Query all security groups
response = self.get()
if response.status_code is 200:
if response.status_code == 200:
sg_all = response.json()
else:
print("ERROR: wrong response status code! Exiting...")
@ -323,7 +323,7 @@ class VSMClient(object):
self.__set_endpoint("/services/spoofguard/policies/")
# Query all spoofguard policies
response = self.get()
if response.status_code is not 200:
if response.status_code != 200:
print("ERROR: Faield to get spoofguard policies")
return
sgp_all = response.json()
@ -395,7 +395,7 @@ def ceil(a, b):
if b == 0:
return 0
div = a / b
mod = 0 if a % b is 0 else 1
mod = 0 if a % b == 0 else 1
return int(div + mod)

View File

@ -3,9 +3,9 @@ coverage==4.0
decorator==4.3.0
eventlet==0.24.1
fixtures==3.0.0
flake8==2.5.5
flake8-import-order==0.12
hacking==0.12.0
flake8==2.6.2
hacking==1.1.0
httplib2==0.9.1
mock==2.0.0
netaddr==0.7.18

View File

@ -1,13 +1,13 @@
# 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!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
hacking>=1.1.0 # Apache-2.0
bandit!=1.6.0,>=1.1.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
flake8>=2.6.0
flake8-import-order==0.12 # LGPLv3
mock>=2.0.0 # BSD
psycopg2>=2.7 # LGPL/ZPL
PyMySQL>=0.7.6 # MIT License
oslotest>=3.2.0 # Apache-2.0
@ -18,7 +18,6 @@ testresources>=2.0.0 # Apache-2.0/BSD
testtools>=2.2.0 # MIT
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.7.6 # GPLv2
python-openstackclient>=3.16.0 # Apache-2.0

18
tox.ini
View File

@ -126,7 +126,7 @@ 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
# Checks for coding and style guidelines
flake8 {toxinidir}/vmware_nsx
flake8
sh ./tools/coding-checks.sh --pylint '{posargs}'
neutron-db-manage --subproject vmware-nsx check_migration
{[testenv:genconfig]commands}
@ -163,7 +163,8 @@ commands = sphinx-build -b html doc/source doc/build/html
# TODO(dougwig) -- uncomment this to test for remaining linkages
# N530 direct neutron imports not allowed
# N531 translations hints
ignore = E125,E126,E128,E129,E265,H305,H307,H404,H405,H904,N530,N531
# W504 line break after binary operator
ignore = E125,E126,E128,E129,E265,H305,H307,H404,H405,H904,N530,N531,W504
show-source = true
builtins = _
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,.ropeproject
@ -205,3 +206,16 @@ deps =
[testenv:venv]
commands = {posargs}
[testenv:requirements-check-dev]
basepython = python3
commands =
pip install -q -e "git+https://opendev.org/openstack/requirements#egg=requirements"
pip freeze
# must have openstack/requirements on latest src/master in ../requirements
{toxinidir}/../requirements/playbooks/files/project-requirements-change.py --reqs={toxinidir}/../requirements {toxinidir}
deps =
-c{toxinidir}/lower-constraints.txt
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/doc/requirements.txt
-r{toxinidir}/requirements.txt

View File

@ -152,5 +152,6 @@ class EventletApiClient(base.ApiClientBase):
return cookie
# Register as subclass.
base.ApiClientBase.register(EventletApiClient)

View File

@ -45,7 +45,8 @@ class DhcpAgentNotifyAPI(dhcp_rpc_agent_api.DhcpAgentNotifyAPI):
if lsn_exists:
# if lsn exists, the network is one created with the new model
if (resource == 'subnet' and action == 'create' and
const.DEVICE_OWNER_DHCP not in plugin.port_special_owners):
const.DEVICE_OWNER_DHCP not in
plugin.port_special_owners):
# network/subnet provisioned in the new model have a plain
# nsx lswitch port, no vif attachment
plugin.port_special_owners.append(const.DEVICE_OWNER_DHCP)

View File

@ -84,9 +84,9 @@ def format_exception(etype, e, exception_locals):
"""
msg = [_("Error. %(type)s exception: %(exc)s.") %
{'type': etype, 'exc': e}]
l = dict((k, v) for k, v in six.iteritems(exception_locals)
lcls = dict((k, v) for k, v in six.iteritems(exception_locals)
if k != 'request')
msg.append(_("locals=[%s]") % str(l))
msg.append(_("locals=[%s]") % str(lcls))
return ' '.join(msg)

View File

@ -1555,6 +1555,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
if (actions['remove_router_link_port'] or
actions['add_router_link_port']):
# GW was changed. update GW and route advertisement
# pylint: disable=unexpected-keyword-arg
self.nsxpolicy.tier1.update_route_advertisement(
router_id,
nat=actions['advertise_route_nat_flag'],

View File

@ -1000,7 +1000,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
if self._vcm:
try:
h, switch = self.nsx_v.vcns.get_vdn_switch(dvs_id)
except Exception as e:
except Exception:
LOG.warning('DVS %s not registered on NSX. Unable to '
'update teaming for network %s',
dvs_id, net_id)
@ -1362,9 +1362,9 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
# requires allowing multiple or cidr-based allowed address pairs
# defined per port but doesn't want to disable spoofguard globally
sg_policy_id = None
allow_multiple_addresses = (not net_data[psec.PORTSECURITY]
and cfg.CONF.nsxv.
allow_multiple_ip_addresses)
allow_multiple_addresses = (not net_data[psec.PORTSECURITY] and
cfg.CONF.
nsxv.allow_multiple_ip_addresses)
if (cfg.CONF.nsxv.spoofguard_enabled and backend_network and not
allow_multiple_addresses):
# This variable is set as the method below may result in a

View File

@ -660,6 +660,7 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
def _init_mac_learning_profiles(self):
with locking.LockManager.get_lock('nsxv3_mac_learning_profile_init'):
if not self._get_mac_learning_profile():
# pylint: disable=unexpected-keyword-arg
self.nsxlib.switching_profile.create_mac_learning_profile(
NSX_V3_MAC_LEARNING_PROFILE_NAME,
'Neutron MAC Learning Profile',
@ -667,6 +668,7 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
tags=self.nsxlib.build_v3_api_version_tag())
self._get_mac_learning_profile()
if not self._get_mac_learning_disabled_profile():
# pylint: disable=unexpected-keyword-arg
self.nsxlib.switching_profile.create_mac_learning_profile(
NSX_V3_MAC_DISABLED_PROFILE_NAME,
'Neutron MAC Learning Disabled Profile',

View File

@ -104,8 +104,9 @@ class EdgeListenerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager):
ssl_profile_binding = self._upload_certificate(
listener['id'], listener['default_tls_container_id'], tags,
certificate=certificate)
if (listener['protocol'] == lb_const.LB_PROTOCOL_TERMINATED_HTTPS
and ssl_profile_binding):
if (listener['protocol'] ==
lb_const.LB_PROTOCOL_TERMINATED_HTTPS and
ssl_profile_binding):
kwargs.update(ssl_profile_binding)
waf_profile, mode = self.core_plugin.get_waf_profile_path_and_mode()

View File

@ -343,6 +343,7 @@ def nsx_fix_name_mismatch(resource, event, trigger, **kwargs):
'Edge %s has no backup prefix on NSX', edge_id)
return
registry.subscribe(nsx_list_backup_edges,
constants.BACKUP_EDGES,
shell.Operations.LIST.value)

View File

@ -327,7 +327,7 @@ def change_edge_ha(ha, edge_id):
'enabled': ha}
try:
nsxv.enable_ha(edge_id, request)
except nsxv_exceptions.ResourceNotFound as e:
except nsxv_exceptions.ResourceNotFound:
LOG.error("Edge %s not found", edge_id)
except exceptions.NeutronException as e:
LOG.error("%s", str(e))
@ -353,7 +353,7 @@ def change_edge_syslog(properties):
edge_id = properties.get('edge-id')
try:
nsxv.update_edge_syslog(edge_id, request)
except nsxv_exceptions.ResourceNotFound as e:
except nsxv_exceptions.ResourceNotFound:
LOG.error("Edge %s not found", edge_id)
except exceptions.NeutronException as e:
LOG.error("%s", str(e))
@ -362,7 +362,7 @@ def change_edge_syslog(properties):
def delete_edge_syslog(edge_id):
try:
nsxv.delete_edge_syslog(edge_id)
except nsxv_exceptions.ResourceNotFound as e:
except nsxv_exceptions.ResourceNotFound:
LOG.error("Edge %s not found", edge_id)
except exceptions.NeutronException as e:
LOG.error("%s", str(e))
@ -404,7 +404,7 @@ def change_edge_loglevel(properties):
try:
edge_utils.update_edge_loglevel(nsxv, edge_id, module, level)
except nsxv_exceptions.ResourceNotFound as e:
except nsxv_exceptions.ResourceNotFound:
LOG.error("Edge %s not found", edge_id)
except exceptions.NeutronException as e:
LOG.error("%s", str(e))
@ -422,7 +422,7 @@ def change_edge_appliance_size(properties):
try:
nsxv.change_edge_appliance_size(
properties.get('edge-id'), size)
except nsxv_exceptions.ResourceNotFound as e:
except nsxv_exceptions.ResourceNotFound:
LOG.error("Edge %s not found", properties.get('edge-id'))
except exceptions.NeutronException as e:
LOG.error("%s", str(e))
@ -462,7 +462,7 @@ def change_edge_appliance(edge_id):
request = {'appliances': appliances, 'applianceSize': size}
try:
nsxv.change_edge_appliance(edge_id, request)
except nsxv_exceptions.ResourceNotFound as e:
except nsxv_exceptions.ResourceNotFound:
LOG.error("Edge %s not found", edge_id)
except exceptions.NeutronException as e:
LOG.error("%s", str(e))
@ -503,7 +503,7 @@ def change_edge_appliance_reservations(properties):
request = {'appliances': appliances}
try:
nsxv.change_edge_appliance(edge_id, request)
except nsxv_exceptions.ResourceNotFound as e:
except nsxv_exceptions.ResourceNotFound:
LOG.error("Edge %s not found", edge_id)
except exceptions.NeutronException as e:
LOG.error("%s", str(e))

View File

@ -71,6 +71,7 @@ class Operations(enum.Enum):
VALIDATE = 'validate'
REUSE = 'reuse'
ops = [op.value for op in Operations]

View File

@ -552,8 +552,8 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
'provider:physical_network': 'xxx',
'qos_policy_id': policy_id,
'port_security_enabled': False}}
with mock_ens, mock_tz, mock_tt,\
mock.patch.object(self.plugin, '_validate_qos_policy_id'):
with mock_ens, mock_tz, mock_tt, mock.patch.object(
self.plugin, '_validate_qos_policy_id'):
self.assertRaises(n_exc.InvalidInput,
self.plugin.create_network,
context.get_admin_context(), data)
@ -1660,10 +1660,10 @@ class NsxPTestL3NatTestCase(NsxPTestL3NatTest,
"NsxPolicySegmentApi.update") as seg_update:
with self.router() as r, self.network() as n:
with self.subnet(network=n, cidr='fd00::0/64',
gateway_ip='fd00::1', ip_version=6,
enable_dhcp=False) as s6, \
self.subnet(network=n, cidr='2.0.0.0/24',
with self.subnet(
network=n, cidr='fd00::0/64', gateway_ip='fd00::1',
ip_version=6, enable_dhcp=False) as s6, self.subnet(
network=n, cidr='2.0.0.0/24',
gateway_ip='2.0.0.1') as s4:
subnets = []
@ -2031,16 +2031,15 @@ class NsxPTestL3NatTestCase(NsxPTestL3NatTest,
path_prefix = ("/infra/sites/default/enforcement-points/default/"
"edge-clusters/")
# create a router and external network
with self.router() as r,\
self._create_l3_ext_network() as ext_net,\
self.subnet(network=ext_net, cidr='10.0.1.0/24',
enable_dhcp=False) as s,\
mock.patch("vmware_nsxlib.v3.policy.core_resources."
with self.router() as r, self._create_l3_ext_network() as ext_net, \
self.subnet(
network=ext_net, cidr='10.0.1.0/24',
enable_dhcp=False) as s, mock.patch(
"vmware_nsxlib.v3.policy.core_resources."
"NsxPolicyTier1Api.get_edge_cluster_path",
return_value=False),\
mock.patch("vmware_nsxlib.v3.policy.core_resources."
"NsxPolicyTier1Api.set_edge_cluster_path"
) as add_srv_router:
return_value=False), mock.patch(
"vmware_nsxlib.v3.policy.core_resources."
"NsxPolicyTier1Api.set_edge_cluster_path") as add_srv_router:
self._add_external_gateway_to_router(
r['router']['id'],
s['subnet']['network_id'])
@ -2133,8 +2132,8 @@ class NsxPTestL3NatTestCase(NsxPTestL3NatTest,
with self.router() as r:
self._router_interface_action('add', r['router']['id'],
None, port_id)
with self.external_network() as public_net,\
self.subnet(network=public_net, cidr='12.0.0.0/24',
with self.external_network() as public_net, self.subnet(
network=public_net, cidr='12.0.0.0/24',
enable_dhcp=False) as public_sub:
self._add_external_gateway_to_router(
r['router']['id'],
@ -2156,8 +2155,8 @@ class NsxPTestL3NatTestCase(NsxPTestL3NatTest,
with self.router() as r:
self._router_interface_action('add', r['router']['id'],
None, port_id)
with self.external_network() as public_net,\
self.subnet(network=public_net, cidr='12.0.0.0/24',
with self.external_network() as public_net, self.subnet(
network=public_net, cidr='12.0.0.0/24',
enable_dhcp=False) as public_sub:
self._add_external_gateway_to_router(
r['router']['id'],

View File

@ -2697,10 +2697,12 @@ class L3NatTestCaseBase(test_l3_plugin.L3NatTestCaseMixin):
to a router places them all on the same router interface.
"""
with self.router() as r, self.network() as n:
with (self.subnet(network=n, cidr='fd00::1/64',
enable_dhcp=False, ip_version=6)
) as s1, self.subnet(network=n, cidr='fd01::1/64',
with self.subnet(
network=n, cidr='fd00::1/64',
enable_dhcp=False, ip_version=6) as s1, self.subnet(
network=n, cidr='fd01::1/64',
ip_version=6, enable_dhcp=False) as s2:
body = self._router_interface_action('add',
r['router']['id'],
s1['subnet']['id'],

View File

@ -996,7 +996,7 @@ class FakeVcns(object):
_section = self._sections[section_id]
if (_section['name'] != section_name and
section_name in self._sections['names']):
# Theres a section with this name already
# There's a section with this name already
headers, response = self._unknown_error()
else:
# Different Etag every successful update

View File

@ -590,8 +590,8 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
'provider:physical_network': 'xxx',
'qos_policy_id': policy_id,
'port_security_enabled': False}}
with mock_ens, mock_tz, mock_tt,\
mock.patch.object(self.plugin, '_validate_qos_policy_id'):
with mock_ens, mock_tz, mock_tt, mock.patch.object(
self.plugin, '_validate_qos_policy_id'):
self.assertRaises(n_exc.InvalidInput,
self.plugin.create_network,
context.get_admin_context(), data)
@ -720,8 +720,9 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
pnet.PHYSICAL_NETWORK:
'fb69d878-958e-4f32-84e4-50286f26226b'}
with mock.patch('vmware_nsxlib.v3.core_resources.NsxLibTransportZone.'
'get_transport_type', return_value='VLAN'):
gtt_path = "vmware_nsxlib.v3.core_resources." \
"NsxLibTransportZone.get_transport_type"
with mock.patch(gtt_path, return_value='VLAN'):
with self.network(name=name, providernet_args=providernet_args,
arg_list=(pnet.NETWORK_TYPE,
pnet.PHYSICAL_NETWORK)) as net:
@ -1069,9 +1070,10 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
self.plugin.update_port, self.ctx, port['id'], data)
def test_fail_create_allowed_address_pairs_over_limit(self):
with self.network() as network,\
self.subnet(network=network, enable_dhcp=True) as s1:
data = {'port': {
with self.network() as network, self.subnet(
network=network, enable_dhcp=True) as s1:
data = {
'port': {
'network_id': network['network']['id'],
'tenant_id': self._tenant_id,
'name': 'pair_port',
@ -1084,8 +1086,7 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
count = 1
address_pairs = []
while count < 129:
address_pairs.append({'ip_address': '10.0.0.%s' %
count})
address_pairs.append({'ip_address': '10.0.0.%s' % count})
count += 1
data['port']['allowed_address_pairs'] = address_pairs
self.assertRaises(n_exc.InvalidInput,
@ -3176,8 +3177,7 @@ class TestL3NatTestCase(L3NatTest,
with self.router() as r:
self._router_interface_action('add', r['router']['id'],
None, port_id)
with self.external_network() as public_net,\
self.subnet(
with self.external_network() as public_net, self.subnet(
network=public_net, cidr='12.0.0.0/24') as public_sub:
self._add_external_gateway_to_router(
r['router']['id'],
@ -3199,8 +3199,7 @@ class TestL3NatTestCase(L3NatTest,
with self.router() as r:
self._router_interface_action('add', r['router']['id'],
None, port_id)
with self.external_network() as public_net,\
self.subnet(
with self.external_network() as public_net, self.subnet(
network=public_net, cidr='12.0.0.0/24') as public_sub:
self._add_external_gateway_to_router(
r['router']['id'],

View File

@ -252,9 +252,9 @@ class TestQosNsxPNotification(base.BaseQosTestCase,
self.ctxt, **self.policy_data['policy'])
# add a rule to the policy
setattr(_policy, "rules", [rule])
with mock.patch.object(QoSPolicy, 'get_object',
return_value=_policy),\
mock.patch('neutron.objects.db.api.update_object',
with mock.patch.object(
QoSPolicy, 'get_object', return_value=_policy), mock.patch(
'neutron.objects.db.api.update_object',
return_value=rule_data):
self.assertRaises(
exceptions.DriverCallError,

View File

@ -266,9 +266,9 @@ class TestQosNsxV3Notification(base.BaseQosTestCase,
self.ctxt, **self.policy_data['policy'])
# add a rule to the policy
setattr(_policy, "rules", [rule])
with mock.patch.object(QoSPolicy, 'get_object',
return_value=_policy),\
mock.patch('neutron.objects.db.api.update_object',
with mock.patch.object(
QoSPolicy, 'get_object', return_value=_policy), mock.patch(
'neutron.objects.db.api.update_object',
return_value=rule_data):
self.assertRaises(
exceptions.DriverCallError,
@ -325,9 +325,9 @@ class TestQosNsxV3Notification(base.BaseQosTestCase,
# add a rule to the policy
setattr(policy, "rules", [min_bw_rule])
with mock.patch.object(
QoSPolicy, 'get_object', return_value=policy),\
mock.patch('neutron.objects.db.api.'
'update_object', return_value=self.dscp_rule_data):
QoSPolicy, 'get_object', return_value=policy), mock.patch(
'neutron.objects.db.api.update_object',
return_value=self.dscp_rule_data):
self.assertRaises(
exceptions.DriverCallError,
self.qos_plugin.update_policy_minimum_bandwidth_rule,

View File

@ -315,16 +315,16 @@ class TestDriverValidation(base.BaseTestCase):
else:
return connections
with mock.patch.object(self.validator.vpn_plugin, '_get_vpnservice',
side_effect=mock_get_service),\
mock.patch.object(self.validator._core_plugin, 'get_routers',
side_effect=mock_get_routers),\
mock.patch.object(self.validator._core_plugin,
'_find_router_subnets_cidrs',
return_value=router_subnets),\
mock.patch.object(self.validator.vpn_plugin,
'get_ipsec_site_connections',
with mock.patch.object(
self.validator.vpn_plugin, '_get_vpnservice',
side_effect=mock_get_service), mock.patch.object(
self.validator._core_plugin, 'get_routers',
side_effect=mock_get_routers), mock.patch.object(
self.validator._core_plugin, '_find_router_subnets_cidrs',
return_value=router_subnets), mock.patch.object(
self.validator.vpn_plugin, 'get_ipsec_site_connections',
side_effect=mock_get_connections):
ipsec_sitecon = {'id': '1',
'vpnservice_id': '1',
'mtu': 1500,
@ -705,7 +705,8 @@ class TestVpnaasDriver(test_plugin.NsxV3PluginTestCaseMixin):
with mock.patch.object(
self.nsxlib_vpn.service, 'list',
return_value={'results': nsx_services}),\
mock.patch.object(self.service_plugin, 'get_vpnservices',
mock.patch.object(
self.service_plugin, 'get_vpnservices',
return_value=[{'id': 'dummy', 'router_id': 'dummy'}]),\
mock.patch.object(self.nsxlib_vpn.service,
'delete') as delete_service: