Browse Source

Bring hacking up to spec

Our version of hacking was ancient, and it loads a pep8 check that
is both very inconsistent in reporting errors and has weaker
constraints.  Fix the pep8 errors revealed and disable some of the
irrelevant tests in tox.ini.

Change-Id: I4ca71aa88456e4ac2baf0cfb3ac058b0a19e3b6b
changes/58/742958/1
Ian Wells 1 year ago
parent
commit
ef2b77f99b
  1. 1
      devstack/make-config.py
  2. 2
      networking_vpp/_i18n.py
  3. 1
      networking_vpp/agent/gpe.py
  4. 20
      networking_vpp/agent/network_interface.py
  5. 11
      networking_vpp/agent/server.py
  6. 50
      networking_vpp/agent/taas_vpp_agent.py
  7. 2
      networking_vpp/agent/vpp.py
  8. 28
      networking_vpp/compat.py
  9. 2
      networking_vpp/etcdutils.py
  10. 14
      networking_vpp/mech_vpp.py
  11. 2
      networking_vpp/tests/unit/test_etcdcom.py
  12. 6
      networking_vpp/tests/unit/test_utils.py
  13. 12
      networking_vpp/tests/unit/test_vppforwarder.py
  14. 1
      networking_vpp/tools/dump_acl_info.py
  15. 1
      networking_vpp/tools/dump_tag_info.py
  16. 1
      networking_vpp/tools/test_etcd_content.py
  17. 2
      networking_vpp/tools/test_vpp_content.py
  18. 1
      networking_vpp/tools/watch_changes.py
  19. 2
      test-requirements.txt
  20. 7
      tox.ini

1
devstack/make-config.py

@ -41,6 +41,7 @@ def overlay_struct(base, add):
out = copy.copy(add)
return out
for f in sys.argv[1:]:
with open(f) as inf:
overlay = yaml.safe_load(inf)

2
networking_vpp/_i18n.py

@ -42,4 +42,4 @@ _LC = _translators.log_critical
def get_available_languages():
return oslo_i18n.get_available_languages(DOMAIN)
return oslo_i18n.get_available_languages(DOMAIN)

1
networking_vpp/agent/gpe.py

@ -327,6 +327,7 @@ class GPEForwarder(object):
LOG.debug('Successfully created a GPE lookup map by querying vpp %s',
self.gpe_map)
GPE_KEY_SPACE = LEADIN + "/global/networks/gpe"

20
networking_vpp/agent/network_interface.py

@ -19,12 +19,13 @@ from networking_vpp.agent import server
from networking_vpp.extension import VPPAgentExtensionBase
from oslo_config import cfg
from oslo_log import log as logging
import sys
import stevedore.driver
import sys
from typing import Dict
LOG = logging.getLogger(__name__)
# TODO(ijw): is this an agent extension? Unclear, but it would be
# nice if it worked out the dependency needs since other extensions
# might depend on it
@ -291,7 +292,6 @@ class BadDriver(Exception):
class NetworkInterfaceDriver(object):
"""A Driver that loads and manages all network types"""
# Class Attributes VPPF and VPP are set on driver init
def __init__(self, vppf):
@ -299,7 +299,8 @@ class NetworkInterfaceDriver(object):
self.vpp = vppf.vpp
# dict is populated when net_types register with the driver
self.net_types: Dict[str, GenericNetworkType] = {} # Network-Type: DriverObj
# Network-Type: DriverObj
self.net_types: Dict[str, GenericNetworkType] = {}
# Register network types with the Driver
self.register_network_types()
@ -316,8 +317,8 @@ class NetworkInterfaceDriver(object):
# Record any driver loading problems so we see them all together
add_failure(
'%s: failed to load %s: %s' % (mgr.namespace,
entrypoint,
ex))
entrypoint,
ex))
drivers_to_load = cfg.CONF.ml2_vpp.network_types.split(',')
drivers_to_load = [f.strip().rstrip()
@ -342,11 +343,12 @@ class NetworkInterfaceDriver(object):
self.net_types[name] = driver
LOG.info("Loaded driver %s", name)
except stevedore.exception.NoMatches as e:
except stevedore.exception.NoMatches:
add_failure('Cannot find VPP network driver %s' % name)
except stevedore.exception.MultipleMatches as e:
add_failure('Multiple copies of VPP network driver %s available'
% name)
except stevedore.exception.MultipleMatches:
add_failure(
'Multiple copies of VPP network driver %s available'
% name)
if failure['msg'] != '':
raise BadDriver(failure['msg'])

11
networking_vpp/agent/server.py

@ -166,9 +166,9 @@ def ipint(ip):
######################################################################
# This mirrors functionality in Neutron so that we're creating a name
# that Neutron can find for its agents.
DEV_NAME_PREFIX = n_const.TAP_DEVICE_PREFIX
######################################################################
@ -289,6 +289,7 @@ def DIRECTION_TAG(tag, is_vm_ingress):
else:
return VM_TO_VPP_TAG(tag)
COMMON_SPOOF_TAG = VPP_TAG('common_spoof')
COMMON_SPOOF_VPP_TO_VM_TAG = VPP_TO_VM_TAG(COMMON_SPOOF_TAG)
COMMON_SPOOF_VM_TO_VPP_TAG = VM_TO_VPP_TAG(COMMON_SPOOF_TAG)
@ -312,6 +313,7 @@ def decode_common_spoof_tag(tag):
return None
SECGROUP_TAG = VPP_TAG('secgroup:')
@ -2185,9 +2187,9 @@ class VPPForwarder(object):
for router in self.router_external_interfaces.values():
if ipaddr(router['gateway_ip']) == \
ipaddr(local_ip):
router['is_local'] = 0
LOG.debug('Router external %s is no longer a local '
'route but now assigned to the BVI', router)
router['is_local'] = 0
LOG.debug('Router external %s is no longer a local '
'route but now assigned to the BVI', router)
else:
# At this point, we can safetly remove both the SNAT and BVI
# loopback interfaces as no local routes exist.
@ -3746,5 +3748,6 @@ def main():
ops.process_ops()
if __name__ == '__main__':
main()

50
networking_vpp/agent/taas_vpp_agent.py

@ -590,31 +590,31 @@ class TaasFlowAgentWatcher(etcdutils.EtcdChangeWatcher):
span_mode = tap_flow_info['span_mode']
if span_mode == 3: # ERSPAN
dest_type = tap_flow_info['tf']['dest_type']
dst_idx = tap_flow_info['dst_idx']
source_port_idx = tap_flow_info['port_idx']
self.vppf.vpp.disable_port_mirroring(source_port_idx,
dst_idx)
if dest_type == 'ERSPAN_INT':
self.vppf.vpp.delete_from_bridge(dst_idx)
taas_id = tap_flow_info['tf']['taas_id']
tf_host = tap_flow_info['tf']['tf_host']
ts_host = tap_flow_info['ts_host']
session_id = tap_flow_info['session_id']
dst_addr = tap_flow_info['dst_adr']
src_addr = self.esp_src_addr
self._delete_erspan_tunnel(src_addr, dst_addr, session_id)
if dest_type == 'ERSPAN_INT':
tf_nb = self._get_num_flow(tf_host, taas_id)
if tf_nb == 0:
loop_idx = tap_flow_info['loop_idx']
self.vppf.vpp.delete_loopback(loop_idx)
if tf_host != ts_host:
physnet = tap_flow_info['physnet']
net_type = 'vlan'
seg_id = taas_id
self.vppf.net_driver.delete_network(
physnet, net_type, seg_id)
dest_type = tap_flow_info['tf']['dest_type']
dst_idx = tap_flow_info['dst_idx']
source_port_idx = tap_flow_info['port_idx']
self.vppf.vpp.disable_port_mirroring(source_port_idx,
dst_idx)
if dest_type == 'ERSPAN_INT':
self.vppf.vpp.delete_from_bridge(dst_idx)
taas_id = tap_flow_info['tf']['taas_id']
tf_host = tap_flow_info['tf']['tf_host']
ts_host = tap_flow_info['ts_host']
session_id = tap_flow_info['session_id']
dst_addr = tap_flow_info['dst_adr']
src_addr = self.esp_src_addr
self._delete_erspan_tunnel(src_addr, dst_addr, session_id)
if dest_type == 'ERSPAN_INT':
tf_nb = self._get_num_flow(tf_host, taas_id)
if tf_nb == 0:
loop_idx = tap_flow_info['loop_idx']
self.vppf.vpp.delete_loopback(loop_idx)
if tf_host != ts_host:
physnet = tap_flow_info['physnet']
net_type = 'vlan'
seg_id = taas_id
self.vppf.net_driver.delete_network(
physnet, net_type, seg_id)
else:
tfn = tap_flow_info['tfn']
if tfn:

2
networking_vpp/agent/vpp.py

@ -226,7 +226,7 @@ class VPPInterface(object):
# being backwards compatible.
try:
func_call = getattr(self._vpp.api, func)
except AttributeError as e:
except AttributeError:
func_call = getattr(self._vpp, func)
# There should not be a need for the debug logs but just in case
# there is just uncomment them below:

28
networking_vpp/compat.py

@ -41,11 +41,12 @@ except ImportError:
import neutron.context
context = neutron.context
try:
from neutron_lib.api.definitions import provider_net as n_provider
from neutron_lib.api.definitions import provider_net as n_provider
except ImportError:
# Newton, at least, has this:
from neutron.extensions import providernet as n_provider
# Newton, at least, has this:
from neutron.extensions import providernet as n_provider # noqa: F401
try:
# Mitaka+
@ -83,9 +84,9 @@ try:
from neutron.callbacks import resources
except ImportError:
# Queens+
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib.callbacks import events # noqa: F401
from neutron_lib.callbacks import registry # noqa: F401
from neutron_lib.callbacks import resources # noqa: F401
try:
# Newton+
@ -112,7 +113,7 @@ try:
except ImportError:
# Stein onwards
from neutron_lib.db import api as neutron_db_api
from neutron_lib.db import resource_extend
from neutron_lib.db import resource_extend # noqa: F401
db_context_writer = neutron_db_api.CONTEXT_WRITER
db_context_reader = neutron_db_api.CONTEXT_READER
@ -124,6 +125,7 @@ try:
except ImportError:
# Map changed trunk constants in Train
from neutron_lib.services.trunk import constants
class new_trunk_const(object):
VLAN = constants.SEGMENTATION_TYPE_VLAN
TRUNK = 'trunk'
@ -144,6 +146,7 @@ except AttributeError:
# Rocky
n_const.L3 = neutron_lib.plugins.constants.L3
# Register security group option
def register_securitygroups_opts(cfg):
# Mitaka compatibility
@ -162,6 +165,7 @@ def register_securitygroups_opts(cfg):
hasattr(cfg.CONF.SECURITYGROUP.enable_security_group)):
cfg.register_opts(security_group_opts, 'SECURITYGROUP')
def register_ml2_base_opts(cfg):
try:
# Older
@ -172,22 +176,24 @@ def register_ml2_base_opts(cfg):
from neutron.conf.plugins.ml2 import config
config.register_ml2_plugin_opts(cfg)
try:
# (for, specifically, get_random_mac)
# Newer:
from neutron_lib.utils import net as net_utils
if not hasattr(net_utils,'get_random_mac'): # Check for Newton
if not hasattr(net_utils, 'get_random_mac'): # Check for Newton
raise AttributeError
except (ImportError, AttributeError):
# Older:
from neutron.common import utils as net_utils
assert hasattr(net_utils,'get_random_mac') == True
assert hasattr(net_utils, 'get_random_mac') is True
try:
from neutron.plugins.ml2 import driver_api
except:
except ImportError:
# Between Pike and Queens
from neutron_lib.plugins.ml2 import api as driver_api
from neutron_lib.plugins.ml2 import api as driver_api # noqa: F401
import os
import re

2
networking_vpp/etcdutils.py

@ -797,8 +797,8 @@ class EtcdHelper(object):
# Already gone, so not a problem
pass
# Base connection to etcd, using standard options.
# Base connection to etcd, using standard options.
_etcd_conn_opts = [
cfg.StrOpt('etcd_host', default="127.0.0.1",
help=_("Etcd host IP address(es) to connect etcd client."

14
networking_vpp/mech_vpp.py

@ -64,7 +64,7 @@ class VPPMechanismDriver(api.MechanismDriver):
self.communicator = EtcdAgentCommunicator(self.port_bind_complete)
names = names = cfg.CONF.ml2_vpp.driver_extensions
if names is not '':
if names != '':
self.mgr = ExtensionManager(
'networking_vpp.driver.extensions',
names,
@ -289,12 +289,12 @@ class VPPMechanismDriver(api.MechanismDriver):
port_context.original['binding:profile'] and
port_context.original['binding:profile']['migrating_to']
== port_context.host):
self.communicator.unbind(
port_context._plugin_context.session,
port_context.original,
port_context.original_host,
current_bind[api.BOUND_SEGMENT]
)
self.communicator.unbind(
port_context._plugin_context.session,
port_context.original,
port_context.original_host,
current_bind[api.BOUND_SEGMENT]
)
def port_bind_complete(self, port_id, host):
"""Tell things that the port is truly bound.

2
networking_vpp/tests/unit/test_etcdcom.py

@ -32,8 +32,6 @@ FAKE_PORT = {'status': 'DOWN',
'fixed_ips': [],
'id': '1',
'security_groups': [],
'allowed_address_pairs': [],
'fixed_ips': [],
'device_id': 'fake_device',
'name': '',
'admin_state_up': True,

6
networking_vpp/tests/unit/test_utils.py

@ -37,11 +37,11 @@ class FakeConfig(object):
class TestAgentUtils(base.BaseTestCase):
def parse_config_test_run(self, host, port, user=None, pw=None):
fk = FakeConfig(host, port, user, pw)
fk = FakeConfig(host, port, user, pw)
cf = etcdutils.EtcdClientFactory(fk)
cf = etcdutils.EtcdClientFactory(fk)
return cf.etcd_args['host']
return cf.etcd_args['host']
def test_pass_user_password(self):
# The defaults

12
networking_vpp/tests/unit/test_vppforwarder.py

@ -682,14 +682,14 @@ class VPPForwarderTestCase(base.BaseTestCase):
return_value=5):
with mock.patch.object(self.vpp.vpp, 'get_snat_interfaces',
return_value=[5]):
with mock.patch.object(
self.vpp.vpp, 'get_interface_ip_addresses',
with mock.patch.object(
self.vpp.vpp, 'get_interface_ip_addresses',
return_value=[(ip_address(six.text_type(interface_ip)),
prefixlen)]):
self.vpp.ensure_router_interface_on_host(
uuidgen.uuid1(), router)
self.vpp.vpp.set_snat_on_interface.assert_not_called()
self.vpp.vpp.set_interface_ip.assert_not_called()
self.vpp.ensure_router_interface_on_host(
uuidgen.uuid1(), router)
self.vpp.vpp.set_snat_on_interface.assert_not_called()
self.vpp.vpp.set_interface_ip.assert_not_called()
def test_delete_router_external_gateway_on_host(self):
router_port = self._get_mock_router_external_interface()

1
networking_vpp/tools/dump_acl_info.py

@ -234,5 +234,6 @@ def main():
rule["tcp_flags_mask"],
rule["tcp_flags_value"]))
if __name__ == '__main__':
main()

1
networking_vpp/tools/dump_tag_info.py

@ -111,5 +111,6 @@ def main():
intf['name'],
intf['tag']))
if __name__ == '__main__':
main()

1
networking_vpp/tools/test_etcd_content.py

@ -109,5 +109,6 @@ def main():
print('OK: key belongs to known port')
port_paths.remove(k)
if __name__ == '__main__':
main()

2
networking_vpp/tools/test_vpp_content.py

@ -42,6 +42,7 @@ binding_host = sys.argv[1]
def VPP_TAG(tag):
return 'net-vpp.' + tag
# MAX_PHYSNET_LENGTH + the tag format must be <= the 64 bytes of a VPP tag
MAX_PHYSNET_LENGTH = 32
TAG_PHYSNET_IF_PREFIX = VPP_TAG('physnet:')
@ -193,5 +194,6 @@ def main():
# Do ports have the right ACLs bound?
if __name__ == '__main__':
main()

1
networking_vpp/tools/watch_changes.py

@ -54,5 +54,6 @@ def main():
# out of history
pass
if __name__ == '__main__':
main()

2
test-requirements.txt

@ -2,7 +2,7 @@
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
hacking<0.11,>=0.10.0
hacking>=3.0.1,<3.1.0
coverage>=3.6 # Apache-2.0
discover # BSD

7
tox.ini

@ -80,6 +80,11 @@ show-source = True
# N531 deals with translation hints and is contraindicated by newer
# versions, but we sometimes want to work with older versions.
# Excluding 531 keeps them sane.
ignore = E123,E125,N530,N531
# We don'y care i there are CRs before or after binary operators
# (though it's hard to pass both simultaneously!) - W503/4 are off for
# this reason.
# E402 - imports at top of files - spoils the compat file and messes
# up eventlet patching
ignore = E123,E125,N530,N531,W503,W504, E402
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,.tmp
Loading…
Cancel
Save