Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 1 | *** Settings *** |
George Keishing | 4d6c1da | 2016-07-15 05:51:22 -0500 | [diff] [blame] | 2 | Documentation This module is for IPMI client for copying ipmitool to |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 3 | ... openbmc box and execute ipmitool IPMI standard |
| 4 | ... command. IPMI raw command will use dbus-send command |
Sandhya Somashekar | 839a0c2 | 2019-01-31 05:05:43 -0600 | [diff] [blame] | 5 | Resource ../lib/resource.robot |
George Keishing | 4d6c1da | 2016-07-15 05:51:22 -0500 | [diff] [blame] | 6 | Resource ../lib/connection_client.robot |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 7 | Resource ../lib/utils.robot |
| 8 | Resource ../lib/state_manager.robot |
| 9 | |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 10 | Library String |
Michael Walsh | 34c79af | 2019-12-09 11:46:48 -0600 | [diff] [blame] | 11 | Library var_funcs.py |
Michael Walsh | 19621ba | 2018-12-03 17:16:02 -0600 | [diff] [blame] | 12 | Library ipmi_client.py |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 13 | |
| 14 | *** Variables *** |
George Keishing | d7f11f7 | 2017-01-04 10:58:19 -0600 | [diff] [blame] | 15 | ${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1 |
| 16 | ${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 17 | ${netfnByte}= ${EMPTY} |
George Keishing | d7f11f7 | 2017-01-04 10:58:19 -0600 | [diff] [blame] | 18 | ${cmdByte}= ${EMPTY} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 19 | ${arrayByte}= array:byte: |
Michael Walsh | a791389 | 2017-04-20 16:29:01 -0500 | [diff] [blame] | 20 | ${IPMI_USER_OPTIONS} ${EMPTY} |
George Keishing | 75f55dc | 2021-03-29 10:48:09 -0500 | [diff] [blame] | 21 | ${IPMI_INBAND_CMD}= ipmitool -C ${IPMI_CIPHER_LEVEL} -N ${IPMI_TIMEOUT} -p ${IPMI_PORT} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 22 | ${HOST}= -H |
| 23 | ${RAW}= raw |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 24 | |
| 25 | *** Keywords *** |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 26 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 27 | Run IPMI Command |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 28 | [Documentation] Run the raw IPMI command. |
| 29 | [Arguments] ${command} ${fail_on_err}=${1} &{options} |
| 30 | |
| 31 | # Description of argument(s): |
| 32 | # command The IPMI command string to be executed |
| 33 | # (e.g. "power status"). |
| 34 | # fail_on_err Fail if the IPMI command execution fails. |
| 35 | # options Additional ipmitool command options (e.g. |
| 36 | # -C=3, -I=lanplus, etc.). Currently, only |
| 37 | # used for external IPMI commands. |
| 38 | |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 39 | ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External' |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 40 | ... Run External IPMI Raw Command ${command} ${fail_on_err} &{options} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 41 | ... ELSE IF '${IPMI_COMMAND}' == 'Inband' |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 42 | ... Run Inband IPMI Raw Command ${command} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 43 | ... ELSE IF '${IPMI_COMMAND}' == 'Dbus' |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 44 | ... Run Dbus IPMI RAW Command ${command} |
| 45 | ... ELSE Fail msg=Invalid IPMI Command type provided: ${IPMI_COMMAND} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 46 | [Return] ${resp} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 47 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 48 | |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 49 | Run IPMI Standard Command |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 50 | [Documentation] Run the standard IPMI command. |
Michael Walsh | d0e58e7 | 2019-05-14 11:07:14 -0500 | [diff] [blame] | 51 | [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options} |
Rahul Maheshwari | 20f3bf7 | 2018-12-18 04:24:20 -0600 | [diff] [blame] | 52 | |
| 53 | # Description of argument(s): |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 54 | # command The IPMI command string to be executed |
| 55 | # (e.g. "0x06 0x36"). |
| 56 | # fail_on_err Fail if the IPMI command execution fails. |
Michael Walsh | d0e58e7 | 2019-05-14 11:07:14 -0500 | [diff] [blame] | 57 | # expected_rc The expected return code from the ipmi |
| 58 | # command (e.g. ${0}, ${1}, etc.). |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 59 | # options Additional ipmitool command options (e.g. |
| 60 | # -C=3, -I=lanplus, etc.). Currently, only |
| 61 | # used for external IPMI commands. |
Rahul Maheshwari | 20f3bf7 | 2018-12-18 04:24:20 -0600 | [diff] [blame] | 62 | |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 63 | ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External' |
Michael Walsh | d0e58e7 | 2019-05-14 11:07:14 -0500 | [diff] [blame] | 64 | ... Run External IPMI Standard Command ${command} ${fail_on_err} ${expected_rc} &{options} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 65 | ... ELSE IF '${IPMI_COMMAND}' == 'Inband' |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 66 | ... Run Inband IPMI Standard Command ${command} ${fail_on_err} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 67 | ... ELSE IF '${IPMI_COMMAND}' == 'Dbus' |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 68 | ... Run Dbus IPMI Standard Command ${command} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 69 | ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 70 | [Return] ${resp} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 71 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 72 | |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 73 | Run Dbus IPMI RAW Command |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 74 | [Documentation] Run the raw IPMI command through dbus. |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 75 | [Arguments] ${command} |
| 76 | ${valueinBytes}= Byte Conversion ${command} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 77 | ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg} |
| 78 | ${cmd}= Catenate ${cmd} ${valueinBytes} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 79 | ${output} ${stderr}= Execute Command ${cmd} return_stderr=True |
| 80 | Should Be Empty ${stderr} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 81 | set test variable ${OUTPUT} "${output}" |
| 82 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 83 | |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 84 | Run Dbus IPMI Standard Command |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 85 | [Documentation] Run the standard IPMI command through dbus. |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 86 | [Arguments] ${command} |
George Keishing | 4d6c1da | 2016-07-15 05:51:22 -0500 | [diff] [blame] | 87 | Copy ipmitool |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 88 | ${stdout} ${stderr} ${output}= Execute Command |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 89 | ... /tmp/ipmitool -I dbus ${command} return_stdout=True |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 90 | ... return_stderr= True return_rc=True |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 91 | Should Be Equal ${output} ${0} msg=${stderr} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 92 | [Return] ${stdout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 93 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 94 | |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 95 | Run Inband IPMI Raw Command |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 96 | [Documentation] Run the raw IPMI command in-band. |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 97 | [Arguments] ${command} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 98 | ... ${os_password}=${OS_PASSWORD} |
| 99 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 100 | # Description of argument(s): |
| 101 | # command The IPMI command string to be executed |
| 102 | # (e.g. "0x06 0x36"). |
| 103 | # os_host The host name or IP address of the OS Host. |
| 104 | # os_username The OS host user name. |
| 105 | # os_password The OS host passwrd. |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 106 | |
| 107 | Login To OS Host ${os_host} ${os_username} ${os_password} |
| 108 | Check If IPMI Tool Exist |
| 109 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 110 | ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${command} |
| 111 | Qprint Issuing ${ipmi_cmd} |
| 112 | ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 113 | Should Be Empty ${stderr} msg=${stdout} |
| 114 | [Return] ${stdout} |
| 115 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 116 | |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 117 | Run Inband IPMI Standard Command |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 118 | [Documentation] Run the standard IPMI command in-band. |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 119 | [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST} |
Rahul Maheshwari | 20f3bf7 | 2018-12-18 04:24:20 -0600 | [diff] [blame] | 120 | ... ${os_username}=${OS_USERNAME} ${os_password}=${OS_PASSWORD} |
Naman Navin Hegde | 9e8c0d8 | 2019-08-11 15:22:44 -0500 | [diff] [blame] | 121 | ... ${login_host}=${1} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 122 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 123 | # Description of argument(s): |
| 124 | # command The IPMI command string to be executed |
| 125 | # (e.g. "power status"). |
| 126 | # os_host The host name or IP address of the OS Host. |
| 127 | # os_username The OS host user name. |
| 128 | # os_password The OS host passwrd. |
Naman Navin Hegde | 9e8c0d8 | 2019-08-11 15:22:44 -0500 | [diff] [blame] | 129 | # login_host Indicates that this keyword should login to host OS. |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 130 | |
Naman Navin Hegde | 9e8c0d8 | 2019-08-11 15:22:44 -0500 | [diff] [blame] | 131 | Run Keyword If ${login_host} == ${1} |
| 132 | ... Login To OS Host ${os_host} ${os_username} ${os_password} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 133 | Check If IPMI Tool Exist |
| 134 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 135 | ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${command} |
| 136 | Qprint Issuing ${ipmi_cmd} |
| 137 | ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True |
Rahul Maheshwari | 20f3bf7 | 2018-12-18 04:24:20 -0600 | [diff] [blame] | 138 | Return From Keyword If ${fail_on_err} == ${0} ${stderr} |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 139 | Should Be Empty ${stderr} msg=${stdout} |
| 140 | [Return] ${stdout} |
| 141 | |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 142 | |
| 143 | Run External IPMI Standard Command |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 144 | [Documentation] Run the external IPMI standard command. |
Michael Walsh | d0e58e7 | 2019-05-14 11:07:14 -0500 | [diff] [blame] | 145 | [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options} |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 146 | |
| 147 | # Description of argument(s): |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 148 | # command The IPMI command string to be executed |
| 149 | # (e.g. "power status"). Note that if |
| 150 | # ${IPMI_USER_OPTIONS} has a value (e.g. |
| 151 | # "-vvv"), it will be pre-pended to this |
| 152 | # command string. |
| 153 | # fail_on_err Fail if the IPMI command execution fails. |
Michael Walsh | d0e58e7 | 2019-05-14 11:07:14 -0500 | [diff] [blame] | 154 | # expected_rc The expected return code from the ipmi |
| 155 | # command (e.g. ${0}, ${1}, etc.). |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 156 | # options Additional ipmitool command options (e.g. |
| 157 | # -C=3, -I=lanplus, etc.). |
Michael Walsh | a791389 | 2017-04-20 16:29:01 -0500 | [diff] [blame] | 158 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 159 | ${command_string}= Process IPMI User Options ${command} |
| 160 | ${ipmi_cmd}= Create IPMI Ext Command String ${command_string} &{options} |
| 161 | Qprint Issuing ${ipmi_cmd} |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 162 | ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd} |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 163 | Return From Keyword If ${fail_on_err} == ${0} ${output} |
Michael Walsh | d0e58e7 | 2019-05-14 11:07:14 -0500 | [diff] [blame] | 164 | Should Be Equal ${rc} ${expected_rc} msg=${output} |
Michael Walsh | a791389 | 2017-04-20 16:29:01 -0500 | [diff] [blame] | 165 | [Return] ${output} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 166 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 167 | |
| 168 | Run External IPMI Raw Command |
| 169 | [Documentation] Run the external IPMI raw command. |
| 170 | [Arguments] ${command} ${fail_on_err}=${1} &{options} |
| 171 | |
| 172 | # This keyword is a wrapper for 'Run External IPMI Standard Command'. See |
| 173 | # that keyword's prolog for argument details. This keyword will pre-pend |
| 174 | # the word "raw" plus a space to command prior to calling 'Run External |
| 175 | # IPMI Standard Command'. |
| 176 | |
| 177 | ${output}= Run External IPMI Standard Command |
| 178 | ... raw ${command} ${fail_on_err} &{options} |
| 179 | [Return] ${output} |
| 180 | |
| 181 | |
Prashanth Katti | ae7c228 | 2017-03-15 07:43:46 -0500 | [diff] [blame] | 182 | Check If IPMI Tool Exist |
| 183 | [Documentation] Check if IPMI Tool installed or not. |
| 184 | ${output}= Execute Command which ipmitool |
| 185 | Should Not Be Empty ${output} msg=ipmitool not installed. |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 186 | |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 187 | |
| 188 | Activate SOL Via IPMI |
| 189 | [Documentation] Start SOL using IPMI and route output to a file. |
| 190 | [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST} |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 191 | |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 192 | # Description of argument(s): |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 193 | # file_path The file path on the local machine (vs. |
| 194 | # OBMC) to collect SOL output. By default |
| 195 | # SOL output is collected at |
| 196 | # /tmp/sol_<BMC_IP> else user input location. |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 197 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 198 | ${ipmi_cmd}= Create IPMI Ext Command String sol activate usesolkeepalive |
| 199 | Qprint Issuing ${ipmi_cmd} |
George Keishing | 2102f6b | 2017-06-06 08:30:10 -0500 | [diff] [blame] | 200 | Start Process ${ipmi_cmd} shell=True stdout=${file_path} |
Rahul Maheshwari | 4f36084 | 2017-06-06 15:05:01 -0500 | [diff] [blame] | 201 | ... alias=sol_proc |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 202 | |
| 203 | |
| 204 | Deactivate SOL Via IPMI |
| 205 | [Documentation] Stop SOL using IPMI and return SOL output. |
| 206 | [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST} |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 207 | |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 208 | # Description of argument(s): |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 209 | # file_path The file path on the local machine to copy |
| 210 | # SOL output collected by above "Activate |
| 211 | # SOL Via IPMI" keyword. By default it |
| 212 | # copies log from /tmp/sol_<BMC_IP>. |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 213 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 214 | ${ipmi_cmd}= Create IPMI Ext Command String sol deactivate |
| 215 | Qprint Issuing ${ipmi_cmd} |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 216 | ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd} |
Rahul Maheshwari | 4f36084 | 2017-06-06 15:05:01 -0500 | [diff] [blame] | 217 | Run Keyword If ${rc} > 0 Run Keywords |
Rahul Maheshwari | 7f48a2c | 2017-06-16 04:00:26 -0500 | [diff] [blame] | 218 | ... Run Keyword And Ignore Error Terminate Process sol_proc |
| 219 | ... AND Return From Keyword ${output} |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 220 | |
George Keishing | aec8b87 | 2019-07-08 23:44:08 -0500 | [diff] [blame] | 221 | ${output}= OperatingSystem.Get File ${file_path} encoding_errors=ignore |
Rahul Maheshwari | 04a2204 | 2017-05-02 01:54:31 -0500 | [diff] [blame] | 222 | |
| 223 | # Logging SOL output for debug purpose. |
| 224 | Log ${output} |
| 225 | |
| 226 | [Return] ${output} |
| 227 | |
| 228 | |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 229 | Byte Conversion |
| 230 | [Documentation] Byte Conversion method receives IPMI RAW commands as |
| 231 | ... argument in string format. |
| 232 | ... Sample argument is as follows |
| 233 | ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00 |
| 234 | ... 0x00" |
| 235 | ... IPMI RAW command format is as follows |
| 236 | ... <netfn Byte> <cmd Byte> <Data Bytes..> |
| 237 | ... This method converts IPMI command format into |
| 238 | ... dbus command format as follows |
| 239 | ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd> |
| 240 | ... <array:byte:data> |
| 241 | ... Sample dbus Host IPMI Received Message argument |
| 242 | ... byte:0x00 byte:0x04 byte:0x00 byte:0x30 |
| 243 | ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00 |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 244 | [Arguments] ${args} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 245 | ${argLength}= Get Length ${args} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 246 | Set Global Variable ${arrayByte} array:byte: |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 247 | @{listargs}= Split String ${args} |
| 248 | ${index}= Set Variable ${0} |
Marissa Garza | 20ccfc7 | 2020-06-19 12:51:10 -0500 | [diff] [blame] | 249 | FOR ${word} IN @{listargs} |
| 250 | Run Keyword if ${index} == 0 Set NetFn Byte ${word} |
| 251 | Run Keyword if ${index} == 1 Set Cmd Byte ${word} |
| 252 | Run Keyword if ${index} > 1 Set Array Byte ${word} |
| 253 | ${index}= Set Variable ${index + 1} |
| 254 | END |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 255 | ${length}= Get Length ${arrayByte} |
| 256 | ${length}= Evaluate ${length} - 1 |
| 257 | ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 258 | Set Global Variable ${arrayByte} ${arrayByteLocal} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 259 | ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00 |
| 260 | ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte} |
| 261 | ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte} |
| 262 | ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00 |
| 263 | ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte} |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 264 | # To Check scenario for smaller IPMI raw commands with only 2 arguments |
| 265 | # instead of usual 12 arguments. |
| 266 | # Sample small IPMI raw command: Run IPMI command 0x06 0x36 |
| 267 | # If IPMI raw argument length is only 9 then return value in bytes without |
| 268 | # array population. |
| 269 | # Equivalent dbus-send argument for smaller IPMI raw command: |
| 270 | # byte:0x00 byte:0x06 byte:0x00 byte:0x36 |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 271 | Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 272 | [Return] ${valueinBytesWithArray} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 273 | |
| 274 | |
| 275 | Set NetFn Byte |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 276 | [Documentation] Set the network function byte. |
| 277 | [Arguments] ${word} |
| 278 | ${netfnByteLocal}= Catenate byte:${word} |
| 279 | Set Global Variable ${netfnByte} ${netfnByteLocal} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 280 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 281 | |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 282 | Set Cmd Byte |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 283 | [Documentation] Set the command byte. |
| 284 | [Arguments] ${word} |
| 285 | ${cmdByteLocal}= Catenate byte:${word} |
| 286 | Set Global Variable ${cmdByte} ${cmdByteLocal} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 287 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 288 | |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 289 | Set Array Byte |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 290 | [Documentation] Set the array byte. |
| 291 | [Arguments] ${word} |
| 292 | ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word} |
| 293 | ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} , |
| 294 | Set Global Variable ${arrayByte} ${arrayByteLocal} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 295 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 296 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 297 | Copy ipmitool |
Joy Onyerikwu | f4a807b | 2018-06-20 08:43:54 -0500 | [diff] [blame] | 298 | [Documentation] Copy the ipmitool to the BMC. |
| 299 | ${ipmitool_error}= Catenate The ipmitool program could not be found in the tools directory. |
| 300 | ... It is not part of the automation code by default. You must manually copy or link the correct openbmc |
| 301 | ... version of the tool in to the tools directory in order to run this test suite. |
| 302 | |
| 303 | OperatingSystem.File Should Exist tools/ipmitool msg=${ipmitool_error} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 304 | |
| 305 | Import Library SCPLibrary WITH NAME scp |
| 306 | scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD} |
| 307 | scp.Put File tools/ipmitool /tmp |
| 308 | SSHLibrary.Open Connection ${OPENBMC_HOST} |
George Keishing | f94de71 | 2021-11-10 13:59:44 -0600 | [diff] [blame] | 309 | SSHLibrary.Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 310 | Execute Command chmod +x /tmp/ipmitool |
Sridevi Ramesh | 0c34f69 | 2017-04-25 02:40:32 -0500 | [diff] [blame] | 311 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 312 | |
Sridevi Ramesh | 0c34f69 | 2017-04-25 02:40:32 -0500 | [diff] [blame] | 313 | Initiate Host Boot Via External IPMI |
| 314 | [Documentation] Initiate host power on using external IPMI. |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 315 | [Arguments] ${wait}=${1} |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 316 | |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 317 | # Description of argument(s): |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 318 | # wait Indicates that this keyword should wait |
| 319 | # for host running state. |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 320 | |
Sridevi Ramesh | 0c34f69 | 2017-04-25 02:40:32 -0500 | [diff] [blame] | 321 | ${output}= Run External IPMI Standard Command chassis power on |
| 322 | Should Not Contain ${output} Error |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 323 | |
| 324 | Run Keyword If '${wait}' == '${0}' Return From Keyword |
| 325 | Wait Until Keyword Succeeds 10 min 10 sec Is Host Running |
Sridevi Ramesh | 0c34f69 | 2017-04-25 02:40:32 -0500 | [diff] [blame] | 326 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 327 | |
Sridevi Ramesh | 0c34f69 | 2017-04-25 02:40:32 -0500 | [diff] [blame] | 328 | Initiate Host PowerOff Via External IPMI |
| 329 | [Documentation] Initiate host power off using external IPMI. |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 330 | [Arguments] ${wait}=${1} |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 331 | |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 332 | # Description of argument(s): |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 333 | # wait Indicates that this keyword should wait |
| 334 | # for host off state. |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 335 | |
Sridevi Ramesh | 0c34f69 | 2017-04-25 02:40:32 -0500 | [diff] [blame] | 336 | ${output}= Run External IPMI Standard Command chassis power off |
| 337 | Should Not Contain ${output} Error |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 338 | |
| 339 | Run Keyword If '${wait}' == '${0}' Return From Keyword |
| 340 | Wait Until Keyword Succeeds 3 min 10 sec Is Host Off |
| 341 | |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 342 | |
Rahul Maheshwari | 460778d | 2020-02-23 22:37:22 -0600 | [diff] [blame] | 343 | Is Host Off Via IPMI |
| 344 | [Documentation] Verify if the Host is off using IPMI command. |
| 345 | |
| 346 | ${status}= Run External IPMI Standard Command chassis power status |
| 347 | Should Contain ${status} off |
| 348 | |
| 349 | |
Rahul Maheshwari | 982fee4 | 2017-05-03 00:33:15 -0500 | [diff] [blame] | 350 | Get Host State Via External IPMI |
| 351 | [Documentation] Returns host state using external IPMI. |
| 352 | |
| 353 | ${output}= Run External IPMI Standard Command chassis power status |
| 354 | Should Not Contain ${output} Error |
| 355 | ${output}= Fetch From Right ${output} ${SPACE} |
| 356 | |
| 357 | [Return] ${output} |
George Keishing | b4d4a4a | 2018-08-27 13:35:39 -0500 | [diff] [blame] | 358 | |
| 359 | |
| 360 | Set BMC Network From Host |
| 361 | [Documentation] Set BMC network from host. |
| 362 | [Arguments] ${nw_info} |
| 363 | |
| 364 | # Description of argument(s): |
Michael Walsh | 3ef2e92 | 2019-01-23 10:40:16 -0600 | [diff] [blame] | 365 | # nw_info A dictionary containing the network |
| 366 | # information to apply. |
George Keishing | b4d4a4a | 2018-08-27 13:35:39 -0500 | [diff] [blame] | 367 | |
| 368 | Run Inband IPMI Standard Command |
| 369 | ... lan set 1 ipaddr ${nw_info['IP Address']} |
| 370 | |
| 371 | Run Inband IPMI Standard Command |
| 372 | ... lan set 1 netmask ${nw_info['Subnet Mask']} |
| 373 | |
| 374 | Run Inband IPMI Standard Command |
| 375 | ... lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']} |
Rahul Maheshwari | c3d1e96 | 2019-03-06 23:53:21 -0600 | [diff] [blame] | 376 | |
| 377 | |
| 378 | Verify IPMI Username And Password |
| 379 | [Documentation] Verify that user is able to run IPMI command |
| 380 | ... with given username and password. |
| 381 | [Arguments] ${username} ${password} |
| 382 | |
| 383 | # Description of argument(s): |
| 384 | # username The user name (e.g. "root", "robert", etc.). |
| 385 | # password The user password (e.g. "0penBmc", "0penBmc1", etc.). |
| 386 | |
Tony Lee | f9379e8 | 2020-01-08 18:20:38 +0800 | [diff] [blame] | 387 | ${output}= Wait Until Keyword Succeeds 15 sec 5 sec Run External IPMI Standard Command |
Rahul Maheshwari | c3d1e96 | 2019-03-06 23:53:21 -0600 | [diff] [blame] | 388 | ... sel info U=${username} P=${password} |
| 389 | Should Contain ${output} SEL Information msg=SEL information not present |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 390 | |
| 391 | |
| 392 | IPMI Create User |
| 393 | [Documentation] Create IPMI user with given userid and username. |
| 394 | [Arguments] ${userid} ${username} |
| 395 | |
| 396 | # Description of argument(s): |
| 397 | # userid The user ID (e.g. "1", "2", etc.). |
| 398 | # username The user name (e.g. "root", "robert", etc.). |
| 399 | |
| 400 | ${ipmi_cmd}= Catenate user set name ${userid} ${username} |
| 401 | ${resp}= Run IPMI Standard Command ${ipmi_cmd} |
| 402 | ${user_info}= Get User Info ${userid} |
| 403 | Should Be Equal ${user_info['user_name']} ${username} |
| 404 | |
| 405 | |
| 406 | Set Channel Access |
| 407 | [Documentation] Verify that user is able to run IPMI command |
| 408 | ... with given username and password. |
Tony Lee | 7c5f4b2 | 2019-12-06 17:21:31 +0800 | [diff] [blame] | 409 | [Arguments] ${userid} ${options} ${channel_number}=${CHANNEL_NUMBER} |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 410 | |
| 411 | # Description of argument(s): |
| 412 | # userid The user ID (e.g. "1", "2", etc.). |
| 413 | # options Set channel command options (e.g. |
| 414 | # "link=on", "ipmi=on", etc.). |
| 415 | # channel_number The user's channel number (e.g. "1"). |
| 416 | |
| 417 | ${ipmi_cmd}= Catenate SEPARATOR= |
Tony Lee | 7c5f4b2 | 2019-12-06 17:21:31 +0800 | [diff] [blame] | 418 | ... channel setaccess${SPACE}${channel_number}${SPACE}${userid} |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 419 | ... ${SPACE}${options} |
| 420 | Run IPMI Standard Command ${ipmi_cmd} |
Rahul Maheshwari | 3e61ce6 | 2019-06-18 02:09:01 -0500 | [diff] [blame] | 421 | |
| 422 | |
| 423 | Delete All Non Root IPMI User |
| 424 | [Documentation] Delete all non-root IPMI user. |
| 425 | |
Michael Walsh | 34c79af | 2019-12-09 11:46:48 -0600 | [diff] [blame] | 426 | # Get complete list of user info records. |
| 427 | ${user_info}= Get User Info ${EMPTY} |
| 428 | # Remove header record. |
| 429 | ${user_info}= Filter Struct ${user_info} [('user_name', None)] invert=1 |
| 430 | ${non_empty_user_info}= Filter Struct ${user_info} [('user_name', '')] invert=1 |
| 431 | ${non_root_user_info}= Filter Struct ${non_empty_user_info} [('user_name', 'root')] invert=1 |
| 432 | |
| 433 | FOR ${user_record} IN @{non_root_user_info} |
| 434 | Run IPMI Standard Command user set name ${user_record['user_id']} "" |
| 435 | Sleep 5s |
Rahul Maheshwari | 460778d | 2020-02-23 22:37:22 -0600 | [diff] [blame] | 436 | END |