ce_mlag_interface:update to fix a bug (#60144)
* update to fix a bug * ansible-test Ignoring 'blacklisted-name' on 'lib/ansible/modules/network/cloudengine/ce_mlag_interface.py' is unnecessary * update * update * update for shippable * update for shippable * Update ce_mlag_interface.py * Update ce_mlag_interface.py * Update ce_mlag_interface.py * Update ce_mlag_interface.py
This commit is contained in:
parent
acd459f909
commit
b2d145d924
1 changed files with 40 additions and 19 deletions
|
@ -152,6 +152,7 @@ CE_NC_GET_MLAG_INFO = """
|
|||
<mlag xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
|
||||
<mlagInstances>
|
||||
<mlagInstance>
|
||||
%s
|
||||
</mlagInstance>
|
||||
</mlagInstances>
|
||||
</mlag>
|
||||
|
@ -162,7 +163,7 @@ CE_NC_CREATE_MLAG_INFO = """
|
|||
<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>
|
||||
|
@ -178,7 +179,6 @@ CE_NC_DELETE_MLAG_INFO = """
|
|||
<mlagInstances>
|
||||
<mlagInstance operation="delete">
|
||||
<dfsgroupId>%s</dfsgroupId>
|
||||
<mlagId>%s</mlagId>
|
||||
<localMlagPort>%s</localMlagPort>
|
||||
</mlagInstance>
|
||||
</mlagInstances>
|
||||
|
@ -265,7 +265,7 @@ CE_NC_CREATE_MLAG_ERROR_DOWN_INFO = """
|
|||
<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>
|
||||
|
@ -386,7 +386,7 @@ class MlagInterface(object):
|
|||
""" 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
|
||||
|
@ -398,7 +398,7 @@ class MlagInterface(object):
|
|||
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:
|
||||
|
@ -424,7 +424,7 @@ class MlagInterface(object):
|
|||
|
||||
root = ElementTree.fromstring(xml_str)
|
||||
global_info = root.findall(
|
||||
"data/ifmtrunk/lacpSysInfo/lacpMlagGlobal")
|
||||
"./ifmtrunk/lacpSysInfo/lacpMlagGlobal")
|
||||
|
||||
if global_info:
|
||||
for tmp in global_info:
|
||||
|
@ -450,7 +450,7 @@ class MlagInterface(object):
|
|||
|
||||
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:
|
||||
|
@ -475,7 +475,7 @@ class MlagInterface(object):
|
|||
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:
|
||||
|
@ -506,7 +506,12 @@ class MlagInterface(object):
|
|||
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):
|
||||
|
@ -582,7 +587,7 @@ class MlagInterface(object):
|
|||
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
|
||||
|
||||
|
@ -713,7 +718,7 @@ class MlagInterface(object):
|
|||
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(
|
||||
|
@ -786,20 +791,27 @@ class MlagInterface(object):
|
|||
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):
|
||||
|
@ -829,17 +841,24 @@ class MlagInterface(object):
|
|||
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):
|
||||
|
@ -878,18 +897,18 @@ class MlagInterface(object):
|
|||
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:
|
||||
|
@ -980,6 +999,8 @@ class MlagInterface(object):
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue