MAC address comparison
Fixes:
- Move common keywords from test suites to
lib/bmc_network_utils.robot
- Add new python function to compare the MAC address.
Resolves openbmc/openbmc-test-automation#1261
Change-Id: Ie3447d6a82679152ccd0b571ade63a1f1b71fd05
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/extended/test_mac.robot b/extended/test_mac.robot
index 6e3966a..7b3750a 100644
--- a/extended/test_mac.robot
+++ b/extended/test_mac.robot
@@ -125,18 +125,6 @@
Validate MAC On BMC ${macaddr}
Set Suite Variable ${macaddr}
-Validate MAC on BMC
- [Documentation] Validate MAC on BMC.
- [Arguments] ${mac_addr}
-
- # Description of argument(s):
- # mac_addr MAC address of the BMC.
-
- ${system_mac}= Get BMC MAC Address
-
- Should Contain ${system_mac} ${mac_addr}
- ... ignore_case=True msg=MAC address does not exist.
-
Configure MAC Settings
[Documentation] Configure MAC settings.
[Arguments] ${mac_addr} ${expected_result}
diff --git a/extended/test_network.robot b/extended/test_network.robot
index 237ae3b..6008e65 100644
--- a/extended/test_network.robot
+++ b/extended/test_network.robot
@@ -473,17 +473,6 @@
... Should Contain ${route_info} ${gateway_ip}
... msg=Gateway IP address not matching.
-Validate MAC on BMC
- [Documentation] Validate MAC on BMC.
- [Arguments] ${macaddr}
-
- # Description of argument(s):
- # macaddr MAC address of the BMC.
-
- ${system_mac}= Get BMC MAC Address
-
- Should Contain ${system_mac} ${macaddr}
- ... ignore_case=True msg=MAC address does not exist.
Configure Network Settings
[Documentation] Configure network settings.
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index 7946974..41b248c 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -3,6 +3,7 @@
Resource ../lib/connection_client.robot
Resource ../lib/boot_utils.robot
Library ../lib/gen_misc.py
+Library ../lib/utils.py
*** Variables ***
# MAC input from user.
@@ -200,3 +201,17 @@
Fail msg=No non-pingable IP could be found in subnet ${network_part}.
+
+Validate MAC On BMC
+ [Documentation] Validate MAC on BMC.
+ [Arguments] ${mac_addr}
+
+ # Description of argument(s):
+ # mac_addr MAC address of the BMC.
+
+ ${system_mac}= Get BMC MAC Address
+
+ ${status}= Compare MAC Address ${system_mac} ${mac_addr}
+ Should Be True ${status}
+ ... msg=MAC address ${system_mac} does not match ${mac_addr}.
+
diff --git a/lib/utils.py b/lib/utils.py
index e7d6843..2964129 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -198,3 +198,23 @@
return int(out_buf, 16)
+def compare_mac_address(sys_mac_addr, user_mac_addr):
+
+ r"""
+ Return 1 if the MAC value matched, otherwise 0.
+
+. Description of argument(s):
+ sys_mac_addr A valid system MAC string (e.g. "70:e2:84:14:2a:08")
+ user_mac_addr A user provided MAC string (e.g. "70:e2:84:14:2a:08")
+ """
+
+ index = 0
+ # Example: ['70', 'e2', '84', '14', '2a', '08']
+ mac_list = user_mac_addr.split(":")
+ for item in sys_mac_addr.split(":"):
+ if int(item, 16) == int(mac_list[index], 16):
+ index = index + 1
+ continue
+ return 0
+
+ return 1