George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Code update utility |
| 3 | |
| 4 | Resource ../../lib/rest_client.robot |
| 5 | Resource ../../lib/connection_client.robot |
| 6 | Resource ../../lib/utils.robot |
| 7 | Library OperatingSystem |
| 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/ |
| 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 Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 17 | |
| 18 | *** Keywords *** |
| 19 | |
| 20 | Preserve BMC Network Setting |
| 21 | [Documentation] Preserve Network setting |
Gunnar Mills | 597ffa0 | 2016-12-06 11:26:53 -0600 | [diff] [blame] | 22 | ${policy}= Set Variable ${1} |
| 23 | ${value}= create dictionary data=${policy} |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 24 | Write Attribute ${BMC_UPD_ATTR} preserve_network_settings data=${value} |
| 25 | ${data}= Read Properties ${BMC_UPD_ATTR} |
Michael Walsh | 6662d18 | 2018-09-11 11:32:53 -0500 | [diff] [blame] | 26 | Should Be Equal As Strings ${data['preserve_network_settings']} ${True} |
| 27 | ... msg=False indicates network is not preserved. |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 28 | |
| 29 | |
| 30 | Activate 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 Mills | 597ffa0 | 2016-12-06 11:26:53 -0600 | [diff] [blame] | 35 | @{img_path}= Create List /tmp/flashimg |
| 36 | ${data}= create dictionary data=@{img_path} |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 37 | ${resp}= openbmc post request ${BMC_UPD_METHOD} data=${data} |
| 38 | should be equal as strings ${resp.status_code} ${HTTP_OK} |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 39 | |
| 40 | ${data}= Read Properties ${BMC_UPD_ATTR} |
George Keishing | 0229cd3 | 2016-08-30 08:32:32 -0500 | [diff] [blame] | 41 | should be equal as strings ${data["filename"]} /tmp/flashimg |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 42 | should contain ${data['status']} to apply |
| 43 | |
| 44 | |
George Keishing | dc5aa58e9 | 2016-09-27 01:35:11 -0500 | [diff] [blame] | 45 | Prepare 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. |
George Keishing | 268099f | 2018-10-05 13:16:27 -0500 | [diff] [blame] | 49 | ${data}= Create Dictionary data=@{EMPTY} |
| 50 | ${resp}= Openbmc Post Request ${BMC_PREP_METHOD} data=${data} |
George Keishing | dc5aa58e9 | 2016-09-27 01:35:11 -0500 | [diff] [blame] | 51 | |
George Keishing | 11319f6 | 2017-03-14 13:28:56 -0500 | [diff] [blame] | 52 | # Update method will reset the BMC, adding delay for reboot to |
| 53 | # come into force. |
| 54 | Sleep 10s |
George Keishing | dc5aa58e9 | 2016-09-27 01:35:11 -0500 | [diff] [blame] | 55 | |
| 56 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 57 | SCP Tar Image File to BMC |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 58 | [Documentation] Copy BMC tar image to BMC. |
| 59 | [Arguments] ${image_file_path} |
| 60 | # Description of argument(s): |
| 61 | # image_file_path Downloaded BMC tar file image path. |
| 62 | |
| 63 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 64 | Open Connection for SCP |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 65 | Open Connection And Log In |
| 66 | Loop SCP Retry ${image_file_path} |
| 67 | |
| 68 | |
| 69 | Loop SCP Retry |
| 70 | [Documentation] Try transferring the file 4 times. |
| 71 | [Arguments] ${image_file_path} |
| 72 | # Description of argument(s): |
| 73 | # image_file_path Downloaded BMC tar file image path. |
| 74 | |
| 75 | : FOR ${index} IN RANGE 0 4 |
| 76 | \ ${status}= Retry SCP ${image_file_path} |
| 77 | \ Exit For Loop If '${status}' == '${True}' |
| 78 | |
| 79 | |
| 80 | Retry SCP |
| 81 | [Documentation] Delete the incomplete file and scp file. |
| 82 | [Arguments] ${image_file_path} |
| 83 | # Description of argument(s): |
| 84 | # image_file_path Downloaded BMC tar file image path. |
| 85 | |
George Keishing | 1f97fd1 | 2017-07-14 14:09:32 -0500 | [diff] [blame] | 86 | ${targ_file_path}= Set Variable /tmp/flashimg |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 87 | |
| 88 | # TODO: Need to remove this when new code update in place. |
| 89 | # Example output: |
| 90 | # root@witherspoon:~# ls -lh /tmp/flashimg |
| 91 | # -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] | 92 | BMC Execute Command rm -f /tmp/flashimg |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 93 | scp.Put File ${image_file_path} ${targ_file_path} |
| 94 | |
Joy Onyerikwu | 2ef965a | 2018-05-24 15:23:27 -0500 | [diff] [blame] | 95 | ${file_size} ${stderr} ${rc}= BMC Execute Command |
| 96 | ... ls -lh ${targ_file_path} |
George Keishing | 7b64a31 | 2017-07-11 12:33:45 -0500 | [diff] [blame] | 97 | ${status}= Run Keyword And Return Status |
| 98 | ... Should Contain ${file_size} 32.0M msg=Incomplete file transfer. |
| 99 | [return] ${status} |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 100 | |
| 101 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 102 | Check If File Exist |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 103 | [Documentation] Verify that the file exists on this machine. |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 104 | [Arguments] ${filepath} |
| 105 | Log \n PATH: ${filepath} |
| 106 | OperatingSystem.File Should Exist ${filepath} |
| 107 | ... msg=${filepath} doesn't exist [ ERROR ] |
| 108 | |
| 109 | Set Global Variable ${FILE_PATH} ${filepath} |
| 110 | |
| 111 | |
| 112 | System Readiness Test |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 113 | [Documentation] Verify that the system can be pinged and authenticated through REST. |
Gunnar Mills | 597ffa0 | 2016-12-06 11:26:53 -0600 | [diff] [blame] | 114 | ${l_status}= Run Keyword and Return Status |
George Keishing | c4d3dc0 | 2016-09-19 03:45:55 -0500 | [diff] [blame] | 115 | ... Verify Ping and REST Authentication |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 116 | Run Keyword If '${l_status}' == '${False}' |
| 117 | ... Fail msg=System not in ideal state to use [ERROR] |
| 118 | |
| 119 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 120 | Validate BMC Version |
George Keishing | 830211e | 2017-07-19 08:44:07 -0500 | [diff] [blame] | 121 | [Documentation] Get BMC version from /etc/os-release and compare. |
| 122 | [Arguments] ${version} |
| 123 | |
| 124 | # Description of argument(s): |
| 125 | # version Software version (e.g. "v1.99.8-41-g86a4abc"). |
| 126 | |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 127 | Open Connection And Log In |
George Keishing | 830211e | 2017-07-19 08:44:07 -0500 | [diff] [blame] | 128 | ${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] | 129 | ${output} ${stderr} ${rc}= BMC Execute Command ${cmd} |
George Keishing | 830211e | 2017-07-19 08:44:07 -0500 | [diff] [blame] | 130 | Should Be Equal As Strings ${version} ${output[1:-1]} |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 131 | |
| 132 | |
| 133 | Trigger Warm Reset via Reboot |
George Keishing | 6c0f715 | 2016-10-20 08:27:16 -0500 | [diff] [blame] | 134 | [Documentation] Execute reboot command on the remote BMC and |
| 135 | ... returns immediately. This keyword "Start Command" |
| 136 | ... returns nothing and does not wait for the command |
| 137 | ... execution to be finished. |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 138 | Open Connection And Log In |
| 139 | |
George Keishing | 6c0f715 | 2016-10-20 08:27:16 -0500 | [diff] [blame] | 140 | Start Command /sbin/reboot |
George Keishing | 8db0e1b | 2016-10-20 13:46:54 -0500 | [diff] [blame] | 141 | |
| 142 | Set Policy Setting |
| 143 | [Documentation] Set the given test policy |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 144 | [Arguments] ${policy} |
George Keishing | 8db0e1b | 2016-10-20 13:46:54 -0500 | [diff] [blame] | 145 | |
Gunnar Mills | 597ffa0 | 2016-12-06 11:26:53 -0600 | [diff] [blame] | 146 | ${valueDict}= create dictionary data=${policy} |
George Keishing | 8db0e1b | 2016-10-20 13:46:54 -0500 | [diff] [blame] | 147 | Write Attribute ${HOST_SETTING} power_policy data=${valueDict} |
| 148 | ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy |
| 149 | Should Be Equal ${currentPolicy} ${policy} |