Skip to content

Commit

Permalink
Fix even more Python warnings (sonic-net#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
jleveque authored Apr 9, 2020
1 parent ac85389 commit 8ee3006
Show file tree
Hide file tree
Showing 24 changed files with 22 additions and 80 deletions.
11 changes: 4 additions & 7 deletions clear/bgp_frr_v6.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import click
from clear.main import *
from clear.main import ipv6, run_command


###############################################################################
Expand All @@ -9,8 +9,7 @@
###############################################################################


@ipv6.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@ipv6.group()
def bgp():
"""Clear IPv6 BGP (Border Gateway Protocol) information"""
pass
Expand All @@ -24,8 +23,7 @@ def default():
run_command(command)


@bgp.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@bgp.group()
def neighbor():
"""Clear specific BGP peers"""
pass
Expand Down Expand Up @@ -69,8 +67,7 @@ def neigh_out(ipaddress):
run_command(command)


@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@neighbor.group()
def soft():
"""Soft reconfig BGP's inbound/outbound updates"""
pass
Expand Down
11 changes: 4 additions & 7 deletions clear/bgp_quagga_v4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import click
from clear.main import *
from clear.main import ip, run_command


###############################################################################
Expand All @@ -9,8 +9,7 @@
###############################################################################


@ip.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@ip.group()
def bgp():
"""Clear BGP (Border Gateway Protocol) peers"""
pass
Expand All @@ -24,8 +23,7 @@ def default():
run_command(command)


@bgp.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@bgp.group()
def neighbor():
"""Clear specific BGP peers"""
pass
Expand Down Expand Up @@ -69,8 +67,7 @@ def neigh_out(ipaddress):
run_command(command)


@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@neighbor.group()
def soft():
"""Soft reconfig BGP's inbound/outbound updates"""
pass
Expand Down
11 changes: 4 additions & 7 deletions clear/bgp_quagga_v6.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import click
from clear.main import *
from clear.main import ipv6, run_command


###############################################################################
Expand All @@ -9,8 +9,7 @@
###############################################################################


@ipv6.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@ipv6.group()
def bgp():
"""Clear IPv6 BGP (Border Gateway Protocol) information"""
pass
Expand All @@ -24,8 +23,7 @@ def default():
run_command(command)


@bgp.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@bgp.group()
def neighbor():
"""Clear specific BGP peers"""
pass
Expand Down Expand Up @@ -69,8 +67,7 @@ def neigh_out(ipaddress):
run_command(command)


@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
context_settings=CONTEXT_SETTINGS)
@neighbor.group()
def soft():
"""Soft reconfig BGP's inbound/outbound updates"""
pass
Expand Down
1 change: 0 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,6 @@ def ztp():

if os.geteuid() != 0:
exit("Root privileges are required for this operation")
pass

@ztp.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
Expand Down
5 changes: 0 additions & 5 deletions config/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def isIpOverlappingWithAnyStaticEntry(ipAddress, table):

for key,values in static_dict.items():
global_ip = "---"
local_ip = "---"
nat_type = "dnat"

if table == 'STATIC_NAPT':
Expand Down Expand Up @@ -542,8 +541,6 @@ def remove_tcp(ctx, global_ip, global_port, local_ip, local_port):
entryFound = False
table = "STATIC_NAPT"
key = "{}|TCP|{}".format(global_ip, global_port)
dataKey1 = 'local_ip'
dataKey2 = 'local_port'

data = config_db.get_entry(table, key)
if data:
Expand Down Expand Up @@ -665,8 +662,6 @@ def add_pool(ctx, pool_name, global_ip_range, global_port_range):
else:
if is_valid_port_address(port_address[0]) is False:
ctx.fail("Given port value {} is invalid. Please enter a valid port value !!".format(port_address[0]))
portLowLimit = int(port_address[0])
portHighLimit = int(port_address[0])
else:
global_port_range = "NULL"

Expand Down
8 changes: 1 addition & 7 deletions fwutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ def is_url(self):
return False

def retrieve(self):
filename, headers = None, None

self.__validate()

result = urlparse(self.__url)
Expand All @@ -126,7 +124,7 @@ def retrieve(self):
self.DOWNLOAD_PATH_TEMPLATE.format(basename),
self.__reporthook
)
except:
except Exception:
if os.path.exists(self.DOWNLOAD_PATH_TEMPLATE.format(basename)):
os.remove(self.DOWNLOAD_PATH_TEMPLATE.format(basename))
raise
Expand Down Expand Up @@ -560,7 +558,6 @@ def get_status(self, force):

firmware_path = NA
firmware_version_current = chassis_component.get_firmware_version()
firmware_version_available = NA
firmware_version = firmware_version_current

status = self.FW_STATUS_UP_TO_DATE
Expand Down Expand Up @@ -608,7 +605,6 @@ def get_status(self, force):

firmware_path = NA
firmware_version_current = module_component.get_firmware_version()
firmware_version_available = NA
firmware_version = firmware_version_current

status = self.FW_STATUS_UP_TO_DATE
Expand Down Expand Up @@ -662,7 +658,6 @@ def update_firmware(self, force):
)

firmware_version_current = chassis_component.get_firmware_version()
firmware_version_available = NA

status = self.FW_STATUS_UP_TO_DATE

Expand Down Expand Up @@ -724,7 +719,6 @@ def update_firmware(self, force):
)

firmware_version_current = module_component.get_firmware_version()
firmware_version_available = NA

status = self.FW_STATUS_UP_TO_DATE

Expand Down
2 changes: 0 additions & 2 deletions pddf_fanutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def direction(index):
status_table = []

for fan in fan_ids:
msg = ""
fan_name = "FAN {}".format(fan)
if fan not in supported_fan:
click.echo("Error! The {} is not available on the platform.\n" \
Expand Down Expand Up @@ -138,7 +137,6 @@ def getspeed(index):
status_table = []

for fan in fan_ids:
msg = ""
fan_name = "FAN {}".format(fan)
if fan not in supported_fan:
click.echo("Error! The {} is not available on the platform.\n" \
Expand Down
3 changes: 0 additions & 3 deletions pddf_psuutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ def mfrinfo(index):
"""Display PSU manufacturer info"""
supported_psu = range(1, platform_psuutil.get_num_psus() + 1)
psu_ids = []
info = ""
if (index < 0):
psu_ids = supported_psu
else:
psu_ids = [index]

for psu in psu_ids:
msg = ""
psu_name = "PSU {}".format(psu)
if psu not in supported_psu:
click.echo("Error! The {} is not available on the platform.\n" \
Expand Down Expand Up @@ -145,7 +143,6 @@ def seninfo(index):
psu_ids = [index]

for psu in psu_ids:
msg = ""
psu_name = "PSU {}".format(psu)
if psu not in supported_psu:
click.echo("Error! The {} is not available on the platform.\n" \
Expand Down
1 change: 0 additions & 1 deletion pddf_thermalutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def gettemp(index):
status_table = []

for thermal in thermal_ids:
msg = ""
thermal_name = "TEMP{}".format(thermal)
if thermal not in supported_thermal:
click.echo("Error! The {} is not available on the platform.\n" \
Expand Down
1 change: 0 additions & 1 deletion psuutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def load_platform_psuutil():
platform_path = "/".join([PLATFORM_ROOT_PATH, platform])
else:
platform_path = PLATFORM_ROOT_PATH_DOCKER
hwsku_path = "/".join([platform_path, hwsku])

try:
module_file = "/".join([platform_path, "plugins", PLATFORM_SPECIFIC_MODULE_NAME + ".py"])
Expand Down
4 changes: 0 additions & 4 deletions scripts/aclshow
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ class AclStat(object):
read redis database for acl counters
"""

def qstrip(string):
return string.strip().strip(" \"").rstrip("\"")

def lowercase_keys(dictionary):
return dict((k.lower(), v) for k,v in dictionary.iteritems()) if dictionary else None

Expand Down Expand Up @@ -128,7 +125,6 @@ class AclStat(object):
"""
Get ACL counters from the DB
"""
counters_cnt = len(self.acl_rules) # num of counters should be the same as rules
for table, rule in self.acl_rules.keys():
cnt_props = lowercase_keys(self.db.get_all(self.db.COUNTERS_DB, "COUNTERS:%s:%s" % (table, rule)))
self.acl_counters[table, rule] = cnt_props
Expand Down
2 changes: 1 addition & 1 deletion scripts/ecnconfig
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def main():

# get current configuration data
wred_profile_data = prof_cfg.get_profile_data(args.profile)
if wred_profile_data == None:
if wred_profile_data is None:
raise Exception("Input arguments error. Invalid WRED profile %s" % (args.profile))

if args.green_max:
Expand Down
1 change: 0 additions & 1 deletion scripts/intfstat
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ def main():
sys.exit(0)

if wait_time_in_seconds == 0:
cnstat_cached_dict = OrderedDict()
if os.path.isfile(cnstat_fqn_file):
try:
cnstat_cached_dict = pickle.load(open(cnstat_fqn_file, 'r'))
Expand Down
3 changes: 1 addition & 2 deletions scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ def get_portchannel_list(get_raw_po_int_configdb_info):
portchannel = po[0]
if portchannel not in portchannel_list:
portchannel_list.append(portchannel)
portchannel = portchannel_list.sort()
return portchannel_list
return natsorted(portchannel_list)

def create_po_int_tuple_list(get_raw_po_int_configdb_info):
"""
Expand Down
6 changes: 0 additions & 6 deletions scripts/natshow
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ class NatShow(object):
continue

ip_protocol = "all"
source = "---"
destination = "---"
translated_dst = "---"
translated_src = "---"

Expand Down Expand Up @@ -280,8 +278,6 @@ class NatShow(object):
nat_twice_values = self.appl_db.get_all(self.appl_db.APPL_DB,'NAT_TWICE_TABLE:{}'.format(nat_twice_entry))

ip_protocol = "all"
source = "---"
destination = "---"

source = nat_twice_keys[0]
destination = nat_twice_keys[1]
Expand All @@ -306,8 +302,6 @@ class NatShow(object):
napt_twice_values = self.appl_db.get_all(self.appl_db.APPL_DB,'NAPT_TWICE_TABLE:{}'.format(napt_twice_entry))

ip_protocol = napt_twice_keys[0]
source = "---"
destination = "---"

source = napt_twice_keys[1] + ':' + napt_twice_keys[2]
destination = napt_twice_keys[3] + ':' + napt_twice_keys[4]
Expand Down
1 change: 0 additions & 1 deletion scripts/nbrshow
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class NbrBase(object):

ent = self.db.get_all('ASIC_DB', s, blocking=True)
br_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][oid_pfx:]
ent_type = ent[b"SAI_FDB_ENTRY_ATTR_TYPE"]
if br_port_id not in self.if_br_oid_map:
continue
port_id = self.if_br_oid_map[br_port_id]
Expand Down
2 changes: 1 addition & 1 deletion scripts/neighbor_advertiser
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def main():
ferret_service_vips = args.vips
operation_mode = args.mode

if operation_mode == 'set' and ferret_service_vips == None:
if operation_mode == 'set' and ferret_service_vips is None:
log_warning('ferret service vip is required in set mode')
sys.exit(1)

Expand Down
2 changes: 0 additions & 2 deletions scripts/pfcstat
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ Examples:
"""
Print the counters of pfc rx counter
"""
cnstat_cached_dict = OrderedDict()
if os.path.isfile(cnstat_fqn_file_rx):
try:
cnstat_cached_dict = pickle.load(open(cnstat_fqn_file_rx, 'r'))
Expand All @@ -240,7 +239,6 @@ Examples:
"""
Print the counters of pfc tx counter
"""
cnstat_cached_dict = OrderedDict()
if os.path.isfile(cnstat_fqn_file_tx):
try:
cnstat_cached_dict = pickle.load(open(cnstat_fqn_file_tx, 'r'))
Expand Down
4 changes: 0 additions & 4 deletions scripts/queuestat
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ class Queuestat(object):
Print the cnstat.
"""
table = []
queue_count = len(cnstat_dict)

for key, data in cnstat_dict.iteritems():
if key == 'time':
Expand All @@ -170,7 +169,6 @@ class Queuestat(object):
return '{:,}'.format(new - old)

table = []
queue_count = len(cnstat_new_dict)

for key, cntr in cnstat_new_dict.iteritems():
if key == 'time':
Expand Down Expand Up @@ -198,7 +196,6 @@ class Queuestat(object):
for port in natsorted(self.counter_port_name_map):
cnstat_dict = self.get_cnstat(self.port_queues_map[port])

cnstat_cached_dict = OrderedDict()
cnstat_fqn_file_name = cnstat_fqn_file + port
if os.path.isfile(cnstat_fqn_file_name):
try:
Expand All @@ -217,7 +214,6 @@ class Queuestat(object):

# Get stat for the port queried
cnstat_dict = self.get_cnstat(self.port_queues_map[port])
cnstat_cached_dict = OrderedDict()
cnstat_fqn_file_name = cnstat_fqn_file + port
if os.path.isfile(cnstat_fqn_file_name):
try:
Expand Down
1 change: 0 additions & 1 deletion scripts/sonic-kdump-config
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def run_command(cmd, use_shell=False):
@param use_shell (bool) Execute subprocess with shell access
'''

pid = None
try:
if isinstance(cmd, list):
if use_shell is False:
Expand Down
Loading

0 comments on commit 8ee3006

Please sign in to comment.