blob: 77b0892f49f402024ed851e5e4122b7a9c9e2ee4 [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}
34 \ ${attr_purpose}= Read Attribute ${index} Purpose quiet=${1}
35 \ Continue For Loop If '${attr_purpose}' != '${version_type}'
36 \ Append To List ${host_list} ${index}
37
38 [return] ${host_list}
39
40
41Get Host Software Property
42 [Documentation] Return a dictionary of host software properties.
43 [Arguments] ${host_object}
44
45 # Description of argument(s):
46 # host_object Host software object path.
47 # (e.g. "/xyz/openbmc_project/software/f3b29aa8").
48
49 ${sw_attributes}= Read Properties ${host_object}
50 [return] ${sw_attributes}
51
Sweta Potthuricd966342017-09-06 03:41:32 -050052Get Host Software Objects Details
53 [Documentation] Return software object details as a list of dictionaries.
54 [Arguments] ${quiet}=${QUIET}
55
56 ${software}= Create List
57
58 ${pnor_details}= Get Software Objects ${VERSION_PURPOSE_HOST}
59 :FOR ${pnor} IN @{pnor_details}
60 \ ${resp}= OpenBMC Get Request ${pnor} quiet=${1}
61 \ ${json}= To JSON ${resp.content}
62 \ Append To List ${software} ${json["data"]}
63
64 [Return] ${software}
George Keishing27bf6932017-08-07 14:30:40 -050065
66Set Host Software Property
67 [Documentation] Set the host software properties of a given object.
68 [Arguments] ${host_object} ${sw_attribute} ${data}
69
70 # Description of argument(s):
71 # host_object Host software object name.
72 # sw_attribute Host software attribute name.
73 # (e.g. "Activation", "Priority", "RequestedActivation" etc).
74 # data Value to be written.
75
76 ${args}= Create Dictionary data=${data}
77 Write Attribute ${host_object} ${sw_attribute} data=${args}
78
Charles Paul Hofercef61992017-08-18 10:14:18 -050079
80Set Property To Invalid Value And Verify No Change
81 [Documentation] Attempt to set a property and check that the value didn't
82 ... change.
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050083 [Arguments] ${property} ${version_type}
Charles Paul Hofercef61992017-08-18 10:14:18 -050084
85 # Description of argument(s):
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050086 # property The property to attempt to set.
87 # version_type Either BMC or host version purpose.
88 # By default host version purpose string.
89 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
90 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
Charles Paul Hofercef61992017-08-18 10:14:18 -050091
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050092 ${software_objects}= Get Software Objects version_type=${version_type}
93 ${prev_properties}= Get Host Software Property @{software_objects}[0]
Charles Paul Hofercef61992017-08-18 10:14:18 -050094 Run Keyword And Expect Error 500 != 200
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050095 ... Set Host Software Property @{software_objects}[0] ${property} foo
96 ${cur_properties}= Get Host Software Property @{software_objects}[0]
97 Should Be Equal As Strings &{prev_properties}[${property}]
98 ... &{cur_properties}[${property}]
Charles Paul Hofercef61992017-08-18 10:14:18 -050099
100
101Upload And Activate Image
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500102 [Documentation] Upload an image to the BMC and activate it with REST.
Charles Paul Hofercef61992017-08-18 10:14:18 -0500103 [Arguments] ${image_file_path}
104
105 # Description of argument(s):
106 # image_file_path The path to the image tarball to upload and activate.
107
108 OperatingSystem.File Should Exist ${image_file_path}
109 ${image_version}= Get Version Tar ${image_file_path}
110
111 ${image_data}= OperatingSystem.Get Binary File ${image_file_path}
112 Upload Image To BMC /upload/image data=${image_data}
113 ${ret} ${version_id}= Verify Image Upload ${image_version}
114 Should Be True ${ret}
115
116 # Verify the image is 'READY' to be activated.
117 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
118 Should Be Equal As Strings &{software_state}[Activation] ${READY}
119
120 # Request the image to be activated.
121 ${args}= Create Dictionary data=${REQUESTED_ACTIVE}
122 Write Attribute ${SOFTWARE_VERSION_URI}${version_id}
123 ... RequestedActivation data=${args}
124 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
125 Should Be Equal As Strings &{software_state}[RequestedActivation]
126 ... ${REQUESTED_ACTIVE}
127
128 # Verify code update was successful and Activation state is Active.
129 Wait For Activation State Change ${version_id} ${ACTIVATING}
130 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
131 Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE}
132
133
Charles Paul Hoferc1fa2bc2017-08-18 16:44:03 -0500134Activate Image And Verify No Duplicate Priorities
135 [Documentation] Upload an image, and then check that no images have the
136 ... same priority.
137 [Arguments] ${image_file_path} ${image_purpose}
138
139 # Description of argument(s):
140 # image_file_path The path to the image to upload.
141 # image_purpose The purpose in the image's MANIFEST file.
142
143 Upload And Activate Image ${image_file_path}
144 Verify No Duplicate Image Priorities ${image_purpose}
145
146
Charles Paul Hofera5673162017-08-30 09:49:16 -0500147Set Same Priority For Multiple Images
148 [Documentation] Find two images, set the priorities to be the same, and
149 ... verify that the priorities are not the same.
150 [Arguments] ${version_purpose}
151
152 # Description of argument(s):
153 # version_purpose Either BMC or host version purpose.
154 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
155 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
156
157 # Make sure we have more than two images.
158 ${software_objects}= Get Software Objects version_type=${version_purpose}
159 ${num_images}= Get Length ${software_objects}
160 Should Be True 1 < ${num_images}
161 ... msg=Only found one image on the BMC with purpose ${version_purpose}.
162
163 # Set the priority of the second image to the priority of the first.
164 ${properties}= Get Host Software Property @{software_objects}[0]
165 Set Host Software Property @{software_objects}[1] Priority
166 ... &{properties}[Priority]
167 Verify No Duplicate Image Priorities ${version_purpose}
168
169 # Set the priority of the first image back to what it was before
170 Set Host Software Property @{software_objects}[0] Priority
171 ... &{properties}[Priority]
172
173
Charles Paul Hoferda24d0a2017-08-09 15:03:40 -0500174Delete Software Object
175 [Documentation] Deletes an image from the BMC.
176 [Arguments] ${software_object}
177
178 # Description of argument(s):
179 # software_object The URI to the software image to delete.
180
181 ${arglist}= Create List
182 ${args}= Create Dictionary data=${arglist}
183 ${resp}= OpenBMC Post Request ${software_object}/action/delete
184 ... data=${args}
185 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500186
187
188Delete Image And Verify
189 [Documentation] Delete an image from the BMC and verify that it was
190 ... removed from software and the /tmp/images directory.
191 [Arguments] ${software_object} ${version_type}
192
193 # Description of argument(s):
194 # software_object The URI of the software object to delete.
195 # version_type The type of the software object, e.g.
196 # xyz.openbmc_project.Software.Version.VersionPurpose.Host
197 # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
198
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500199 Log To Console Deleteing ${software_object}
200
Charles Paul Hofercef61992017-08-18 10:14:18 -0500201 # Delete the image.
202 Delete Software Object ${software_object}
203 # TODO: If/when we don't have to delete twice anymore, take this out
204 Run Keyword And Ignore Error Delete Software Object ${software_object}
205
206 # Verify that it's gone from software.
207 ${software_objects}= Get Software Objects version_type=${version_type}
208 Should Not Contain ${software_objects} ${software_object}
209
210 # Check that there is no file in the /tmp/images directory.
211 ${image_id}= Fetch From Right ${software_object} /
212 BMC Execute Command
213 ... [ ! -d "/tmp/images/${image_id}" ]
George Keishing00715492017-08-18 11:46:37 -0500214
215
216Check Error And Collect FFDC
217 [Documentation] Collect FFDC if error log exists.
218
219 ${status}= Run Keyword And Return Status Error Logs Should Not Exist
220 Run Keyword If '${status}' == 'False' FFDC
221 Delete Error Logs