blob: 6946d9082dc9f922d0c6fe5d9d3776519e1883f4 [file] [log] [blame]
George Keishing5e870cd2016-08-24 10:05:47 -05001*** Settings ***
2Documentation Code update utility
3
Steven Sombar7d0e25d2018-12-12 12:24:14 -06004Resource ../../lib/rest_client.robot
5Resource ../../lib/connection_client.robot
6Resource ../../lib/utils.robot
7Library OperatingSystem
George Keishing5e870cd2016-08-24 10:05:47 -05008
9*** Variables ***
10
George Keishingf26367c2017-10-24 04:59:59 -050011# Fix old org path locally for non-witherspoon system.
12${ORG_OPENBMC_BASE_URI} /org/openbmc/
Steven Sombar7d0e25d2018-12-12 12:24:14 -060013${ORG_CONTROL_FLASH} ${ORG_OPENBMC_BASE_URI}control/flash/
14${BMC_UPD_METHOD} ${ORG_CONTROL_FLASH}bmc/action/update
15${BMC_PREP_METHOD} ${ORG_CONTROL_FLASH}bmc/action/PrepareForUpdate
16${BMC_UPD_ATTR} ${ORG_CONTROL_FLASH}bmc
17${HOST_SETTING} ${ORG_OPENBMC_BASE_URI}settings/host0
George Keishing5e870cd2016-08-24 10:05:47 -050018
19*** Keywords ***
20
21Preserve BMC Network Setting
22 [Documentation] Preserve Network setting
Steven Sombar7d0e25d2018-12-12 12:24:14 -060023
24 ${policy}= Set Variable ${1}
25 ${value}= Create Dictionary data=${policy}
26 Write Attribute ${BMC_UPD_ATTR} preserve_network_settings data=${value}
27 ${data}= Read Properties ${BMC_UPD_ATTR}
28 Should Be Equal As Strings
29 ... ${data['preserve_network_settings']} ${True}
30 ... msg=False indicates network is not preserved.
George Keishing5e870cd2016-08-24 10:05:47 -050031
32
Michael Walsh317878a2018-12-11 12:59:19 -060033Activate BMC Flash Image
34 [Documentation] Activate and verify the update status.
35 ... The status could be either one of these:
George Keishing5e870cd2016-08-24 10:05:47 -050036 ... 'Deferred for mounted filesystem. reboot BMC to apply.'
37 ... 'Image ready to apply.'
Steven Sombar7d0e25d2018-12-12 12:24:14 -060038
Michael Walsh317878a2018-12-11 12:59:19 -060039 @{img_path}= Create List /tmp/flashimg
40 ${data}= Create Dictionary data=@{img_path}
41 ${resp}= OpenBMC Post Request ${BMC_UPD_METHOD} data=${data}
42 ... timeout=${30}
43 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishing5e870cd2016-08-24 10:05:47 -050044
Michael Walsh317878a2018-12-11 12:59:19 -060045 ${data}= Read Properties ${BMC_UPD_ATTR}
46 Should Be Equal As Strings ${data["filename"]} /tmp/flashimg
47 Should Contain ${data['status']} to apply
George Keishing5e870cd2016-08-24 10:05:47 -050048
49
George Keishingdc5aa58e92016-09-27 01:35:11 -050050Prepare For Update
51 [Documentation] Switch to update mode in progress. This method calls
52 ... the Abort method to remove the pending update if there
53 ... is any before code activation.
Steven Sombar7d0e25d2018-12-12 12:24:14 -060054
George Keishing268099f2018-10-05 13:16:27 -050055 ${data}= Create Dictionary data=@{EMPTY}
56 ${resp}= Openbmc Post Request ${BMC_PREP_METHOD} data=${data}
George Keishingdc5aa58e92016-09-27 01:35:11 -050057
George Keishing11319f62017-03-14 13:28:56 -050058 # Update method will reset the BMC, adding delay for reboot to
59 # come into force.
60 Sleep 10s
George Keishingdc5aa58e92016-09-27 01:35:11 -050061
62
George Keishing5e870cd2016-08-24 10:05:47 -050063SCP Tar Image File to BMC
George Keishing7b64a312017-07-11 12:33:45 -050064 [Documentation] Copy BMC tar image to BMC.
65 [Arguments] ${image_file_path}
Steven Sombar7d0e25d2018-12-12 12:24:14 -060066
George Keishing7b64a312017-07-11 12:33:45 -050067 # Description of argument(s):
68 # image_file_path Downloaded BMC tar file image path.
69
George Keishing5e870cd2016-08-24 10:05:47 -050070 Open Connection for SCP
George Keishing7b64a312017-07-11 12:33:45 -050071 Open Connection And Log In
72 Loop SCP Retry ${image_file_path}
73
74
75Loop SCP Retry
76 [Documentation] Try transferring the file 4 times.
77 [Arguments] ${image_file_path}
Steven Sombar7d0e25d2018-12-12 12:24:14 -060078
George Keishing7b64a312017-07-11 12:33:45 -050079 # Description of argument(s):
80 # image_file_path Downloaded BMC tar file image path.
81
82 : FOR ${index} IN RANGE 0 4
83 \ ${status}= Retry SCP ${image_file_path}
84 \ Exit For Loop If '${status}' == '${True}'
85
86
87Retry SCP
88 [Documentation] Delete the incomplete file and scp file.
89 [Arguments] ${image_file_path}
Steven Sombar7d0e25d2018-12-12 12:24:14 -060090
George Keishing7b64a312017-07-11 12:33:45 -050091 # Description of argument(s):
92 # image_file_path Downloaded BMC tar file image path.
93
George Keishing1f97fd12017-07-14 14:09:32 -050094 ${targ_file_path}= Set Variable /tmp/flashimg
George Keishing7b64a312017-07-11 12:33:45 -050095
George Keishing7b64a312017-07-11 12:33:45 -050096 # Example output:
97 # root@witherspoon:~# ls -lh /tmp/flashimg
98 # -rwxr-xr-x 1 root root 32.0M Jun 29 01:12 /tmp/flashimg
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -050099 BMC Execute Command rm -f /tmp/flashimg
George Keishing7b64a312017-07-11 12:33:45 -0500100 scp.Put File ${image_file_path} ${targ_file_path}
101
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -0500102 ${file_size} ${stderr} ${rc}= BMC Execute Command
103 ... ls -lh ${targ_file_path}
George Keishing7b64a312017-07-11 12:33:45 -0500104 ${status}= Run Keyword And Return Status
105 ... Should Contain ${file_size} 32.0M msg=Incomplete file transfer.
106 [return] ${status}
George Keishing5e870cd2016-08-24 10:05:47 -0500107
108
George Keishing5e870cd2016-08-24 10:05:47 -0500109Check If File Exist
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500110 [Documentation] Verify that the file exists on this machine.
George Keishing5e870cd2016-08-24 10:05:47 -0500111 [Arguments] ${filepath}
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600112
113 # Description of argument(s):
114 # filepath The path of the file whose existence is to be checked.
115
George Keishing5e870cd2016-08-24 10:05:47 -0500116 Log \n PATH: ${filepath}
117 OperatingSystem.File Should Exist ${filepath}
118 ... msg=${filepath} doesn't exist [ ERROR ]
119
120 Set Global Variable ${FILE_PATH} ${filepath}
121
122
123System Readiness Test
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600124 [Documentation] Verify ping and REST authenticatec for the target
125 ... system.
126
127 ${l_status}= Run Keyword and Return Status
128 ... Verify Ping and REST Authentication
George Keishing5e870cd2016-08-24 10:05:47 -0500129 Run Keyword If '${l_status}' == '${False}'
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600130 ... Fail msg=System not in ideal state to use [ERROR]
George Keishing5e870cd2016-08-24 10:05:47 -0500131
132
George Keishing5e870cd2016-08-24 10:05:47 -0500133Validate BMC Version
George Keishing830211e2017-07-19 08:44:07 -0500134 [Documentation] Get BMC version from /etc/os-release and compare.
135 [Arguments] ${version}
136
137 # Description of argument(s):
138 # version Software version (e.g. "v1.99.8-41-g86a4abc").
139
George Keishing5e870cd2016-08-24 10:05:47 -0500140 Open Connection And Log In
George Keishing830211e2017-07-19 08:44:07 -0500141 ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -0500142 ${output} ${stderr} ${rc}= BMC Execute Command ${cmd}
George Keishing830211e2017-07-19 08:44:07 -0500143 Should Be Equal As Strings ${version} ${output[1:-1]}
George Keishing5e870cd2016-08-24 10:05:47 -0500144
145
146Trigger Warm Reset via Reboot
George Keishing6c0f7152016-10-20 08:27:16 -0500147 [Documentation] Execute reboot command on the remote BMC and
148 ... returns immediately. This keyword "Start Command"
149 ... returns nothing and does not wait for the command
150 ... execution to be finished.
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600151
George Keishing5e870cd2016-08-24 10:05:47 -0500152 Open Connection And Log In
153
George Keishing6c0f7152016-10-20 08:27:16 -0500154 Start Command /sbin/reboot
George Keishing8db0e1b2016-10-20 13:46:54 -0500155
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600156
George Keishing8db0e1b2016-10-20 13:46:54 -0500157Set Policy Setting
158 [Documentation] Set the given test policy
Gunnar Mills38032802016-12-12 13:43:40 -0600159 [Arguments] ${policy}
George Keishing8db0e1b2016-10-20 13:46:54 -0500160
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600161 # Description of argument(s):
162 # policy Policy value to set (e.g. ${RESTORE_LAST_STATE},
163 # ${ALWAYS_POWER_ON}, or ${ALWAYS_POWER_OFF}).
164
165 ${valueDict}= Create Dictionary data=${policy}
166 Write Attribute ${HOST_SETTING} power_policy data=${valueDict}
167 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy
168 Should Be Equal ${currentPolicy} ${policy}