From a69b936ac650fee178a5c07c74db6aeea739267a Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 10 Aug 2020 11:13:45 -0400 Subject: vyos_interface : refactor testcases (#71) vyos_interface : refactor testcases Reviewed-by: https://github.com/apps/ansible-zuul --- plugins/modules/vyos_interface.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'plugins/modules/vyos_interface.py') diff --git a/plugins/modules/vyos_interface.py b/plugins/modules/vyos_interface.py index 839e559..21b0dc2 100644 --- a/plugins/modules/vyos_interface.py +++ b/plugins/modules/vyos_interface.py @@ -277,7 +277,6 @@ def search_obj_in_list(name, lst): def map_obj_to_commands(updates): commands = list() want, have = updates - params = ("speed", "description", "duplex", "mtu") for w in want: name = w["name"] @@ -402,6 +401,18 @@ def map_params_to_obj(module): return obj +def get_interfaces_data(module, name): + command = "show interfaces ethernet %s" % name + rc, out, err = exec_command(module, command) + return [rc, out, err] + + +def get_lldp_neighbor(module): + command = "show lldp neighbors detail" + rc, out, err = exec_command(module, command) + return [rc, out, err] + + def check_declarative_intent_params(module, want, result): failed_conditions = [] have_neighbors = None @@ -416,7 +427,7 @@ def check_declarative_intent_params(module, want, result): sleep(w["delay"]) command = "show interfaces ethernet %s" % w["name"] - rc, out, err = exec_command(module, command) + rc, out, err = get_interfaces_data(w["name"], module) if rc != 0: module.fail_json( msg=to_text(err, errors="surrogate_then_replace"), @@ -438,9 +449,7 @@ def check_declarative_intent_params(module, want, result): have_host = [] have_port = [] if have_neighbors is None: - rc, have_neighbors, err = exec_command( - module, "show lldp neighbors detail" - ) + rc, have_neighbors, err = get_lldp_neighbor(module) if rc != 0: module.fail_json( msg=to_text(err, errors="surrogate_then_replace"), -- cgit v1.2.3