Skip to content

Commit 30445b8

Browse files
jvanderaajeffkala
andauthored
Pylint updates (#282)
* reprep 0.20.3 (#260) (#261) * Updates errors and aireos files for pylint. * ASA pylint updates. * EOS pylint updates. * F5 pylint. * IOS updates. * xe wlc pylint updates. * Juniper pylint. * nxos pylint * Final lints. * Formatting * Fix my mistakes. * Test updates from linting. --------- Co-authored-by: Jeff Kala <48843785+jeffkala@users.noreply.github.com>
1 parent 77c0d43 commit 30445b8

15 files changed

Lines changed: 228 additions & 208 deletions

File tree

pyntc/devices/aireos_device.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def open(self, confirm_active=True):
10861086
if self.connected:
10871087
try:
10881088
self.native.find_prompt()
1089-
except: # noqa E722
1089+
except: # noqa E722 pylint: disable=bare-except
10901090
self._connected = False
10911091

10921092
if not self.connected:
@@ -1198,8 +1198,8 @@ def redundancy_mode(self):
11981198
'sso enabled'
11991199
>>>
12001200
"""
1201-
ha = self.show("show redundancy summary")
1202-
ha_mode = re.search(r"^\s*Redundancy\s+Mode\s*=\s*(.+?)\s*$", ha, re.M)
1201+
high_availability = self.show("show redundancy summary")
1202+
ha_mode = re.search(r"^\s*Redundancy\s+Mode\s*=\s*(.+?)\s*$", high_availability, re.M)
12031203
log.debug("Host %s: Redundancy mode: {ha_mode.group(1).lower()}", self.host, ha_mode.group(1).lower())
12041204
return ha_mode.group(1).lower()
12051205

@@ -1400,13 +1400,13 @@ def startup_config(self):
14001400
"""
14011401
raise NotImplementedError
14021402

1403-
def transfer_image_to_ap(self, image, timeout=None):
1403+
def transfer_image_to_ap(self, image):
14041404
"""
14051405
Transfer ``image`` file to all APs connected to the WLC.
14061406
14071407
Args:
14081408
image (str): The image that should be sent to the APs.
1409-
timeout (int): The max time to wait for all APs to download the image.
1409+
timeout (int): Removed, The max time to wait for all APs to download the image.
14101410
14111411
Returns:
14121412
bool: True if AP images are transferred or swapped, False otherwise.
@@ -1513,7 +1513,7 @@ def uptime_string(self):
15131513
>>>
15141514
"""
15151515
days, hours, minutes = self._uptime_components()
1516-
return "%02d:%02d:%02d:00" % (days, hours, minutes)
1516+
return f"{days:02d}:{hours:02d}:{minutes:02d}:00"
15171517

15181518
@property
15191519
def wlans(self):

pyntc/devices/asa_device.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def _file_copy(self, src: str, dest: str, file_system: str) -> None:
7676
self.enable()
7777

7878
if not self.file_copy_remote_exists(src, dest, file_system):
79-
fc: CiscoAsaFileTransfer = self._file_copy_instance(src, dest, file_system)
79+
file_copy: CiscoAsaFileTransfer = self._file_copy_instance(src, dest, file_system)
8080

8181
try:
82-
fc.establish_scp_conn()
83-
fc.transfer_file()
82+
file_copy.establish_scp_conn()
83+
file_copy.transfer_file()
8484
# Allow EOFErrors to be caught and only raise an error if the file is not actually on the device
8585
except EOFError:
8686
log.error("Host %s: EOF error.", self.host)
@@ -90,7 +90,7 @@ def _file_copy(self, src: str, dest: str, file_system: str) -> None:
9090
raise FileTransferError
9191
finally:
9292
log.error("Host %s: An error occurred when transferring file %s.", self.host, src)
93-
fc.close_scp_chan()
93+
file_copy.close_scp_chan()
9494

9595
if not self.file_copy_remote_exists(src, dest, file_system):
9696
log.error(
@@ -109,9 +109,9 @@ def _file_copy_instance(
109109
if dest is None:
110110
dest = os.path.basename(src)
111111

112-
fc = CiscoAsaFileTransfer(self.native, src, dest, file_system=file_system)
113-
log.debug("Host %s: File copy instance %s.", self.host, fc)
114-
return fc
112+
file_copy = CiscoAsaFileTransfer(self.native, src, dest, file_system=file_system)
113+
log.debug("Host %s: File copy instance %s.", self.host, file_copy)
114+
return file_copy
115115

116116
def _get_file_system(self):
117117
"""Determine the default file system or directory for device.
@@ -261,7 +261,7 @@ def _show_vlan(self):
261261
log.debug("Host %s: Successfully executed command 'show vlan' with responses %s.", self.host, show_vlan_out)
262262
return show_vlan_out.split(",")
263263

264-
def _uptime_components(self, uptime_full_string):
264+
def _uptime_components(self, uptime_full_string): # pylint: disable=no-self-use
265265
match_days = re.search(r"(\d+) days?", uptime_full_string)
266266
match_hours = re.search(r"(\d+) hours?", uptime_full_string)
267267
match_minutes = re.search(r"(\d+) mins?", uptime_full_string)
@@ -283,7 +283,7 @@ def _uptime_to_seconds(self, uptime_full_string):
283283

284284
def _uptime_to_string(self, uptime_full_string):
285285
days, hours, minutes = self._uptime_components(uptime_full_string)
286-
return "%02d:%02d:%02d:00" % (days, hours, minutes)
286+
return f"{days:02d}:{hours:02d}:{minutes:02d}:00"
287287

288288
def _wait_for_device_reboot(self, timeout=3600):
289289
start = time.time()
@@ -292,7 +292,7 @@ def _wait_for_device_reboot(self, timeout=3600):
292292
self.open()
293293
log.debug("Host %s: Device rebooted.", self.host)
294294
return
295-
except: # noqa E722 # nosec
295+
except: # noqa E722 # nosec # pylint: disable=bare-except
296296
pass
297297

298298
# TODO: Get proper hostname parameter
@@ -352,8 +352,8 @@ def backup_running_config(self, filename):
352352
Args:
353353
filename (str): Name of backup file.
354354
"""
355-
with open(filename, "w") as f:
356-
f.write(self.running_config)
355+
with open(filename, "w", encoding="utf-8") as file_name:
356+
file_name.write(self.running_config)
357357

358358
log.debug("Host %s: Running config backed up to %s.", self.host, self.running_config)
359359

@@ -498,7 +498,7 @@ def enable_scp(self) -> None:
498498
device.save()
499499

500500
@property
501-
def facts(self):
501+
def facts(self): # pylint: disable=invalid-overridden-method
502502
"""Implement this once facts re-factor is done."""
503503
return {}
504504

@@ -542,7 +542,7 @@ def file_copy(
542542
self.enable_scp()
543543
self._file_copy(src, dest, file_system)
544544
if peer:
545-
self.peer_device._file_copy(src, dest, file_system)
545+
self.peer_device._file_copy(src, dest, file_system) # pylint: disable=protected-access
546546

547547
# logging removed because it messes up unit test mock_basename.assert_not_called()
548548
# for tests test_file_copy_no_peer_pass_args, test_file_copy_include_peer
@@ -573,8 +573,8 @@ def file_copy_remote_exists(self, src, dest=None, file_system=None):
573573
if file_system is None:
574574
file_system = self._get_file_system()
575575

576-
fc = self._file_copy_instance(src, dest, file_system=file_system)
577-
if fc.check_file_exists() and fc.compare_md5():
576+
file_copy = self._file_copy_instance(src, dest, file_system=file_system)
577+
if file_copy.check_file_exists() and file_copy.compare_md5():
578578
log.debug("Host %s: File %s already exists on remote.", self.host, src)
579579
return True
580580

@@ -630,14 +630,13 @@ def ip_address(self) -> Union[IPv4Address, IPv6Address]:
630630
>>>
631631
"""
632632
try:
633-
ip = ip_address(self.host)
633+
ip_add = ip_address(self.host)
634634
except ValueError:
635635
# Assume hostname was used, and retrieve resolved IP from paramiko transport
636636
log.error("Host %s: value error for ip address used to establish connection.", self.host)
637-
ip = ip_address(self.native.remote_conn.transport.getpeername()[0])
638-
639-
log.debug("Host %s: ip address used to establish connection %s.", self.host, ip)
640-
return ip
637+
ip_add = ip_address(self.native.remote_conn.transport.getpeername()[0])
638+
log.debug("Host %s: ip address used to establish connection %s.", self.host, ip_add)
639+
return ip_add
641640

642641
@property
643642
def ipv4_addresses(self) -> Dict[str, List[IPv4Address]]:
@@ -718,7 +717,7 @@ def open(self):
718717
if self._connected:
719718
try:
720719
self.native.find_prompt()
721-
except: # noqa E722
720+
except: # noqa E722 pylint: disable=bare-except
722721
self._connected = False
723722

724723
if not self._connected:
@@ -1028,7 +1027,7 @@ def save(self, filename="startup-config"):
10281027
Returns:
10291028
bool: True if configuration saved succesfully.
10301029
"""
1031-
command = "copy running-config %s" % filename
1030+
command = f"copy running-config {filename}"
10321031
# Changed to send_command_timing to not require a direct prompt return.
10331032
self.native.send_command_timing(command)
10341033
# If the user has enabled 'file prompt quiet' which dose not require any confirmation or feedback.
@@ -1056,26 +1055,26 @@ def set_boot_options(self, image_name, **vendor_specifics):
10561055
if file_system is None:
10571056
file_system = self._get_file_system()
10581057

1059-
file_system_files = self.show("dir {0}".format(file_system))
1058+
file_system_files = self.show(f"dir {file_system}")
10601059
if re.search(image_name, file_system_files) is None:
10611060
log.error("Host %s: File not found error for image %s.", self.host, image_name)
10621061
raise NTCFileNotFoundError(
10631062
# TODO: Update to use hostname
10641063
hostname=self.host,
10651064
file=image_name,
1066-
dir=file_system,
1065+
directory=file_system,
10671066
)
10681067

10691068
current_images = current_boot.splitlines()
1070-
commands_to_exec = ["no {0}".format(image) for image in current_images]
1071-
commands_to_exec.append("boot system {0}/{1}".format(file_system, image_name))
1069+
commands_to_exec = [f"no {image}" for image in current_images]
1070+
commands_to_exec.append(f"boot system {file_system}/{image_name}")
10721071
self.config(commands_to_exec)
10731072

10741073
self.save()
10751074
if self.boot_options["sys"] != image_name:
10761075
log.error("Host %s: Setting boot command did not yield expected results", self.host)
10771076
raise CommandError(
1078-
command="boot system {0}/{1}".format(file_system, image_name),
1077+
command=f"boot system {file_system}/{image_name}",
10791078
message="Setting boot command did not yield expected results",
10801079
)
10811080

@@ -1224,4 +1223,4 @@ def vlans(self):
12241223
class RebootSignal(NTCError):
12251224
"""Not implemented."""
12261225

1227-
pass
1226+
pass # pylint: disable=unnecessary-pass

0 commit comments

Comments
 (0)