George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Code update utility |
| 3 | |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 4 | Resource ../../lib/rest_client.robot |
| 5 | Resource ../../lib/connection_client.robot |
| 6 | Resource ../../lib/utils.robot |
| 7 | Library OperatingSystem |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 8 | |
| 9 | *** Variables *** |
| 10 | |
George Keishing | f26367c | 2017-10-24 04:59:59 -0500 | [diff] [blame] | 11 | # Fix old org path locally for non-witherspoon system. |
| 12 | ${ORG_OPENBMC_BASE_URI} /org/openbmc/ |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 13 | ${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 Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 18 | |
| 19 | *** Keywords *** |
| 20 | |
| 21 | Preserve BMC Network Setting |
| 22 | [Documentation] Preserve Network setting |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 23 | |
| 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 Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 31 | |
| 32 | |
Michael Walsh | 317878a | 2018-12-11 12:59:19 -0600 | [diff] [blame] | 33 | Activate BMC Flash Image |
| 34 | [Documentation] Activate and verify the update status. |
| 35 | ... The status could be either one of these: |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 36 | ... 'Deferred for mounted filesystem. reboot BMC to apply.' |
| 37 | ... 'Image ready to apply.' |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 38 | |
Michael Walsh | 317878a | 2018-12-11 12:59:19 -0600 | [diff] [blame] | 39 | @{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 Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 44 | |
Michael Walsh | 317878a | 2018-12-11 12:59:19 -0600 | [diff] [blame] | 45 | ${data}= Read Properties ${BMC_UPD_ATTR} |
| 46 | Should Be Equal As Strings ${data["filename"]} /tmp/flashimg |
| 47 | Should Contain ${data['status']} to apply |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 48 | |
| 49 | |
George Keishing | dc5aa58e9 | 2016-09-27 01:35:11 -0500 | [diff] [blame] | 50 | Prepare 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 Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 54 | |
George Keishing | 268099f | 2018-10-05 13:16:27 -0500 | [diff] [blame] | 55 | ${data}= Create Dictionary data=@{EMPTY} |
| 56 | ${resp}= Openbmc Post Request ${BMC_PREP_METHOD} data=${data} |
George Keishing | dc5aa58e9 | 2016-09-27 01:35:11 -0500 | [diff] [blame] | 57 | |
George Keishing | 11319f6 | 2017-03-14 13:28:56 -0500 | [diff] [blame] | 58 | # Update method will reset the BMC, adding delay for reboot to |
| 59 | # come into force. |
| 60 | Sleep 10s |
George Keishing | dc5aa58e9 | 2016-09-27 01:35:11 -0500 | [diff] [blame] | 61 | |
| 62 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 63 | SCP Tar Image File to BMC |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 64 | [Documentation] Copy BMC tar image to BMC. |
| 65 | [Arguments] ${image_file_path} |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 66 | |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 67 | # Description of argument(s): |
| 68 | # image_file_path Downloaded BMC tar file image path. |
| 69 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 70 | Open Connection for SCP |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 71 | Open Connection And Log In |
| 72 | Loop SCP Retry ${image_file_path} |
| 73 | |
| 74 | |
| 75 | Loop SCP Retry |
| 76 | [Documentation] Try transferring the file 4 times. |
| 77 | [Arguments] ${image_file_path} |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 78 | |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 79 | # 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 | |
| 87 | Retry SCP |
| 88 | [Documentation] Delete the incomplete file and scp file. |
| 89 | [Arguments] ${image_file_path} |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 90 | |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 91 | # Description of argument(s): |
| 92 | # image_file_path Downloaded BMC tar file image path. |
| 93 | |
George Keishing | 1f97fd1 | 2017-07-14 14:09:32 -0500 | [diff] [blame] | 94 | ${targ_file_path}= Set Variable /tmp/flashimg |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 95 | |
| 96 | # TODO: Need to remove this when new code update in place. |
| 97 | # 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 Onyerikwu | 2ef965a | 2018-05-24 15:23:27 -0500 | [diff] [blame] | 100 | BMC Execute Command rm -f /tmp/flashimg |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 101 | scp.Put File ${image_file_path} ${targ_file_path} |
| 102 | |
Joy Onyerikwu | 2ef965a | 2018-05-24 15:23:27 -0500 | [diff] [blame] | 103 | ${file_size} ${stderr} ${rc}= BMC Execute Command |
| 104 | ... ls -lh ${targ_file_path} |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 105 | ${status}= Run Keyword And Return Status |
| 106 | ... Should Contain ${file_size} 32.0M msg=Incomplete file transfer. |
| 107 | [return] ${status} |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 108 | |
| 109 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 110 | Check If File Exist |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 111 | [Documentation] Verify that the file exists on this machine. |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 112 | [Arguments] ${filepath} |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 113 | |
| 114 | # Description of argument(s): |
| 115 | # filepath The path of the file whose existence is to be checked. |
| 116 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 117 | 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 | |
| 124 | System Readiness Test |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 125 | [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 Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 130 | Run Keyword If '${l_status}' == '${False}' |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 131 | ... Fail msg=System not in ideal state to use [ERROR] |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 132 | |
| 133 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 134 | Validate BMC Version |
George Keishing | 830211e | 2017-07-19 08:44:07 -0500 | [diff] [blame] | 135 | [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 Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 141 | Open Connection And Log In |
George Keishing | 830211e | 2017-07-19 08:44:07 -0500 | [diff] [blame] | 142 | ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '=' |
Joy Onyerikwu | 2ef965a | 2018-05-24 15:23:27 -0500 | [diff] [blame] | 143 | ${output} ${stderr} ${rc}= BMC Execute Command ${cmd} |
George Keishing | 830211e | 2017-07-19 08:44:07 -0500 | [diff] [blame] | 144 | Should Be Equal As Strings ${version} ${output[1:-1]} |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 145 | |
| 146 | |
| 147 | Trigger Warm Reset via Reboot |
George Keishing | 6c0f715 | 2016-10-20 08:27:16 -0500 | [diff] [blame] | 148 | [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 Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 152 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 153 | Open Connection And Log In |
| 154 | |
George Keishing | 6c0f715 | 2016-10-20 08:27:16 -0500 | [diff] [blame] | 155 | Start Command /sbin/reboot |
George Keishing | 8db0e1b | 2016-10-20 13:46:54 -0500 | [diff] [blame] | 156 | |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 157 | |
George Keishing | 8db0e1b | 2016-10-20 13:46:54 -0500 | [diff] [blame] | 158 | Set Policy Setting |
| 159 | [Documentation] Set the given test policy |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 160 | [Arguments] ${policy} |
George Keishing | 8db0e1b | 2016-10-20 13:46:54 -0500 | [diff] [blame] | 161 | |
Steven Sombar | 7d0e25d | 2018-12-12 12:24:14 -0600 | [diff] [blame^] | 162 | # 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} |