1*** 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 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 17 18*** Keywords *** 19 20Preserve BMC Network Setting 21 [Documentation] Preserve Network setting 22 ${policy}= Set Variable ${1} 23 ${value}= create dictionary data=${policy} 24 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.' 35 @{img_path}= Create List /tmp/flashimg 36 ${data}= create dictionary data=@{img_path} 37 ${resp}= openbmc post request ${BMC_UPD_METHOD} data=${data} 38 should be equal as strings ${resp.status_code} ${HTTP_OK} 39 40 ${data}= Read Properties ${BMC_UPD_ATTR} 41 should be equal as strings ${data["filename"]} /tmp/flashimg 42 should contain ${data['status']} to apply 43 44 45Prepare 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. 49 ${data}= create dictionary data=@{EMPTY} 50 ${resp}= openbmc post request ${BMC_PREP_METHOD} data=${data} 51 should be equal as strings ${resp.status_code} ${HTTP_OK} 52 53 # Update method will reset the BMC, adding delay for reboot to 54 # come into force. 55 Sleep 10s 56 57 58SCP Tar Image File to BMC 59 [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 65 Open Connection for SCP 66 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 87 ${targ_file_path}= Set Variable /tmp/flashimg 88 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 93 Execute Command On BMC rm -f /tmp/flashimg 94 scp.Put File ${image_file_path} ${targ_file_path} 95 96 ${file_size}= Execute Command On BMC ls -lh ${targ_file_path} 97 ${status}= Run Keyword And Return Status 98 ... Should Contain ${file_size} 32.0M msg=Incomplete file transfer. 99 [return] ${status} 100 101 102Check If File Exist 103 [Arguments] ${filepath} 104 Log \n PATH: ${filepath} 105 OperatingSystem.File Should Exist ${filepath} 106 ... msg=${filepath} doesn't exist [ ERROR ] 107 108 Set Global Variable ${FILE_PATH} ${filepath} 109 110 111System Readiness Test 112 ${l_status}= Run Keyword and Return Status 113 ... Verify Ping and REST Authentication 114 Run Keyword If '${l_status}' == '${False}' 115 ... Fail msg=System not in ideal state to use [ERROR] 116 117 118Validate BMC Version 119 [Documentation] Get BMC version from /etc/os-release and compare. 120 [Arguments] ${version} 121 122 # Description of argument(s): 123 # version Software version (e.g. "v1.99.8-41-g86a4abc"). 124 125 Open Connection And Log In 126 ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '=' 127 ${output}= Execute Command On BMC ${cmd} 128 Should Be Equal As Strings ${version} ${output[1:-1]} 129 130 131Trigger Warm Reset via Reboot 132 [Documentation] Execute reboot command on the remote BMC and 133 ... returns immediately. This keyword "Start Command" 134 ... returns nothing and does not wait for the command 135 ... execution to be finished. 136 Open Connection And Log In 137 138 Start Command /sbin/reboot 139 140Set Policy Setting 141 [Documentation] Set the given test policy 142 [Arguments] ${policy} 143 144 ${valueDict}= create dictionary data=${policy} 145 Write Attribute ${HOST_SETTING} power_policy data=${valueDict} 146 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy 147 Should Be Equal ${currentPolicy} ${policy} 148