1*** Settings ***
2Documentation  Network interface configuration and verification
3               ...  tests.
4
5Resource       ../../lib/bmc_redfish_resource.robot
6Resource       ../../lib/bmc_network_utils.robot
7Resource       ../../lib/openbmc_ffdc.robot
8Library        ../../lib/bmc_network_utils.py
9Library        Collections
10
11Test Setup     Test Setup Execution
12Test Teardown  Test Teardown Execution
13
14*** Variables ***
15${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
20${broadcast_ip}            10.7.7.255
21${loopback_ip}             127.0.0.2
22${multicast_ip}            224.6.6.6
23${out_of_range_ip}         10.7.7.256
24
25# Valid netmask is 4 bytes long and has continuos block of 1s.
26# Maximum valid value in each octet is 255 and least value is 0.
27# 253 is not valid, as binary value is 11111101.
28${invalid_netmask}         255.255.253.0
29${alpha_netmask}           ff.ff.ff.ff
30# Maximum value of octet in netmask is 255.
31${out_of_range_netmask}    255.256.255.0
32${more_byte_netmask}       255.255.255.0.0
33${less_byte_netmask}       255.255.255
34${threshold_netmask}       255.255.255.255
35${lowest_netmask}          128.0.0.0
36
37# There will be 4 octets in IP address (e.g. xx.xx.xx.xx)
38# but trying to configure xx.xx.xx
39${less_octet_ip}           10.3.36
40
41# For the address 10.6.6.6, the 10.6.6.0 portion describes the
42# network ID and the 6 describe the host.
43
44${network_id}              10.7.7.0
45${hex_ip}                  0xa.0xb.0xc.0xd
46${negative_ip}             10.-7.-7.7
47${hex_ip}                  0xa.0xb.0xc.0xd
48
49*** Test Cases ***
50
51Get IP Address And Verify
52    [Documentation]  Get IP Address And Verify.
53    [Tags]  Get_IP_Address_And_Verify
54
55    : FOR  ${network_configuration}  IN  @{network_configurations}
56    \  Verify IP On BMC  ${network_configuration['Address']}
57
58Get Netmask And Verify
59    [Documentation]  Get Netmask And Verify.
60    [Tags]  Get_Netmask_And_Verify
61
62    : FOR  ${network_configuration}  IN  @{network_configurations}
63    \  Verify Netmask On BMC  ${network_configuration['SubnetMask']}
64
65Get Gateway And Verify
66    [Documentation]  Get gateway and verify it's existence on the BMC.
67    [Tags]  Get_Gateway_And_Verify
68
69    : FOR  ${network_configuration}  IN  @{network_configurations}
70    \  Verify Gateway On BMC  ${network_configuration['Gateway']}
71
72Get MAC Address And Verify
73    [Documentation]  Get MAC address and verify it's existence on the BMC.
74    [Tags]  Get_MAC_Address_And_Verify
75
76    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH0_URI}
77    ${macaddr}=  Get From Dictionary  ${resp.dict}  MACAddress
78    Validate MAC On BMC  ${macaddr}
79
80Verify All Configured IP And Netmask
81    [Documentation]  Verify all configured IP and netmask on BMC.
82    [Tags]  Verify_All_Configured_IP_And_Netmask
83
84    : FOR  ${network_configuration}  IN  @{network_configurations}
85    \  Verify IP And Netmask On BMC  ${network_configuration['Address']}
86    ...  ${network_configuration['SubnetMask']}
87
88Get Hostname And Verify
89    [Documentation]  Get hostname via Redfish and verify.
90    [Tags]  Get_Hostname_And_Verify
91
92    ${hostname}=  Redfish_Utils.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  HostName
93
94    Validate Hostname On BMC  ${hostname}
95
96Configure Hostname And Verify
97    [Documentation]  Configure hostname via Redfish and verify.
98    [Tags]  Configure_Hostname_And_Verify
99
100    ${hostname}=  Redfish_Utils.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  HostName
101
102    Configure Hostname  ${test_hostname}
103    Validate Hostname On BMC  ${test_hostname}
104
105    # Revert back to initial hostname.
106    Configure Hostname  ${hostname}
107    Validate Hostname On BMC  ${hostname}
108
109Add Valid IPv4 Address And Verify
110    [Documentation]  Add IPv4 Address via Redfish and verify.
111    [Tags]  Add_Valid_IPv4_Addres_And_Verify
112
113     Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
114     Delete IP Address  ${test_ipv4_addr}
115
116Add Invalid IPv4 Address And Verify
117    [Documentation]  Add Invalid IPv4 Address via Redfish and verify.
118    [Tags]  Add_Invalid_IPv4_Addres_And_Verify
119
120    Add IP Address  ${test_ipv4_invalid_addr}  ${test_subnet_mask}
121    ...  ${test_gateway}  valid_status_codes=${HTTP_BAD_REQUEST}
122
123Configure Out Of Range IP
124    [Documentation]  Configure out-of-range IP address.
125    [Tags]  Configure_Out_Of_Range_IP
126    [Template]  Add IP Address
127
128    # ip                subnet_mask          gateway          valid_status_codes
129    ${out_of_range_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
130
131Configure Broadcast IP
132    [Documentation]  Configure broadcast IP address.
133    [Tags]  Configure_Broadcast_IP
134    [Template]  Add IP Address
135    [Teardown]  Clear IP Settings On Fail  ${broadcast_ip}
136
137    # ip             subnet_mask          gateway          valid_status_codes
138    ${broadcast_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
139
140Configure Multicast IP
141    [Documentation]  Configure multicast IP address.
142    [Tags]  Configure_Multicast_IP
143    [Template]  Add IP Address
144    [Teardown]  Clear IP Settings On Fail  ${multicast_ip}
145
146    # ip             subnet_mask          gateway          valid_status_codes
147    ${multicast_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
148
149Configure Loopback IP
150    [Documentation]  Configure loopback IP address.
151    [Tags]  Configure_Loopback_IP
152    [Template]  Add IP Address
153    [Teardown]  Clear IP Settings On Fail  ${loopback_ip}
154
155    # ip            subnet_mask          gateway          valid_status_codes
156    ${loopback_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
157
158Add Valid IPv4 Address And Check Persistency
159    [Documentation]  Add IPv4 address and check peristency.
160    [Tags]  Add_Valid_IPv4_Addres_And_Check_Persistency
161
162    Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
163
164    # Reboot BMC and verify persistency.
165    OBMC Reboot (off)
166    Verify IP On BMC  ${test_ipv4_addr}
167    Delete IP Address  ${test_ipv4_addr}
168
169Add Fourth Octet Threshold IP And Verify
170    [Documentation]  Add fourth octet threshold IP and verify.
171    [Tags]  Add_Fourth_Octet_Threshold_IP_And_Verify
172
173     Add IP Address  10.7.7.254  ${test_subnet_mask}  ${test_gateway}
174     Delete IP Address  10.7.7.254
175
176Add Fourth Octet Lowest IP And Verify
177    [Documentation]  Add fourth octet lowest IP and verify.
178    [Tags]  Add_Fourth_Octet_Lowest_IP_And_Verify
179
180     Add IP Address  10.7.7.1  ${test_subnet_mask}  ${test_gateway}
181     Delete IP Address  10.7.7.1
182
183Add Third Octet Threshold IP And Verify
184    [Documentation]  Add third octet threshold IP and verify.
185    [Tags]  Add_Third_Octet_Threshold_IP_And_Verify
186
187     Add IP Address  10.7.255.7  ${test_subnet_mask}  ${test_gateway}
188     Delete IP Address  10.7.255.7
189
190Add Third Octet Lowest IP And Verify
191    [Documentation]  Add third octet lowest IP and verify.
192    [Tags]  Add_Third_Octet_Lowest_IP_And_Verify
193
194     Add IP Address  10.7.0.7  ${test_subnet_mask}  ${test_gateway}
195     Delete IP Address  10.7.0.7
196
197Add Second Octet Threshold IP And Verify
198    [Documentation]  Add second octet threshold IP and verify.
199    [Tags]  Add_Second_Octet_Threshold_IP_And_Verify
200
201     Add IP Address  10.255.7.7  ${test_subnet_mask}  ${test_gateway}
202     Delete IP Address  10.255.7.7
203
204Add Second Octet Lowest IP And Verify
205    [Documentation]  Add second octet lowest IP and verify.
206    [Tags]  Add_Second_Octet_Lowest_IP_And_Verify
207
208     Add IP Address  10.0.7.7  ${test_subnet_mask}  ${test_gateway}
209     Delete IP Address  10.0.7.7
210
211Add First Octet Threshold IP And Verify
212    [Documentation]  Add first octet threshold IP and verify.
213    [Tags]  Add_First_Octet_Threshold_IP_And_Verify
214
215     Add IP Address  223.7.7.7  ${test_subnet_mask}  ${test_gateway}
216     Delete IP Address  223.7.7.7
217
218Add First Octet Lowest IP And Verify
219    [Documentation]  Add first octet lowest IP and verify.
220    [Tags]  Add_First_Octet_Lowest_IP_And_Verify
221
222     Add IP Address  1.7.7.7  ${test_subnet_mask}  ${test_gateway}
223     Delete IP Address  1.7.7.7
224
225Configure Invalid Netmask
226    [Documentation]  Verify error while setting invalid netmask.
227    [Tags]  Configure_Invalid_Netmask
228    [Template]  Add IP Address
229
230    # ip               subnet_mask         gateway          valid_status_codes
231    ${test_ipv4_addr}  ${invalid_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
232
233Configure Out Of Range Netmask
234    [Documentation]  Verify error while setting out of range netmask.
235    [Tags]  Configure_Out_Of_Range_Netmask
236    [Template]  Add IP Address
237
238    # ip               subnet_mask              gateway          valid_status_codes
239    ${test_ipv4_addr}  ${out_of_range_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
240
241Configure Alpha Netmask
242    [Documentation]  Verify error while setting alpha netmask.
243    [Tags]  Configure_Alpha_Netmask
244    [Template]  Add IP Address
245
246    # ip               subnet_mask       gateway          valid_status_codes
247    ${test_ipv4_addr}  ${alpha_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
248
249Configure More Byte Netmask
250    [Documentation]  Verify error while setting more byte netmask.
251    [Tags]  Configure_More_Byte_Netmask
252    [Template]  Add IP Address
253
254    # ip               subnet_mask           gateway          valid_status_codes
255    ${test_ipv4_addr}  ${more_byte_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
256
257Configure Less Byte Netmask
258    [Documentation]  Verify error while setting less byte netmask.
259    [Tags]  Configure_Less_Byte_Netmask
260    [Template]  Add IP Address
261
262    # ip               subnet_mask           gateway          valid_status_codes
263    ${test_ipv4_addr}  ${less_byte_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
264
265Configure Threshold Netmask And Verify
266    [Documentation]  Configure threshold netmask and verify.
267    [Tags]  Configure_Threshold_Netmask_And_verify
268
269     Add IP Address  ${test_ipv4_addr}  ${threshold_netmask}  ${test_gateway}
270     Delete IP Address  ${test_ipv4_addr}
271
272Configure Lowest Netmask And Verify
273    [Documentation]  Configure lowest netmask and verify.
274    [Tags]  Configure_Lowest_Netmask_And_verify
275
276     Add IP Address  ${test_ipv4_addr}  ${lowest_netmask}  ${test_gateway}
277     Delete IP Address  ${test_ipv4_addr}
278
279Configure Network ID
280    [Documentation]  Verify error while configuring network ID.
281    [Tags]  Configure_Network_ID
282    [Template]  Add IP Address
283    [Teardown]  Clear IP Settings On Fail  ${network_id}
284
285    # ip           subnet_mask          gateway          valid_status_codes
286    ${network_id}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
287
288Configure Less Octet IP
289    [Documentation]  Verify error while Configuring less octet IP address.
290    [Tags]  Configure_Less_Octet_IP
291    [Template]  Add IP Address
292
293    # ip              subnet_mask          gateway          valid_status_codes
294    ${less_octet_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
295
296Configure Empty IP
297    [Documentation]  Verify error while Configuring empty IP address.
298    [Tags]  Configure_Empty_IP
299    [Template]  Add IP Address
300
301    # ip      subnet_mask          gateway          valid_status_codes
302    ${EMPTY}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
303
304Configure Special Char IP
305    [Documentation]  Configure invalid IP address containing special chars.
306    [Tags]  Configure_Special_Char_IP
307    [Template]  Add IP Address
308
309    # ip          subnet_mask          gateway          valid_status_codes
310    @@@.%%.44.11  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
311
312Configure Hexadecimal IP
313    [Documentation]  Configure invalid IP address containing hex value.
314    [Tags]  Configure_Hexadecimal_IP
315    [Template]  Add IP Address
316
317    # ip       subnet_mask          gateway          valid_status_codes
318    ${hex_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
319
320Configure Negative Octet IP
321    [Documentation]  Configure invalid IP address containing negative octet.
322    [Tags]  Configure_Negative_Octet_IP
323    [Template]  Add IP Address
324
325    # ip            subnet_mask          gateway          valid_status_codes
326    ${negative_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
327
328*** Keywords ***
329
330Test Setup Execution
331    [Documentation]  Test setup execution.
332
333    Redfish.Login
334
335    @{network_configurations}=  Get Network Configuration
336    Set Test Variable  @{network_configurations}
337
338    # Get BMC IP address and prefix length.
339    ${ip_data}=  Get BMC IP Info
340    Set Test Variable  ${ip_data}
341
342
343Get Network Configuration
344    [Documentation]  Get network configuration.
345
346    # Sample output:
347    #{
348    #  "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
349    #  "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
350    #  "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface",
351    #  "Description": "Management Network Interface",
352    #  "IPv4Addresses": [
353    #    {
354    #      "Address": "169.254.xx.xx",
355    #      "AddressOrigin": "IPv4LinkLocal",
356    #      "Gateway": "0.0.0.0",
357    #      "SubnetMask": "255.255.0.0"
358    #    },
359    #    {
360    #      "Address": "xx.xx.xx.xx",
361    #      "AddressOrigin": "Static",
362    #      "Gateway": "xx.xx.xx.1",
363    #      "SubnetMask": "xx.xx.xx.xx"
364    #    }
365    #  ],
366    #  "Id": "eth0",
367    #  "MACAddress": "xx:xx:xx:xx:xx:xx",
368    #  "Name": "Manager Ethernet Interface",
369    #  "SpeedMbps": 0,
370    #  "VLAN": {
371    #    "VLANEnable": false,
372    #    "VLANId": 0
373    #  }
374
375    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH0_URI}
376    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4Addresses
377    [Return]  @{network_configurations}
378
379
380Verify IP On BMC
381    [Documentation]  Verify IP on BMC.
382    [Arguments]  ${ip}
383
384    # Description of argument(s):
385    # ip  IP address to be verified (e.g. "10.7.7.7").
386
387    # Get IP address details on BMC using IP command.
388    @{ip_data}=  Get BMC IP Info
389    Should Contain Match  ${ip_data}  ${ip}/*
390    ...  msg=IP address does not exist.
391
392Add IP Address
393    [Documentation]  Add IP Address To BMC.
394    [Arguments]  ${ip}  ${subnet_mask}  ${gateway}
395    ...  ${valid_status_codes}=${HTTP_OK}
396
397    # Description of argument(s):
398    # ip                  IP address to be added (e.g. "10.7.7.7").
399    # subnet_mask         Subnet mask for the IP to be added
400    #                     (e.g. "255.255.0.0").
401    # gateway             Gateway for the IP to be added (e.g. "10.7.7.1").
402    # valid_status_codes  Expected return code from patch operation
403    #                     (e.g. "200").  See prolog of rest_request
404    #                     method in redfish_plut.py for details.
405
406    ${empty_dict}=  Create Dictionary
407    ${ip_data}=  Create Dictionary  Address=${ip}
408    ...  AddressOrigin=Static  SubnetMask=${subnet_mask}
409    ...  Gateway=${gateway}
410
411    ${patch_list}=  Create List
412    ${network_configurations}=  Get Network Configuration
413    ${num_entries}=  Get Length  ${network_configurations}
414
415    : FOR  ${INDEX}  IN RANGE  0  ${num_entries}
416    \  Append To List  ${patch_list}  ${empty_dict}
417
418    # We need not check for existence of IP on BMC while adding.
419    Append To List  ${patch_list}  ${ip_data}
420    ${data}=  Create Dictionary  IPv4Addresses=${patch_list}
421
422    Redfish.patch  ${REDFISH_NW_ETH0_URI}  body=&{data}
423    ...  valid_status_codes=[${valid_status_codes}]
424
425    Return From Keyword If  '${valid_status_codes}' != '${HTTP_OK}'
426
427    # Note: Network restart takes around 15-18s after patch request processing.
428    Sleep  ${NETWORK_TIMEOUT}s
429    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
430
431    Verify IP On BMC  ${ip}
432    Validate Network Config On BMC
433
434
435Delete IP Address
436    [Documentation]  Delete IP Address Of BMC.
437    [Arguments]  ${ip}  ${valid_status_codes}=${HTTP_OK}
438
439    # Description of argument(s):
440    # ip                  IP address to be deleted (e.g. "10.7.7.7").
441    # valid_status_codes  Expected return code from patch operation
442    #                     (e.g. "200").  See prolog of rest_request
443    #                     method in redfish_plut.py for details.
444
445    ${empty_dict}=  Create Dictionary
446    ${patch_list}=  Create List
447
448    @{network_configurations}=  Get Network Configuration
449    : FOR  ${network_configuration}  IN  @{network_configurations}
450    \  Run Keyword If  '${network_configuration['Address']}' == '${ip}'
451       ...  Append To List  ${patch_list}  ${null}
452       ...  ELSE  Append To List  ${patch_list}  ${empty_dict}
453
454    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
455    ...  ${patch_list}  ${null}  msg=${ip} does not exist on BMC
456    Pass Execution If  ${ip_found} == ${False}  ${ip} does not exist on BMC
457
458    # Run patch command only if given IP is found on BMC
459    ${data}=  Create Dictionary  IPv4Addresses=${patch_list}
460
461    Redfish.patch  ${REDFISH_NW_ETH0_URI}  body=&{data}
462    ...  valid_status_codes=[${valid_status_codes}]
463
464    # Note: Network restart takes around 15-18s after patch request processing
465    Sleep  ${NETWORK_TIMEOUT}s
466    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
467
468    ${delete_status}=  Run Keyword And Return Status  Verify IP On BMC  ${ip}
469    Run Keyword If  '${valid_status_codes}' == '${HTTP_OK}'
470    ...  Should Be True  ${delete_status} == ${False}
471    ...  ELSE  Should Be True  ${delete_status} == ${True}
472
473    Validate Network Config On BMC
474
475
476Validate Network Config On BMC
477    [Documentation]  Check that network info obtained via redfish matches info
478    ...              obtained via CLI.
479
480    @{network_configurations}=  Get Network Configuration
481    ${ip_data}=  Get BMC IP Info
482    : FOR  ${network_configuration}  IN  @{network_configurations}
483    \  Should Contain Match  ${ip_data}  ${network_configuration['Address']}/*
484    ...  msg=IP address does not exist.
485
486
487Verify Netmask On BMC
488    [Documentation]  Verify netmask on BMC.
489    [Arguments]  ${netmask}
490
491    # Description of the argument(s):
492    # netmask  netmask value to be verified.
493
494    ${prefix_length}=  Netmask Prefix Length  ${netmask}
495
496    Should Contain Match  ${ip_data}  */${prefix_length}
497    ...  msg=Prefix length does not exist.
498
499Verify Gateway On BMC
500    [Documentation]  Verify gateway on BMC.
501    [Arguments]  ${gateway_ip}=0.0.0.0
502
503    # Description of argument(s):
504    # gateway_ip  Gateway IP address.
505
506    ${route_info}=  Get BMC Route Info
507
508    # If gateway IP is empty or 0.0.0.0 it will not have route entry.
509
510    Run Keyword If  '${gateway_ip}' == '0.0.0.0'
511    ...      Pass Execution  Gateway IP is "0.0.0.0".
512    ...  ELSE
513    ...      Should Contain  ${route_info}  ${gateway_ip}
514    ...      msg=Gateway IP address not matching.
515
516Verify IP And Netmask On BMC
517    [Documentation]  Verify IP and netmask on BMC.
518    [Arguments]  ${ip}  ${netmask}
519
520    # Description of the argument(s):
521    # ip       IP address to be verified.
522    # netmask  netmask value to be verified.
523
524    ${prefix_length}=  Netmask Prefix Length  ${netmask}
525    @{ip_data}=  Get BMC IP Info
526
527    ${ip_with_netmask}=  Catenate  ${ip}/${prefix_length}
528    Should Contain  ${ip_data}  ${ip_with_netmask}
529    ...  msg=IP and netmask pair does not exist.
530
531Validate Hostname On BMC
532    [Documentation]  Verify that the hostname read via Redfish is the same as the
533    ...  hostname configured on system.
534    [Arguments]  ${hostname}
535
536    # Description of argument(s):
537    # hostname  A hostname value which is to be compared to the hostname
538    #           configured on system.
539
540    ${sys_hostname}=  Get BMC Hostname
541    Should Be Equal  ${sys_hostname}  ${hostname}
542    ...  ignore_case=True  msg=Hostname does not exist.
543
544Test Teardown Execution
545    [Documentation]  Test teardown execution.
546
547    FFDC On Test Case Fail
548    Redfish.Logout
549
550Clear IP Settings On Fail
551    [Documentation]  Clear IP settings on fail.
552    [Arguments]  ${ip}
553
554    # Description of argument(s):
555    # ip  IP address to be deleted.
556
557    Run Keyword If  '${TEST STATUS}' == 'FAIL'
558    ...  Delete IP Address  ${ip}
559
560    Test Teardown Execution
561
562