1*** Settings ***
2Documentation  Test BMC network interface functionalities.
3
4Resource       ../../lib/bmc_redfish_resource.robot
5Resource       ../../lib/bmc_network_utils.robot
6Resource       ../../lib/openbmc_ffdc.robot
7Library        ../../lib/bmc_network_utils.py
8
9Suite Setup    Suite Setup Execution
10Test Teardown  Test Teardown Execution
11
12Force Tags     MAC_Test
13
14*** Variables ***
15
16# AA:AA:AA:AA:AA:AA series is a valid MAC and does not exist in
17# our network, so this is chosen to avoid MAC conflict.
18${valid_mac}         AA:E2:84:14:28:79
19${zero_mac}          00:00:00:00:00:00
20${broadcast_mac}     FF:FF:FF:FF:FF:FF
21${out_of_range_mac}  AA:FF:FF:FF:FF:100
22
23# There will be 6 bytes in MAC address (e.g. xx.xx.xx.xx.xx.xx).
24# Here trying to configure xx.xx.xx.xx.xx
25${less_byte_mac}     AA:AA:AA:AA:BB
26# Here trying to configure xx.xx.xx.xx.xx.xx.xx
27${more_byte_mac}     AA:AA:AA:AA:AA:AA:BB
28
29# MAC address with special characters.
30${special_char_mac}  &A:$A:AA:AA:AA:^^
31
32*** Test Cases ***
33
34Configure Valid MAC And Verify
35    [Documentation]  Configure valid MAC via Redfish and verify.
36    [Tags]  Configure_Valid_MAC_And_Verify
37
38    Configure MAC Settings  ${valid_mac}  valid
39
40    # Verify whether new MAC is configured on BMC.
41    Validate MAC On BMC  ${valid_mac}
42
43
44Configure Zero MAC And Verify
45    [Documentation]  Configure zero MAC via Redfish and verify.
46    [Tags]  Configure_Zero_MAC_And_Verify
47
48    [Template]  Configure MAC Settings
49    # MAC address  scenario
50    ${zero_mac}    error
51
52
53Configure Broadcast MAC And Verify
54    [Documentation]  Configure broadcast MAC via Redfish and verify.
55    [Tags]  Configure_Broadcast_MAC_And_Verify
56
57    [Template]  Configure MAC Settings
58    # MAC address    scenario
59    ${broadcast_mac}  error
60
61Configure Invalid MAC And Verify
62    [Documentation]  Configure invalid MAC address which is a string.
63    [Tags]  Configure_Invalid_MAC_And_Verify
64
65    [Template]  Configure MAC Settings
66    # MAC Address        Expected_Result
67    ${special_char_mac}  error
68
69Configure Valid MAC And Check Persistency
70    [Documentation]  Configure valid MAC and check persistency.
71    [Tags]  Configure_Valid_MAC_And_Check_Persistency
72
73    Configure MAC Settings  ${valid_mac}  valid
74
75    # Verify whether new MAC is configured on BMC.
76    Validate MAC On BMC  ${valid_mac}
77
78    # Reboot BMC and check whether MAC is persistent.
79    OBMC Reboot (off)
80    Validate MAC On BMC  ${valid_mac}
81
82Configure Out Of Range MAC And Verify
83    [Documentation]  Configure out of range MAC via Redfish and verify.
84    [Tags]  Configure_Out_Of_Range_MAC_And_Verify
85
86    [Template]  Configure MAC Settings
87    # MAC address        scenario
88    ${out_of_range_mac}  error
89
90Configure Less Byte MAC And Verify
91    [Documentation]  Configure less byte MAC via Redfish and verify.
92    [Tags]  Configure_Less_Byte_MAC_And_Verify
93
94    [Template]  Configure MAC Settings
95    # MAC address     scenario
96    ${less_byte_mac}  error
97
98Configure More Byte MAC And Verify
99    [Documentation]  Configure more byte MAC via Redfish and verify.
100    [Tags]  Configure_More_Byte_MAC_And_Verify
101
102    [Template]  Configure MAC Settings
103    # MAC address     scenario
104    ${more_byte_mac}  error
105
106*** Keywords ***
107
108Test Teardown Execution
109    [Documentation]  Do the post test teardown.
110
111    # Revert to initial MAC address.
112    Configure MAC Settings  ${initial_mac_address}  valid
113
114    # Verify whether new MAC is configured on BMC.
115    Validate MAC On BMC  ${initial_mac_address}
116
117    FFDC On Test Case Fail
118    Redfish.Logout
119
120
121Suite Setup Execution
122    [Documentation]  Do suite setup tasks.
123
124    Redfish.Login
125
126    # Get BMC MAC address.
127    ${resp}=  redfish.Get  ${REDFISH_NW_ETH0_URI}
128    Set Suite Variable  ${initial_mac_address}  ${resp.dict['MACAddress']}
129
130    Validate MAC On BMC  ${initial_mac_address}
131
132    Redfish.Logout
133
134
135Configure MAC Settings
136    [Documentation]  Configure MAC settings via Redfish.
137    [Arguments]  ${mac_address}  ${expected_result}
138
139    # Description of argument(s):
140    # mac_address      MAC address of BMC.
141    # expected_result  Expected status of MAC configuration.
142
143    Redfish.Login
144    ${payload}=  Create Dictionary  MACAddress=${mac_address}
145
146    Redfish.Patch  ${REDFISH_NW_ETH0_URI}  body=&{payload}
147    ...  valid_status_codes=[200, 400, 500]
148
149    # After any modification on network interface, BMC restarts network
150    # module, wait until it is reachable.
151
152    Wait Until Keyword Succeeds  ${NETWORK_TIMEOUT}  ${NETWORK_RETRY_TIME}
153    ...  redfish.Get  ${REDFISH_NW_ETH0_URI}
154
155    # Verify whether new MAC address is populated on BMC system.
156    # It should not allow to configure invalid settings.
157
158    ${status}=  Run Keyword And Return Status
159    ...  Validate MAC On BMC  ${mac_address}
160
161    Run Keyword If  '${expected_result}' == 'error'
162    ...      Should Be Equal  ${status}  ${False}
163    ...      msg=Allowing the configuration of an invalid MAC.
164    ...  ELSE
165    ...      Should Be Equal  ${status}  ${True}
166    ...      msg=Not allowing the configuration of a valid MAC.
167
168