From fd2d0c254ecc6ab951db910f20ed5150bc61d421 Mon Sep 17 00:00:00 2001 From: yanzhangi <51999930+yanzhangi@users.noreply.github.com> Date: Thu, 19 Sep 2019 00:41:48 +0800 Subject: [PATCH] [Backport/2.8/61774]Update ce_stp to fix bugs (#62511) * Update ce_stp to fix bugs (cherry picked from commit c62a0b35c78b4a2c1f2c17b9b9b1e0771ffc5c23) * Update ce_stp modified information --- .../fragments/61774-ce_stp-to-fix-bugs.yml | 2 ++ .../modules/network/cloudengine/ce_stp.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/61774-ce_stp-to-fix-bugs.yml diff --git a/changelogs/fragments/61774-ce_stp-to-fix-bugs.yml b/changelogs/fragments/61774-ce_stp-to-fix-bugs.yml new file mode 100644 index 00000000000..395adb10664 --- /dev/null +++ b/changelogs/fragments/61774-ce_stp-to-fix-bugs.yml @@ -0,0 +1,2 @@ +bugfixes: +- ce_stp - update to fix some bugs - Modify the configured query statement and replace get_config with exec_command. (https://github.com/ansible/ansible/pull/61774) diff --git a/lib/ansible/modules/network/cloudengine/ce_stp.py b/lib/ansible/modules/network/cloudengine/ce_stp.py index 99738f3338d..046af50d55f 100644 --- a/lib/ansible/modules/network/cloudengine/ce_stp.py +++ b/lib/ansible/modules/network/cloudengine/ce_stp.py @@ -167,14 +167,23 @@ updates: import re from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.cloudengine.ce import load_config, ce_argument_spec -from ansible.module_utils.network.cloudengine.ce import get_config as get_cli_config +from ansible.module_utils.network.cloudengine.ce import exec_command, load_config, ce_argument_spec def get_config(module, flags): - cfg = get_cli_config(module, flags) - config = cfg.strip() if cfg else "" + """Retrieves the current config from the device or cache""" + + flags = [] if flags is None else flags + + cmd = 'display current-configuration ' + cmd += ' '.join(flags) + cmd = cmd.strip() + + rc, out, err = exec_command(module, cmd) + if rc != 0: + module.fail_json(msg=err) + config = str(out).strip() if config.startswith("display"): configs = config.split("\n") if len(configs) > 1: