blob: 96f0378cbe5921d60c6a0638528ff0b53ecd6a9e [file] [log] [blame]
George Keishing5e870cd2016-08-24 10:05:47 -05001*** Settings ***
2Documentation Code update utility
3
4Resource ../../lib/rest_client.robot
5Resource ../../lib/connection_client.robot
6Resource ../../lib/utils.robot
7Library OperatingSystem
8
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/
13${BMC_UPD_METHOD} ${ORG_OPENBMC_BASE_URI}control/flash/bmc/action/update
14${BMC_PREP_METHOD} ${ORG_OPENBMC_BASE_URI}control/flash/bmc/action/PrepareForUpdate
15${BMC_UPD_ATTR} ${ORG_OPENBMC_BASE_URI}control/flash/bmc
16${HOST_SETTING} ${ORG_OPENBMC_BASE_URI}settings/host0
George Keishing5e870cd2016-08-24 10:05:47 -050017
18*** Keywords ***
19
20Preserve BMC Network Setting
21 [Documentation] Preserve Network setting
Gunnar Mills597ffa02016-12-06 11:26:53 -060022 ${policy}= Set Variable ${1}
23 ${value}= create dictionary data=${policy}
George Keishing5e870cd2016-08-24 10:05:47 -050024 Write Attribute ${BMC_UPD_ATTR} preserve_network_settings data=${value}
25 ${data}= Read Properties ${BMC_UPD_ATTR}
26 should be equal as strings ${data['preserve_network_settings']} ${1}
27 ... msg=0 indicates network is not preserved
28
29
30Activate BMC flash image
31 [Documentation] Activate and verify the update status
32 ... The status could be either one of these
33 ... 'Deferred for mounted filesystem. reboot BMC to apply.'
34 ... 'Image ready to apply.'
Gunnar Mills597ffa02016-12-06 11:26:53 -060035 @{img_path}= Create List /tmp/flashimg
36 ${data}= create dictionary data=@{img_path}
George Keishing5e870cd2016-08-24 10:05:47 -050037 ${resp}= openbmc post request ${BMC_UPD_METHOD} data=${data}
38 should be equal as strings ${resp.status_code} ${HTTP_OK}
George Keishing5e870cd2016-08-24 10:05:47 -050039
40 ${data}= Read Properties ${BMC_UPD_ATTR}
George Keishing0229cd32016-08-30 08:32:32 -050041 should be equal as strings ${data["filename"]} /tmp/flashimg
George Keishing5e870cd2016-08-24 10:05:47 -050042 should contain ${data['status']} to apply
43
44
George Keishingdc5aa58e92016-09-27 01:35:11 -050045Prepare For Update
46 [Documentation] Switch to update mode in progress. This method calls
47 ... the Abort method to remove the pending update if there
48 ... is any before code activation.
Gunnar Mills597ffa02016-12-06 11:26:53 -060049 ${data}= create dictionary data=@{EMPTY}
George Keishingdc5aa58e92016-09-27 01:35:11 -050050 ${resp}= openbmc post request ${BMC_PREP_METHOD} data=${data}
51 should be equal as strings ${resp.status_code} ${HTTP_OK}
52
George Keishing11319f62017-03-14 13:28:56 -050053 # Update method will reset the BMC, adding delay for reboot to
54 # come into force.
55 Sleep 10s
George Keishingdc5aa58e92016-09-27 01:35:11 -050056
57
George Keishing5e870cd2016-08-24 10:05:47 -050058SCP Tar Image File to BMC
George Keishing7b64a312017-07-11 12:33:45 -050059 [Documentation] Copy BMC tar image to BMC.
60 [Arguments] ${image_file_path}
61 # Description of argument(s):
62 # image_file_path Downloaded BMC tar file image path.
63
64
George Keishing5e870cd2016-08-24 10:05:47 -050065 Open Connection for SCP
George Keishing7b64a312017-07-11 12:33:45 -050066 Open Connection And Log In
67 Loop SCP Retry ${image_file_path}
68
69
70Loop SCP Retry
71 [Documentation] Try transferring the file 4 times.
72 [Arguments] ${image_file_path}
73 # Description of argument(s):
74 # image_file_path Downloaded BMC tar file image path.
75
76 : FOR ${index} IN RANGE 0 4
77 \ ${status}= Retry SCP ${image_file_path}
78 \ Exit For Loop If '${status}' == '${True}'
79
80
81Retry SCP
82 [Documentation] Delete the incomplete file and scp file.
83 [Arguments] ${image_file_path}
84 # Description of argument(s):
85 # image_file_path Downloaded BMC tar file image path.
86
George Keishing1f97fd12017-07-14 14:09:32 -050087 ${targ_file_path}= Set Variable /tmp/flashimg
George Keishing7b64a312017-07-11 12:33:45 -050088
89 # TODO: Need to remove this when new code update in place.
90 # Example output:
91 # root@witherspoon:~# ls -lh /tmp/flashimg
92 # -rwxr-xr-x 1 root root 32.0M Jun 29 01:12 /tmp/flashimg
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -050093 BMC Execute Command rm -f /tmp/flashimg
George Keishing7b64a312017-07-11 12:33:45 -050094 scp.Put File ${image_file_path} ${targ_file_path}
95
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -050096 ${file_size} ${stderr} ${rc}= BMC Execute Command
97 ... ls -lh ${targ_file_path}
George Keishing7b64a312017-07-11 12:33:45 -050098 ${status}= Run Keyword And Return Status
99 ... Should Contain ${file_size} 32.0M msg=Incomplete file transfer.
100 [return] ${status}
George Keishing5e870cd2016-08-24 10:05:47 -0500101
102
George Keishing5e870cd2016-08-24 10:05:47 -0500103Check If File Exist
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500104 [Documentation] Verify that the file exists on this machine.
George Keishing5e870cd2016-08-24 10:05:47 -0500105 [Arguments] ${filepath}
106 Log \n PATH: ${filepath}
107 OperatingSystem.File Should Exist ${filepath}
108 ... msg=${filepath} doesn't exist [ ERROR ]
109
110 Set Global Variable ${FILE_PATH} ${filepath}
111
112
113System Readiness Test
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500114 [Documentation] Verify that the system can be pinged and authenticated through REST.
Gunnar Mills597ffa02016-12-06 11:26:53 -0600115 ${l_status}= Run Keyword and Return Status
George Keishingc4d3dc02016-09-19 03:45:55 -0500116 ... Verify Ping and REST Authentication
George Keishing5e870cd2016-08-24 10:05:47 -0500117 Run Keyword If '${l_status}' == '${False}'
118 ... Fail msg=System not in ideal state to use [ERROR]
119
120
George Keishing5e870cd2016-08-24 10:05:47 -0500121Validate BMC Version
George Keishing830211e2017-07-19 08:44:07 -0500122 [Documentation] Get BMC version from /etc/os-release and compare.
123 [Arguments] ${version}
124
125 # Description of argument(s):
126 # version Software version (e.g. "v1.99.8-41-g86a4abc").
127
George Keishing5e870cd2016-08-24 10:05:47 -0500128 Open Connection And Log In
George Keishing830211e2017-07-19 08:44:07 -0500129 ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
Joy Onyerikwu2ef965a2018-05-24 15:23:27 -0500130 ${output} ${stderr} ${rc}= BMC Execute Command ${cmd}
George Keishing830211e2017-07-19 08:44:07 -0500131 Should Be Equal As Strings ${version} ${output[1:-1]}
George Keishing5e870cd2016-08-24 10:05:47 -0500132
133
134Trigger Warm Reset via Reboot
George Keishing6c0f7152016-10-20 08:27:16 -0500135 [Documentation] Execute reboot command on the remote BMC and
136 ... returns immediately. This keyword "Start Command"
137 ... returns nothing and does not wait for the command
138 ... execution to be finished.
George Keishing5e870cd2016-08-24 10:05:47 -0500139 Open Connection And Log In
140
George Keishing6c0f7152016-10-20 08:27:16 -0500141 Start Command /sbin/reboot
George Keishing8db0e1b2016-10-20 13:46:54 -0500142
143Set Policy Setting
144 [Documentation] Set the given test policy
Gunnar Mills38032802016-12-12 13:43:40 -0600145 [Arguments] ${policy}
George Keishing8db0e1b2016-10-20 13:46:54 -0500146
Gunnar Mills597ffa02016-12-06 11:26:53 -0600147 ${valueDict}= create dictionary data=${policy}
George Keishing8db0e1b2016-10-20 13:46:54 -0500148 Write Attribute ${HOST_SETTING} power_policy data=${valueDict}
149 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy
150 Should Be Equal ${currentPolicy} ${policy}