Skip to content

Commit 46a2868

Browse files
committed
fix issues found by code review
1 parent 0acd80e commit 46a2868

File tree

9 files changed

+38
-58
lines changed

9 files changed

+38
-58
lines changed

library/network_connections.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,7 @@ def connection_compare(
777777
if compare_flags is None:
778778
compare_flags = NM.SettingCompareFlags.IGNORE_TIMESTAMP
779779

780-
# this is really odd, but I'm assuming there is a double-negative
781-
# here for a reason . . . .
782-
# pylint: disable=unneeded-not
783-
return not (not (con_a.compare(con_b, compare_flags)))
780+
return con_a.compare(con_b, compare_flags)
784781

785782
def connection_is_active(self, con):
786783
NM = Util.NM()
@@ -1625,10 +1622,7 @@ def connections_data(self):
16251622
raise AssertionError(
16261623
"invalid value {0} for self.check_mode".format(self.check_mode)
16271624
)
1628-
c = []
1629-
# pylint: disable=blacklisted-name
1630-
for _ in range(0, len(self.connections)):
1631-
c.append({"changed": False})
1625+
c = [{"changed": False}] * len(self.connections)
16321626
self._connections_data = c
16331627
return c
16341628

@@ -2015,8 +2009,7 @@ def _check_ethtool_setting_support(self, idx, connection):
20152009
idx, "ethtool.%s specified but not supported by NM", specified
20162010
)
20172011

2018-
# pylint: disable=blacklisted-name
2019-
for option, _ in specified.items():
2012+
for option in specified.keys():
20202013
nm_name = nm_get_name_fcnt(option)
20212014
if not nm_name:
20222015
self.log_fatal(

module_utils/network_lsr/ethtool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def get_perm_addr(ifname):
5050
res = ecmd.tobytes()
5151
except AttributeError: # tobytes() is not available in python2
5252
res = ecmd.tostring()
53-
# pylint: disable=blacklisted-name
53+
# disable check for bad names:
54+
# pylint: disable=C0102
5455
_, size, perm_addr = struct.unpack("II%is" % MAX_ADDR_LEN, res)
5556
perm_addr = Util.mac_ntoa(perm_addr[:size])
5657
except IOError:

module_utils/network_lsr/nm/active_connection.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,15 @@ def deactivate_active_connection(nm_ac, timeout, check_mode):
2525
return False
2626
if not check_mode:
2727
main_loop = client.get_mainloop(timeout)
28-
# pylint: disable=logging-format-interpolation
29-
logging.debug(
30-
"Deactivating {id} with timeout {timeout}".format(
31-
id=nm_ac.get_id(), timeout=timeout
32-
)
33-
)
28+
logging.debug("Deactivating %s with timeout %s", nm_ac.get_id(), timeout)
3429
user_data = main_loop
3530
handler_id = nm_ac.connect(
3631
NM_AC_STATE_CHANGED_SIGNAL, _nm_ac_state_change_callback, user_data
3732
)
38-
# pylint: disable=logging-format-interpolation
3933
logging.debug(
40-
"Registered {signal} on client.NM.ActiveConnection {id}".format(
41-
signal=NM_AC_STATE_CHANGED_SIGNAL, id=nm_ac.get_id()
42-
)
34+
"Registered %s on client.NM.ActiveConnection %s",
35+
NM_AC_STATE_CHANGED_SIGNAL,
36+
nm_ac.get_id(),
4337
)
4438
if nm_ac.props.state != client.NM.ActiveConnectionState.DEACTIVATING:
4539
nm_client = client.get_client()
@@ -50,10 +44,7 @@ def deactivate_active_connection(nm_ac, timeout, check_mode):
5044
_nm_ac_deactivate_call_back,
5145
user_data,
5246
)
53-
# pylint: disable=logging-format-interpolation
54-
logging.debug(
55-
"Deactivating client.NM.ActiveConnection {0}".format(nm_ac.get_id())
56-
)
47+
logging.debug("Deactivating client.NM.ActiveConnection %s", nm_ac.get_id())
5748
main_loop.run()
5849
return True
5950

@@ -62,17 +53,14 @@ def _nm_ac_state_change_callback(nm_ac, state, reason, user_data):
6253
main_loop = user_data
6354
if main_loop.is_cancelled:
6455
return
65-
# pylint: disable=logging-format-interpolation
6656
logging.debug(
67-
"Got client.NM.ActiveConnection state change: {id}: {state} {reason}".format(
68-
id=nm_ac.get_id(), state=state, reason=reason
69-
)
57+
"Got client.NM.ActiveConnection state change: %s: %s %s",
58+
nm_ac.get_id(),
59+
state,
60+
reason,
7061
)
7162
if nm_ac.props.state == client.NM.ActiveConnectionState.DEACTIVATED:
72-
# pylint: disable=logging-format-interpolation
73-
logging.debug(
74-
"client.NM.ActiveConnection {0} is deactivated".format(nm_ac.get_id())
75-
)
63+
logging.debug("client.NM.ActiveConnection %s is deactivated", nm_ac.get_id())
7664
main_loop.quit()
7765

7866

@@ -90,11 +78,8 @@ def _nm_ac_deactivate_call_back(nm_client, result, user_data):
9078
if e.matches(
9179
client.NM.ManagerError.quark(), client.NM.ManagerError.CONNECTIONNOTACTIVE
9280
):
93-
# pylint: disable=logging-format-interpolation
9481
logging.info(
95-
"Connection is not active on {0}, no need to deactivate".format(
96-
nm_ac_id
97-
)
82+
"Connection is not active on %s, no need to deactivate", nm_ac_id
9883
)
9984
if nm_ac:
10085
nm_ac.handler_disconnect(handler_id)

module_utils/network_lsr/nm/connection.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def delete_remote_connection(nm_profile, timeout, check_mode):
2929
_nm_profile_delete_call_back,
3030
user_data,
3131
)
32-
# pylint: disable=logging-format-interpolation
3332
logging.debug(
34-
"Deleting profile {id}/{uuid} with timeout {timeout}".format(
35-
id=nm_profile.get_id(), uuid=nm_profile.get_uuid(), timeout=timeout
36-
)
33+
"Deleting profile %s/%s with timeout %s",
34+
nm_profile.get_id(),
35+
nm_profile.get_uuid(),
36+
timeout,
3737
)
3838
main_loop.run()
3939
return True
@@ -82,11 +82,11 @@ def volatilize_remote_connection(nm_profile, timeout, check_mode):
8282
_nm_profile_volatile_update2_call_back,
8383
user_data,
8484
)
85-
# pylint: disable=logging-format-interpolation
8685
logging.debug(
87-
"Volatilizing profile {id}/{uuid} with timeout {timeout}".format(
88-
id=nm_profile.get_id(), uuid=nm_profile.get_uuid(), timeout=timeout
89-
)
86+
"Volatilizing profile %s/%s with timeout %s",
87+
nm_profile.get_id(),
88+
nm_profile.get_uuid(),
89+
timeout,
9090
)
9191
main_loop.run()
9292
return True

module_utils/network_lsr/nm/provider.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def deactivate_connection(self, connection_name, timeout, check_mode):
2929
nm_ac, timeout, check_mode
3030
)
3131
if not changed:
32-
# pylint: disable=logging-format-interpolation
33-
logging.info("No active connection for {0}".format(connection_name))
32+
logging.info("No active connection for %s", connection_name)
3433

3534
return changed
3635

@@ -54,8 +53,7 @@ def volatilize_connection_by_uuid(self, uuid, timeout, check_mode):
5453
nm_profile, timeout, check_mode
5554
)
5655
if not changed:
57-
# pylint: disable=logging-format-interpolation
58-
logging.info("No connection with UUID {0} to volatilize".format(uuid))
56+
logging.info("No connection with UUID %s to volatilize", uuid)
5957

6058
return changed
6159

tests/ensure_provider_tests.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ def create_nm_playbook(test_playbook):
118118
EXTRA_RUN_CONDITION, ""
119119
)
120120
if extra_run_condition:
121-
extra_run_condition = "{0}{1}\n".format(
122-
EXTRA_RUN_CONDITION_PREFIX, extra_run_condition
123-
)
121+
extra_run_condition = f"{EXTRA_RUN_CONDITION_PREFIX}{extra_run_condition}\n"
124122

125123
nm_version_check = ""
126124
if minimum_nm_version:
@@ -213,7 +211,7 @@ def main():
213211

214212
if missing:
215213
print("ERROR: No NM or initscripts tests found for:\n" + ", \n".join(missing))
216-
print("Try to generate them with '{0} generate'".format(sys.argv[0]))
214+
print(f"Try to generate them with '{sys.argv[0]} generate'")
217215
returncode = 1
218216

219217
return returncode

tests/get_coverage.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ call_ansible() {
3131
}
3232

3333
remote_coverage_dir="$(mktemp -d /tmp/remote_coverage-XXXXXX)"
34-
trap 'rm -rf "${remote_coverage_dir}"' EXIT
34+
# we want to expand ${remote_coverage_dir} here, so tell SC to be quiet
35+
# https://github.com/koalaman/shellcheck/wiki/SC2064
36+
# shellcheck disable=SC2064
37+
trap "rm -rf '${remote_coverage_dir}'" EXIT
3538
ansible-playbook -i "${host}", get_coverage.yml -e "test_playbook=${playbook} destdir=${remote_coverage_dir}"
3639

3740
#COVERAGE_FILE=remote-coverage coverage combine remote-coverage/tests_*/*/root/.coverage

tests/integration/test_ethernet.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424

2525
class PytestRunEnvironment(nc.RunEnvironment):
2626
def log(self, connections, idx, severity, msg, **kwargs):
27-
# pylint: disable=logging-format-interpolation
2827
if severity == nc.LogLevel.ERROR:
29-
logging.error("Error: {0}".format(connections[idx]))
28+
logging.error("Error: %s", connections[idx])
3029
raise RuntimeError(msg)
3130
else:
32-
logging.debug("Log: {0}".format(connections[idx]))
31+
logging.debug("Log: %s", connections[idx])
3332

3433
def run_command(self, argv, encoding=None):
3534
command = subprocess.Popen(

tests/merge_coverage.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export COVERAGE_FILE="${1}"
2323
shift
2424

2525
tempdir="$(mktemp -d /tmp/coverage_merge-XXXXXX)"
26-
trap 'rm -rf "${tempdir}"' EXIT
26+
# we want to expand ${tempdir} here, so tell SC to be quiet
27+
# https://github.com/koalaman/shellcheck/wiki/SC2064
28+
# shellcheck disable=SC2064
29+
trap "rm -rf '${tempdir}'" EXIT
2730

2831
cp --backup=numbered -- "${@}" "${tempdir}"
2932
# FIXME: Would not work if coverage files are not hidden but they are by

0 commit comments

Comments
 (0)