Backport/2.8/59347 ce_stp: update to fix a bug. (#59347) (#59685)

* ce_stp: update to fix a bug. (#59347)

* update to fix a bug.

* update for shippable.

* Update ce_stp.py

(cherry picked from commit c3d1f9b085)

* add a changelog fragment.

* Update 59685-ce_stp-to-fix-bugs.yml
This commit is contained in:
Xu Yuandong 2019-07-31 04:34:14 +08:00 committed by Toshio Kuratomi
parent 2a1e7403c4
commit 8badf3b3cb
2 changed files with 29 additions and 10 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- ce_stp - update to fix some bugs - The config of first time showing is same as second because of 'get_config', using regular to search & show config (https://github.com/ansible/ansible/pull/59347 )

View file

@ -167,7 +167,22 @@ updates:
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.cloudengine.ce import get_config, load_config, ce_argument_spec
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
def get_config(module, flags):
cfg = get_cli_config(module, flags)
config = cfg.strip() if cfg else ""
if config.startswith("display"):
configs = config.split("\n")
if len(configs) > 1:
return "\n".join(configs[1:])
else:
return ""
else:
return config
class Stp(object):
@ -219,17 +234,14 @@ class Stp(object):
def cli_get_stp_config(self):
""" Cli get stp configuration """
regular = "| include stp"
flags = list()
flags.append(regular)
flags = [r"| section include #\s*\n\s*stp", r"| section exclude #\s*\n+\s*stp process \d+"]
self.stp_cfg = get_config(self.module, flags)
def cli_get_interface_stp_config(self):
""" Cli get interface's stp configuration """
if self.interface:
regular = "| ignore-case section include ^interface %s$" % self.interface
regular = r"| ignore-case section include ^#\s+interface %s\s+" % self.interface.replace(" ", "")
flags = list()
flags.append(regular)
tmp_cfg = get_config(self.module, flags)
@ -399,7 +411,8 @@ class Stp(object):
self.existing["bpdu_protection"] = "disable"
if self.tc_protection:
if "stp tc-protection" in self.stp_cfg:
pre_cfg = self.stp_cfg.split("\n")
if "stp tc-protection" in pre_cfg:
self.cur_cfg["tc_protection"] = "enable"
self.existing["tc_protection"] = "enable"
else:
@ -513,7 +526,8 @@ class Stp(object):
self.end_state["bpdu_protection"] = "disable"
if self.tc_protection:
if "stp tc-protection" in self.stp_cfg:
pre_cfg = self.stp_cfg.split("\n")
if "stp tc-protection" in pre_cfg:
self.end_state["tc_protection"] = "enable"
else:
self.end_state["tc_protection"] = "disable"
@ -545,18 +559,21 @@ class Stp(object):
else:
self.end_state["cost"] = tmp_value[0][1]
if self.root_protection:
if self.root_protection or self.loop_protection:
if "stp root-protection" in self.interface_stp_cfg:
self.end_state["root_protection"] = "enable"
else:
self.end_state["root_protection"] = "disable"
if self.loop_protection:
if "stp loop-protection" in self.interface_stp_cfg:
self.end_state["loop_protection"] = "enable"
else:
self.end_state["loop_protection"] = "disable"
if self.existing == self.end_state:
self.changed = False
self.updates_cmd = list()
def present_stp(self):
""" Present stp configuration """