blob: d33688852404ab46ddcdb2b9aa5f12fe085b4f56 [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.
69 [Arguments] ${property}
70
71 # Description of argument(s):
72 # property The property to attempt to set.
73
74 ${sw_objs}= Get Software Objects
75 ${prev_props}= Get Host Software Property @{sw_objs}[0]
76 Run Keyword And Expect Error 500 != 200
77 ... Set Host Software Property @{sw_objs}[0] ${property} foo
78 ${cur_props}= Get Host Software Property @{sw_objs}[0]
79 Should Be Equal As Strings &{prev_props}[${property}]
80 ... &{cur_props}[${property}]
81
82
83Upload And Activate Image
84 [Documentation] Uploads an image to the BMC and activates it with REST.
85 [Arguments] ${image_file_path}
86
87 # Description of argument(s):
88 # image_file_path The path to the image tarball to upload and activate.
89
90 OperatingSystem.File Should Exist ${image_file_path}
91 ${image_version}= Get Version Tar ${image_file_path}
92
93 ${image_data}= OperatingSystem.Get Binary File ${image_file_path}
94 Upload Image To BMC /upload/image data=${image_data}
95 ${ret} ${version_id}= Verify Image Upload ${image_version}
96 Should Be True ${ret}
97
98 # Verify the image is 'READY' to be activated.
99 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
100 Should Be Equal As Strings &{software_state}[Activation] ${READY}
101
102 # Request the image to be activated.
103 ${args}= Create Dictionary data=${REQUESTED_ACTIVE}
104 Write Attribute ${SOFTWARE_VERSION_URI}${version_id}
105 ... RequestedActivation data=${args}
106 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
107 Should Be Equal As Strings &{software_state}[RequestedActivation]
108 ... ${REQUESTED_ACTIVE}
109
110 # Verify code update was successful and Activation state is Active.
111 Wait For Activation State Change ${version_id} ${ACTIVATING}
112 ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
113 Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE}
114
115
Charles Paul Hoferda24d0a2017-08-09 15:03:40 -0500116Delete Software Object
117 [Documentation] Deletes an image from the BMC.
118 [Arguments] ${software_object}
119
120 # Description of argument(s):
121 # software_object The URI to the software image to delete.
122
123 ${arglist}= Create List
124 ${args}= Create Dictionary data=${arglist}
125 ${resp}= OpenBMC Post Request ${software_object}/action/delete
126 ... data=${args}
127 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Charles Paul Hofercef61992017-08-18 10:14:18 -0500128
129
130Delete Image And Verify
131 [Documentation] Delete an image from the BMC and verify that it was
132 ... removed from software and the /tmp/images directory.
133 [Arguments] ${software_object} ${version_type}
134
135 # Description of argument(s):
136 # software_object The URI of the software object to delete.
137 # version_type The type of the software object, e.g.
138 # xyz.openbmc_project.Software.Version.VersionPurpose.Host
139 # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
140
141 # Delete the image.
142 Delete Software Object ${software_object}
143 # TODO: If/when we don't have to delete twice anymore, take this out
144 Run Keyword And Ignore Error Delete Software Object ${software_object}
145
146 # Verify that it's gone from software.
147 ${software_objects}= Get Software Objects version_type=${version_type}
148 Should Not Contain ${software_objects} ${software_object}
149
150 # Check that there is no file in the /tmp/images directory.
151 ${image_id}= Fetch From Right ${software_object} /
152 BMC Execute Command
153 ... [ ! -d "/tmp/images/${image_id}" ]