blob: 3a4df5f3077ac495c437b50cdd1ee52f69755f89 [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
Sushil Singhab209cd2020-07-01 09:01:14 -050082 FOR ${index} IN RANGE 0 4
83 ${status}= Retry SCP ${image_file_path}
84 Exit For Loop If '${status}' == '${True}'
85 END
George Keishing7b64a312017-07-11 12:33:45 -050086
87
88Retry SCP
89 [Documentation] Delete the incomplete file and scp file.
90 [Arguments] ${image_file_path}
Steven Sombar7d0e25d2018-12-12 12:24:14 -060091
George Keishing7b64a312017-07-11 12:33:45 -050092 # Description of argument(s):
93 # image_file_path Downloaded BMC tar file image path.
94
George Keishing1f97fd12017-07-14 14:09:32 -050095 ${targ_file_path}= Set Variable /tmp/flashimg
George Keishing7b64a312017-07-11 12:33:45 -050096
George Keishing7b64a312017-07-11 12:33:45 -050097 # Example output:
98 # root@witherspoon:~# ls -lh /tmp/flashimg
99 # -rwxr-xr-x 1 root root 32.0M Jun 29 01:12 /tmp/flashimg
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -0500100 BMC Execute Command rm -f /tmp/flashimg
George Keishing7b64a312017-07-11 12:33:45 -0500101 scp.Put File ${image_file_path} ${targ_file_path}
102
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -0500103 ${file_size} ${stderr} ${rc}= BMC Execute Command
104 ... ls -lh ${targ_file_path}
George Keishing7b64a312017-07-11 12:33:45 -0500105 ${status}= Run Keyword And Return Status
106 ... Should Contain ${file_size} 32.0M msg=Incomplete file transfer.
107 [return] ${status}
George Keishing5e870cd2016-08-24 10:05:47 -0500108
109
George Keishing5e870cd2016-08-24 10:05:47 -0500110Check If File Exist
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500111 [Documentation] Verify that the file exists on this machine.
George Keishing5e870cd2016-08-24 10:05:47 -0500112 [Arguments] ${filepath}
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600113
114 # Description of argument(s):
115 # filepath The path of the file whose existence is to be checked.
116
George Keishing5e870cd2016-08-24 10:05:47 -0500117 Log \n PATH: ${filepath}
118 OperatingSystem.File Should Exist ${filepath}
119 ... msg=${filepath} doesn't exist [ ERROR ]
120
121 Set Global Variable ${FILE_PATH} ${filepath}
122
123
124System Readiness Test
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600125 [Documentation] Verify ping and REST authenticatec for the target
126 ... system.
127
128 ${l_status}= Run Keyword and Return Status
129 ... Verify Ping and REST Authentication
George Keishing5e870cd2016-08-24 10:05:47 -0500130 Run Keyword If '${l_status}' == '${False}'
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600131 ... Fail msg=System not in ideal state to use [ERROR]
George Keishing5e870cd2016-08-24 10:05:47 -0500132
133
George Keishing5e870cd2016-08-24 10:05:47 -0500134Validate BMC Version
George Keishing830211e2017-07-19 08:44:07 -0500135 [Documentation] Get BMC version from /etc/os-release and compare.
136 [Arguments] ${version}
137
138 # Description of argument(s):
139 # version Software version (e.g. "v1.99.8-41-g86a4abc").
140
George Keishing5e870cd2016-08-24 10:05:47 -0500141 Open Connection And Log In
George Keishing830211e2017-07-19 08:44:07 -0500142 ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -0500143 ${output} ${stderr} ${rc}= BMC Execute Command ${cmd}
George Keishing830211e2017-07-19 08:44:07 -0500144 Should Be Equal As Strings ${version} ${output[1:-1]}
George Keishing5e870cd2016-08-24 10:05:47 -0500145
146
147Trigger Warm Reset via Reboot
George Keishing6c0f7152016-10-20 08:27:16 -0500148 [Documentation] Execute reboot command on the remote BMC and
149 ... returns immediately. This keyword "Start Command"
150 ... returns nothing and does not wait for the command
151 ... execution to be finished.
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600152
George Keishing5e870cd2016-08-24 10:05:47 -0500153 Open Connection And Log In
154
George Keishing6c0f7152016-10-20 08:27:16 -0500155 Start Command /sbin/reboot
George Keishing8db0e1b2016-10-20 13:46:54 -0500156
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600157
George Keishing8db0e1b2016-10-20 13:46:54 -0500158Set Policy Setting
159 [Documentation] Set the given test policy
Gunnar Mills38032802016-12-12 13:43:40 -0600160 [Arguments] ${policy}
George Keishing8db0e1b2016-10-20 13:46:54 -0500161
Steven Sombar7d0e25d2018-12-12 12:24:14 -0600162 # Description of argument(s):
163 # policy Policy value to set (e.g. ${RESTORE_LAST_STATE},
164 # ${ALWAYS_POWER_ON}, or ${ALWAYS_POWER_OFF}).
165
166 ${valueDict}= Create Dictionary data=${policy}
167 Write Attribute ${HOST_SETTING} power_policy data=${valueDict}
168 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy
169 Should Be Equal ${currentPolicy} ${policy}