blob: 5c8d0251b1d6dad375477c9272ed596268d8e84e [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
George Keishing81ae45b2017-09-28 14:05:04 -05007Library utilities.py
Charles Paul Hofercef61992017-08-18 10:14:18 -05008Variables ../data/variables.py
Charles Paul Hofere0e17802017-09-21 09:19:33 -05009Resource boot_utils.robot
Charles Paul Hofercef61992017-08-18 10:14:18 -050010Resource rest_client.robot
George Keishing00715492017-08-18 11:46:37 -050011Resource openbmc_ffdc.robot
George Keishing27bf6932017-08-07 14:30:40 -050012
13*** Keywords ***
14
15Get Software Objects
16 [Documentation] Get the host software objects and return as a list.
17 [Arguments] ${version_type}=${VERSION_PURPOSE_HOST}
18
19 # Description of argument(s):
20 # version_type Either BMC or host version purpose.
21 # By default host version purpose string.
22 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
23 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
24
25 # Example:
26 # "data": [
27 # "/xyz/openbmc_project/software/f3b29aa8",
28 # "/xyz/openbmc_project/software/e49bc78e",
29 # ],
30 # Iterate the list and return the host object name path list.
31
32 ${host_list}= Create List
33 ${sw_list}= Read Properties ${SOFTWARE_VERSION_URI}
34
35 :FOR ${index} IN @{sw_list}
George Keishingd62db0f2017-09-13 08:50:33 -050036 \ ${attr_purpose}= Read Software Attribute ${index} Purpose
George Keishing27bf6932017-08-07 14:30:40 -050037 \ Continue For Loop If '${attr_purpose}' != '${version_type}'
38 \ Append To List ${host_list} ${index}
39
George Keishingd62db0f2017-09-13 08:50:33 -050040 [Return] ${host_list}
41
42
43Read Software Attribute
44 [Documentation] Return software attribute data.
45 [Arguments] ${software_object} ${attribute_name}
46
47 # Description of argument(s):
48 # software_object Software object path.
49 # (e.g. "/xyz/openbmc_project/software/f3b29aa8").
50 # attribute_name Software object attribute name.
51
52 ${resp}= OpenBMC Get Request ${software_object}/attr/${attribute_name}
53 ... quiet=${1}
54 Return From Keyword If ${resp.status_code} != ${HTTP_OK}
55 ${content}= To JSON ${resp.content}
56 [Return] ${content["data"]}
George Keishing27bf6932017-08-07 14:30:40 -050057
58
George Keishingfe4ebd22017-09-12 06:05:22 -050059Get Software Objects Id
60 [Documentation] Get the software objects id and return as a list.
61 [Arguments] ${version_type}=${VERSION_PURPOSE_HOST}
62
63 # Description of argument(s):
64 # version_type Either BMC or host version purpose.
65 # By default host version purpose string.
66 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
67 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
68
69 ${sw_id_list}= Create List
70 ${sw_list}= Get Software Objects ${version_type}
71
72 :FOR ${index} IN @{sw_list}
73 \ Append To List ${sw_id_list} ${index.rsplit('/', 1)[1]}
74
75 [Return] ${sw_id_list}
76
77
George Keishing27bf6932017-08-07 14:30:40 -050078Get Host Software Property
79 [Documentation] Return a dictionary of host software properties.
80 [Arguments] ${host_object}
81
82 # Description of argument(s):
83 # host_object Host software object path.
84 # (e.g. "/xyz/openbmc_project/software/f3b29aa8").
85
86 ${sw_attributes}= Read Properties ${host_object}
87 [return] ${sw_attributes}
88
Sweta Potthuricd966342017-09-06 03:41:32 -050089Get Host Software Objects Details
90 [Documentation] Return software object details as a list of dictionaries.
91 [Arguments] ${quiet}=${QUIET}
92
93 ${software}= Create List
94
95 ${pnor_details}= Get Software Objects ${VERSION_PURPOSE_HOST}
96 :FOR ${pnor} IN @{pnor_details}
97 \ ${resp}= OpenBMC Get Request ${pnor} quiet=${1}
98 \ ${json}= To JSON ${resp.content}
99 \ Append To List ${software} ${json["data"]}
100
101 [Return] ${software}
George Keishing27bf6932017-08-07 14:30:40 -0500102
103Set Host Software Property
104 [Documentation] Set the host software properties of a given object.
105 [Arguments] ${host_object} ${sw_attribute} ${data}
106
107 # Description of argument(s):
108 # host_object Host software object name.
109 # sw_attribute Host software attribute name.
110 # (e.g. "Activation", "Priority", "RequestedActivation" etc).
111 # data Value to be written.
112
113 ${args}= Create Dictionary data=${data}
114 Write Attribute ${host_object} ${sw_attribute} data=${args}
115
Charles Paul Hofercef61992017-08-18 10:14:18 -0500116
117Set Property To Invalid Value And Verify No Change
118 [Documentation] Attempt to set a property and check that the value didn't
119 ... change.
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500120 [Arguments] ${property} ${version_type}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500121
122 # Description of argument(s):
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500123 # property The property to attempt to set.
124 # version_type Either BMC or host version purpose.
125 # By default host version purpose string.
126 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
127 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
Charles Paul Hofercef61992017-08-18 10:14:18 -0500128
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500129 ${software_objects}= Get Software Objects version_type=${version_type}
130 ${prev_properties}= Get Host Software Property @{software_objects}[0]
Charles Paul Hofercef61992017-08-18 10:14:18 -0500131 Run Keyword And Expect Error 500 != 200
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500132 ... Set Host Software Property @{software_objects}[0] ${property} foo
133 ${cur_properties}= Get Host Software Property @{software_objects}[0]
134 Should Be Equal As Strings &{prev_properties}[${property}]
135 ... &{cur_properties}[${property}]
Charles Paul Hofercef61992017-08-18 10:14:18 -0500136
137
Charles Paul Hofer42f17462017-09-12 14:09:32 -0500138Set Priority To Invalid Value And Expect Error
139 [Documentation] Set the priority of an image to an invalid value and
140 ... check that an error was returned.
141 [Arguments] ${version_type} ${priority}
142
143 # Description of argument(s):
144 # version_type Either BMC or host version purpose.
145 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
146 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
147 # priority The priority value to set. Should be an integer outside of
148 # the range of 0 through 255.
149
150 ${images}= Get Software Objects version_type=${version_type}
151 ${num_images}= Get Length ${images}
152 Should Be True 0 < ${num_images}
153
154 Run Keyword And Expect Error 403 != 200
155 ... Set Host Software Property @{images}[0] Priority ${priority}
156
157
Charles Paul Hofercef61992017-08-18 10:14:18 -0500158Upload And Activate Image
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500159 [Documentation] Upload an image to the BMC and activate it with REST.
Charles Paul Hoferb7842a52017-09-22 10:11:33 -0500160 [Arguments] ${image_file_path} ${wait}=${1} ${skip_if_active}=false
Charles Paul Hofercef61992017-08-18 10:14:18 -0500161
162 # Description of argument(s):
George Keishing71c24ed2017-09-25 13:11:10 -0500163 # image_file_path The path to the image tarball to upload and activate.
164 # wait Indicates that this keyword should wait for host or
165 # BMC activation is completed.
Charles Paul Hoferb7842a52017-09-22 10:11:33 -0500166 # skip_if_active If set to true, will skip the code update if this
167 # image is already on the BMC.
Charles Paul Hofercef61992017-08-18 10:14:18 -0500168
169 OperatingSystem.File Should Exist ${image_file_path}
170 ${image_version}= Get Version Tar ${image_file_path}
171
172 ${image_data}= OperatingSystem.Get Binary File ${image_file_path}
Leonel Gonzalez6ac206e2017-10-12 16:04:23 -0500173
174 Wait Until Keyword Succeeds 3 times 60 sec
175 ... Upload Image To BMC /upload/image data=${image_data}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500176 ${ret} ${version_id}= Verify Image Upload ${image_version}
177 Should Be True ${ret}
178
Charles Paul Hoferb7842a52017-09-22 10:11:33 -0500179 # Verify the image is 'READY' to be activated or if it's already active,
180 # set priority to 0 and reboot the BMC.
Charles Paul Hofercef61992017-08-18 10:14:18 -0500181 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
Charles Paul Hoferb7842a52017-09-22 10:11:33 -0500182 ${activation}= Set Variable &{software_state}[Activation]
George Keishingd5949852018-01-31 12:56:55 -0600183
Charles Paul Hoferb7842a52017-09-22 10:11:33 -0500184 Run Keyword If
185 ... '${skip_if_active}' == 'true' and '${activation}' == '${ACTIVE}'
Charles Paul Hoferb420c572017-10-31 09:24:12 -0500186 ... Run Keywords
187 ... Set Host Software Property ${SOFTWARE_VERSION_URI}${version_id}
188 ... Priority ${0}
189 ... AND
190 ... Return From Keyword
191
Charles Paul Hofercef61992017-08-18 10:14:18 -0500192 Should Be Equal As Strings &{software_state}[Activation] ${READY}
193
194 # Request the image to be activated.
195 ${args}= Create Dictionary data=${REQUESTED_ACTIVE}
196 Write Attribute ${SOFTWARE_VERSION_URI}${version_id}
197 ... RequestedActivation data=${args}
198 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
199 Should Be Equal As Strings &{software_state}[RequestedActivation]
200 ... ${REQUESTED_ACTIVE}
201
George Keishing71c24ed2017-09-25 13:11:10 -0500202 # Does caller want to wait for activation to complete?
Charles Paul Hofere0e17802017-09-21 09:19:33 -0500203 Return From Keyword If '${wait}' == '${0}' ${version_id}
George Keishing71c24ed2017-09-25 13:11:10 -0500204
Charles Paul Hofercef61992017-08-18 10:14:18 -0500205 # Verify code update was successful and Activation state is Active.
206 Wait For Activation State Change ${version_id} ${ACTIVATING}
207 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
208 Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE}
209
George Keishingd5949852018-01-31 12:56:55 -0600210 # Uploaded and activated image should have priority set to 0. Due to timing
211 # contention, it may take upto 10 seconds to complete updating priority.
212 Wait Until Keyword Succeeds 10 sec 5 sec
213 ... Check Software Object Attribute ${version_id} Priority ${0}
214
Charles Paul Hofere0e17802017-09-21 09:19:33 -0500215 [Return] ${version_id}
216
Charles Paul Hofercef61992017-08-18 10:14:18 -0500217
Charles Paul Hofere09408d2017-10-02 14:42:38 -0500218Attempt To Reboot BMC During Image Activation
219 [Documentation] Attempt to reboot the BMC while an image is activating and
220 ... check that the BMC ignores the reboot command and finishes
221 ... activation.
222 [Arguments] ${image_file_path}
223
224 # Description of argument(s):
225 # image_file_path Path to the image to update to.
226
227 # Attempt to reboot during activation.
228 ${version_id}= Upload And Activate Image ${image_file_path}
229 ... wait=${0}
George Keishingfd346d12017-11-20 23:23:01 -0600230 ${resp}= OpenBMC Get Request ${SOFTWARE_VERSION_URI}${version_id}
231 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Charles Paul Hofere09408d2017-10-02 14:42:38 -0500232
George Keishingfd346d12017-11-20 23:23:01 -0600233 OBMC Reboot (off)
Charles Paul Hofere09408d2017-10-02 14:42:38 -0500234
George Keishingfd346d12017-11-20 23:23:01 -0600235 ${resp}= OpenBMC Get Request ${SOFTWARE_VERSION_URI}${version_id}
236 Should Be Equal As Strings ${resp.status_code} ${HTTP_NOT_FOUND}
Charles Paul Hofere09408d2017-10-02 14:42:38 -0500237
238
Charles Paul Hoferc1fa2bc2017-08-18 16:44:03 -0500239Activate Image And Verify No Duplicate Priorities
240 [Documentation] Upload an image, and then check that no images have the
241 ... same priority.
242 [Arguments] ${image_file_path} ${image_purpose}
243
244 # Description of argument(s):
245 # image_file_path The path to the image to upload.
246 # image_purpose The purpose in the image's MANIFEST file.
247
George Keishing72373f82017-11-20 09:18:41 -0600248 Upload And Activate Image ${image_file_path} skip_if_active=true
Charles Paul Hoferc1fa2bc2017-08-18 16:44:03 -0500249 Verify No Duplicate Image Priorities ${image_purpose}
250
251
Charles Paul Hofera5673162017-08-30 09:49:16 -0500252Set Same Priority For Multiple Images
253 [Documentation] Find two images, set the priorities to be the same, and
254 ... verify that the priorities are not the same.
255 [Arguments] ${version_purpose}
256
257 # Description of argument(s):
258 # version_purpose Either BMC or host version purpose.
259 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
260 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
261
262 # Make sure we have more than two images.
263 ${software_objects}= Get Software Objects version_type=${version_purpose}
264 ${num_images}= Get Length ${software_objects}
265 Should Be True 1 < ${num_images}
266 ... msg=Only found one image on the BMC with purpose ${version_purpose}.
267
268 # Set the priority of the second image to the priority of the first.
269 ${properties}= Get Host Software Property @{software_objects}[0]
270 Set Host Software Property @{software_objects}[1] Priority
271 ... &{properties}[Priority]
272 Verify No Duplicate Image Priorities ${version_purpose}
273
274 # Set the priority of the first image back to what it was before
275 Set Host Software Property @{software_objects}[0] Priority
276 ... &{properties}[Priority]
277
278
Charles Paul Hoferda24d0a2017-08-09 15:03:40 -0500279Delete Software Object
280 [Documentation] Deletes an image from the BMC.
281 [Arguments] ${software_object}
282
283 # Description of argument(s):
284 # software_object The URI to the software image to delete.
285
286 ${arglist}= Create List
287 ${args}= Create Dictionary data=${arglist}
288 ${resp}= OpenBMC Post Request ${software_object}/action/delete
289 ... data=${args}
290 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500291
292
293Delete Image And Verify
294 [Documentation] Delete an image from the BMC and verify that it was
295 ... removed from software and the /tmp/images directory.
296 [Arguments] ${software_object} ${version_type}
297
298 # Description of argument(s):
299 # software_object The URI of the software object to delete.
300 # version_type The type of the software object, e.g.
301 # xyz.openbmc_project.Software.Version.VersionPurpose.Host
302 # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
303
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500304 Log To Console Deleteing ${software_object}
305
Charles Paul Hofercef61992017-08-18 10:14:18 -0500306 # Delete the image.
307 Delete Software Object ${software_object}
308 # TODO: If/when we don't have to delete twice anymore, take this out
309 Run Keyword And Ignore Error Delete Software Object ${software_object}
310
311 # Verify that it's gone from software.
312 ${software_objects}= Get Software Objects version_type=${version_type}
313 Should Not Contain ${software_objects} ${software_object}
314
315 # Check that there is no file in the /tmp/images directory.
316 ${image_id}= Fetch From Right ${software_object} /
317 BMC Execute Command
318 ... [ ! -d "/tmp/images/${image_id}" ]
George Keishing00715492017-08-18 11:46:37 -0500319
320
Charles Paul Hofere8dc5252017-10-10 13:50:18 -0500321Delete All Non Running BMC Images
322 [Documentation] Delete all BMC images that are not running on the BMC.
323
324 @{datalist}= Create List
325 ${data}= Create Dictionary data=@{datalist}
326 Call Method ${SOFTWARE_VERSION_URI} DeleteAll data=${data}
327
328
George Keishing00715492017-08-18 11:46:37 -0500329Check Error And Collect FFDC
330 [Documentation] Collect FFDC if error log exists.
331
332 ${status}= Run Keyword And Return Status Error Logs Should Not Exist
333 Run Keyword If '${status}' == 'False' FFDC
334 Delete Error Logs
Charles Paul Hofere43fb2f2017-09-26 15:36:18 -0500335
336
337Verify Running BMC Image
338 [Documentation] Verify that the version on the BMC is the same as the
339 ... version in the given image.
340 [Arguments] ${image_file_path}
341
342 # Description of argument(s):
343 # image_file_path Path to the BMC image tarball.
344
345 ${tar_version}= Get Version Tar ${image_file_path}
346 ${bmc_version}= Get BMC Version
347 ${bmc_version}= Remove String ${bmc_version} "
348 Should Be Equal ${tar_version} ${bmc_version}
349
350
351Verify Running Host Image
352 [Documentation] Verify that the version of the PNOR image that is on the
353 ... BMC is the same as the one in the given image.
354 [Arguments] ${image_file_path}
355
356 # Description of argument(s):
357 # image_file_path Path to the PNOR image tarball.
358
359 ${tar_version}= Get Version Tar ${image_file_path}
360 ${pnor_version}= Get PNOR Version
361 Should Be Equal ${tar_version} ${pnor_version}
Charles Paul Hofere0e17802017-09-21 09:19:33 -0500362
George Keishing81ae45b2017-09-28 14:05:04 -0500363
364Get Least Value Priority Image
365 [Documentation] Find the least value in "Priority" attribute and return.
366 [Arguments] ${version_type}
367
368 # Description of argument(s):
369 # version_type Either BMC or host version purpose.
370
371 ${priority_value_list}= Create List
372 ${sw_list}= Get Software Objects version_type=${version_type}
373
374 :FOR ${index} IN @{sw_list}
375 \ ${priority_value}=
376 ... Read Software Attribute ${index} Priority
377 \ Append To List ${priority_value_list} ${priority_value}
378
379 ${min_value}= Min List Value ${priority_value_list}
380
381 [Return] ${min_value}
George Keishingfb762032017-11-14 11:18:21 -0600382
383
384Enable Field Mode And Verify Unmount
385 [Documentation] Enable field mode and check that /usr/local is unmounted.
386
387 # After running, /xyz/openbmc_project/software should look like this:
388 # /xyz/openbmc_project/software
389 # {
390 # "FieldModeEnabled": 1,
391 # "associations": [
392 # [
393 # "active",
394 # "software_version",
395 # "/xyz/openbmc_project/software/fcf8e182"
396 # ],
397 # [
398 # "functional",
399 # "software_version",
400 # "/xyz/openbmc_project/software/fcf8e182"
401 # ]
402 # ]
403 # }
404
405 ${args}= Create Dictionary data=${1}
406 Write Attribute ${SOFTWARE_VERSION_URI} FieldModeEnabled data=${args}
407 Sleep 5s
408 BMC Execute Command [ ! -d "/usr/local/share" ]
409
George Keishingef97f3f2017-11-15 10:32:59 -0600410
411Disable Field Mode And Verify Unmount
412 [Documentation] Disable field mode, unmask usr local mount and reboot.
413
414 BMC Execute Command /sbin/fw_setenv fieldmode
415 BMC Execute Command /bin/systemctl unmask usr-local.mount
George Keishingc9031582017-12-18 11:58:11 -0600416 OBMC Reboot (off) stack_mode=normal
George Keishingef97f3f2017-11-15 10:32:59 -0600417 BMC Execute Command [ -d "/usr/local/share" ]
418
George Keishing13b8a212017-11-17 00:35:13 -0600419
420Field Mode Should Be Enabled
421 [Documentation] Check that field mode is enabled.
422
423 ${value}= Read Attribute ${SOFTWARE_VERSION_URI} FieldModeEnabled
424 Should Be True ${value} ${1}
Sweta Potthuri8c7ada42018-01-15 05:05:59 -0600425
426List Installed Images
427 [Documentation] List all the installed images.
428 [Arguments] ${image_type}
429
430 # Desciption of argument(s):
431 # image_type Either "BMC" or "PNOR".
432
433 # List the installed images.
434 ${installed_images}= Get Software Objects
435 ... ${SOFTWARE_PURPOSE}.${image_type}
436
437 Run Keyword If ${installed_images} != []
438 ... Get List of Images ${installed_images}
439 ... ELSE Log No ${image_type} images are present.
440
441Get List of Images
442 [Documentation] Get List of Images
443 [Arguments] ${installed_images}
444
445 :FOR ${uri} IN @{installed_images}
446 \ ${resp}= OpenBMC Get Request ${uri}
447 \ ${json}= To JSON ${resp.content}
448 \ Log ${json}["data"]
George Keishingd5949852018-01-31 12:56:55 -0600449
450
451Check Software Object Attribute
452 [Documentation] Get the software property of a given object and verify.
453 [Arguments] ${image_object} ${sw_attribute} ${value}
454
455 # Description of argument(s):
456 # image_object Image software object name.
457 # sw_attribute Software attribute name.
458 # (e.g. "Activation", "Priority", "RequestedActivation" etc).
459 # value Software attribute value to compare.
460
461 ${data}= Read Attribute
462 ... ${SOFTWARE_VERSION_URI}${image_object} ${sw_attribute}
463
464 Should Be True ${data} == ${value}
465 ... msg=Given attribute value ${data} mismatch ${value}.