Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ce_mlag_interface:update to fix a bug #60144

Merged
merged 10 commits into from
Sep 18, 2019
59 changes: 40 additions & 19 deletions lib/ansible/modules/network/cloudengine/ce_mlag_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<mlag xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<mlagInstances>
<mlagInstance>
%s
</mlagInstance>
</mlagInstances>
</mlag>
Expand All @@ -162,7 +163,7 @@
<config>
<mlag xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<mlagInstances>
<mlagInstance operation="create">
<mlagInstance operation="merge">
<dfsgroupId>%s</dfsgroupId>
<mlagId>%s</mlagId>
<localMlagPort>%s</localMlagPort>
Expand All @@ -178,7 +179,6 @@
<mlagInstances>
<mlagInstance operation="delete">
<dfsgroupId>%s</dfsgroupId>
<mlagId>%s</mlagId>
<localMlagPort>%s</localMlagPort>
</mlagInstance>
</mlagInstances>
Expand Down Expand Up @@ -265,7 +265,7 @@
<config>
<mlag xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<errordowns>
<errordown operation="create">
<errordown operation="merge">
<dfsgroupId>1</dfsgroupId>
<portName>%s</portName>
</errordown>
Expand Down Expand Up @@ -386,7 +386,7 @@ def get_mlag_info(self):
""" get mlag info."""

mlag_info = dict()
conf_str = CE_NC_GET_MLAG_INFO
conf_str = CE_NC_GET_MLAG_INFO % ("<localMlagPort>Eth-Trunk%s</localMlagPort>" % self.eth_trunk_id)
xml_str = get_nc_config(self.module, conf_str)
if "<data/>" in xml_str:
return mlag_info
Expand All @@ -398,7 +398,7 @@ def get_mlag_info(self):
mlag_info["mlagInfos"] = list()
root = ElementTree.fromstring(xml_str)
dfs_mlag_infos = root.findall(
"data/mlag/mlagInstances/mlagInstance")
"./mlag/mlagInstances/mlagInstance")

if dfs_mlag_infos:
for dfs_mlag_info in dfs_mlag_infos:
Expand All @@ -424,7 +424,7 @@ def get_mlag_global_info(self):

root = ElementTree.fromstring(xml_str)
global_info = root.findall(
"data/ifmtrunk/lacpSysInfo/lacpMlagGlobal")
"./ifmtrunk/lacpSysInfo/lacpMlagGlobal")

if global_info:
for tmp in global_info:
Expand All @@ -450,7 +450,7 @@ def get_mlag_trunk_attribute_info(self):

root = ElementTree.fromstring(xml_str)
global_info = root.findall(
"data/ifmtrunk/TrunkIfs/TrunkIf/lacpMlagIf")
"./ifmtrunk/TrunkIfs/TrunkIf/lacpMlagIf")

if global_info:
for tmp in global_info:
Expand All @@ -475,7 +475,7 @@ def get_mlag_error_down_info(self):
mlag_error_down_info["mlagErrorDownInfos"] = list()
root = ElementTree.fromstring(xml_str)
mlag_error_infos = root.findall(
"data/mlag/errordowns/errordown")
"./mlag/errordowns/errordown")

if mlag_error_infos:
for mlag_error_info in mlag_error_infos:
Expand Down Expand Up @@ -506,7 +506,12 @@ def check_macaddr(self):
for _, value in enumerate(mac, start=0):
if value.lower() not in valid_char:
return False

if all((int(mac_list[0], base=16) == 0, int(mac_list[1], base=16) == 0, int(mac_list[2], base=16) == 0)):
return False
a = "000" + mac_list[0]
b = "000" + mac_list[1]
c = "000" + mac_list[2]
self.mlag_system_id = "-".join([a[-4:], b[-4:], c[-4:]])
return True

def check_params(self):
Expand Down Expand Up @@ -582,7 +587,7 @@ def is_mlag_info_exist(self):
eth_trunk += self.eth_trunk_id

for info in self.mlag_info["mlagInfos"]:
if info["mlagId"] == self.mlag_id and info["localMlagPort"] == eth_trunk:
if info["localMlagPort"] == eth_trunk:
return True
return False

Expand Down Expand Up @@ -713,7 +718,7 @@ def delete_mlag(self):
mlag_port = "Eth-Trunk"
mlag_port += self.eth_trunk_id
conf_str = CE_NC_DELETE_MLAG_INFO % (
self.dfs_group_id, self.mlag_id, mlag_port)
self.dfs_group_id, mlag_port)
recv_xml = set_nc_config(self.module, conf_str)
if "<ok/>" not in recv_xml:
self.module.fail_json(
Expand Down Expand Up @@ -786,20 +791,27 @@ def delete_mlag_interface(self):
if self.is_mlag_interface_info_exist():
mlag_port = "Eth-Trunk"
mlag_port += self.eth_trunk_id

conf_str = CE_NC_SET_LACP_MLAG_INFO_HEAD % mlag_port
cmd = "interface %s" % mlag_port
self.cli_add_command(cmd)

if self.mlag_priority_id:
cmd = "lacp m-lag priority %s" % self.mlag_priority_id
conf_str += "<lacpMlagPriority></lacpMlagPriority>"
self.cli_add_command(cmd, True)

if self.mlag_system_id:
cmd = "lacp m-lag system-id %s" % self.mlag_system_id
conf_str += "<lacpMlagSysId></lacpMlagSysId>"
self.cli_add_command(cmd, True)

if self.commands:
self.cli_load_config(self.commands)
conf_str += CE_NC_SET_LACP_MLAG_INFO_TAIL
recv_xml = set_nc_config(self.module, conf_str)
if "<ok/>" not in recv_xml:
self.module.fail_json(
msg='Error: set mlag interface atrribute info failed.')

self.changed = True

def set_mlag_global(self):
Expand Down Expand Up @@ -829,17 +841,24 @@ def set_mlag_global(self):
def delete_mlag_global(self):
"""delete mlag global attribute info"""

xml_str = ''
if self.is_mlag_global_info_exist():
if self.mlag_priority_id:
cmd = "lacp m-lag priority %s" % self.mlag_priority_id
xml_str += '<lacpMlagPriority></lacpMlagPriority>'
self.cli_add_command(cmd, True)

if self.mlag_system_id:
cmd = "lacp m-lag system-id %s" % self.mlag_system_id
xml_str += '<lacpMlagSysId></lacpMlagSysId>'
self.cli_add_command(cmd, True)

if self.commands:
self.cli_load_config(self.commands)
if xml_str != '':
conf_str = CE_NC_SET_GLOBAL_LACP_MLAG_INFO_HEAD + xml_str + CE_NC_SET_GLOBAL_LACP_MLAG_INFO_TAIL
recv_xml = set_nc_config(self.module, conf_str)
if "<ok/>" not in recv_xml:
self.module.fail_json(
msg='Error: set mlag interface atrribute info failed.')
self.changed = True

def get_proposed(self):
Expand Down Expand Up @@ -878,18 +897,18 @@ def get_existing(self):
if self.eth_trunk_id:
if self.mlag_trunk_attribute_info:
if self.mlag_system_id:
self.end_state["lacpMlagSysId"] = self.mlag_trunk_attribute_info[
self.existing["lacpMlagSysId"] = self.mlag_trunk_attribute_info[
"lacpMlagSysId"]
if self.mlag_priority_id:
self.end_state["lacpMlagPriority"] = self.mlag_trunk_attribute_info[
self.existing["lacpMlagPriority"] = self.mlag_trunk_attribute_info[
"lacpMlagPriority"]
else:
if self.mlag_global_info:
if self.mlag_system_id:
self.end_state["lacpMlagSysId"] = self.mlag_global_info[
self.existing["lacpMlagSysId"] = self.mlag_global_info[
"lacpMlagSysId"]
if self.mlag_priority_id:
self.end_state["lacpMlagPriority"] = self.mlag_global_info[
self.existing["lacpMlagPriority"] = self.mlag_global_info[
"lacpMlagPriority"]

if self.interface or self.mlag_error_down:
Expand Down Expand Up @@ -980,6 +999,8 @@ def work(self):
msg='Error: interface, mlag_error_down must be config at the same time.')

self.get_end_state()
if self.existing == self.end_state:
self.changed = False
self.results['changed'] = self.changed
self.results['proposed'] = self.proposed
self.results['existing'] = self.existing
Expand Down