blob: 82fbc948e0446ba82e166f9aa4341a9d7e9c1e19 [file] [log] [blame]
George Keishing27bf6932017-08-07 14:30:40 -05001*** Settings ***
2Documentation BMC and PNOR update utilities keywords.
3
Charles Paul Hofercef61992017-08-18 10:14:18 -05004Library code_update_utils.py
5Library OperatingSystem
6Library String
7Variables ../data/variables.py
8Resource rest_client.robot
George Keishing00715492017-08-18 11:46:37 -05009Resource openbmc_ffdc.robot
George Keishing27bf6932017-08-07 14:30:40 -050010
11*** Keywords ***
12
13Get Software Objects
14 [Documentation] Get the host software objects and return as a list.
15 [Arguments] ${version_type}=${VERSION_PURPOSE_HOST}
16
17 # Description of argument(s):
18 # version_type Either BMC or host version purpose.
19 # By default host version purpose string.
20 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
21 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
22
23 # Example:
24 # "data": [
25 # "/xyz/openbmc_project/software/f3b29aa8",
26 # "/xyz/openbmc_project/software/e49bc78e",
27 # ],
28 # Iterate the list and return the host object name path list.
29
30 ${host_list}= Create List
31 ${sw_list}= Read Properties ${SOFTWARE_VERSION_URI}
32
33 :FOR ${index} IN @{sw_list}
George Keishingd62db0f2017-09-13 08:50:33 -050034 \ ${attr_purpose}= Read Software Attribute ${index} Purpose
George Keishing27bf6932017-08-07 14:30:40 -050035 \ Continue For Loop If '${attr_purpose}' != '${version_type}'
36 \ Append To List ${host_list} ${index}
37
George Keishingd62db0f2017-09-13 08:50:33 -050038 [Return] ${host_list}
39
40
41Read Software Attribute
42 [Documentation] Return software attribute data.
43 [Arguments] ${software_object} ${attribute_name}
44
45 # Description of argument(s):
46 # software_object Software object path.
47 # (e.g. "/xyz/openbmc_project/software/f3b29aa8").
48 # attribute_name Software object attribute name.
49
50 ${resp}= OpenBMC Get Request ${software_object}/attr/${attribute_name}
51 ... quiet=${1}
52 Return From Keyword If ${resp.status_code} != ${HTTP_OK}
53 ${content}= To JSON ${resp.content}
54 [Return] ${content["data"]}
George Keishing27bf6932017-08-07 14:30:40 -050055
56
57Get Host Software Property
58 [Documentation] Return a dictionary of host software properties.
59 [Arguments] ${host_object}
60
61 # Description of argument(s):
62 # host_object Host software object path.
63 # (e.g. "/xyz/openbmc_project/software/f3b29aa8").
64
65 ${sw_attributes}= Read Properties ${host_object}
66 [return] ${sw_attributes}
67
Sweta Potthuricd966342017-09-06 03:41:32 -050068Get Host Software Objects Details
69 [Documentation] Return software object details as a list of dictionaries.
70 [Arguments] ${quiet}=${QUIET}
71
72 ${software}= Create List
73
74 ${pnor_details}= Get Software Objects ${VERSION_PURPOSE_HOST}
75 :FOR ${pnor} IN @{pnor_details}
76 \ ${resp}= OpenBMC Get Request ${pnor} quiet=${1}
77 \ ${json}= To JSON ${resp.content}
78 \ Append To List ${software} ${json["data"]}
79
80 [Return] ${software}
George Keishing27bf6932017-08-07 14:30:40 -050081
82Set Host Software Property
83 [Documentation] Set the host software properties of a given object.
84 [Arguments] ${host_object} ${sw_attribute} ${data}
85
86 # Description of argument(s):
87 # host_object Host software object name.
88 # sw_attribute Host software attribute name.
89 # (e.g. "Activation", "Priority", "RequestedActivation" etc).
90 # data Value to be written.
91
92 ${args}= Create Dictionary data=${data}
93 Write Attribute ${host_object} ${sw_attribute} data=${args}
94
Charles Paul Hofercef61992017-08-18 10:14:18 -050095
96Set Property To Invalid Value And Verify No Change
97 [Documentation] Attempt to set a property and check that the value didn't
98 ... change.
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050099 [Arguments] ${property} ${version_type}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500100
101 # Description of argument(s):
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500102 # property The property to attempt to set.
103 # version_type Either BMC or host version purpose.
104 # By default host version purpose string.
105 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
106 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
Charles Paul Hofercef61992017-08-18 10:14:18 -0500107
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500108 ${software_objects}= Get Software Objects version_type=${version_type}
109 ${prev_properties}= Get Host Software Property @{software_objects}[0]
Charles Paul Hofercef61992017-08-18 10:14:18 -0500110 Run Keyword And Expect Error 500 != 200
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500111 ... Set Host Software Property @{software_objects}[0] ${property} foo
112 ${cur_properties}= Get Host Software Property @{software_objects}[0]
113 Should Be Equal As Strings &{prev_properties}[${property}]
114 ... &{cur_properties}[${property}]
Charles Paul Hofercef61992017-08-18 10:14:18 -0500115
116
Charles Paul Hofer42f17462017-09-12 14:09:32 -0500117Set Priority To Invalid Value And Expect Error
118 [Documentation] Set the priority of an image to an invalid value and
119 ... check that an error was returned.
120 [Arguments] ${version_type} ${priority}
121
122 # Description of argument(s):
123 # version_type Either BMC or host version purpose.
124 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
125 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
126 # priority The priority value to set. Should be an integer outside of
127 # the range of 0 through 255.
128
129 ${images}= Get Software Objects version_type=${version_type}
130 ${num_images}= Get Length ${images}
131 Should Be True 0 < ${num_images}
132
133 Run Keyword And Expect Error 403 != 200
134 ... Set Host Software Property @{images}[0] Priority ${priority}
135
136
Charles Paul Hofercef61992017-08-18 10:14:18 -0500137Upload And Activate Image
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500138 [Documentation] Upload an image to the BMC and activate it with REST.
George Keishing71c24ed2017-09-25 13:11:10 -0500139 [Arguments] ${image_file_path} ${wait}=${1}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500140
141 # Description of argument(s):
George Keishing71c24ed2017-09-25 13:11:10 -0500142 # image_file_path The path to the image tarball to upload and activate.
143 # wait Indicates that this keyword should wait for host or
144 # BMC activation is completed.
Charles Paul Hofercef61992017-08-18 10:14:18 -0500145
146 OperatingSystem.File Should Exist ${image_file_path}
147 ${image_version}= Get Version Tar ${image_file_path}
148
149 ${image_data}= OperatingSystem.Get Binary File ${image_file_path}
150 Upload Image To BMC /upload/image data=${image_data}
151 ${ret} ${version_id}= Verify Image Upload ${image_version}
152 Should Be True ${ret}
153
154 # Verify the image is 'READY' to be activated.
155 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
156 Should Be Equal As Strings &{software_state}[Activation] ${READY}
157
158 # Request the image to be activated.
159 ${args}= Create Dictionary data=${REQUESTED_ACTIVE}
160 Write Attribute ${SOFTWARE_VERSION_URI}${version_id}
161 ... RequestedActivation data=${args}
162 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
163 Should Be Equal As Strings &{software_state}[RequestedActivation]
164 ... ${REQUESTED_ACTIVE}
165
George Keishing71c24ed2017-09-25 13:11:10 -0500166 # Does caller want to wait for activation to complete?
167 Run Keyword If '${wait}' == '${0}' Return From Keyword
168
Charles Paul Hofercef61992017-08-18 10:14:18 -0500169 # Verify code update was successful and Activation state is Active.
170 Wait For Activation State Change ${version_id} ${ACTIVATING}
171 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
172 Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE}
173
174
Charles Paul Hoferc1fa2bc2017-08-18 16:44:03 -0500175Activate Image And Verify No Duplicate Priorities
176 [Documentation] Upload an image, and then check that no images have the
177 ... same priority.
178 [Arguments] ${image_file_path} ${image_purpose}
179
180 # Description of argument(s):
181 # image_file_path The path to the image to upload.
182 # image_purpose The purpose in the image's MANIFEST file.
183
184 Upload And Activate Image ${image_file_path}
185 Verify No Duplicate Image Priorities ${image_purpose}
186
187
Charles Paul Hofera5673162017-08-30 09:49:16 -0500188Set Same Priority For Multiple Images
189 [Documentation] Find two images, set the priorities to be the same, and
190 ... verify that the priorities are not the same.
191 [Arguments] ${version_purpose}
192
193 # Description of argument(s):
194 # version_purpose Either BMC or host version purpose.
195 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
196 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
197
198 # Make sure we have more than two images.
199 ${software_objects}= Get Software Objects version_type=${version_purpose}
200 ${num_images}= Get Length ${software_objects}
201 Should Be True 1 < ${num_images}
202 ... msg=Only found one image on the BMC with purpose ${version_purpose}.
203
204 # Set the priority of the second image to the priority of the first.
205 ${properties}= Get Host Software Property @{software_objects}[0]
206 Set Host Software Property @{software_objects}[1] Priority
207 ... &{properties}[Priority]
208 Verify No Duplicate Image Priorities ${version_purpose}
209
210 # Set the priority of the first image back to what it was before
211 Set Host Software Property @{software_objects}[0] Priority
212 ... &{properties}[Priority]
213
214
Charles Paul Hoferda24d0a2017-08-09 15:03:40 -0500215Delete Software Object
216 [Documentation] Deletes an image from the BMC.
217 [Arguments] ${software_object}
218
219 # Description of argument(s):
220 # software_object The URI to the software image to delete.
221
222 ${arglist}= Create List
223 ${args}= Create Dictionary data=${arglist}
224 ${resp}= OpenBMC Post Request ${software_object}/action/delete
225 ... data=${args}
226 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500227
228
229Delete Image And Verify
230 [Documentation] Delete an image from the BMC and verify that it was
231 ... removed from software and the /tmp/images directory.
232 [Arguments] ${software_object} ${version_type}
233
234 # Description of argument(s):
235 # software_object The URI of the software object to delete.
236 # version_type The type of the software object, e.g.
237 # xyz.openbmc_project.Software.Version.VersionPurpose.Host
238 # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
239
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500240 Log To Console Deleteing ${software_object}
241
Charles Paul Hofercef61992017-08-18 10:14:18 -0500242 # Delete the image.
243 Delete Software Object ${software_object}
244 # TODO: If/when we don't have to delete twice anymore, take this out
245 Run Keyword And Ignore Error Delete Software Object ${software_object}
246
247 # Verify that it's gone from software.
248 ${software_objects}= Get Software Objects version_type=${version_type}
249 Should Not Contain ${software_objects} ${software_object}
250
251 # Check that there is no file in the /tmp/images directory.
252 ${image_id}= Fetch From Right ${software_object} /
253 BMC Execute Command
254 ... [ ! -d "/tmp/images/${image_id}" ]
George Keishing00715492017-08-18 11:46:37 -0500255
256
257Check Error And Collect FFDC
258 [Documentation] Collect FFDC if error log exists.
259
260 ${status}= Run Keyword And Return Status Error Logs Should Not Exist
261 Run Keyword If '${status}' == 'False' FFDC
262 Delete Error Logs