blob: 21b7c226024b1698c41b1b70259feb3b2b4432e3 [file] [log] [blame]
Sweta Potthurid52b2732021-08-12 12:48:24 -05001*** Settings ***
2Documentation Vmi network utilities keywords.
3
4Resource ../../lib/resource.robot
5Resource ../../lib/bmc_redfish_resource.robot
6Resource ../../lib/openbmc_ffdc.robot
7Resource ../../lib/bmc_redfish_utils.robot
8Resource ../../lib/state_manager.robot
shrsuman1237ba02f32021-08-26 04:50:56 -05009Resource ../../lib/bmc_network_utils.robot
Sweta Potthurid52b2732021-08-12 12:48:24 -050010Library ../../lib/bmc_network_utils.py
11
12*** Variables ***
13
shrsuman1237e9b2122021-09-28 06:06:16 -050014&{DHCP_ENABLED} DHCPEnabled=${True}
15&{DHCP_DISABLED} DHCPEnabled=${False}
16
17&{ENABLE_DHCP} DHCPv4=&{DHCP_ENABLED}
18&{DISABLE_DHCP} DHCPv4=&{DHCP_DISABLED}
19
Megha G Na2148332025-03-06 07:28:15 -060020&{SLAAC_ENABLED} IPv6AutoConfigEnabled=${True}
21&{SLAAC_DISABLED} IPv6AutoConfigEnabled=${False}
22
23&{ENABLE_SLAAC} StatelessAddressAutoConfig=&{SLAAC_ENABLED}
24&{DISABLE_SLAAC} StatelessAddressAutoConfig=&{SLAAC_DISABLED}
25
26&{DHCPv6_ENABLED} OperatingMode=Enabled
27&{DHCPv6_DISABLED} OperatingMode=Disabled
28
29&{ENABLE_DHCPv6} DHCPv6=&{DHCPv6_ENABLED}
30&{DISABLE_DHCPv6} DHCPv6=&{DHCPv6_DISABLED}
31
Megha G Na9cf2d82023-10-09 07:41:11 -050032${wait_time} 40s
shrsuman123a0355782021-10-18 05:56:56 -050033${ethernet_interface} eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050034
35*** Keywords ***
36
37Set Static IPv4 Address To VMI And Verify
38 [Documentation] Set static IPv4 address to VMI.
39 [Arguments] ${ip} ${gateway} ${netmask} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123a0355782021-10-18 05:56:56 -050040 ... ${interface}=${ethernet_interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050041
42 # Description of argument(s):
43 # ip VMI IPv4 address.
44 # gateway Gateway for VMI IP.
45 # netmask Subnetmask for VMI IP.
46 # valid_status_code Expected valid status code from GET request. Default is HTTP_ACCEPTED.
shrsuman123298e8042021-08-20 07:36:21 -050047 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050048
shrsuman123298e8042021-08-20 07:36:21 -050049 ${ip_details}= Create dictionary Address=${ip} SubnetMask=${netmask} Gateway=${gateway}
50 ${ip_data}= Create List ${ip_details}
51 ${resp}= Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
52 ... body={'IPv4StaticAddresses':${ip_data}} valid_status_codes=[${valid_status_code}]
Sweta Potthurid52b2732021-08-12 12:48:24 -050053
54 # Wait few seconds for new configuration to get populated on runtime.
55 Sleep ${wait_time}
56
57 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
58 ${host_power_state} ${host_state}= Redfish Get Host State
59 Run Keyword If '${host_power_state}' == 'On' and '${host_state}' == 'Enabled'
shrsuman123298e8042021-08-20 07:36:21 -050060 ... Verify VMI Network Interface Details ${ip} Static ${gateway} ${netmask} ${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050061
62Verify VMI Network Interface Details
63 [Documentation] Verify VMI network interface details.
64 [Arguments] ${ip} ${origin} ${gateway} ${netmask}
shrsuman123a0355782021-10-18 05:56:56 -050065 ... ${interface}=${ethernet_interface} ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -050066
67 # Description of argument(s):
68 # ip VMI IPv4 address.
69 # origin Origin of IPv4 address eg. Static or DHCP.
70 # gateway Gateway for VMI IP.
71 # netmask Subnetmask for VMI IP.
shrsuman123298e8042021-08-20 07:36:21 -050072 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050073 # valid_status_code Expected valid status code from GET request. Default is HTTP_OK.
74
shrsuman123298e8042021-08-20 07:36:21 -050075 ${vmi_ip}= Get VMI Network Interface Details ${interface} ${valid_status_code}
Sweta Potthurid52b2732021-08-12 12:48:24 -050076 Should Be Equal As Strings ${origin} ${vmi_ip["IPv4_AddressOrigin"]}
77 Should Be Equal As Strings ${gateway} ${vmi_ip["IPv4_Gateway"]}
78 Should Be Equal As Strings ${netmask} ${vmi_ip["IPv4_SubnetMask"]}
79 Should Be Equal As Strings ${ip} ${vmi_ip["IPv4_Address"]}
80
81Delete VMI IPv4 Address
82 [Documentation] Delete VMI IPv4 address.
83 [Arguments] ${delete_param}=IPv4StaticAddresses ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123a0355782021-10-18 05:56:56 -050084 ... ${interface}=${ethernet_interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050085
86 # Description of argument(s):
87 # delete_param Parameter to be deleted eg. IPv4StaticAddresses or IPv4Addresses.
88 # Default is IPv4StaticAddresses.
89 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -050090 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050091
92 ${data}= Set Variable {"${delete_param}": [${Null}]}
93 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -050094 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050095 ... body=${data} valid_status_codes=[${valid_status_code}]
96
97 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
shrsuman123a3759b32021-11-02 02:50:42 -050098
99 # Wait few seconds for configuration to get effective.
100 Sleep ${wait_time}
shrsuman123298e8042021-08-20 07:36:21 -0500101 ${vmi_ip}= Get VMI Network Interface Details ${interface}
Megha GN80ef5ca2022-06-09 00:29:57 -0500102 ${default}= Set Variable 0.0.0.0
103 Verify VMI Network Interface Details ${default} Static ${default} ${default}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500104
105Set VMI IPv4 Origin
106 [Documentation] Set VMI IPv4 origin.
107 [Arguments] ${dhcp_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123a0355782021-10-18 05:56:56 -0500108 ... ${interface}=${ethernet_interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500109
110 # Description of argument(s):
111 # dhcp_enabled True if user wants to enable DHCP. Default is Static, hence value is set to False.
112 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -0500113 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -0500114
115 ${data}= Set Variable If ${dhcp_enabled} == ${False} ${DISABLE_DHCP} ${ENABLE_DHCP}
116 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -0500117 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500118 ... body=${data} valid_status_codes=[${valid_status_code}]
119
120 Sleep ${wait_time}
121 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
122 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -0500123 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500124 Should Be Equal ${resp.dict["DHCPv4"]["DHCPEnabled"]} ${dhcp_enabled}
125
Megha G Na9cf2d82023-10-09 07:41:11 -0500126
Sweta Potthurid52b2732021-08-12 12:48:24 -0500127Get VMI Network Interface Details
128 [Documentation] Get VMI network interface details.
shrsuman123a0355782021-10-18 05:56:56 -0500129 [Arguments] ${interface}=${ethernet_interface} ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500130
131 # Description of argument(s):
shrsuman123298e8042021-08-20 07:36:21 -0500132 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -0500133 # valid_status_code Expected valid status code from GET request.
134
135 # Note: It returns a dictionary of VMI ethernet interface parameters.
136
137 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -0500138 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500139 ... valid_status_codes=[${valid_status_code}]
140
141 ${ip_resp}= Evaluate json.loads(r'''${resp.text}''') json
142
143 ${ip_exists}= Set Variable If ${ip_resp["IPv4Addresses"]} == @{empty} ${False} ${True}
144 ${static_exists}= Set Variable If ${ip_resp["IPv4StaticAddresses"]} == @{empty} ${False} ${True}
145
146 ${vmi_ip}= Run Keyword If ${ip_exists} == ${True}
147 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
148 ... Description=${ip_resp["Description"]} IPv4_Address=${ip_resp["IPv4Addresses"][0]["Address"]}
149 ... IPv4_AddressOrigin=${ip_resp["IPv4Addresses"][0]["AddressOrigin"]} Name=${ip_resp["Name"]}
150 ... IPv4_Gateway=${ip_resp["IPv4Addresses"][0]["Gateway"]}
151 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
152 ... IPv4_SubnetMask=${ip_resp["IPv4Addresses"][0]["SubnetMask"]}
153 ... IPv4StaticAddresses=${${static_exists}}
154 ... ELSE
155 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
156 ... Description=${ip_resp["Description"]} IPv4StaticAddresses=${ip_resp["IPv4StaticAddresses"]}
157 ... IPv4_Address=${ip_resp["IPv4Addresses"]} Name=${ip_resp["Name"]}
158 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
159
George Keishing409df052024-01-17 22:36:14 +0530160 RETURN &{vmi_ip}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500161
shrsuman123298e8042021-08-20 07:36:21 -0500162
163Get VMI Interfaces
164 [Documentation] Get VMI network interface.
165 [Arguments] ${valid_status_code}=${HTTP_OK}
166
167 # Description of argument(s):
168 # valid_status_code Expected valid status code from GET request.
169 # By default set to ${HTTP_OK}.
170
171 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
172 ... valid_status_codes=[${valid_status_code}]
173
174 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
175 ${interfaces_uri}= Set Variable ${resp["Members"]}
176 ${interface_list}= Create List
177 ${number_of_interfaces}= Get Length ${interfaces_uri}
178 FOR ${interface} IN RANGE ${number_of_interfaces}
179 ${_} ${interface_value}= Split String From Right ${interfaces_uri[${interface}]}[@odata.id] / 1
180 Append To List ${interface_list} ${interface_value}
181 END
182
George Keishing409df052024-01-17 22:36:14 +0530183 RETURN @{interface_list}
shrsuman123298e8042021-08-20 07:36:21 -0500184
185
Sweta Potthurid52b2732021-08-12 12:48:24 -0500186Verify VMI EthernetInterfaces
187 [Documentation] Verify VMI ethernet interfaces.
188 [Arguments] ${valid_status_code}=${HTTP_OK}
189
190 # Description of argument(s):
191 # valid_status_code Expected valid status code from GET request.
192
193 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
194 ... valid_status_codes=[${valid_status_code}]
195
196 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
197 ${interfaces}= Set Variable ${resp["Members"]}
198
199 ${number_of_interfaces}= Get Length ${interfaces}
200 FOR ${i} IN RANGE ${number_of_interfaces}
201 Should Be Equal As Strings ${interfaces[${i}]}[@odata.id]
202 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth${i}
203 END
204 Should Be Equal ${resp["Members@odata.count"]} ${number_of_interfaces}
shrsuman1237ba02f32021-08-26 04:50:56 -0500205
206Get And Set Static VMI IP
207 [Documentation] Get a suitable VMI IP and set it.
208 [Arguments] ${host}=${OPENBMC_HOST} ${network_active_channel}=${CHANNEL_NUMBER}
209 ... ${interface}=eth0 ${valid_status_code}=${HTTP_ACCEPTED}
210
211 # Description of argument(s):
212 # host BMC host name or IP address.
213 # network_active_channel Ethernet channel number (e.g.1 or 2).
214 # interface VMI interface (eg. eth0 or eth1).
215 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_ACCEPTED.
216
217 ${vmi_ip}= Get First Non Pingable IP From Subnet ${host}
218 ${bmc_ip_data}= Get Network Configuration ${network_active_channel}
219
220 Set Static IPv4 Address To VMI And Verify ${vmi_ip} ${bmc_ip_data[0]['Gateway']}
221 ... ${bmc_ip_data[0]['SubnetMask']} ${valid_status_code} ${interface}
222
George Keishing409df052024-01-17 22:36:14 +0530223 RETURN ${vmi_ip} ${bmc_ip_data}
Megha G Na2148332025-03-06 07:28:15 -0600224
225
226Set VMI SLAACv6 Origin
227 [Documentation] Set VMI SLAACv6 origin.
228 [Arguments] ${slaac_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED}
229 ... ${interface}=${ethernet_interface}
230
231 # Description of argument(s):
232 # slaacv6_enabled True if user wants to enable SLAACv6. Default is Static, hence value is set to False.
233 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
234 # interface VMI interface (eg. eth0 or eth1).
235
236 ${data}= Set Variable If ${slaac_enabled} == ${False} ${DISABLE_SLAAC} ${ENABLE_SLAAC}
237 ${resp}= Redfish.Patch
238 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
239 ... body=${data} valid_status_codes=[${valid_status_code}]
240
241 Sleep ${wait_time}
242 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
243 ${resp}= Redfish.Get
244 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
245 Should Be Equal ${resp.dict["StatelessAddressAutoConfig"]["IPv6AutoConfigEnabled"]} ${slaac_enabled}
246
247
248Verify VMI IPv6 Address
249 [Documentation] Verify VMI IPv6 address configurations.
250 [Arguments] ${ipv6_origin} ${interface}=${ethernet_interface}
251
252 # Description of argument(s):
253 # ipv6_origin Origin of IPv6 address eg. Static or DHCPv6 or SLAAC.
254 # interface VMI interface (eg. eth0 or eth1).
255
256 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
257
258 @{vmi_ipv6_configurations}= Get From Dictionary ${resp.dict} IPv6Addresses
259 ${vmi_ipv6_config}= Get From List ${vmi_ipv6_configurations} 0
260 Should Not Be Empty ${vmi_ipv6_config["Address"]}
261 Should Be Equal As Strings   ${vmi_ipv6_config["AddressOrigin"]} ${ipv6_origin}
262 RETURN &{vmi_ipv6_config}
263
264
265Set VMI DHCPv6 Property
266 [Documentation] Set VMI DHCPv6 attribute.
267 [Arguments] ${dhcpv6_operatingmode}=${Disabled} ${valid_status_code}=${HTTP_ACCEPTED}
268 ... ${interface}=${ethernet_interface}
269
270 # Description of argument(s):
271 # dhcpv6_operatingmode Enabled if user wants to enable DHCPv6.
272 # ... Default is Static, hence value is set to Disabled.
273 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
274 # interface VMI interface (eg. eth0 or eth1).
275
276 ${data}= Set Variable If '${dhcpv6_operatingmode}' == 'Disabled' ${DISABLE_DHCPv6} ${ENABLE_DHCPv6}
277 ${resp}= Redfish.Patch
278 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
279 ... body=${data} valid_status_codes=[${valid_status_code}]
280
281 Sleep ${wait_time}
282 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
283 ${resp}= Redfish.Get
284 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
285 Should Be Equal ${resp.dict["DHCPv6"]["OperatingMode"]} ${dhcpv6_operatingmode}
286
287
288Set Static VMI IPv6 Address
289 [Documentation] Add static VMI IPv6 address.
290 [Arguments] ${vmi_ipv6_addr} ${prefix_len} ${valid_status_codes}=${HTTP_ACCEPTED}
291 ... ${interface}=${ethernet_interface}
292
293 # Description of argument(s):
294 # vmi_ipv6_addr VMI IPv6 address to be added.
295 # prefix_len Prefix length for the VMI IPv6 to be added.
296 # valid_status_codes Expected valid status code from PATCH request.
297 # interface VMI interface (eg. eth0 or eth1).
298
299 ${prefix_length}= Convert To Integer ${prefix_len}
300 ${empty_dict}= Create Dictionary
301 ${vmi_ipv6_data}= Create Dictionary Address=${vmi_ipv6_addr}
302 ... PrefixLength=${prefix_length}
303
304 ${patch_list}= Create List
305
306 Append To List ${patch_list} ${vmi_ipv6_data}
307 ${data}= Create Dictionary IPv6StaticAddresses=${patch_list}
308
309 ${active_channel_config}= Get Active Channel Config
310 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
311
312 Redfish.patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
313 ... body=&{data} valid_status_codes=[${valid_status_codes}]
314
Megha G N1361edf2025-03-18 03:09:41 -0500315 Sleep 5s
Megha G Na2148332025-03-06 07:28:15 -0600316
317Set VMI IPv6 Static Default Gateway
318 [Documentation] Set VMI IPv6 static default gateway address.
319 [Arguments] ${vmi_staticipv6_gateway} ${valid_status_codes}=${HTTP_ACCEPTED}
320 ... ${interface}=${ethernet_interface}
321
322 # Description of argument(s):
323 # vmi_staticipv6_gateway VMI static IPv6 default gateway address.
324 # valid_status_codes Expected valid status code from PATCH request.
325 # interface VMI interface (eg. eth0 or eth1).
326
327 ${patch_list}= Create List ${vmi_staticipv6_gateway}
328 ${data}= Create Dictionary IPv6StaticDefaultGateways=${patch_list}
329
330 Redfish.patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
331 ... body=&{data} valid_status_codes=[${valid_status_codes}]
332
333
334Delete VMI IPv6 Static Address
335 [Documentation] Delete VMI IPv6 static address.
336 [Arguments] ${valid_status_codes}=${HTTP_ACCEPTED}
337 ... ${interface}=${ethernet_interface}
338
339 # Description of argument(s):
340 # valid_status_codes Expected valid status code from PATCH request.
341 # interface VMI interface (eg. eth0 or eth1).
342
343 ${data}= Set Variable {"IPv6StaticAddresses": [${Null}]}
344 Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
345 ... body=${data} valid_status_codes=[${valid_status_codes}]
346
347 Sleep 5s