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

Address CodeQL warnings #558

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions library/network_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,14 @@ def connection_compare(
try:
con_a.normalize()
except Exception:
# We ignore any errors that might happen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment does not provide any additional value since it just describes the code. The comment should include the reason why it is the right thing to do this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment does not provide any additional value since it just describes the code. The comment should include the reason why it is the right thing to do this here.

#558 (comment)

The proper comment would be # We ignore any errors that might happen, which seems a pretty meaningless thing to say. This linter rule seems questionable to me, but OK, it needs to be worked around.

We could just say # Workaround CodeQL warning, then?

pass
if normalize_b:
con_b = NM.SimpleConnection.new_clone(con_b)
try:
con_b.normalize()
except Exception:
# We ignore any errors that might happen
pass
if compare_flags is None:
compare_flags = NM.SettingCompareFlags.IGNORE_TIMESTAMP
Expand Down
28 changes: 15 additions & 13 deletions module_utils/network_lsr/argument_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,17 @@ def __init__(

def _validate_impl(self, value, name):
table = None
try:
if isinstance(value, bool):
# bool can (probably) be converted to integer type,
# but here we don't want to accept a boolean value.
pass
elif isinstance(value, int):
table = int(value)
elif isinstance(value, Util.STRING_TYPE):
try:
table = int(value)
except Exception:
table = value
except Exception:
if isinstance(value, bool):
# bool can (probably) be converted to integer type,
# but here we don't want to accept a boolean value.
pass
elif isinstance(value, int):
table = value
elif isinstance(value, Util.STRING_TYPE):
try:
table = int(value)
except Exception:
table = value
if table is None:
raise ValidationError(
name,
Expand Down Expand Up @@ -336,6 +333,7 @@ def _validate_impl(self, value, name):
if isinstance(value, Util.STRING_TYPE) or v2 == value:
v = v2
except Exception:
# Exception handling is done next.
pass
if v is None:
raise ValidationError(
Expand Down Expand Up @@ -374,11 +372,13 @@ def _validate_impl(self, value, name):
try:
range = (int(match_group.group(1)), int(match_group.group(2)))
except Exception:
# Exception handling is done below.
pass
else:
try:
range = (int(value), int(value))
except Exception:
# Exception handling is done below.
pass
elif isinstance(value, bool):
# bool can (probably) be converted to integer type,
Expand Down Expand Up @@ -425,6 +425,7 @@ def _validate_impl(self, value, name):
if isinstance(value, Util.STRING_TYPE) or isinstance(value, int):
return Util.boolean(value)
except Exception:
# Exception handling is done next.
pass
raise ValidationError(name, "must be an boolean but is '%s'" % (value))

Expand Down Expand Up @@ -2665,6 +2666,7 @@ def _parse_route_tables_mapping(cls, file_content, mapping):
try:
tableid = int(table[2:], 16)
except Exception:
# Exception handling is done next.
tyll marked this conversation as resolved.
Show resolved Hide resolved
pass
if tableid is None or tableid < 0 or tableid > 0xFFFFFFFF:
continue
Expand Down
2 changes: 2 additions & 0 deletions module_utils/network_lsr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def addr_family_norm(addr_family):
if addr_family in ["6", "inet6", "ip6", "ipv6", "IPv6"]:
return socket.AF_INET6
Util.addr_family_check(addr_family)
return None

@staticmethod
def addr_family_prefix_length(family):
Expand All @@ -348,6 +349,7 @@ def addr_family_prefix_length(family):
if addr_family == socket.AF_INET6:
return 128
Util.addr_family_check(addr_family)
return None

@staticmethod
def addr_family_valid_prefix(family, prefix):
Expand Down
Loading