[BugFix] Fix the bug that it gets error system-mac of centec platform (#12721)

Why I did it
When getting system mac of centec platform, it would increase by 1 the last byte of mac, but it could not consider the case of carry.

How I did it
Firstly, I would replace the ":" with "" of mac to a string.
And then, I would convert the mac from string to int and increase by 1, at last convert it to string with inserting ":".
This commit is contained in:
Yoush 2023-01-19 01:24:28 +08:00 committed by Qi Luo
parent 83b6518ae2
commit 7adf2b1c05

View File

@ -473,9 +473,10 @@ def get_system_mac(namespace=None):
# Align last byte of MAC if necessary # Align last byte of MAC if necessary
if version_info and version_info['asic_type'] == 'centec': if version_info and version_info['asic_type'] == 'centec':
last_byte = mac[-2:] mac_tmp = mac.replace(':','')
aligned_last_byte = format(int(int(last_byte, 16) + 1), '02x') mac_tmp = "{:012x}".format(int(mac_tmp, 16) + 1)
mac = mac[:-2] + aligned_last_byte mac_tmp = re.sub("(.{2})", "\\1:", mac_tmp, 0, re.DOTALL)
mac = mac_tmp[:-1]
return mac return mac