blob: 03c6d3fe1a1ef0ebee40962bfb06c7524aeb6214 [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 Hoferda24d0a2017-08-09 15:03:40 -0500147Delete Software Object
148 [Documentation] Deletes an image from the BMC.
149 [Arguments] ${software_object}
150
151 # Description of argument(s):
152 # software_object The URI to the software image to delete.
153
154 ${arglist}= Create List
155 ${args}= Create Dictionary data=${arglist}
156 ${resp}= OpenBMC Post Request ${software_object}/action/delete
157 ... data=${args}
158 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500159
160
161Delete Image And Verify
162 [Documentation] Delete an image from the BMC and verify that it was
163 ... removed from software and the /tmp/images directory.
164 [Arguments] ${software_object} ${version_type}
165
166 # Description of argument(s):
167 # software_object The URI of the software object to delete.
168 # version_type The type of the software object, e.g.
169 # xyz.openbmc_project.Software.Version.VersionPurpose.Host
170 # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
171
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500172 Log To Console Deleteing ${software_object}
173
Charles Paul Hofercef61992017-08-18 10:14:18 -0500174 # Delete the image.
175 Delete Software Object ${software_object}
176 # TODO: If/when we don't have to delete twice anymore, take this out
177 Run Keyword And Ignore Error Delete Software Object ${software_object}
178
179 # Verify that it's gone from software.
180 ${software_objects}= Get Software Objects version_type=${version_type}
181 Should Not Contain ${software_objects} ${software_object}
182
183 # Check that there is no file in the /tmp/images directory.
184 ${image_id}= Fetch From Right ${software_object} /
185 BMC Execute Command
186 ... [ ! -d "/tmp/images/${image_id}" ]
George Keishing00715492017-08-18 11:46:37 -0500187
188
189Check Error And Collect FFDC
190 [Documentation] Collect FFDC if error log exists.
191
192 ${status}= Run Keyword And Return Status Error Logs Should Not Exist
193 Run Keyword If '${status}' == 'False' FFDC
194 Delete Error Logs