Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 12, 2023
1 parent 6166a4f commit 3e5ef1c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
39 changes: 18 additions & 21 deletions plugins/cliconf/ioscm.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,19 @@ def get_diff(
option_values = self.get_option_values()

if candidate is None and device_operations["supports_generate_diff"]:
raise ValueError("candidate configuration is required to generate diff")
msg = "candidate configuration is required to generate diff"
raise ValueError(msg)

if diff_match not in option_values["diff_match"]:
msg = "'match' value {} in invalid, valid values are {}".format(diff_match, ", ".join(option_values["diff_match"]))
raise ValueError(
"'match' value {} in invalid, valid values are {}".format(
diff_match,
", ".join(option_values["diff_match"]),
),
msg,
)

if diff_replace not in option_values["diff_replace"]:
msg = "'replace' value {} in invalid, valid values are {}".format(diff_replace, ", ".join(option_values["diff_replace"]))
raise ValueError(
"'replace' value {} in invalid, valid values are {}".format(
diff_replace,
", ".join(option_values["diff_replace"]),
),
msg,
)

cand_pattern = r"(?P<parent>^\w.*\n?)(?P<child>(?:\s+.*\n?)*)"
Expand Down Expand Up @@ -291,22 +288,19 @@ def __get_diff(
option_values = self.get_option_values()

if candidate is None and device_operations["supports_generate_diff"]:
raise ValueError("candidate configuration is required to generate diff")
msg = "candidate configuration is required to generate diff"
raise ValueError(msg)

if diff_match not in option_values["diff_match"]:
msg = "'match' value {} in invalid, valid values are {}".format(diff_match, ", ".join(option_values["diff_match"]))
raise ValueError(
"'match' value {} in invalid, valid values are {}".format(
diff_match,
", ".join(option_values["diff_match"]),
),
msg,
)

if diff_replace not in option_values["diff_replace"]:
msg = "'replace' value {} in invalid, valid values are {}".format(diff_replace, ", ".join(option_values["diff_replace"]))
raise ValueError(
"'replace' value {} in invalid, valid values are {}".format(
diff_replace,
", ".join(option_values["diff_replace"]),
),
msg,
)

cand_pattern = r"(?P<parent>^\w.*\n?)(?P<child>(?:\s+.*\n?)*)"
Expand Down Expand Up @@ -436,7 +430,8 @@ def edit_config(self, candidate=None, commit=True, replace=None, comment=None):
# if commit_confirm:

else:
raise ValueError("check mode is not supported")
msg = "check mode is not supported"
raise ValueError(msg)

resp["request"] = requests
resp["response"] = results
Expand Down Expand Up @@ -498,7 +493,8 @@ def get(
check_all=False,
):
if not command:
raise ValueError("must provide value of command to execute")
msg = "must provide value of command to execute"
raise ValueError(msg)
if output:
raise ValueError("'output' value %s is not supported for get" % output)

Expand Down Expand Up @@ -627,7 +623,8 @@ def edit_banner(self, candidate=None, multiline_delimiter="@", commit=True):

def run_commands(self, commands=None, check_rc=True):
if commands is None:
raise ValueError("'commands' value is required")
msg = "'commands' value is required"
raise ValueError(msg)

responses = []
for cmd in to_list(commands):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def run_commands(self, conditionals, commands):
retries = self.module.params.get("retries")
while retries >= 0:
responses = run_commands(self.module, commands)
for item in list(conditionals):
for item in conditionals:
if item(responses):
if self.module.params.get("match") == "any":
conditionals = []
Expand Down
6 changes: 2 additions & 4 deletions plugins/module_utils/network/ioscm/config/ping/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def execute_module(self):
def build_ping(self, params):
tmplt = PingTemplate()
params = utils.remove_empties(params)
cmd = tmplt.render(params, "rate", False)
return cmd
return tmplt.render(params, "rate", False)

def validate_results(self, module, loss, results):
"""This function is used to validate whether the ping results were unexpected per "state" param."""
Expand All @@ -67,8 +66,7 @@ def generate_command(self):
self.result["commands"] = self.build_ping(self.module.params)

def run_command(self):
ping_results = run_commands(self.module, commands=self.result["commands"])
return ping_results
return run_commands(self.module, commands=self.result["commands"])

def process_result(self, ping_results):
"""
Expand Down
3 changes: 1 addition & 2 deletions plugins/module_utils/network/ioscm/ioscm.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,5 @@ def _get_number(name):
number_list = name.split(" ")
if_number = number_list[-1].strip() if len(number_list) == 2 else _get_number(name)

proper_interface = if_type + if_number if if_type else name
return if_type + if_number if if_type else name

return proper_interface
6 changes: 4 additions & 2 deletions plugins/terminal/ioscm.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def on_open_shell(self):
self._exec_cli_command(b"screen-length 0") # support to SD-WAN mode
_is_sdWan = True
except AnsibleConnectionFailure: # fails as length required for handling prompt
raise AnsibleConnectionFailure("unable to set terminal parameters")
msg = "unable to set terminal parameters"
raise AnsibleConnectionFailure(msg)
try:
if _is_sdWan:
self._exec_cli_command(b"screen-width 512") # support to SD-WAN mode
Expand Down Expand Up @@ -115,8 +116,9 @@ def on_become(self, passwd=None):
privilege_level = self.get_privilege_level()
except AnsibleConnectionFailure as e:
prompt = self._get_prompt()
msg = f"failed to elevate privilege to enable mode, at prompt [{prompt}] with error: {e.message}"
raise AnsibleConnectionFailure(
f"failed to elevate privilege to enable mode, at prompt [{prompt}] with error: {e.message}",
msg,
)

if prompt is None or not prompt.endswith(b"#") or privilege_level != 15:
Expand Down

0 comments on commit 3e5ef1c

Please sign in to comment.