blob: 10e21712de79e3d34e09d2ffc33b9ef3b66ebca7 [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
51
52Set Host Software Property
53 [Documentation] Set the host software properties of a given object.
54 [Arguments] ${host_object} ${sw_attribute} ${data}
55
56 # Description of argument(s):
57 # host_object Host software object name.
58 # sw_attribute Host software attribute name.
59 # (e.g. "Activation", "Priority", "RequestedActivation" etc).
60 # data Value to be written.
61
62 ${args}= Create Dictionary data=${data}
63 Write Attribute ${host_object} ${sw_attribute} data=${args}
64
Charles Paul Hofercef61992017-08-18 10:14:18 -050065
66Set Property To Invalid Value And Verify No Change
67 [Documentation] Attempt to set a property and check that the value didn't
68 ... change.
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050069 [Arguments] ${property} ${version_type}
Charles Paul Hofercef61992017-08-18 10:14:18 -050070
71 # Description of argument(s):
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050072 # property The property to attempt to set.
73 # version_type Either BMC or host version purpose.
74 # By default host version purpose string.
75 # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
76 # "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
Charles Paul Hofercef61992017-08-18 10:14:18 -050077
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050078 ${software_objects}= Get Software Objects version_type=${version_type}
79 ${prev_properties}= Get Host Software Property @{software_objects}[0]
Charles Paul Hofercef61992017-08-18 10:14:18 -050080 Run Keyword And Expect Error 500 != 200
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050081 ... Set Host Software Property @{software_objects}[0] ${property} foo
82 ${cur_properties}= Get Host Software Property @{software_objects}[0]
83 Should Be Equal As Strings &{prev_properties}[${property}]
84 ... &{cur_properties}[${property}]
Charles Paul Hofercef61992017-08-18 10:14:18 -050085
86
87Upload And Activate Image
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -050088 [Documentation] Upload an image to the BMC and activate it with REST.
Charles Paul Hofercef61992017-08-18 10:14:18 -050089 [Arguments] ${image_file_path}
90
91 # Description of argument(s):
92 # image_file_path The path to the image tarball to upload and activate.
93
94 OperatingSystem.File Should Exist ${image_file_path}
95 ${image_version}= Get Version Tar ${image_file_path}
96
97 ${image_data}= OperatingSystem.Get Binary File ${image_file_path}
98 Upload Image To BMC /upload/image data=${image_data}
99 ${ret} ${version_id}= Verify Image Upload ${image_version}
100 Should Be True ${ret}
101
102 # Verify the image is 'READY' to be activated.
103 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
104 Should Be Equal As Strings &{software_state}[Activation] ${READY}
105
106 # Request the image to be activated.
107 ${args}= Create Dictionary data=${REQUESTED_ACTIVE}
108 Write Attribute ${SOFTWARE_VERSION_URI}${version_id}
109 ... RequestedActivation data=${args}
110 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
111 Should Be Equal As Strings &{software_state}[RequestedActivation]
112 ... ${REQUESTED_ACTIVE}
113
114 # Verify code update was successful and Activation state is Active.
115 Wait For Activation State Change ${version_id} ${ACTIVATING}
116 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
117 Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE}
118
119
Charles Paul Hoferc1fa2bc2017-08-18 16:44:03 -0500120Activate Image And Verify No Duplicate Priorities
121 [Documentation] Upload an image, and then check that no images have the
122 ... same priority.
123 [Arguments] ${image_file_path} ${image_purpose}
124
125 # Description of argument(s):
126 # image_file_path The path to the image to upload.
127 # image_purpose The purpose in the image's MANIFEST file.
128
129 Upload And Activate Image ${image_file_path}
130 Verify No Duplicate Image Priorities ${image_purpose}
131
132
Charles Paul Hoferda24d0a2017-08-09 15:03:40 -0500133Delete Software Object
134 [Documentation] Deletes an image from the BMC.
135 [Arguments] ${software_object}
136
137 # Description of argument(s):
138 # software_object The URI to the software image to delete.
139
140 ${arglist}= Create List
141 ${args}= Create Dictionary data=${arglist}
142 ${resp}= OpenBMC Post Request ${software_object}/action/delete
143 ... data=${args}
144 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500145
146
147Delete Image And Verify
148 [Documentation] Delete an image from the BMC and verify that it was
149 ... removed from software and the /tmp/images directory.
150 [Arguments] ${software_object} ${version_type}
151
152 # Description of argument(s):
153 # software_object The URI of the software object to delete.
154 # version_type The type of the software object, e.g.
155 # xyz.openbmc_project.Software.Version.VersionPurpose.Host
156 # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
157
Charles Paul Hofer9f74d3a2017-08-18 09:54:28 -0500158 Log To Console Deleteing ${software_object}
159
Charles Paul Hofercef61992017-08-18 10:14:18 -0500160 # Delete the image.
161 Delete Software Object ${software_object}
162 # TODO: If/when we don't have to delete twice anymore, take this out
163 Run Keyword And Ignore Error Delete Software Object ${software_object}
164
165 # Verify that it's gone from software.
166 ${software_objects}= Get Software Objects version_type=${version_type}
167 Should Not Contain ${software_objects} ${software_object}
168
169 # Check that there is no file in the /tmp/images directory.
170 ${image_id}= Fetch From Right ${software_object} /
171 BMC Execute Command
172 ... [ ! -d "/tmp/images/${image_id}" ]