blob: ebb48a30eb408dd4cfd6def4a00ffa0b52bee9c5 [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 Keishing27bf6932017-08-07 14:30:40 -05009
10*** Keywords ***
11
12Get Software Objects
13 [Documentation] Get the host software objects and return as a list.
14 [Arguments] ${version_type}=${VERSION_PURPOSE_HOST}
15
16 # Description of argument(s):
17 # version_type Either BMC or host version purpose.
18 # By default host version purpose string.
19 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
20 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
21
22 # Example:
23 # "data": [
24 # "/xyz/openbmc_project/software/f3b29aa8",
25 # "/xyz/openbmc_project/software/e49bc78e",
26 # ],
27 # Iterate the list and return the host object name path list.
28
29 ${host_list}= Create List
30 ${sw_list}= Read Properties ${SOFTWARE_VERSION_URI}
31
32 :FOR ${index} IN @{sw_list}
33 \ ${attr_purpose}= Read Attribute ${index} Purpose quiet=${1}
34 \ Continue For Loop If '${attr_purpose}' != '${version_type}'
35 \ Append To List ${host_list} ${index}
36
37 [return] ${host_list}
38
39
40Get Host Software Property
41 [Documentation] Return a dictionary of host software properties.
42 [Arguments] ${host_object}
43
44 # Description of argument(s):
45 # host_object Host software object path.
46 # (e.g. "/xyz/openbmc_project/software/f3b29aa8").
47
48 ${sw_attributes}= Read Properties ${host_object}
49 [return] ${sw_attributes}
50
Sweta Potthuricd966342017-09-06 03:41:32 -050051Get Host Software Objects Details
52 [Documentation] Return software object details as a list of dictionaries.
53 [Arguments] ${quiet}=${QUIET}
54
55 ${software}= Create List
56
57 ${pnor_details}= Get Software Objects ${VERSION_PURPOSE_HOST}
58 :FOR ${pnor} IN @{pnor_details}
59 \ ${resp}= OpenBMC Get Request ${pnor} quiet=${1}
60 \ ${json}= To JSON ${resp.content}
61 \ Append To List ${software} ${json["data"]}
62
63 [Return] ${software}
George Keishing27bf6932017-08-07 14:30:40 -050064
65Set Host Software Property
66 [Documentation] Set the host software properties of a given object.
67 [Arguments] ${host_object} ${sw_attribute} ${data}
68
69 # Description of argument(s):
70 # host_object Host software object name.
71 # sw_attribute Host software attribute name.
72 # (e.g. "Activation", "Priority", "RequestedActivation" etc).
73 # data Value to be written.
74
75 ${args}= Create Dictionary data=${data}
76 Write Attribute ${host_object} ${sw_attribute} data=${args}
77
Charles Paul Hofercef61992017-08-18 10:14:18 -050078
79Set Property To Invalid Value And Verify No Change
80 [Documentation] Attempt to set a property and check that the value didn't
81 ... change.
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050082 [Arguments] ${property} ${version_type}
Charles Paul Hofercef61992017-08-18 10:14:18 -050083
84 # Description of argument(s):
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050085 # property The property to attempt to set.
86 # version_type Either BMC or host version purpose.
87 # By default host version purpose string.
88 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
89 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
Charles Paul Hofercef61992017-08-18 10:14:18 -050090
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050091 ${software_objects}= Get Software Objects version_type=${version_type}
92 ${prev_properties}= Get Host Software Property @{software_objects}[0]
Charles Paul Hofercef61992017-08-18 10:14:18 -050093 Run Keyword And Expect Error 500 != 200
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050094 ... Set Host Software Property @{software_objects}[0] ${property} foo
95 ${cur_properties}= Get Host Software Property @{software_objects}[0]
96 Should Be Equal As Strings &{prev_properties}[${property}]
97 ... &{cur_properties}[${property}]
Charles Paul Hofercef61992017-08-18 10:14:18 -050098
99
100Upload And Activate Image
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500101 [Documentation] Upload an image to the BMC and activate it with REST.
Charles Paul Hofercef61992017-08-18 10:14:18 -0500102 [Arguments] ${image_file_path}
103
104 # Description of argument(s):
105 # image_file_path The path to the image tarball to upload and activate.
106
107 OperatingSystem.File Should Exist ${image_file_path}
108 ${image_version}= Get Version Tar ${image_file_path}
109
110 ${image_data}= OperatingSystem.Get Binary File ${image_file_path}
111 Upload Image To BMC /upload/image data=${image_data}
112 ${ret} ${version_id}= Verify Image Upload ${image_version}
113 Should Be True ${ret}
114
115 # Verify the image is 'READY' to be activated.
116 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
117 Should Be Equal As Strings &{software_state}[Activation] ${READY}
118
119 # Request the image to be activated.
120 ${args}= Create Dictionary data=${REQUESTED_ACTIVE}
121 Write Attribute ${SOFTWARE_VERSION_URI}${version_id}
122 ... RequestedActivation data=${args}
123 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
124 Should Be Equal As Strings &{software_state}[RequestedActivation]
125 ... ${REQUESTED_ACTIVE}
126
127 # Verify code update was successful and Activation state is Active.
128 Wait For Activation State Change ${version_id} ${ACTIVATING}
129 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
130 Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE}
131
132
Charles Paul Hoferc1fa2bc2017-08-18 16:44:03 -0500133Activate Image And Verify No Duplicate Priorities
134 [Documentation] Upload an image, and then check that no images have the
135 ... same priority.
136 [Arguments] ${image_file_path} ${image_purpose}
137
138 # Description of argument(s):
139 # image_file_path The path to the image to upload.
140 # image_purpose The purpose in the image's MANIFEST file.
141
142 Upload And Activate Image ${image_file_path}
143 Verify No Duplicate Image Priorities ${image_purpose}
144
145
Charles Paul Hoferda24d0a2017-08-09 15:03:40 -0500146Delete Software Object
147 [Documentation] Deletes an image from the BMC.
148 [Arguments] ${software_object}
149
150 # Description of argument(s):
151 # software_object The URI to the software image to delete.
152
153 ${arglist}= Create List
154 ${args}= Create Dictionary data=${arglist}
155 ${resp}= OpenBMC Post Request ${software_object}/action/delete
156 ... data=${args}
157 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500158
159
160Delete Image And Verify
161 [Documentation] Delete an image from the BMC and verify that it was
162 ... removed from software and the /tmp/images directory.
163 [Arguments] ${software_object} ${version_type}
164
165 # Description of argument(s):
166 # software_object The URI of the software object to delete.
167 # version_type The type of the software object, e.g.
168 # xyz.openbmc_project.Software.Version.VersionPurpose.Host
169 # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
170
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500171 Log To Console Deleteing ${software_object}
172
Charles Paul Hofercef61992017-08-18 10:14:18 -0500173 # Delete the image.
174 Delete Software Object ${software_object}
175 # TODO: If/when we don't have to delete twice anymore, take this out
176 Run Keyword And Ignore Error Delete Software Object ${software_object}
177
178 # Verify that it's gone from software.
179 ${software_objects}= Get Software Objects version_type=${version_type}
180 Should Not Contain ${software_objects} ${software_object}
181
182 # Check that there is no file in the /tmp/images directory.
183 ${image_id}= Fetch From Right ${software_object} /
184 BMC Execute Command
185 ... [ ! -d "/tmp/images/${image_id}" ]