blob: 4dac55c7b867447651014641b3cb4fd026703d76 [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
Sweta Potthurid52b2732021-08-12 12:48:24 -050020${wait_time} 10s
shrsuman123a0355782021-10-18 05:56:56 -050021${ethernet_interface} eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050022
23*** Keywords ***
24
25Set Static IPv4 Address To VMI And Verify
26 [Documentation] Set static IPv4 address to VMI.
27 [Arguments] ${ip} ${gateway} ${netmask} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123a0355782021-10-18 05:56:56 -050028 ... ${interface}=${ethernet_interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050029
30 # Description of argument(s):
31 # ip VMI IPv4 address.
32 # gateway Gateway for VMI IP.
33 # netmask Subnetmask for VMI IP.
34 # valid_status_code Expected valid status code from GET request. Default is HTTP_ACCEPTED.
shrsuman123298e8042021-08-20 07:36:21 -050035 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050036
shrsuman123298e8042021-08-20 07:36:21 -050037 ${ip_details}= Create dictionary Address=${ip} SubnetMask=${netmask} Gateway=${gateway}
38 ${ip_data}= Create List ${ip_details}
39 ${resp}= Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
40 ... body={'IPv4StaticAddresses':${ip_data}} valid_status_codes=[${valid_status_code}]
Sweta Potthurid52b2732021-08-12 12:48:24 -050041
42 # Wait few seconds for new configuration to get populated on runtime.
43 Sleep ${wait_time}
44
45 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
46 ${host_power_state} ${host_state}= Redfish Get Host State
47 Run Keyword If '${host_power_state}' == 'On' and '${host_state}' == 'Enabled'
shrsuman123298e8042021-08-20 07:36:21 -050048 ... Verify VMI Network Interface Details ${ip} Static ${gateway} ${netmask} ${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050049
50Verify VMI Network Interface Details
51 [Documentation] Verify VMI network interface details.
52 [Arguments] ${ip} ${origin} ${gateway} ${netmask}
shrsuman123a0355782021-10-18 05:56:56 -050053 ... ${interface}=${ethernet_interface} ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -050054
55 # Description of argument(s):
56 # ip VMI IPv4 address.
57 # origin Origin of IPv4 address eg. Static or DHCP.
58 # gateway Gateway for VMI IP.
59 # netmask Subnetmask for VMI IP.
shrsuman123298e8042021-08-20 07:36:21 -050060 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050061 # valid_status_code Expected valid status code from GET request. Default is HTTP_OK.
62
shrsuman123298e8042021-08-20 07:36:21 -050063 ${vmi_ip}= Get VMI Network Interface Details ${interface} ${valid_status_code}
Sweta Potthurid52b2732021-08-12 12:48:24 -050064 Should Be Equal As Strings ${origin} ${vmi_ip["IPv4_AddressOrigin"]}
65 Should Be Equal As Strings ${gateway} ${vmi_ip["IPv4_Gateway"]}
66 Should Be Equal As Strings ${netmask} ${vmi_ip["IPv4_SubnetMask"]}
67 Should Be Equal As Strings ${ip} ${vmi_ip["IPv4_Address"]}
68
69Delete VMI IPv4 Address
70 [Documentation] Delete VMI IPv4 address.
71 [Arguments] ${delete_param}=IPv4StaticAddresses ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123a0355782021-10-18 05:56:56 -050072 ... ${interface}=${ethernet_interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050073
74 # Description of argument(s):
75 # delete_param Parameter to be deleted eg. IPv4StaticAddresses or IPv4Addresses.
76 # Default is IPv4StaticAddresses.
77 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -050078 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050079
80 ${data}= Set Variable {"${delete_param}": [${Null}]}
81 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -050082 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050083 ... body=${data} valid_status_codes=[${valid_status_code}]
84
85 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
shrsuman123a3759b32021-11-02 02:50:42 -050086
87 # Wait few seconds for configuration to get effective.
88 Sleep ${wait_time}
shrsuman123298e8042021-08-20 07:36:21 -050089 ${vmi_ip}= Get VMI Network Interface Details ${interface}
Megha GN80ef5ca2022-06-09 00:29:57 -050090 ${default}= Set Variable 0.0.0.0
91 Verify VMI Network Interface Details ${default} Static ${default} ${default}
Sweta Potthurid52b2732021-08-12 12:48:24 -050092
93Set VMI IPv4 Origin
94 [Documentation] Set VMI IPv4 origin.
95 [Arguments] ${dhcp_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123a0355782021-10-18 05:56:56 -050096 ... ${interface}=${ethernet_interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050097
98 # Description of argument(s):
99 # dhcp_enabled True if user wants to enable DHCP. Default is Static, hence value is set to False.
100 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -0500101 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -0500102
103 ${data}= Set Variable If ${dhcp_enabled} == ${False} ${DISABLE_DHCP} ${ENABLE_DHCP}
104 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -0500105 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500106 ... body=${data} valid_status_codes=[${valid_status_code}]
107
108 Sleep ${wait_time}
109 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
110 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -0500111 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500112 Should Be Equal ${resp.dict["DHCPv4"]["DHCPEnabled"]} ${dhcp_enabled}
113
114Get VMI Network Interface Details
115 [Documentation] Get VMI network interface details.
shrsuman123a0355782021-10-18 05:56:56 -0500116 [Arguments] ${interface}=${ethernet_interface} ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500117
118 # Description of argument(s):
shrsuman123298e8042021-08-20 07:36:21 -0500119 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -0500120 # valid_status_code Expected valid status code from GET request.
121
122 # Note: It returns a dictionary of VMI ethernet interface parameters.
123
124 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -0500125 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500126 ... valid_status_codes=[${valid_status_code}]
127
128 ${ip_resp}= Evaluate json.loads(r'''${resp.text}''') json
129
130 ${ip_exists}= Set Variable If ${ip_resp["IPv4Addresses"]} == @{empty} ${False} ${True}
131 ${static_exists}= Set Variable If ${ip_resp["IPv4StaticAddresses"]} == @{empty} ${False} ${True}
132
133 ${vmi_ip}= Run Keyword If ${ip_exists} == ${True}
134 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
135 ... Description=${ip_resp["Description"]} IPv4_Address=${ip_resp["IPv4Addresses"][0]["Address"]}
136 ... IPv4_AddressOrigin=${ip_resp["IPv4Addresses"][0]["AddressOrigin"]} Name=${ip_resp["Name"]}
137 ... IPv4_Gateway=${ip_resp["IPv4Addresses"][0]["Gateway"]}
138 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
139 ... IPv4_SubnetMask=${ip_resp["IPv4Addresses"][0]["SubnetMask"]}
140 ... IPv4StaticAddresses=${${static_exists}}
141 ... ELSE
142 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
143 ... Description=${ip_resp["Description"]} IPv4StaticAddresses=${ip_resp["IPv4StaticAddresses"]}
144 ... IPv4_Address=${ip_resp["IPv4Addresses"]} Name=${ip_resp["Name"]}
145 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
146
147 [Return] &{vmi_ip}
148
shrsuman123298e8042021-08-20 07:36:21 -0500149
150Get VMI Interfaces
151 [Documentation] Get VMI network interface.
152 [Arguments] ${valid_status_code}=${HTTP_OK}
153
154 # Description of argument(s):
155 # valid_status_code Expected valid status code from GET request.
156 # By default set to ${HTTP_OK}.
157
158 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
159 ... valid_status_codes=[${valid_status_code}]
160
161 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
162 ${interfaces_uri}= Set Variable ${resp["Members"]}
163 ${interface_list}= Create List
164 ${number_of_interfaces}= Get Length ${interfaces_uri}
165 FOR ${interface} IN RANGE ${number_of_interfaces}
166 ${_} ${interface_value}= Split String From Right ${interfaces_uri[${interface}]}[@odata.id] / 1
167 Append To List ${interface_list} ${interface_value}
168 END
169
170 [Return] @{interface_list}
171
172
Sweta Potthurid52b2732021-08-12 12:48:24 -0500173Verify VMI EthernetInterfaces
174 [Documentation] Verify VMI ethernet interfaces.
175 [Arguments] ${valid_status_code}=${HTTP_OK}
176
177 # Description of argument(s):
178 # valid_status_code Expected valid status code from GET request.
179
180 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
181 ... valid_status_codes=[${valid_status_code}]
182
183 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
184 ${interfaces}= Set Variable ${resp["Members"]}
185
186 ${number_of_interfaces}= Get Length ${interfaces}
187 FOR ${i} IN RANGE ${number_of_interfaces}
188 Should Be Equal As Strings ${interfaces[${i}]}[@odata.id]
189 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth${i}
190 END
191 Should Be Equal ${resp["Members@odata.count"]} ${number_of_interfaces}
shrsuman1237ba02f32021-08-26 04:50:56 -0500192
193Get And Set Static VMI IP
194 [Documentation] Get a suitable VMI IP and set it.
195 [Arguments] ${host}=${OPENBMC_HOST} ${network_active_channel}=${CHANNEL_NUMBER}
196 ... ${interface}=eth0 ${valid_status_code}=${HTTP_ACCEPTED}
197
198 # Description of argument(s):
199 # host BMC host name or IP address.
200 # network_active_channel Ethernet channel number (e.g.1 or 2).
201 # interface VMI interface (eg. eth0 or eth1).
202 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_ACCEPTED.
203
204 ${vmi_ip}= Get First Non Pingable IP From Subnet ${host}
205 ${bmc_ip_data}= Get Network Configuration ${network_active_channel}
206
207 Set Static IPv4 Address To VMI And Verify ${vmi_ip} ${bmc_ip_data[0]['Gateway']}
208 ... ${bmc_ip_data[0]['SubnetMask']} ${valid_status_code} ${interface}
209
210 [Return] ${vmi_ip} ${bmc_ip_data}