Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeCheck - Part2b #3907

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clib/clib_mininet_test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def expand_tests(modules, requested_test_classes, regex_test_classes, excluded_t
return (sanity_tests, single_tests, parallel_tests)


class FaucetResult(unittest.runner.TextTestResult): # pytype: disable=module-attr
class FaucetResult(unittest.runner.TextTestResult): # pytype: disable=module-attr

root_tmpdir = None
test_duration_secs = {}
Expand Down
24 changes: 12 additions & 12 deletions clib/docker_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DockerHost(Host):
pollOut = None
stdout = None
execed = None
lastCmd = None # pylint: disable=invalid-name
lastCmd = None # pylint: disable=invalid-name
readbuf = None
lastPid = None
pid = None
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, name, image=None, tmpdir=None, prefix=None, env_vars=None, vo
self.pullImage()
Host.__init__(self, name, **kwargs)

def pullImage(self): # pylint: disable=invalid-name
def pullImage(self): # pylint: disable=invalid-name
"Pull docker image if necessary"
if self.image not in quietRun('docker images'):
error('%s: docker image' % self.name, self.image,
Expand Down Expand Up @@ -112,15 +112,15 @@ def startShell(self, mnopts=None):
self.shell = self._popen(cmd, stdin=self.slave, stdout=self.slave, stderr=self.slave)
self.stdin = os.fdopen(self.master, 'r')
self.stdout = self.stdin
self.pollOut = select.poll() # pylint: disable=invalid-name
self.pollOut.register(self.stdout) # pylint: disable=no-member
self.outToNode[self.stdout.fileno()] = self # pylint: disable=no-member
self.pollIn = select.poll() # pylint: disable=invalid-name
self.pollIn.register(self.stdout, select.POLLIN) # pylint: disable=no-member
self.inToNode[self.stdin.fileno()] = self # pylint: disable=no-member
self.pollOut = select.poll() # pylint: disable=invalid-name
self.pollOut.register(self.stdout) # pylint: disable=no-member
self.outToNode[self.stdout.fileno()] = self # pylint: disable=no-member
self.pollIn = select.poll() # pylint: disable=invalid-name
self.pollIn.register(self.stdout, select.POLLIN) # pylint: disable=no-member
self.inToNode[self.stdin.fileno()] = self # pylint: disable=no-member
self.execed = False
self.lastCmd = None # pylint: disable=invalid-name
self.lastPid = None # pylint: disable=invalid-name
self.lastCmd = None # pylint: disable=invalid-name
self.lastPid = None # pylint: disable=invalid-name
self.readbuf = ''
self.waiting = True
data = ''
Expand All @@ -141,7 +141,7 @@ def startShell(self, mnopts=None):
self.pid = self.inspect_pid()
debug("Container %s created pid %s/%s." % (self.container, self.pid, self.shell.pid))

self.cmd('unset HISTFILE; stty -echo; set +m') # pylint: disable=no-member
self.cmd('unset HISTFILE; stty -echo; set +m') # pylint: disable=no-member

def kill(self, purge=False):
"""Kill a container."""
Expand Down Expand Up @@ -261,7 +261,7 @@ def terminate(self):
if self.active_log:
self.active_log.close()
self.active_log = None
self.cleanup() # pylint: disable=no-member
self.cleanup() # pylint: disable=no-member
return self.active_pipe_returncode

def popen(self, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions clib/mininet_test_topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def _add_cargs(self, cargs, name):
socket_type = socket.AF_INET
if self.controller_ipv6:
socket_type = socket.AF_INET6
self.controller_ip = netifaces.ifaddresses( # pylint: disable=c-extension-no-member
self.controller_ip = netifaces.ifaddresses( # pylint: disable=c-extension-no-member
self.controller_intf)[socket_type][0]['addr']
ofp_listen_host_arg = '--ryu-ofp-listen-host=%s' % self.controller_ip
self.pid_file = os.path.join(self.tmpdir, name + '.pid')
Expand All @@ -470,7 +470,7 @@ def _start_tcpdump(self):
'-n',
'-U',
'-q',
'-W 1', # max files 1
'-W 1', # max files 1
'-G %u' % (self.MAX_CTL_TIME - 1),
'-c %u' % (self.MAX_OF_PKTS),
'-i %s' % self.controller_intf,
Expand Down
2 changes: 1 addition & 1 deletion clib/mininet_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def queue_free_ports(min_queue_size):
if isinstance(response, int):
response = [response]
response_str = ''.join(['%u\n' % i for i in response])
connection.sendall(response_str.encode()) # pylint: disable=no-member
connection.sendall(response_str.encode()) # pylint: disable=no-member
connection.close()


Expand Down
4 changes: 2 additions & 2 deletions faucet/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_config_condition(cond, msg):
class Conf:
"""Base class for FAUCET configuration."""

mutable_attrs = frozenset() # type: frozenset
mutable_attrs = frozenset() # type: frozenset
defaults = {} # type: dict
defaults_types = {} # type: dict
dyn_finalized = False
Expand Down Expand Up @@ -106,7 +106,7 @@ def _check_conf_types(self, conf, conf_types):
test_config_condition(
not isinstance(conf_value, conf_type), '%s value %s must be %s not %s' % (
conf_key, conf_value,
conf_type, type(conf_value))) # pytype: disable=invalid-typevar
conf_type, type(conf_value))) # pytype: disable=invalid-typevar

@staticmethod
def _set_unknown_conf(conf, conf_types):
Expand Down
8 changes: 4 additions & 4 deletions faucet/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _dp_parse_tagged_port_vlans():
return port


def _dp_add_ports(dp, dp_conf, dp_id, vlans): # pylint: disable=invalid-name
def _dp_add_ports(dp, dp_conf, dp_id, vlans): # pylint: disable=invalid-name
ports_conf = dp_conf.get('interfaces', {})
port_ranges_conf = dp_conf.get('interface_ranges', {})
# as users can config port VLAN by using VLAN name, we store vid in
Expand Down Expand Up @@ -154,19 +154,19 @@ def _parse_port_ranges(port_ranges_conf, port_num_to_port_conf):
dp.add_port(port)


def _parse_acls(dp, acls_conf): # pylint: disable=invalid-name
def _parse_acls(dp, acls_conf): # pylint: disable=invalid-name
for acl_key, acl_conf in acls_conf.items():
acl = ACL(acl_key, dp.dp_id, acl_conf)
dp.add_acl(acl_key, acl)


def _parse_routers(dp, routers_conf): # pylint: disable=invalid-name
def _parse_routers(dp, routers_conf): # pylint: disable=invalid-name
for router_key, router_conf in routers_conf.items():
router = Router(router_key, dp.dp_id, router_conf)
dp.add_router(router_key, router)


def _parse_meters(dp, meters_conf): # pylint: disable=invalid-name
def _parse_meters(dp, meters_conf): # pylint: disable=invalid-name
for meter_key, meter_conf in meters_conf.items():
meter = Meter(meter_key, dp.dp_id, meter_conf)
dp.meters[meter_key] = meter
Expand Down
8 changes: 4 additions & 4 deletions faucet/config_parser_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# handle libyaml-dev not installed
try:
from yaml import CLoader as Loader # type: ignore
from yaml import CLoader as Loader # type: ignore
except ImportError:
from yaml import Loader

Expand Down Expand Up @@ -76,10 +76,10 @@ def read_config(config_file, logname):
conf_txt = stream.read()
conf = yaml.safe_load(conf_txt)
except (yaml.YAMLError, UnicodeDecodeError,
PermissionError, ValueError) as err: # pytype: disable=name-error
PermissionError, ValueError) as err: # pytype: disable=name-error
logger.error('Error in file %s (%s)', config_file, str(err))
except FileNotFoundError as err: # pytype: disable=name-error
logger.error('Could not find requested file: %s', config_file)
except FileNotFoundError as err: # pytype: disable=name-error
logger.error('Could not find requested file: %s (%s)', config_file, str(err))
return conf, conf_txt


Expand Down
4 changes: 2 additions & 2 deletions faucet/faucet_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def update_metrics(self, _now):
for neighbor, neighbor_state in neighbor_states:
neighbor_labels = dict(
valve.dp.base_prom_labels(), vlan=vlan.vid, neighbor=neighbor)
self.metrics.bgp_neighbor_uptime_seconds.labels( # pylint: disable=no-member
self.metrics.bgp_neighbor_uptime_seconds.labels( # pylint: disable=no-member
**neighbor_labels).set(neighbor_state['info']['uptime'])
self.metrics.bgp_neighbor_routes.labels( # pylint: disable=no-member
self.metrics.bgp_neighbor_routes.labels( # pylint: disable=no-member
**dict(neighbor_labels, ipv=ipv)).set(vlan.route_count_by_ipv(ipv))
8 changes: 4 additions & 4 deletions faucet/faucet_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import eventlet
eventlet.monkey_patch()

from ryu.lib import hub # pylint: disable=wrong-import-position
from ryu.lib.hub import StreamServer # pylint: disable=wrong-import-position
from ryu.lib import hub # pylint: disable=wrong-import-position
from ryu.lib.hub import StreamServer # pylint: disable=wrong-import-position


class NonBlockLock:
Expand Down Expand Up @@ -123,7 +123,7 @@ def check_path(self, socket_path):
if not os.path.exists(socket_dir):
try:
os.makedirs(socket_dir)
except (PermissionError) as err: # pytype: disable=name-error
except (PermissionError) as err: # pytype: disable=name-error
self.logger.error('Unable to create event socket directory: %s', err)
return None
# Check directory permissions.
Expand All @@ -134,7 +134,7 @@ def check_path(self, socket_path):
if os.path.exists(socket_path):
try:
os.remove(socket_path)
except (PermissionError) as err: # pytype: disable=name-error
except (PermissionError) as err: # pytype: disable=name-error
self.logger.error('Unable to remove old socket: %s', err)
return None
return socket_path
9 changes: 5 additions & 4 deletions faucet/faucet_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,17 @@ def __init__(self, reg=None):
'number of changes in stack root', [])

def _counter(self, var, var_help, labels):
return Counter(var, var_help, labels, registry=self._reg) # pylint: disable=unexpected-keyword-arg
return Counter(var, var_help, labels, registry=self._reg) # pylint: disable=unexpected-keyword-arg

def _gauge(self, var, var_help, labels):
return PromGauge(var, var_help, labels, registry=self._reg) # pylint: disable=unexpected-keyword-arg
return PromGauge(var, var_help, labels, registry=self._reg) # pylint: disable=unexpected-keyword-arg

def _info(self, var, var_help):
return Info(var, var_help, registry=self._reg) # pylint: disable=unexpected-keyword-arg
return Info(var, var_help, registry=self._reg) # pylint: disable=unexpected-keyword-arg

def _histogram(self, var, var_help, labels, buckets):
return Histogram(var, var_help, labels, buckets=buckets, registry=self._reg) # pylint: disable=unexpected-keyword-arg
# pylint: disable=unexpected-keyword-arg
return Histogram(var, var_help, labels, buckets=buckets, registry=self._reg)

def _dpid_counter(self, var, var_help):
counter = self._counter(var, var_help, self.REQUIRED_LABELS)
Expand Down
4 changes: 2 additions & 2 deletions faucet/faucet_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from faucet.faucet_metadata import EGRESS_METADATA_MASK


class ValveTableConfig: # pylint: disable=too-few-public-methods,too-many-instance-attributes
class ValveTableConfig: # pylint: disable=too-few-public-methods,too-many-instance-attributes
"""Configuration for a single table."""

def __init__(self, name, table_id, # pylint: disable=too-many-arguments
def __init__(self, name, table_id, # pylint: disable=too-many-arguments
exact_match=None, meter=None, output=True, miss_goto=None,
size=None, match_types=None, set_fields=None, dec_ttl=None,
vlan_scale=None, vlan_port_scale=None,
Expand Down
2 changes: 1 addition & 1 deletion faucet/gauge_influx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from influxdb import InfluxDBClient
from influxdb.exceptions import InfluxDBClientError, InfluxDBServerError
import requests # pytype: disable=pyi-error
import requests # pytype: disable=pyi-error
from faucet.gauge_pollers import GaugePortStatePoller, GaugeFlowTablePoller, GaugePortStatsPoller


Expand Down
12 changes: 6 additions & 6 deletions faucet/gauge_pollers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GaugePoller:
"""Abstraction for a poller for statistics."""

def __init__(self, conf, logname, prom_client):
self.dp = conf.dp # pylint: disable=invalid-name
self.dp = conf.dp # pylint: disable=invalid-name
self.conf = conf
self.prom_client = prom_client
self.reply_pending = False
Expand All @@ -47,7 +47,7 @@ def __init__(self, conf, logname, prom_client):
def report_dp_status(self, dp_status):
"""Report DP status."""
self.prom_client.dp_status.labels(
**dict(dp_id=hex(self.dp.dp_id), dp_name=self.dp.name)).set(dp_status) # pylint: disable=no-member
**dict(dp_id=hex(self.dp.dp_id), dp_name=self.dp.name)).set(dp_status) # pylint: disable=no-member

def start(self, ryudp, active):
"""Start the poller."""
Expand All @@ -72,7 +72,7 @@ def is_active():

def send_req(self):
"""Send a stats request to a datapath."""
raise NotImplementedError # pragma: no cover
raise NotImplementedError # pragma: no cover

def no_response(self):
"""Called when a polling cycle passes without receiving a response."""
Expand Down Expand Up @@ -194,7 +194,7 @@ def __call__(self):

def send_req(self):
"""Send a stats request to a datapath."""
raise NotImplementedError # pragma: no cover
raise NotImplementedError # pragma: no cover


class GaugeMeterStatsPoller(GaugeThreadPoller):
Expand Down Expand Up @@ -280,8 +280,8 @@ class GaugePortStatePoller(GaugePoller):

def send_req(self):
"""Send a stats request to a datapath."""
raise NotImplementedError # pragma: no cover
raise NotImplementedError # pragma: no cover

def no_response(self):
"""Called when a polling cycle passes without receiving a response."""
raise NotImplementedError # pragma: no cover
raise NotImplementedError # pragma: no cover
6 changes: 3 additions & 3 deletions faucet/gauge_prom.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, reg=None):
super().__init__(reg=reg)
self.table_tags = collections.defaultdict(set)
self.metrics = {}
self.dp_status = Gauge( # pylint: disable=unexpected-keyword-arg
self.dp_status = Gauge( # pylint: disable=unexpected-keyword-arg
'dp_status',
'status of datapaths',
self.REQUIRED_LABELS,
Expand Down Expand Up @@ -203,7 +203,7 @@ def _update(self, rcv_time, msg):
table_tags.update(unreg_tags)
self.prom_client.reregister_flow_vars(
table_name, table_tags)
self.logger.info( # pylint: disable=logging-not-lazy
self.logger.info( # pylint: disable=logging-not-lazy
'Adding tags %s to %s for table %s' % (
unreg_tags, table_tags, table_name))
# Add blank tags for any tags not present.
Expand All @@ -214,6 +214,6 @@ def _update(self, rcv_time, msg):
try:
self.prom_client.metrics[table_prom_var].labels(**tags).set(count)
except ValueError:
self.logger.error( # pylint: disable=logging-not-lazy
self.logger.error( # pylint: disable=logging-not-lazy
'labels %s versus %s incorrect on %s' % (
tags, table_tags, table_prom_var))
6 changes: 3 additions & 3 deletions faucet/prom_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def prometheus_app(environ, start_response):
return prometheus_app


class PromClient: # pylint: disable=too-few-public-methods
class PromClient: # pylint: disable=too-few-public-methods
"""Prometheus client."""

REQUIRED_LABELS = ['dp_id', 'dp_name']
Expand All @@ -54,7 +54,7 @@ def __init__(self, reg=None):
if reg is not None:
self._reg = reg
self.version = VersionInfo('faucet').semantic_version().release_string()
self.faucet_version = PromGauge( # pylint: disable=unexpected-keyword-arg
self.faucet_version = PromGauge( # pylint: disable=unexpected-keyword-arg
'faucet_pbr_version',
'Faucet PBR version',
['version'],
Expand All @@ -76,7 +76,7 @@ def start(self, prom_port, prom_addr, use_test_thread=False):
class NoLoggingWSGIRequestHandler(WSGIRequestHandler):
"""Don't log requests."""

def log_message(self, *_args): # pylint: disable=arguments-differ
def log_message(self, *_args): # pylint: disable=arguments-differ
pass

self.server = make_server(
Expand Down
2 changes: 1 addition & 1 deletion faucet/valve_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from faucet import valve_util
from faucet import valve_of

FAUCET_MAC = '0e:00:00:00:00:01' # Default FAUCET MAC address
FAUCET_MAC = '0e:00:00:00:00:01' # Default FAUCET MAC address

ETH_HEADER_SIZE = 14
ETH_VLAN_HEADER_SIZE = ETH_HEADER_SIZE + 4 # https://en.wikipedia.org/wiki/IEEE_802.1Q#Frame_format
Expand Down
Loading