blob: fddafd79c5ef2e2ca7ed7fbb25c65a8d8db16613 [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
21
22*** Keywords ***
23
24Set Static IPv4 Address To VMI And Verify
25 [Documentation] Set static IPv4 address to VMI.
26 [Arguments] ${ip} ${gateway} ${netmask} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050027 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050028
29 # Description of argument(s):
30 # ip VMI IPv4 address.
31 # gateway Gateway for VMI IP.
32 # netmask Subnetmask for VMI IP.
33 # valid_status_code Expected valid status code from GET request. Default is HTTP_ACCEPTED.
shrsuman123298e8042021-08-20 07:36:21 -050034 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050035
shrsuman123298e8042021-08-20 07:36:21 -050036 ${ip_details}= Create dictionary Address=${ip} SubnetMask=${netmask} Gateway=${gateway}
37 ${ip_data}= Create List ${ip_details}
38 ${resp}= Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
39 ... body={'IPv4StaticAddresses':${ip_data}} valid_status_codes=[${valid_status_code}]
Sweta Potthurid52b2732021-08-12 12:48:24 -050040
41 # Wait few seconds for new configuration to get populated on runtime.
42 Sleep ${wait_time}
43
44 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
45 ${host_power_state} ${host_state}= Redfish Get Host State
46 Run Keyword If '${host_power_state}' == 'On' and '${host_state}' == 'Enabled'
shrsuman123298e8042021-08-20 07:36:21 -050047 ... Verify VMI Network Interface Details ${ip} Static ${gateway} ${netmask} ${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050048
49Verify VMI Network Interface Details
50 [Documentation] Verify VMI network interface details.
51 [Arguments] ${ip} ${origin} ${gateway} ${netmask}
shrsuman123298e8042021-08-20 07:36:21 -050052 ... ${interface}=eth0 ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -050053
54 # Description of argument(s):
55 # ip VMI IPv4 address.
56 # origin Origin of IPv4 address eg. Static or DHCP.
57 # gateway Gateway for VMI IP.
58 # netmask Subnetmask for VMI IP.
shrsuman123298e8042021-08-20 07:36:21 -050059 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050060 # valid_status_code Expected valid status code from GET request. Default is HTTP_OK.
61
shrsuman123298e8042021-08-20 07:36:21 -050062 ${vmi_ip}= Get VMI Network Interface Details ${interface} ${valid_status_code}
Sweta Potthurid52b2732021-08-12 12:48:24 -050063 Should Be Equal As Strings ${origin} ${vmi_ip["IPv4_AddressOrigin"]}
64 Should Be Equal As Strings ${gateway} ${vmi_ip["IPv4_Gateway"]}
65 Should Be Equal As Strings ${netmask} ${vmi_ip["IPv4_SubnetMask"]}
66 Should Be Equal As Strings ${ip} ${vmi_ip["IPv4_Address"]}
67
68Delete VMI IPv4 Address
69 [Documentation] Delete VMI IPv4 address.
70 [Arguments] ${delete_param}=IPv4StaticAddresses ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050071 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050072
73 # Description of argument(s):
74 # delete_param Parameter to be deleted eg. IPv4StaticAddresses or IPv4Addresses.
75 # Default is IPv4StaticAddresses.
76 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -050077 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050078
79 ${data}= Set Variable {"${delete_param}": [${Null}]}
80 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -050081 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050082 ... body=${data} valid_status_codes=[${valid_status_code}]
83
84 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
shrsuman123a3759b32021-11-02 02:50:42 -050085
86 # Wait few seconds for configuration to get effective.
87 Sleep ${wait_time}
shrsuman123298e8042021-08-20 07:36:21 -050088 ${vmi_ip}= Get VMI Network Interface Details ${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050089 Should Be Empty ${vmi_ip["IPv4_Address"]}
90
91Set VMI IPv4 Origin
92 [Documentation] Set VMI IPv4 origin.
93 [Arguments] ${dhcp_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050094 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050095
96 # Description of argument(s):
97 # dhcp_enabled True if user wants to enable DHCP. Default is Static, hence value is set to False.
98 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -050099 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -0500100
101 ${data}= Set Variable If ${dhcp_enabled} == ${False} ${DISABLE_DHCP} ${ENABLE_DHCP}
102 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -0500103 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500104 ... body=${data} valid_status_codes=[${valid_status_code}]
105
106 Sleep ${wait_time}
107 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
108 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -0500109 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500110 Should Be Equal ${resp.dict["DHCPv4"]["DHCPEnabled"]} ${dhcp_enabled}
111
112Get VMI Network Interface Details
113 [Documentation] Get VMI network interface details.
shrsuman123298e8042021-08-20 07:36:21 -0500114 [Arguments] ${interface}=eth0 ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500115
116 # Description of argument(s):
shrsuman123298e8042021-08-20 07:36:21 -0500117 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -0500118 # valid_status_code Expected valid status code from GET request.
119
120 # Note: It returns a dictionary of VMI ethernet interface parameters.
121
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 ... valid_status_codes=[${valid_status_code}]
125
126 ${ip_resp}= Evaluate json.loads(r'''${resp.text}''') json
127
128 ${ip_exists}= Set Variable If ${ip_resp["IPv4Addresses"]} == @{empty} ${False} ${True}
129 ${static_exists}= Set Variable If ${ip_resp["IPv4StaticAddresses"]} == @{empty} ${False} ${True}
130
131 ${vmi_ip}= Run Keyword If ${ip_exists} == ${True}
132 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
133 ... Description=${ip_resp["Description"]} IPv4_Address=${ip_resp["IPv4Addresses"][0]["Address"]}
134 ... IPv4_AddressOrigin=${ip_resp["IPv4Addresses"][0]["AddressOrigin"]} Name=${ip_resp["Name"]}
135 ... IPv4_Gateway=${ip_resp["IPv4Addresses"][0]["Gateway"]}
136 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
137 ... IPv4_SubnetMask=${ip_resp["IPv4Addresses"][0]["SubnetMask"]}
138 ... IPv4StaticAddresses=${${static_exists}}
139 ... ELSE
140 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
141 ... Description=${ip_resp["Description"]} IPv4StaticAddresses=${ip_resp["IPv4StaticAddresses"]}
142 ... IPv4_Address=${ip_resp["IPv4Addresses"]} Name=${ip_resp["Name"]}
143 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
144
145 [Return] &{vmi_ip}
146
shrsuman123298e8042021-08-20 07:36:21 -0500147
148Get VMI Interfaces
149 [Documentation] Get VMI network interface.
150 [Arguments] ${valid_status_code}=${HTTP_OK}
151
152 # Description of argument(s):
153 # valid_status_code Expected valid status code from GET request.
154 # By default set to ${HTTP_OK}.
155
156 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
157 ... valid_status_codes=[${valid_status_code}]
158
159 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
160 ${interfaces_uri}= Set Variable ${resp["Members"]}
161 ${interface_list}= Create List
162 ${number_of_interfaces}= Get Length ${interfaces_uri}
163 FOR ${interface} IN RANGE ${number_of_interfaces}
164 ${_} ${interface_value}= Split String From Right ${interfaces_uri[${interface}]}[@odata.id] / 1
165 Append To List ${interface_list} ${interface_value}
166 END
167
168 [Return] @{interface_list}
169
170
Sweta Potthurid52b2732021-08-12 12:48:24 -0500171Verify VMI EthernetInterfaces
172 [Documentation] Verify VMI ethernet interfaces.
173 [Arguments] ${valid_status_code}=${HTTP_OK}
174
175 # Description of argument(s):
176 # valid_status_code Expected valid status code from GET request.
177
178 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
179 ... valid_status_codes=[${valid_status_code}]
180
181 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
182 ${interfaces}= Set Variable ${resp["Members"]}
183
184 ${number_of_interfaces}= Get Length ${interfaces}
185 FOR ${i} IN RANGE ${number_of_interfaces}
186 Should Be Equal As Strings ${interfaces[${i}]}[@odata.id]
187 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth${i}
188 END
189 Should Be Equal ${resp["Members@odata.count"]} ${number_of_interfaces}
shrsuman1237ba02f32021-08-26 04:50:56 -0500190
191Get And Set Static VMI IP
192 [Documentation] Get a suitable VMI IP and set it.
193 [Arguments] ${host}=${OPENBMC_HOST} ${network_active_channel}=${CHANNEL_NUMBER}
194 ... ${interface}=eth0 ${valid_status_code}=${HTTP_ACCEPTED}
195
196 # Description of argument(s):
197 # host BMC host name or IP address.
198 # network_active_channel Ethernet channel number (e.g.1 or 2).
199 # interface VMI interface (eg. eth0 or eth1).
200 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_ACCEPTED.
201
202 ${vmi_ip}= Get First Non Pingable IP From Subnet ${host}
203 ${bmc_ip_data}= Get Network Configuration ${network_active_channel}
204
205 Set Static IPv4 Address To VMI And Verify ${vmi_ip} ${bmc_ip_data[0]['Gateway']}
206 ... ${bmc_ip_data[0]['SubnetMask']} ${valid_status_code} ${interface}
207
208 [Return] ${vmi_ip} ${bmc_ip_data}