blob: a90055c95ed024350fb6a763fd116e5abbedc8c4 [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
14${wait_time} 10s
15
16*** Keywords ***
17
18Set Static IPv4 Address To VMI And Verify
19 [Documentation] Set static IPv4 address to VMI.
20 [Arguments] ${ip} ${gateway} ${netmask} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050021 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050022
23 # Description of argument(s):
24 # ip VMI IPv4 address.
25 # gateway Gateway for VMI IP.
26 # netmask Subnetmask for VMI IP.
27 # valid_status_code Expected valid status code from GET request. Default is HTTP_ACCEPTED.
shrsuman123298e8042021-08-20 07:36:21 -050028 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050029
shrsuman123298e8042021-08-20 07:36:21 -050030 ${ip_details}= Create dictionary Address=${ip} SubnetMask=${netmask} Gateway=${gateway}
31 ${ip_data}= Create List ${ip_details}
32 ${resp}= Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
33 ... body={'IPv4StaticAddresses':${ip_data}} valid_status_codes=[${valid_status_code}]
Sweta Potthurid52b2732021-08-12 12:48:24 -050034
35 # Wait few seconds for new configuration to get populated on runtime.
36 Sleep ${wait_time}
37
38 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
39 ${host_power_state} ${host_state}= Redfish Get Host State
40 Run Keyword If '${host_power_state}' == 'On' and '${host_state}' == 'Enabled'
shrsuman123298e8042021-08-20 07:36:21 -050041 ... Verify VMI Network Interface Details ${ip} Static ${gateway} ${netmask} ${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050042
43Verify VMI Network Interface Details
44 [Documentation] Verify VMI network interface details.
45 [Arguments] ${ip} ${origin} ${gateway} ${netmask}
shrsuman123298e8042021-08-20 07:36:21 -050046 ... ${interface}=eth0 ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -050047
48 # Description of argument(s):
49 # ip VMI IPv4 address.
50 # origin Origin of IPv4 address eg. Static or DHCP.
51 # gateway Gateway for VMI IP.
52 # netmask Subnetmask for VMI IP.
shrsuman123298e8042021-08-20 07:36:21 -050053 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050054 # valid_status_code Expected valid status code from GET request. Default is HTTP_OK.
55
shrsuman123298e8042021-08-20 07:36:21 -050056 ${vmi_ip}= Get VMI Network Interface Details ${interface} ${valid_status_code}
Sweta Potthurid52b2732021-08-12 12:48:24 -050057 Should Be Equal As Strings ${origin} ${vmi_ip["IPv4_AddressOrigin"]}
58 Should Be Equal As Strings ${gateway} ${vmi_ip["IPv4_Gateway"]}
59 Should Be Equal As Strings ${netmask} ${vmi_ip["IPv4_SubnetMask"]}
60 Should Be Equal As Strings ${ip} ${vmi_ip["IPv4_Address"]}
61
62Delete VMI IPv4 Address
63 [Documentation] Delete VMI IPv4 address.
64 [Arguments] ${delete_param}=IPv4StaticAddresses ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050065 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050066
67 # Description of argument(s):
68 # delete_param Parameter to be deleted eg. IPv4StaticAddresses or IPv4Addresses.
69 # Default is IPv4StaticAddresses.
70 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -050071 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050072
73 ${data}= Set Variable {"${delete_param}": [${Null}]}
74 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -050075 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050076 ... body=${data} valid_status_codes=[${valid_status_code}]
77
78 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050079 ${vmi_ip}= Get VMI Network Interface Details ${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050080 Should Be Empty ${vmi_ip["IPv4_Address"]}
81
82Set VMI IPv4 Origin
83 [Documentation] Set VMI IPv4 origin.
84 [Arguments] ${dhcp_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050085 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050086
87 # Description of argument(s):
88 # dhcp_enabled True if user wants to enable DHCP. Default is Static, hence value is set to False.
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 If ${dhcp_enabled} == ${False} ${DISABLE_DHCP} ${ENABLE_DHCP}
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 Sleep ${wait_time}
98 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
99 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -0500100 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500101 Should Be Equal ${resp.dict["DHCPv4"]["DHCPEnabled"]} ${dhcp_enabled}
102
103Get VMI Network Interface Details
104 [Documentation] Get VMI network interface details.
shrsuman123298e8042021-08-20 07:36:21 -0500105 [Arguments] ${interface}=eth0 ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500106
107 # Description of argument(s):
shrsuman123298e8042021-08-20 07:36:21 -0500108 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -0500109 # valid_status_code Expected valid status code from GET request.
110
111 # Note: It returns a dictionary of VMI ethernet interface parameters.
112
113 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -0500114 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500115 ... valid_status_codes=[${valid_status_code}]
116
117 ${ip_resp}= Evaluate json.loads(r'''${resp.text}''') json
118
119 ${ip_exists}= Set Variable If ${ip_resp["IPv4Addresses"]} == @{empty} ${False} ${True}
120 ${static_exists}= Set Variable If ${ip_resp["IPv4StaticAddresses"]} == @{empty} ${False} ${True}
121
122 ${vmi_ip}= Run Keyword If ${ip_exists} == ${True}
123 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
124 ... Description=${ip_resp["Description"]} IPv4_Address=${ip_resp["IPv4Addresses"][0]["Address"]}
125 ... IPv4_AddressOrigin=${ip_resp["IPv4Addresses"][0]["AddressOrigin"]} Name=${ip_resp["Name"]}
126 ... IPv4_Gateway=${ip_resp["IPv4Addresses"][0]["Gateway"]}
127 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
128 ... IPv4_SubnetMask=${ip_resp["IPv4Addresses"][0]["SubnetMask"]}
129 ... IPv4StaticAddresses=${${static_exists}}
130 ... ELSE
131 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
132 ... Description=${ip_resp["Description"]} IPv4StaticAddresses=${ip_resp["IPv4StaticAddresses"]}
133 ... IPv4_Address=${ip_resp["IPv4Addresses"]} Name=${ip_resp["Name"]}
134 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
135
136 [Return] &{vmi_ip}
137
shrsuman123298e8042021-08-20 07:36:21 -0500138
139Get VMI Interfaces
140 [Documentation] Get VMI network interface.
141 [Arguments] ${valid_status_code}=${HTTP_OK}
142
143 # Description of argument(s):
144 # valid_status_code Expected valid status code from GET request.
145 # By default set to ${HTTP_OK}.
146
147 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
148 ... valid_status_codes=[${valid_status_code}]
149
150 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
151 ${interfaces_uri}= Set Variable ${resp["Members"]}
152 ${interface_list}= Create List
153 ${number_of_interfaces}= Get Length ${interfaces_uri}
154 FOR ${interface} IN RANGE ${number_of_interfaces}
155 ${_} ${interface_value}= Split String From Right ${interfaces_uri[${interface}]}[@odata.id] / 1
156 Append To List ${interface_list} ${interface_value}
157 END
158
159 [Return] @{interface_list}
160
161
Sweta Potthurid52b2732021-08-12 12:48:24 -0500162Verify VMI EthernetInterfaces
163 [Documentation] Verify VMI ethernet interfaces.
164 [Arguments] ${valid_status_code}=${HTTP_OK}
165
166 # Description of argument(s):
167 # valid_status_code Expected valid status code from GET request.
168
169 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
170 ... valid_status_codes=[${valid_status_code}]
171
172 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
173 ${interfaces}= Set Variable ${resp["Members"]}
174
175 ${number_of_interfaces}= Get Length ${interfaces}
176 FOR ${i} IN RANGE ${number_of_interfaces}
177 Should Be Equal As Strings ${interfaces[${i}]}[@odata.id]
178 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth${i}
179 END
180 Should Be Equal ${resp["Members@odata.count"]} ${number_of_interfaces}
shrsuman1237ba02f32021-08-26 04:50:56 -0500181
182Get And Set Static VMI IP
183 [Documentation] Get a suitable VMI IP and set it.
184 [Arguments] ${host}=${OPENBMC_HOST} ${network_active_channel}=${CHANNEL_NUMBER}
185 ... ${interface}=eth0 ${valid_status_code}=${HTTP_ACCEPTED}
186
187 # Description of argument(s):
188 # host BMC host name or IP address.
189 # network_active_channel Ethernet channel number (e.g.1 or 2).
190 # interface VMI interface (eg. eth0 or eth1).
191 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_ACCEPTED.
192
193 ${vmi_ip}= Get First Non Pingable IP From Subnet ${host}
194 ${bmc_ip_data}= Get Network Configuration ${network_active_channel}
195
196 Set Static IPv4 Address To VMI And Verify ${vmi_ip} ${bmc_ip_data[0]['Gateway']}
197 ... ${bmc_ip_data[0]['SubnetMask']} ${valid_status_code} ${interface}
198
199 [Return] ${vmi_ip} ${bmc_ip_data}