blob: 1a9c65a509281b884c4192f22c2b1343d0040dea [file] [log] [blame]
Prashanth Kattif58cce02019-02-06 03:05:14 -06001*** Settings ***
2Documentation Network interface configuration and verification
3 ... tests.
4
George Keishing5d467552019-02-08 23:30:48 -06005Resource ../../lib/bmc_redfish_resource.robot
6Resource ../../lib/bmc_network_utils.robot
7Resource ../../lib/openbmc_ffdc.robot
Prashanth Katti747ce9d2019-02-07 07:23:48 -06008Library ../../lib/bmc_network_utils.py
Vijayde3bf7b2019-04-16 04:56:09 -05009Library Collections
Prashanth Kattif58cce02019-02-06 03:05:14 -060010
11Test Setup Test Setup Execution
12Test Teardown Test Teardown Execution
13
Prashanth Katti23efc6e2019-03-13 06:07:15 -050014*** Variables ***
Vijayde3bf7b2019-04-16 04:56:09 -050015${test_hostname} openbmc
16${test_ipv4_addr} 10.7.7.7
17${test_ipv4_invalid_addr} 0.0.1.a
18${test_subnet_mask} 255.255.0.0
19${test_gateway} 10.7.7.1
Prashanth Katti23efc6e2019-03-13 06:07:15 -050020
Prashanth Kattif58cce02019-02-06 03:05:14 -060021*** Test Cases ***
22
23Get IP Address And Verify
24 [Documentation] Get IP Address And Verify.
George Keishing5d467552019-02-08 23:30:48 -060025 [Tags] Get_IP_Address_And_Verify
Prashanth Kattif58cce02019-02-06 03:05:14 -060026
27 : FOR ${network_configuration} IN @{network_configurations}
Prashanth Katti747ce9d2019-02-07 07:23:48 -060028 \ Verify IP On BMC ${network_configuration['Address']}
29
Prashanth Kattif58cce02019-02-06 03:05:14 -060030Get Netmask And Verify
31 [Documentation] Get Netmask And Verify.
George Keishing5d467552019-02-08 23:30:48 -060032 [Tags] Get_Netmask_And_Verify
Prashanth Kattif58cce02019-02-06 03:05:14 -060033
34 : FOR ${network_configuration} IN @{network_configurations}
Prashanth Katti747ce9d2019-02-07 07:23:48 -060035 \ Verify Netmask On BMC ${network_configuration['SubnetMask']}
36
Prashanth Katti2ec9d8b2019-02-12 05:20:19 -060037Get Gateway And Verify
38 [Documentation] Get gateway and verify it's existence on the BMC.
39 [Tags] Get_Gateway_And_Verify
40
41 : FOR ${network_configuration} IN @{network_configurations}
42 \ Verify Gateway On BMC ${network_configuration['Gateway']}
43
44Get MAC Address And Verify
45 [Documentation] Get MAC address and verify it's existence on the BMC.
46 [Tags] Get_MAC_Address_And_Verify
47
George Keishing97c93942019-03-04 12:45:07 -060048 ${resp}= Redfish.Get ${REDFISH_NW_ETH0_URI}
Prashanth Katti2ec9d8b2019-02-12 05:20:19 -060049 ${macaddr}= Get From Dictionary ${resp.dict} MACAddress
50 Validate MAC On BMC ${macaddr}
Prashanth Kattif58cce02019-02-06 03:05:14 -060051
Prashanth Katti2c5c3bb2019-02-14 04:23:07 -060052Verify All Configured IP And Netmask
53 [Documentation] Verify all configured IP and netmask on BMC.
54 [Tags] Verify_All_Configured_IP_And_Netmask
55
56 : FOR ${network_configuration} IN @{network_configurations}
57 \ Verify IP And Netmask On BMC ${network_configuration['Address']}
58 ... ${network_configuration['SubnetMask']}
59
Prashanth Katti23efc6e2019-03-13 06:07:15 -050060Get Hostname And Verify
61 [Documentation] Get hostname via Redfish and verify.
62 [Tags] Get_Hostname_And_Verify
63
64 ${hostname}= Redfish_Utils.Get Attribute ${REDFISH_NW_PROTOCOL_URI} HostName
65
66 Validate Hostname On BMC ${hostname}
67
68Configure Hostname And Verify
69 [Documentation] Configure hostname via Redfish and verify.
70 [Tags] Configure_Hostname_And_Verify
71
72 Configure Hostname ${test_hostname}
73
74 Validate Hostname On BMC ${test_hostname}
75
Vijayde3bf7b2019-04-16 04:56:09 -050076Add Valid IPv4 Address And Verify
77 [Documentation] Add IPv4 Address via Redfish and verify.
78 [Tags] Add_Valid_IPv4_Addres_And_Verify
79
80 Add IP Address ${test_ipv4_addr} ${test_subnet_mask} ${test_gateway}
81 Delete IP Address ${test_ipv4_addr}
82
83Add Invalid IPv4 Address And Verify
84 [Documentation] Add Invalid IPv4 Address via Redfish and verify.
85 [Tags] Add_Invalid_IPv4_Addres_And_Verify
86
87 Add IP Address ${test_ipv4_invalid_addr} ${test_subnet_mask}
88 ... ${test_gateway} valid_status_codes=${HTTP_BAD_REQUEST}
89
90
Prashanth Kattif58cce02019-02-06 03:05:14 -060091*** Keywords ***
92
93Test Setup Execution
94 [Documentation] Test setup execution.
95
George Keishing97c93942019-03-04 12:45:07 -060096 Redfish.Login
Prashanth Kattif58cce02019-02-06 03:05:14 -060097
98 @{network_configurations}= Get Network Configuration
99 Set Test Variable @{network_configurations}
100
101 # Get BMC IP address and prefix length.
102 ${ip_data}= Get BMC IP Info
103 Set Test Variable ${ip_data}
104
Prashanth Katti747ce9d2019-02-07 07:23:48 -0600105
Prashanth Kattif58cce02019-02-06 03:05:14 -0600106Get Network Configuration
107 [Documentation] Get network configuration.
108
109 # Sample output:
110 #{
111 # "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
112 # "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
113 # "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface",
114 # "Description": "Management Network Interface",
115 # "IPv4Addresses": [
116 # {
117 # "Address": "169.254.xx.xx",
118 # "AddressOrigin": "IPv4LinkLocal",
119 # "Gateway": "0.0.0.0",
120 # "SubnetMask": "255.255.0.0"
121 # },
122 # {
123 # "Address": "xx.xx.xx.xx",
124 # "AddressOrigin": "Static",
125 # "Gateway": "xx.xx.xx.1",
126 # "SubnetMask": "xx.xx.xx.xx"
127 # }
128 # ],
129 # "Id": "eth0",
130 # "MACAddress": "xx:xx:xx:xx:xx:xx",
131 # "Name": "Manager Ethernet Interface",
132 # "SpeedMbps": 0,
133 # "VLAN": {
134 # "VLANEnable": false,
135 # "VLANId": 0
136 # }
137
George Keishing97c93942019-03-04 12:45:07 -0600138 ${resp}= Redfish.Get ${REDFISH_NW_ETH0_URI}
Prashanth Kattif58cce02019-02-06 03:05:14 -0600139 @{network_configurations}= Get From Dictionary ${resp.dict} IPv4Addresses
140 [Return] @{network_configurations}
141
George Keishing5d467552019-02-08 23:30:48 -0600142
Prashanth Katti747ce9d2019-02-07 07:23:48 -0600143Verify IP On BMC
144 [Documentation] Verify IP on BMC.
Prashanth Kattif58cce02019-02-06 03:05:14 -0600145 [Arguments] ${ip}
146
Vijayde3bf7b2019-04-16 04:56:09 -0500147 # Description of argument(s):
148 # ip IP address to be verified (e.g. "10.7.7.7").
Prashanth Kattif58cce02019-02-06 03:05:14 -0600149
150 # Get IP address details on BMC using IP command.
151 @{ip_data}= Get BMC IP Info
152 Should Contain Match ${ip_data} ${ip}/*
153 ... msg=IP address does not exist.
154
Vijayde3bf7b2019-04-16 04:56:09 -0500155Add IP Address
156 [Documentation] Add IP Address To BMC.
157 [Arguments] ${ip} ${subnet_mask} ${gateway}
158 ... ${valid_status_codes}=${HTTP_OK}
159
160 # Description of argument(s):
161 # ip IP address to be added (e.g. "10.7.7.7").
162 # subnet_mask Subnet mask for the IP to be added
163 # (e.g. "255.255.0.0").
164 # gateway Gateway for the IP to be added (e.g. "10.7.7.1").
165 # valid_status_codes Expected return code from patch operation
166 # (e.g. "200"). See prolog of rest_request
167 # method in redfish_plut.py for details.
168
169 ${empty_dict}= Create Dictionary
170 ${ip_data}= Create Dictionary Address=${ip}
171 ... AddressOrigin=Static SubnetMask=${subnet_mask}
172 ... Gateway=${gateway}
173
174 ${patch_list}= Create List
175 ${network_configurations}= Get Network Configuration
176 ${num_entries}= Get Length ${network_configurations}
177
178 : FOR ${INDEX} IN RANGE 0 ${num_entries}
179 \ Append To List ${patch_list} ${empty_dict}
180
181 # We need not check for existance of IP on BMC while adding.
182 Append To List ${patch_list} ${ip_data}
183 ${data}= Create Dictionary IPv4Addresses=${patch_list}
184
185 Redfish.patch ${REDFISH_NW_ETH0_URI} body=&{data}
186 ... valid_status_codes=[${valid_status_codes}]
187
188 Return From Keyword If '${valid_status_codes}' != '${HTTP_OK}'
189
190 # Note: Network restart takes around 15-18s after patch request processing.
191 Sleep ${NETWORK_TIMEOUT}s
192 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
193
194 Verify IP On BMC ${ip}
195 Validate Network Config On BMC
196
197
198Delete IP Address
199 [Documentation] Delete IP Address Of BMC.
200 [Arguments] ${ip} ${valid_status_codes}=${HTTP_OK}
201
202 # Description of argument(s):
203 # ip IP address to be deleted (e.g. "10.7.7.7").
204 # valid_status_codes Expected return code from patch operation
205 # (e.g. "200"). See prolog of rest_request
206 # method in redfish_plut.py for details.
207
208 ${empty_dict}= Create Dictionary
209 ${patch_list}= Create List
210
211 @{network_configurations}= Get Network Configuration
212 : FOR ${network_configuration} IN @{network_configurations}
213 \ Run Keyword If '${network_configuration['Address']}' == '${ip}'
214 ... Append To List ${patch_list} ${null}
215 ... ELSE Append To List ${patch_list} ${empty_dict}
216
217 ${ip_found}= Run Keyword And Return Status List Should Contain Value
218 ... ${patch_list} ${null} msg=${ip} does not exist on BMC
219 Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC
220
221 # Run patch command only if given IP is found on BMC
222 ${data}= Create Dictionary IPv4Addresses=${patch_list}
223
224 Redfish.patch ${REDFISH_NW_ETH0_URI} body=&{data}
225 ... valid_status_codes=[${valid_status_codes}]
226
227 # Note: Network restart takes around 15-18s after patch request processing
228 Sleep ${NETWORK_TIMEOUT}s
229 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
230
231 ${delete_status}= Run Keyword And Return Status Verify IP On BMC ${ip}
232 Run Keyword If '${valid_status_codes}' == '${HTTP_OK}'
233 ... Should Be True ${delete_status} == ${False}
234 ... ELSE Should Be True ${delete_status} == ${True}
235
236 Validate Network Config On BMC
237
238
239Validate Network Config On BMC
240 [Documentation] Check that network info obtained via redfish matches info
241 ... obtained via CLI.
242
243 @{network_configurations}= Get Network Configuration
244 ${ip_data}= Get BMC IP Info
245 : FOR ${network_configuration} IN @{network_configurations}
246 \ Should Contain Match ${ip_data} ${network_configuration['Address']}/*
247 ... msg=IP address does not exist.
248
George Keishing5d467552019-02-08 23:30:48 -0600249
Prashanth Katti747ce9d2019-02-07 07:23:48 -0600250Verify Netmask On BMC
251 [Documentation] Verify netmask on BMC.
Prashanth Kattif58cce02019-02-06 03:05:14 -0600252 [Arguments] ${netmask}
253
254 # Description of the argument(s):
255 # netmask netmask value to be verified.
256
Prashanth Katti747ce9d2019-02-07 07:23:48 -0600257 ${prefix_length}= Netmask Prefix Length ${netmask}
258
259 Should Contain Match ${ip_data} */${prefix_length}
260 ... msg=Prefix length does not exist.
Prashanth Kattif58cce02019-02-06 03:05:14 -0600261
Prashanth Katti2ec9d8b2019-02-12 05:20:19 -0600262Verify Gateway On BMC
263 [Documentation] Verify gateway on BMC.
264 [Arguments] ${gateway_ip}=0.0.0.0
265
266 # Description of argument(s):
267 # gateway_ip Gateway IP address.
268
269 ${route_info}= Get BMC Route Info
270
271 # If gateway IP is empty or 0.0.0.0 it will not have route entry.
272
273 Run Keyword If '${gateway_ip}' == '0.0.0.0'
274 ... Pass Execution Gateway IP is "0.0.0.0".
275 ... ELSE
276 ... Should Contain ${route_info} ${gateway_ip}
277 ... msg=Gateway IP address not matching.
George Keishing5d467552019-02-08 23:30:48 -0600278
Prashanth Katti2c5c3bb2019-02-14 04:23:07 -0600279Verify IP And Netmask On BMC
280 [Documentation] Verify IP and netmask on BMC.
281 [Arguments] ${ip} ${netmask}
282
283 # Description of the argument(s):
284 # ip IP address to be verified.
285 # netmask netmask value to be verified.
286
287 ${prefix_length}= Netmask Prefix Length ${netmask}
288 @{ip_data}= Get BMC IP Info
289
290 ${ip_with_netmask}= Catenate ${ip}/${prefix_length}
291 Should Contain ${ip_data} ${ip_with_netmask}
292 ... msg=IP and netmask pair does not exist.
293
Prashanth Katti23efc6e2019-03-13 06:07:15 -0500294Configure Hostname
295 [Documentation] Configure hostname on BMC via Redfish.
296 [Arguments] ${hostname}
297
298 # Description of argument(s):
299 # hostname A hostname value which is to be configured on BMC.
300
301 ${data}= Create Dictionary HostName=${hostname}
302 Redfish.patch ${REDFISH_NW_PROTOCOL_URI} body=&{data}
303
304Validate Hostname On BMC
305 [Documentation] Verify that the hostname read via Redfish is the same as the
306 ... hostname configured on system.
307 [Arguments] ${hostname}
308
309 # Description of argument(s):
310 # hostname A hostname value which is to be compared to the hostname
311 # configured on system.
312
313 ${sys_hostname}= Get BMC Hostname
Prashanth Katti466d8342019-03-21 08:58:50 -0500314 Should Be Equal ${sys_hostname} ${hostname}
Prashanth Katti23efc6e2019-03-13 06:07:15 -0500315 ... ignore_case=True msg=Hostname does not exist.
316
Prashanth Kattif58cce02019-02-06 03:05:14 -0600317Test Teardown Execution
318 [Documentation] Test teardown execution.
319
320 FFDC On Test Case Fail
George Keishing97c93942019-03-04 12:45:07 -0600321 Redfish.Logout