blob: 980ba15ff2b1820f48c5eb94d03eeee013e507fd [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
9Library ../../lib/bmc_network_utils.py
10
11*** Variables ***
12
13${wait_time} 10s
14
15*** Keywords ***
16
17Set Static IPv4 Address To VMI And Verify
18 [Documentation] Set static IPv4 address to VMI.
19 [Arguments] ${ip} ${gateway} ${netmask} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050020 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050021
22 # Description of argument(s):
23 # ip VMI IPv4 address.
24 # gateway Gateway for VMI IP.
25 # netmask Subnetmask for VMI IP.
26 # valid_status_code Expected valid status code from GET request. Default is HTTP_ACCEPTED.
shrsuman123298e8042021-08-20 07:36:21 -050027 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050028
shrsuman123298e8042021-08-20 07:36:21 -050029 ${ip_details}= Create dictionary Address=${ip} SubnetMask=${netmask} Gateway=${gateway}
30 ${ip_data}= Create List ${ip_details}
31 ${resp}= Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
32 ... body={'IPv4StaticAddresses':${ip_data}} valid_status_codes=[${valid_status_code}]
Sweta Potthurid52b2732021-08-12 12:48:24 -050033
34 # Wait few seconds for new configuration to get populated on runtime.
35 Sleep ${wait_time}
36
37 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
38 ${host_power_state} ${host_state}= Redfish Get Host State
39 Run Keyword If '${host_power_state}' == 'On' and '${host_state}' == 'Enabled'
shrsuman123298e8042021-08-20 07:36:21 -050040 ... Verify VMI Network Interface Details ${ip} Static ${gateway} ${netmask} ${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050041
42Verify VMI Network Interface Details
43 [Documentation] Verify VMI network interface details.
44 [Arguments] ${ip} ${origin} ${gateway} ${netmask}
shrsuman123298e8042021-08-20 07:36:21 -050045 ... ${interface}=eth0 ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -050046
47 # Description of argument(s):
48 # ip VMI IPv4 address.
49 # origin Origin of IPv4 address eg. Static or DHCP.
50 # gateway Gateway for VMI IP.
51 # netmask Subnetmask for VMI IP.
shrsuman123298e8042021-08-20 07:36:21 -050052 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050053 # valid_status_code Expected valid status code from GET request. Default is HTTP_OK.
54
shrsuman123298e8042021-08-20 07:36:21 -050055 ${vmi_ip}= Get VMI Network Interface Details ${interface} ${valid_status_code}
Sweta Potthurid52b2732021-08-12 12:48:24 -050056 Should Be Equal As Strings ${origin} ${vmi_ip["IPv4_AddressOrigin"]}
57 Should Be Equal As Strings ${gateway} ${vmi_ip["IPv4_Gateway"]}
58 Should Be Equal As Strings ${netmask} ${vmi_ip["IPv4_SubnetMask"]}
59 Should Be Equal As Strings ${ip} ${vmi_ip["IPv4_Address"]}
60
61Delete VMI IPv4 Address
62 [Documentation] Delete VMI IPv4 address.
63 [Arguments] ${delete_param}=IPv4StaticAddresses ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050064 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050065
66 # Description of argument(s):
67 # delete_param Parameter to be deleted eg. IPv4StaticAddresses or IPv4Addresses.
68 # Default is IPv4StaticAddresses.
69 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -050070 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050071
72 ${data}= Set Variable {"${delete_param}": [${Null}]}
73 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -050074 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050075 ... body=${data} valid_status_codes=[${valid_status_code}]
76
77 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050078 ${vmi_ip}= Get VMI Network Interface Details ${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050079 Should Be Empty ${vmi_ip["IPv4_Address"]}
80
81Set VMI IPv4 Origin
82 [Documentation] Set VMI IPv4 origin.
83 [Arguments] ${dhcp_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED}
shrsuman123298e8042021-08-20 07:36:21 -050084 ... ${interface}=eth0
Sweta Potthurid52b2732021-08-12 12:48:24 -050085
86 # Description of argument(s):
87 # dhcp_enabled True if user wants to enable DHCP. Default is Static, hence value is set to False.
88 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK.
shrsuman123298e8042021-08-20 07:36:21 -050089 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -050090
91 ${data}= Set Variable If ${dhcp_enabled} == ${False} ${DISABLE_DHCP} ${ENABLE_DHCP}
92 ${resp}= Redfish.Patch
shrsuman123298e8042021-08-20 07:36:21 -050093 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -050094 ... body=${data} valid_status_codes=[${valid_status_code}]
95
96 Sleep ${wait_time}
97 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED}
98 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -050099 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500100 Should Be Equal ${resp.dict["DHCPv4"]["DHCPEnabled"]} ${dhcp_enabled}
101
102Get VMI Network Interface Details
103 [Documentation] Get VMI network interface details.
shrsuman123298e8042021-08-20 07:36:21 -0500104 [Arguments] ${interface}=eth0 ${valid_status_code}=${HTTP_OK}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500105
106 # Description of argument(s):
shrsuman123298e8042021-08-20 07:36:21 -0500107 # interface VMI interface (eg. eth0 or eth1).
Sweta Potthurid52b2732021-08-12 12:48:24 -0500108 # valid_status_code Expected valid status code from GET request.
109
110 # Note: It returns a dictionary of VMI ethernet interface parameters.
111
112 ${resp}= Redfish.Get
shrsuman123298e8042021-08-20 07:36:21 -0500113 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface}
Sweta Potthurid52b2732021-08-12 12:48:24 -0500114 ... valid_status_codes=[${valid_status_code}]
115
116 ${ip_resp}= Evaluate json.loads(r'''${resp.text}''') json
117
118 ${ip_exists}= Set Variable If ${ip_resp["IPv4Addresses"]} == @{empty} ${False} ${True}
119 ${static_exists}= Set Variable If ${ip_resp["IPv4StaticAddresses"]} == @{empty} ${False} ${True}
120
121 ${vmi_ip}= Run Keyword If ${ip_exists} == ${True}
122 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
123 ... Description=${ip_resp["Description"]} IPv4_Address=${ip_resp["IPv4Addresses"][0]["Address"]}
124 ... IPv4_AddressOrigin=${ip_resp["IPv4Addresses"][0]["AddressOrigin"]} Name=${ip_resp["Name"]}
125 ... IPv4_Gateway=${ip_resp["IPv4Addresses"][0]["Gateway"]}
126 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
127 ... IPv4_SubnetMask=${ip_resp["IPv4Addresses"][0]["SubnetMask"]}
128 ... IPv4StaticAddresses=${${static_exists}}
129 ... ELSE
130 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]}
131 ... Description=${ip_resp["Description"]} IPv4StaticAddresses=${ip_resp["IPv4StaticAddresses"]}
132 ... IPv4_Address=${ip_resp["IPv4Addresses"]} Name=${ip_resp["Name"]}
133 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}}
134
135 [Return] &{vmi_ip}
136
shrsuman123298e8042021-08-20 07:36:21 -0500137
138Get VMI Interfaces
139 [Documentation] Get VMI network interface.
140 [Arguments] ${valid_status_code}=${HTTP_OK}
141
142 # Description of argument(s):
143 # valid_status_code Expected valid status code from GET request.
144 # By default set to ${HTTP_OK}.
145
146 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
147 ... valid_status_codes=[${valid_status_code}]
148
149 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
150 ${interfaces_uri}= Set Variable ${resp["Members"]}
151 ${interface_list}= Create List
152 ${number_of_interfaces}= Get Length ${interfaces_uri}
153 FOR ${interface} IN RANGE ${number_of_interfaces}
154 ${_} ${interface_value}= Split String From Right ${interfaces_uri[${interface}]}[@odata.id] / 1
155 Append To List ${interface_list} ${interface_value}
156 END
157
158 [Return] @{interface_list}
159
160
Sweta Potthurid52b2732021-08-12 12:48:24 -0500161Verify VMI EthernetInterfaces
162 [Documentation] Verify VMI ethernet interfaces.
163 [Arguments] ${valid_status_code}=${HTTP_OK}
164
165 # Description of argument(s):
166 # valid_status_code Expected valid status code from GET request.
167
168 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces
169 ... valid_status_codes=[${valid_status_code}]
170
171 ${resp}= Evaluate json.loads(r'''${resp.text}''') json
172 ${interfaces}= Set Variable ${resp["Members"]}
173
174 ${number_of_interfaces}= Get Length ${interfaces}
175 FOR ${i} IN RANGE ${number_of_interfaces}
176 Should Be Equal As Strings ${interfaces[${i}]}[@odata.id]
177 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth${i}
178 END
179 Should Be Equal ${resp["Members@odata.count"]} ${number_of_interfaces}