1*** Settings ***
2
3Documentation    VMI static/dynamic IP config and certificate exchange tests.
4
5Resource         ../../lib/resource.robot
6Resource         ../../lib/bmc_redfish_resource.robot
7Resource         ../../lib/openbmc_ffdc.robot
8Library          ../../lib/bmc_network_utils.py
9
10Suite Setup       Redfish.Login
11Test Teardown     FFDC On Test Case Fail
12Suite Teardown    Redfish.Logout
13
14*** Variables ***
15
16${test_ipv4}              10.10.20.30
17${test_gateway}           0.0.0.0
18${test_netmask}           255.255.252.0
19&{DHCP_ENABLED}           DHCPEnabled=${${True}}
20&{DHCP_DISABLED}          DHCPEnabled=${${False}}
21
22&{ENABLE_DHCP}            DHCPv4=&{DHCP_ENABLED}
23&{DISABLE_DHCP}           DHCPv4=&{DHCP_DISABLED}
24
25
26*** Test Cases ***
27
28Verify All VMI EthernetInterfaces
29    [Documentation]  Verify all VMI ethernet interfaces.
30    [Tags]  Verify_All_VMI_EthernetINterfaces
31
32    Verify VMI EthernetInterfaces
33
34
35Verify Existing VMI Network Interface Details
36    [Documentation]  Verify existing VMI network interface details.
37    [Tags]  Verify_VMI_Network_Interface_Details
38
39    ${vmi_ip}=  Get VMI Network Interface Details
40    ${origin}=  Set Variable If  ${vmi_ip["DHCPv4"]} == ${False}  Static  DHCP
41
42    Should Not Be Equal  ${vmi_ip["DHCPv4"]}  ${vmi_ip["IPv4StaticAddresses"]}
43    Should Be Equal As Strings  ${origin}  ${vmi_ip["IPv4_AddressOrigin"]}
44    Should Be Equal As Strings  ${vmi_ip["Id"]}  intf0
45    Should Be Equal As Strings  ${vmi_ip["Description"]}
46    ...  Ethernet Interface for Virtual Management Interface
47    Should Be Equal As Strings  ${vmi_ip["Name"]}  Virtual Management Interface
48    Should Be True  ${vmi_ip["InterfaceEnabled"]}
49
50
51Delete Existing Static VMI IP Address
52    [Documentation]  Delete existing static VMI IP address.
53    [Tags]  Delete_Existing_Static_VMI_IP_Address
54
55    ${curr_origin}=  Get Immediate Child Parameter From VMI Network Interface  DHCPEnabled
56    Run Keyword If  ${curr_origin} == ${True}  Set VMI IPv4 Origin  ${False}  ${HTTP_ACCEPTED}
57
58    Delete VMI IPv4 Address  IPv4StaticAddresses  valid_status_code=${HTTP_ACCEPTED}
59    ${default}=  Set Variable  0.0.0.0
60    Verify VMI Network Interface Details  ${default}  Static  ${default}  ${default}  ${True}
61
62
63Verify User Cannot Delete ReadOnly Property IPv4Addresses
64    [Documentation]  Verify user cannot delete readonly property IPv4Addresses.
65    [Tags]  Verify_User_Cannot_Delete_ReadOnly_Property_IPv4Addresses
66
67    ${curr_origin}=  Get Immediate Child Parameter From VMI Network Interface  DHCPEnabled
68    Run Keyword If  ${curr_origin} == ${False}  Set VMI IPv4 Origin  ${True}  ${HTTP_ACCEPTED}
69    Delete VMI IPv4 Address  IPv4Addresses  valid_status_code=${HTTP_BAD_REQUEST}
70
71
72Assign Valid And Invalid Static IPv4 Address To VMI
73    [Documentation]  Assign static IPv4 address to VMI.
74    [Tags]  Assign_Valid_And_Invalid_Static_IPv4_Address_To_VMI
75    [Template]  Verify Assigning Static IPv4 Address To VMI
76    [Teardown]  Delete VMI IPv4 Address  IPv4Addresses  ${HTTP_ACCEPTED}
77
78    # ip          gateway     netmask          del_curr_ip   host_reboot   valid_status_code
79    10.5.20.30    0.0.0.0     255.255.252.0    ${False}      ${True}       ${HTTP_ACCEPTED}
80    a.3.118.94    0.0.0.0     255.255.252.0    ${False}      ${False}      ${HTTP_BAD_REQUEST}
81
82
83Switch Between IP Origins On VMI And Verify Details
84    [Documentation]  Switch between IP origins on VMI and verify details.
85    [Tags]  Switch_Between_IP_Origins_On_VMI_And_Verify_Details
86
87    Switch VMI IPv4 Origin And Verify Details
88    Switch VMI IPv4 Origin And Verify Details
89
90
91Verify Persistency Of VMI IPv4 Details After Host Reboot
92    [Documentation]  Verify persistency of VMI IPv4 details after host reboot.
93    [Tags]  Verify_Persistency_Of_VMI_IPv4_Details_After_Host_Reboot
94
95    # Verifying persistency of dynamic address.
96    Set VMI IPv4 Origin  ${True}  ${HTTP_ACCEPTED}
97    ${default}=  Set Variable  0.0.0.0
98    Verify VMI Network Interface Details  ${default}  DHCP  ${default}  ${default}  ${True}
99    Verify VMI Network Interface Details  ${default}  DHCP  ${default}  ${default}  ${True}
100
101    # Verifying persistency of static address.
102    Switch VMI IPv4 Origin And Verify Details  ${True}
103    Verify Assigning Static IPv4 Address To VMI  ${VMI_IP}  ${VMI_GATEWAY}  ${VMI_NETMASK}  ${False}
104    Verify VMI Network Interface Details  ${VMI_IP}  Static  ${VMI_GATEWAY}  ${VMI_NETMASK}  ${True}
105
106
107Delete VMI Static IP Address And Verify
108   [Documentation]  Delete VMI static IP address and verify.
109   [Tags]  Delete_VMI_Static_IP_Address_And_Verify
110
111   Set Static IPv4 Address To VMI  10.10.20.30  0.0.0.0  255.255.252.0
112   Verify VMI Network Interface Details  10.10.20.30  Static  0.0.0.0  255.255.252.0  ${True}
113   Delete VMI IPv4 Address  IPv4Addresses  ${HTTP_ACCEPTED}
114   ${active_channel_config}=  Get Active Channel Config
115   ${resp}=  Redfish.Get
116   ...  /redfish/v1/Systems/hypervisor/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
117   Should Be Empty  ${resp.dict["IPv4Addresses"]}
118
119Verify Successful VMI IP Static Configuration On HOST Boot After Session Delete
120    [Documentation]  Verify VMI IP static Configuration On HOST Boot After session deleted.
121    [Tags]  Verify_Successful_VMI_IP_Static_Configuration_On_HOST_Boot_After_Session_Delete
122    [Teardown]  Run keywords  Delete VMI IPv4 Address  IPv4Addresses  AND  Test Teardown
123
124    Set Static IPv4 Address To VMI  ${test_ipv4}  ${test_gateway}  ${test_netmask}
125
126    ${session_info}=  Get Redfish Session Info
127    Redfish.Delete  ${session_info["location"]}
128
129    # Create a new Redfish session
130    Run Keywords  Redfish Power Off  AND  Redfish Power On   AND  Redfish.Login
131
132    Verify VMI Network Interface Details  ${test_ipv4}  Static  ${test_gateway}  ${test_netmask}
133
134Verify Persistency Of VMI DHCP IP Configuration After Multiple HOST Reboots
135    [Documentation]  Verify Persistency Of VMI DHCP IP configuration After Multiple HOST Reboots
136    [Tags]  Verify_Persistency_Of_VMI_DHCP_IP_Configuration_After_Multiple_HOST_Reboots
137
138    ${LOOP_COUNT}=  Set Variable  ${3}
139    Set VMI IPv4 Origin  ${True}  ${HTTP_ACCEPTED}
140    Run Keywords  Redfish Power Off  AND  Redfish Power On
141    ${vmi_ip_config}=  Get VMI Network Interface Details
142    # Verifying persistency of dynamic address after multiple reboots.
143    Repeat Keyword  ${LOOP_COUNT} times
144    ...  Verify VMI Network Interface Details  ${vmi_ip_config["IPv4_Address"]}  DHCP  ${vmi_ip_config["IPv4_Gateway"]}
145    ...  ${vmi_ip_config["IPv4_SubnetMask"]}  ${True}
146
147*** Keywords ***
148
149Get VMI Network Interface Details
150    [Documentation]  Get VMI network interface details.
151    [Arguments]  ${valid_status_code}=${HTTP_OK}
152
153    # Description of argument(s):
154    # valid_status_code  Expected valid status code from GET request.
155
156    # Note: It returns a dictionary of VMI eth0 parameters.
157
158    ${active_channel_config}=  Get Active Channel Config
159    ${resp}=  Redfish.Get
160    ...  /redfish/v1/Systems/hypervisor/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
161    ...  valid_status_codes=[${valid_status_code}]
162
163    ${ip_resp}=  Evaluate  json.loads('''${resp.text}''')  json
164
165    ${static_exists}=  Run Keyword And Ignore Error
166    ...  Set Variable  ${ip_resp["IPv4StaticAddresses"][0]["Address"]}
167    ${static_exists}=  Set Variable If  '${static_exists[0]}' == 'PASS'  ${True}  ${False}
168
169    ${vmi_ip}=  Create Dictionary  DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}}  Id=${ip_resp["Id"]}
170    ...  Description=${ip_resp["Description"]}  IPv4_Address=${ip_resp["IPv4Addresses"][0]["Address"]}
171    ...  IPv4_AddressOrigin=${ip_resp["IPv4Addresses"][0]["AddressOrigin"]}  Name=${ip_resp["Name"]}
172    ...  IPv4_Gateway=${ip_resp["IPv4Addresses"][0]["Gateway"]}
173    ...  InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
174    ...  IPv4_SubnetMask=${ip_resp["IPv4Addresses"][0]["SubnetMask"]}  MACAddress=${ip_resp["MACAddress"]}
175    ...  IPv4StaticAddresses=${${static_exists}}
176
177    [Return]  &{vmi_ip}
178
179
180Get Immediate Child Parameter From VMI Network Interface
181    [Documentation]  Get immediate child parameter from VMI network interface.
182    [Arguments]  ${parameter}  ${valid_status_code}=${HTTP_OK}
183
184    # Description of argument(s):
185    # parameter          parameter for which value is required. Ex: DHCPEnabled, MACAddress etc.
186    # valid_status_code  Expected valid status code from GET request.
187
188    ${active_channel_config}=  Get Active Channel Config
189    ${resp}=  Redfish.Get
190    ...  /redfish/v1/Systems/hypervisor/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
191    ...  valid_status_codes=[${valid_status_code}]
192
193    ${ip_resp}=  Evaluate  json.loads('''${resp.text}''')  json
194    ${value}=  Set Variable If  '${parameter}' != 'DHCPEnabled'   ${ip_resp["${parameter}"]}
195    ...  ${ip_resp["DHCPv4"]["${parameter}"]}
196
197    [Return]  ${value}
198
199Verify VMI EthernetInterfaces
200    [Documentation]  Verify VMI ethernet interfaces.
201    [Arguments]  ${valid_status_code}=${HTTP_OK}
202
203    # Description of argument(s):
204    # valid_status_code  Expected valid status code from GET request.
205
206    ${resp}=  Redfish.Get  /redfish/v1/Systems/hypervisor/EthernetInterfaces
207    ...  valid_status_codes=[${valid_status_code}]
208
209    ${resp}=  Evaluate  json.loads('''${resp.text}''')  json
210    ${interfaces}=  Set Variable  ${resp["Members"]}
211
212    Should Be Equal As Strings  ${interfaces[0]}[@odata.id]
213    ...  /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth0
214    Should Be Equal As Strings  ${interfaces[1]}[@odata.id]
215    ...  /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth1
216
217    Should Be Equal  ${resp["Members@odata.count"]}  ${2}
218
219
220Verify VMI Network Interface Details
221    [Documentation]  Verify VMI network interface details.
222    [Arguments]  ${ip}  ${origin}  ${gateway}  ${netmask}
223    ...  ${host_reboot}=${False}  ${valid_status_code}=${HTTP_OK}
224
225    # Description of argument(s):
226    # ip                 VMI IPv4 address.
227    # origin             Origin of IPv4 address eg. Static or DHCP.
228    # gateway            Gateway for VMI IP.
229    # netmask            Subnetmask for VMI IP.
230    # valid_status_code  Expected valid status code from GET request. Default is HTTP_OK.
231    # host_reboot        Reboot HOST if True.
232
233    Run Keyword If  ${host_reboot} == ${True}  Run Keywords
234    ...  Redfish Power Off  AND  Redfish Power On  AND  Redfish.Login
235
236    ${vmi_ip}=  Get VMI Network Interface Details  ${valid_status_code}
237    Should Be Equal As Strings  ${origin}  ${vmi_ip["IPv4_AddressOrigin"]}
238    Should Be Equal As Strings  ${gateway}  ${vmi_ip["IPv4_Gateway"]}
239    Should Be Equal As Strings  ${netmask}  ${vmi_ip["IPv4_SubnetMask"]}
240    Should Be Equal As Strings  ${ip}  ${vmi_ip["IPv4_Address"]}
241
242
243Set Static IPv4 Address To VMI
244    [Documentation]  Set static IPv4 address to VMI.
245    [Arguments]  ${ip}  ${gateway}  ${netmask}  ${valid_status_code}=${HTTP_ACCEPTED}
246
247    # Description of argument(s):
248    # ip                 VMI IPv4 address.
249    # gateway            Gateway for VMI IP.
250    # netmask            Subnetmask for VMI IP.
251    # valid_status_code  Expected valid status code from GET request. Default is HTTP_ACCEPTED.
252
253    ${data}=  Set Variable
254    ...  {"IPv4StaticAddresses": [{"Address": "${ip}","SubnetMask": "${netmask}","Gateway": "${gateway}"}]}
255
256    ${active_channel_config}=  Get Active Channel Config
257    ${resp}=  Redfish.Patch
258    ...  /redfish/v1/Systems/hypervisor/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
259    ...  body=${data}  valid_status_codes=[${valid_status_code}]
260    Redfish Power On  stack_mode=skip
261    Log To Console  ${resp.text}
262
263
264Verify Assigning Static IPv4 Address To VMI
265    [Documentation]    Verify assigning static IPv4 address to VMI.
266    [Arguments]  ${ip}  ${gateway}  ${netmask}  ${del_curr_ip}=${True}  ${host_reboot}=${True}
267    ...  ${valid_status_code}=${HTTP_ACCEPTED}
268
269    # Description of argument(s):
270    # ip                 VMI IPv4 address.
271    # gateway            Gateway for VMI IP.
272    # netmask            Subnetmask for VMI IP.
273    # del_curr_ip        Delete current VMI static IP if True.
274    # host_reboot        True when HOST reboot is required.
275    # valid_status_code  Expected valid status code from GET request. Default is HTTP_ACCEPTED.
276
277    # Delete current static IP based on user input.
278    ${curr_origin}=  Get Immediate Child Parameter From VMI Network Interface  DHCPEnabled
279    Run Keyword If  ${curr_origin} == ${False} and ${del_curr_ip} == ${True}  Delete VMI IPv4 Address
280
281    Set Static IPv4 Address To VMI  ${ip}  ${gateway}  ${netmask}  valid_status_code=${valid_status_code}
282    Return From Keyword If  ${valid_status_code} != ${HTTP_ACCEPTED}
283
284    Verify VMI Network Interface Details  ${ip}  Static  ${gateway}  ${netmask}  host_reboot=${host_reboot}
285
286
287Delete VMI IPv4 Address
288    [Documentation]  Delete VMI IPv4 address.
289    [Arguments]  ${delete_param}=IPv4StaticAddresses  ${valid_status_code}=${HTTP_ACCEPTED}
290
291    # Description of argument(s):
292    # delete_param       Parameter to be deleted eg. IPv4StaticAddresses or IPv4Addresses.
293    #                    Default is IPv4StaticAddresses.
294    # valid_status_code  Expected valid status code from PATCH request. Default is HTTP_OK.
295
296    ${data}=  Set Variable  {"${delete_param}": [${Null}]}
297    ${active_channel_config}=  Get Active Channel Config
298    ${resp}=  Redfish.Patch
299    ...  /redfish/v1/Systems/hypervisor/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
300    ...  body=${data}  valid_status_codes=[${valid_status_code}]
301
302
303Set VMI IPv4 Origin
304    [Documentation]  Set VMI IPv4 origin.
305    [Arguments]  ${dhcp_enabled}=${False}  ${valid_status_code}=${HTTP_ACCEPTED}
306
307    # Description of argument(s):
308    # dhcp_enabled       True if user wants to enable DHCP. Default is Static, hence value is set to False.
309    # valid_status_code  Expected valid status code from PATCH request. Default is HTTP_OK.
310
311    ${data}=  Set Variable If  ${dhcp_enabled} == ${False}  ${DISABLE_DHCP}  ${ENABLE_DHCP}
312    ${resp}=  Redfish.Patch  /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth0  body=${data}
313    ...  valid_status_codes=[${valid_status_code}]
314
315
316Switch VMI IPv4 Origin And Verify Details
317    [Documentation]  Switch VMI IPv4 origin and verify details.
318    [Arguments]  ${host_reboot}=${False}
319
320    # Description of argument(s):
321    # host_reboot        Reboot HOST if True.
322
323    ${curr_mode}=  Get Immediate Child Parameter From VMI Network Interface  DHCPEnabled
324    ${dhcp_enabled}=  Set Variable If  ${curr_mode} == ${False}  ${True}  ${False}
325
326    ${default}=  Set Variable  0.0.0.0
327    ${origin}=  Set Variable If  ${curr_mode} == ${False}  DHCP  Static
328    Set VMI IPv4 Origin  ${dhcp_enabled}  ${HTTP_ACCEPTED}
329    Verify VMI Network Interface Details  ${default}  ${origin}  ${default}  ${default}  ${host_reboot}
330
331    [Return]  ${origin}
332