diff --git a/plugins/cliconf/ioscm.py b/plugins/cliconf/ioscm.py index 1beda4f..a0b423c 100644 --- a/plugins/cliconf/ioscm.py +++ b/plugins/cliconf/ioscm.py @@ -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^\w.*\n?)(?P(?:\s+.*\n?)*)" @@ -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^\w.*\n?)(?P(?:\s+.*\n?)*)" @@ -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 @@ -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) @@ -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): diff --git a/plugins/module_utils/network/ioscm/config/command/command.py b/plugins/module_utils/network/ioscm/config/command/command.py index bf66af6..f889713 100644 --- a/plugins/module_utils/network/ioscm/config/command/command.py +++ b/plugins/module_utils/network/ioscm/config/command/command.py @@ -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 = [] diff --git a/plugins/module_utils/network/ioscm/config/ping/ping.py b/plugins/module_utils/network/ioscm/config/ping/ping.py index 691c682..24f905c 100644 --- a/plugins/module_utils/network/ioscm/config/ping/ping.py +++ b/plugins/module_utils/network/ioscm/config/ping/ping.py @@ -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.""" @@ -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): """ diff --git a/plugins/module_utils/network/ioscm/ioscm.py b/plugins/module_utils/network/ioscm/ioscm.py index ece2e24..333a9f9 100644 --- a/plugins/module_utils/network/ioscm/ioscm.py +++ b/plugins/module_utils/network/ioscm/ioscm.py @@ -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 diff --git a/plugins/terminal/ioscm.py b/plugins/terminal/ioscm.py index c3ab52e..7663050 100644 --- a/plugins/terminal/ioscm.py +++ b/plugins/terminal/ioscm.py @@ -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 @@ -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: