From b7f4e2a190199f9d2b5d9e9224c5d0cecf9cf3f9 Mon Sep 17 00:00:00 2001 From: xuxiaowei0512 Date: Thu, 30 May 2019 00:40:31 +0800 Subject: [PATCH] update ospf modules to fix bugs as software version changes (#56974) --- .../modules/network/cloudengine/ce_ospf.py | 22 +++++++++---------- .../network/cloudengine/ce_ospf_vrf.py | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/network/cloudengine/ce_ospf.py b/lib/ansible/modules/network/cloudengine/ce_ospf.py index 8840b1b16d..2569281f8e 100644 --- a/lib/ansible/modules/network/cloudengine/ce_ospf.py +++ b/lib/ansible/modules/network/cloudengine/ce_ospf.py @@ -442,7 +442,7 @@ class OSPF(object): # get process base info root = ElementTree.fromstring(xml_str) - ospfsite = root.find("data/ospfv2/ospfv2comm/ospfSites/ospfSite") + ospfsite = root.find("ospfv2/ospfv2comm/ospfSites/ospfSite") if ospfsite: for site in ospfsite: if site.tag in ["processId", "routerId", "vrfName"]: @@ -450,7 +450,7 @@ class OSPF(object): # get Topology info topo = root.find( - "data/ospfv2/ospfv2comm/ospfSites/ospfSite/ProcessTopologys/ProcessTopology") + "ospfv2/ospfv2comm/ospfSites/ospfSite/ProcessTopologys/ProcessTopology") if topo: for eles in topo: if eles.tag in ["maxLoadBalancing"]: @@ -459,7 +459,7 @@ class OSPF(object): # get nexthop info ospf_info["nexthops"] = list() nexthops = root.findall( - "data/ospfv2/ospfv2comm/ospfSites/ospfSite/ProcessTopologys/ProcessTopology/nexthopMTs/nexthopMT") + "ospfv2/ospfv2comm/ospfSites/ospfSite/ProcessTopologys/ProcessTopology/nexthopMTs/nexthopMT") if nexthops: for nexthop in nexthops: nh_dict = dict() @@ -471,7 +471,7 @@ class OSPF(object): # get areas info ospf_info["areas"] = list() areas = root.findall( - "data/ospfv2/ospfv2comm/ospfSites/ospfSite/areas/area") + "ospfv2/ospfv2comm/ospfSites/ospfSite/areas/area") if areas: for area in areas: area_dict = dict() @@ -490,15 +490,12 @@ class OSPF(object): area_dict["networks"].append(net_dict) ospf_info["areas"].append(area_dict) - return ospf_info def is_area_exist(self): """is ospf area exist""" - if not self.ospf_info: return False - for area in self.ospf_info["areas"]: if area["areaId"] == self.get_area_ip(): return True @@ -507,7 +504,6 @@ class OSPF(object): def is_network_exist(self): """is ospf area network exist""" - if not self.ospf_info: return False @@ -528,7 +524,6 @@ class OSPF(object): if not self.ospf_info: return False - for nexthop in self.ospf_info["nexthops"]: if nexthop["ipAddress"] == self.nexthop_addr: return True @@ -537,7 +532,6 @@ class OSPF(object): def is_nexthop_change(self): """is ospf nexthop change""" - if not self.ospf_info: return True @@ -555,6 +549,8 @@ class OSPF(object): xml_area = "" self.updates_cmd.append("ospf %s" % self.process_id) + xml_create = CE_NC_CREATE_PROCESS % self.process_id + set_nc_config(self.module, xml_create) # nexthop weight xml_nh = "" @@ -607,7 +603,7 @@ class OSPF(object): self.updates_cmd.pop() self.updates_cmd.append( "authentication-mode %s %s %s" % (self.auth_mode, self.auth_key_id, self.auth_text_md5)) - if xml_network or xml_auth: + if xml_network or xml_auth or not self.is_area_exist(): xml_area += CE_NC_XML_BUILD_MERGE_AREA % ( self.get_area_ip(), xml_network + xml_auth) @@ -884,6 +880,7 @@ class OSPF(object): """get end state info""" ospf_info = self.get_ospf_dict(self.process_id) + if not ospf_info: return @@ -892,6 +889,9 @@ class OSPF(object): self.end_state["nexthops"] = ospf_info["nexthops"] self.end_state["max_load_balance"] = ospf_info.get("maxLoadBalancing") + if self.end_state == self.existing: + self.changed = False + def work(self): """worker""" diff --git a/lib/ansible/modules/network/cloudengine/ce_ospf_vrf.py b/lib/ansible/modules/network/cloudengine/ce_ospf_vrf.py index ff084668f4..6eed6dcd02 100644 --- a/lib/ansible/modules/network/cloudengine/ce_ospf_vrf.py +++ b/lib/ansible/modules/network/cloudengine/ce_ospf_vrf.py @@ -1047,7 +1047,7 @@ class OspfVrf(object): # get the vpn address family and RD text ospf_sites = root.findall( - "data/ospfv2/ospfv2comm/ospfSites/ospfSite") + "ospfv2/ospfv2comm/ospfSites/ospfSite") if ospf_sites: for ospf_site in ospf_sites: ospf_ele_info = dict() @@ -1063,7 +1063,8 @@ class OspfVrf(object): "spfScheduleIntervalType"]: ospf_ele_info[ ospf_site_ele.tag] = ospf_site_ele.text - self.ospf_info["ospfsite"].append(ospf_ele_info) + if ospf_ele_info["processId"] == self.ospf: + self.ospf_info["ospfsite"].append(ospf_ele_info) def get_proposed(self): """get proposed info"""