1b29d2e84SChris Austen*** Settings *** 2b29d2e84SChris AustenDocumentation This module is for IPMI client for copying ipmitool to 3a2dab3c8SSivas SRR... openbmc box and execute ipmitool IPMI standard 4a2dab3c8SSivas SRR... command. IPMI raw command will use dbus-send command 5b29d2e84SChris AustenResource ../lib/resource.txt 64d6c1dabSGeorge KeishingResource ../lib/connection_client.robot 7ae7c2281SPrashanth KattiResource ../lib/utils.robot 8ae7c2281SPrashanth KattiResource ../lib/state_manager.robot 9ae7c2281SPrashanth Katti 10a2dab3c8SSivas SRRLibrary String 11a2dab3c8SSivas SRR 12a2dab3c8SSivas SRR*** Variables *** 13d7f11f70SGeorge Keishing${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1 14d7f11f70SGeorge Keishing${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage 15a2dab3c8SSivas SRR${netfnByte}= ${EMPTY} 16a2dab3c8SSivas SRR${cmdByte}= ${EMPTY} 17a2dab3c8SSivas SRR${arrayByte}= array:byte: 1839967ebcSGeorge Keishing${IPMI_EXT_CMD}= ipmitool -I lanplus -C ${IPMI_CIPHER_LEVEL} 19a7913898SMichael Walsh${IPMI_USER_OPTIONS} ${EMPTY} 2039967ebcSGeorge Keishing${IPMI_INBAND_CMD}= ipmitool -C ${IPMI_CIPHER_LEVEL} 217a212a09SRahul Maheshwari${HOST}= -H 227a212a09SRahul Maheshwari${RAW}= raw 23b29d2e84SChris Austen 24b29d2e84SChris Austen*** Keywords *** 257a212a09SRahul Maheshwari 26b29d2e84SChris AustenRun IPMI Command 27*f4a807bfSJoy Onyerikwu [Documentation] Run the given IPMI command. 2838032805SGunnar Mills [Arguments] ${args} 297a212a09SRahul Maheshwari ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External' 307a212a09SRahul Maheshwari ... Run External IPMI RAW Command ${args} 31ae7c2281SPrashanth Katti ... ELSE IF '${IPMI_COMMAND}' == 'Inband' 32ae7c2281SPrashanth Katti ... Run Inband IPMI RAW Command ${args} 337a212a09SRahul Maheshwari ... ELSE IF '${IPMI_COMMAND}' == 'Dbus' 347a212a09SRahul Maheshwari ... Run Dbus IPMI RAW Command ${args} 35ae7c2281SPrashanth Katti ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND} 36c9ea9368SGunnar Mills [Return] ${resp} 377a212a09SRahul Maheshwari 387a212a09SRahul MaheshwariRun IPMI Standard Command 39*f4a807bfSJoy Onyerikwu [Documentation] Run the standard IPMI command. 4038032805SGunnar Mills [Arguments] ${args} 417a212a09SRahul Maheshwari ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External' 427a212a09SRahul Maheshwari ... Run External IPMI Standard Command ${args} 43ae7c2281SPrashanth Katti ... ELSE IF '${IPMI_COMMAND}' == 'Inband' 44ae7c2281SPrashanth Katti ... Run Inband IPMI Standard Command ${args} 457a212a09SRahul Maheshwari ... ELSE IF '${IPMI_COMMAND}' == 'Dbus' 467a212a09SRahul Maheshwari ... Run Dbus IPMI Standard Command ${args} 47ae7c2281SPrashanth Katti ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND} 487a212a09SRahul Maheshwari 49c9ea9368SGunnar Mills [Return] ${resp} 507a212a09SRahul Maheshwari 517a212a09SRahul MaheshwariRun Dbus IPMI RAW Command 52*f4a807bfSJoy Onyerikwu [Documentation] Run the raw IPMI command through dbus. 5338032805SGunnar Mills [Arguments] ${args} 54a2dab3c8SSivas SRR ${valueinBytes}= Byte Conversion ${args} 55a2dab3c8SSivas SRR ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg} 56a2dab3c8SSivas SRR ${cmd}= Catenate ${cmd} ${valueinBytes} 57a2dab3c8SSivas SRR ${output} ${stderr}= Execute Command ${cmd} return_stderr=True 58b29d2e84SChris Austen Should Be Empty ${stderr} 59b29d2e84SChris Austen set test variable ${OUTPUT} "${output}" 60b29d2e84SChris Austen 617a212a09SRahul MaheshwariRun Dbus IPMI Standard Command 62*f4a807bfSJoy Onyerikwu [Documentation] Run the standard IPMI command through dbus. 6338032805SGunnar Mills [Arguments] ${args} 644d6c1dabSGeorge Keishing Copy ipmitool 657a212a09SRahul Maheshwari ${stdout} ${stderr} ${output}= Execute Command 667a212a09SRahul Maheshwari ... /tmp/ipmitool -I dbus ${args} return_stdout=True 677a212a09SRahul Maheshwari ... return_stderr= True return_rc=True 68b29d2e84SChris Austen Should Be Equal ${output} ${0} msg=${stderr} 69c9ea9368SGunnar Mills [Return] ${stdout} 70b29d2e84SChris Austen 71ae7c2281SPrashanth KattiRun Inband IPMI Raw Command 72*f4a807bfSJoy Onyerikwu [Documentation] Run the raw IPMI command in-band. 73ae7c2281SPrashanth Katti [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 74ae7c2281SPrashanth Katti ... ${os_password}=${OS_PASSWORD} 75ae7c2281SPrashanth Katti 7628e403b8SGunnar Mills # Description of arguments: 77ae7c2281SPrashanth Katti # ${args} parameters to IPMI command. 78ae7c2281SPrashanth Katti # ${os_host} IP address of the OS Host. 79ae7c2281SPrashanth Katti # ${os_username} OS Host Login user name. 80ae7c2281SPrashanth Katti # ${os_password} OS Host Login passwrd. 81ae7c2281SPrashanth Katti 82ae7c2281SPrashanth Katti Login To OS Host ${os_host} ${os_username} ${os_password} 83ae7c2281SPrashanth Katti Check If IPMI Tool Exist 84ae7c2281SPrashanth Katti 85ae7c2281SPrashanth Katti ${inband_raw_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${args} 86ae7c2281SPrashanth Katti ${stdout} ${stderr}= Execute Command ${inband_raw_cmd} return_stderr=True 87ae7c2281SPrashanth Katti Should Be Empty ${stderr} msg=${stdout} 88ae7c2281SPrashanth Katti [Return] ${stdout} 89ae7c2281SPrashanth Katti 90ae7c2281SPrashanth KattiRun Inband IPMI Standard Command 91*f4a807bfSJoy Onyerikwu [Documentation] Run the standard IPMI command in-band. 92ae7c2281SPrashanth Katti [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 93ae7c2281SPrashanth Katti ... ${os_password}=${OS_PASSWORD} 94ae7c2281SPrashanth Katti 9528e403b8SGunnar Mills # Description of arguments: 96ae7c2281SPrashanth Katti # ${args} parameters to IPMI command. 97ae7c2281SPrashanth Katti # ${os_host} IP address of the OS Host. 98ae7c2281SPrashanth Katti # ${os_username} OS Host Login user name. 99ae7c2281SPrashanth Katti # ${os_password} OS Host Login passwrd. 100ae7c2281SPrashanth Katti 101ae7c2281SPrashanth Katti Login To OS Host ${os_host} ${os_username} ${os_password} 102ae7c2281SPrashanth Katti Check If IPMI Tool Exist 103ae7c2281SPrashanth Katti 104ae7c2281SPrashanth Katti ${inband_std_cmd}= Catenate ${IPMI_INBAND_CMD} ${args} 105ae7c2281SPrashanth Katti ${stdout} ${stderr}= Execute Command ${inband_std_cmd} return_stderr=True 106ae7c2281SPrashanth Katti Should Be Empty ${stderr} msg=${stdout} 107ae7c2281SPrashanth Katti [Return] ${stdout} 108ae7c2281SPrashanth Katti 1097a212a09SRahul MaheshwariRun External IPMI RAW Command 110*f4a807bfSJoy Onyerikwu [Documentation] Run the raw IPMI command externally. 11138032805SGunnar Mills [Arguments] ${args} 1127a212a09SRahul Maheshwari ${ipmi_raw_cmd}= Catenate SEPARATOR= 113a7913898SMichael Walsh ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE} 1147a212a09SRahul Maheshwari ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${RAW}${SPACE}${args} 1157a212a09SRahul Maheshwari ${rc} ${output}= Run and Return RC and Output ${ipmi_raw_cmd} 1167a212a09SRahul Maheshwari Should Be Equal ${rc} ${0} msg=${output} 117c9ea9368SGunnar Mills [Return] ${output} 1187a212a09SRahul Maheshwari 1197a212a09SRahul MaheshwariRun External IPMI Standard Command 120*f4a807bfSJoy Onyerikwu [Documentation] Run the standard IPMI command in-band. 12102651f0cSGeorge Keishing [Arguments] ${args} ${fail_on_err}=${1} 12202651f0cSGeorge Keishing 12302651f0cSGeorge Keishing # Description of argument(s): 12402651f0cSGeorge Keishing # args IPMI command to be executed. 12502651f0cSGeorge Keishing # fail_on_err Fail if keyword the IPMI command fails 126a7913898SMichael Walsh 1277a212a09SRahul Maheshwari ${ipmi_cmd}= Catenate SEPARATOR= 128a7913898SMichael Walsh ... ${IPMI_EXT_CMD} ${IPMI_USER_OPTIONS} -P${SPACE}${IPMI_PASSWORD} 129a7913898SMichael Walsh ... ${SPACE}${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${args} 13004a2204bSRahul Maheshwari ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd} 13102651f0cSGeorge Keishing Return From Keyword If ${fail_on_err} == ${0} ${output} 1327a212a09SRahul Maheshwari Should Be Equal ${rc} ${0} msg=${output} 133c9ea9368SGunnar Mills [Return] ${output} 1347a212a09SRahul Maheshwari 135ae7c2281SPrashanth KattiCheck If IPMI Tool Exist 136ae7c2281SPrashanth Katti [Documentation] Check if IPMI Tool installed or not. 137ae7c2281SPrashanth Katti ${output}= Execute Command which ipmitool 138ae7c2281SPrashanth Katti Should Not Be Empty ${output} msg=ipmitool not installed. 1397a212a09SRahul Maheshwari 14004a2204bSRahul Maheshwari 14104a2204bSRahul MaheshwariActivate SOL Via IPMI 14204a2204bSRahul Maheshwari [Documentation] Start SOL using IPMI and route output to a file. 14304a2204bSRahul Maheshwari [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST} 14404a2204bSRahul Maheshwari # Description of argument(s): 14504a2204bSRahul Maheshwari # file_path The file path on the local machine (vs OBMC) to collect SOL 14604a2204bSRahul Maheshwari # output. By default SOL output is collected at 14704a2204bSRahul Maheshwari # /tmp/sol_<BMC_IP> else user input location. 14804a2204bSRahul Maheshwari 14904a2204bSRahul Maheshwari ${ipmi_cmd}= Catenate SEPARATOR= 150c8470881SRahul Maheshwari ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}${HOST} 151c8470881SRahul Maheshwari ... ${SPACE}${OPENBMC_HOST}${SPACE}sol activate usesolkeepalive 15204a2204bSRahul Maheshwari 1532102f6bfSGeorge Keishing Start Process ${ipmi_cmd} shell=True stdout=${file_path} 1544f360843SRahul Maheshwari ... alias=sol_proc 15504a2204bSRahul Maheshwari 15604a2204bSRahul Maheshwari 15704a2204bSRahul MaheshwariDeactivate SOL Via IPMI 15804a2204bSRahul Maheshwari [Documentation] Stop SOL using IPMI and return SOL output. 15904a2204bSRahul Maheshwari [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST} 16004a2204bSRahul Maheshwari # Description of argument(s): 16104a2204bSRahul Maheshwari # file_path The file path on the local machine to copy SOL output 16204a2204bSRahul Maheshwari # collected by above "Activate SOL Via IPMI" keyword. 16304a2204bSRahul Maheshwari # By default it copies log from /tmp/sol_<BMC_IP>. 16404a2204bSRahul Maheshwari 16504a2204bSRahul Maheshwari ${ipmi_cmd}= Catenate SEPARATOR= 16604a2204bSRahul Maheshwari ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE} 16704a2204bSRahul Maheshwari ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}sol deactivate 16804a2204bSRahul Maheshwari 16904a2204bSRahul Maheshwari ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd} 1704f360843SRahul Maheshwari Run Keyword If ${rc} > 0 Run Keywords 1717f48a2c6SRahul Maheshwari ... Run Keyword And Ignore Error Terminate Process sol_proc 1727f48a2c6SRahul Maheshwari ... AND Return From Keyword ${output} 17304a2204bSRahul Maheshwari 17404a2204bSRahul Maheshwari ${rc} ${output}= Run and Return RC and Output cat ${file_path} 17504a2204bSRahul Maheshwari Should Be Equal ${rc} ${0} msg=${output} 17604a2204bSRahul Maheshwari 17704a2204bSRahul Maheshwari # Logging SOL output for debug purpose. 17804a2204bSRahul Maheshwari Log ${output} 17904a2204bSRahul Maheshwari 18004a2204bSRahul Maheshwari [Return] ${output} 18104a2204bSRahul Maheshwari 18204a2204bSRahul Maheshwari 183a2dab3c8SSivas SRRByte Conversion 184a2dab3c8SSivas SRR [Documentation] Byte Conversion method receives IPMI RAW commands as 185a2dab3c8SSivas SRR ... argument in string format. 186a2dab3c8SSivas SRR ... Sample argument is as follows 187a2dab3c8SSivas SRR ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00 188a2dab3c8SSivas SRR ... 0x00" 189a2dab3c8SSivas SRR ... IPMI RAW command format is as follows 190a2dab3c8SSivas SRR ... <netfn Byte> <cmd Byte> <Data Bytes..> 191a2dab3c8SSivas SRR ... This method converts IPMI command format into 192a2dab3c8SSivas SRR ... dbus command format as follows 193a2dab3c8SSivas SRR ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd> 194a2dab3c8SSivas SRR ... <array:byte:data> 195a2dab3c8SSivas SRR ... Sample dbus Host IPMI Received Message argument 196a2dab3c8SSivas SRR ... byte:0x00 byte:0x04 byte:0x00 byte:0x30 197a2dab3c8SSivas SRR ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00 19838032805SGunnar Mills [Arguments] ${args} 199a2dab3c8SSivas SRR ${argLength}= Get Length ${args} 200a2dab3c8SSivas SRR Set Global Variable ${arrayByte} array:byte: 201a2dab3c8SSivas SRR @{listargs}= Split String ${args} 202a2dab3c8SSivas SRR ${index}= Set Variable ${0} 203a2dab3c8SSivas SRR :FOR ${word} in @{listargs} 204a2dab3c8SSivas SRR \ Run Keyword if ${index} == 0 Set NetFn Byte ${word} 205a2dab3c8SSivas SRR \ Run Keyword if ${index} == 1 Set Cmd Byte ${word} 206a2dab3c8SSivas SRR \ Run Keyword if ${index} > 1 Set Array Byte ${word} 207a2dab3c8SSivas SRR \ ${index}= Set Variable ${index + 1} 208a2dab3c8SSivas SRR ${length}= Get Length ${arrayByte} 209a2dab3c8SSivas SRR ${length}= Evaluate ${length} - 1 210a2dab3c8SSivas SRR ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length} 211a2dab3c8SSivas SRR Set Global Variable ${arrayByte} ${arrayByteLocal} 212a2dab3c8SSivas SRR ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00 213a2dab3c8SSivas SRR ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte} 214a2dab3c8SSivas SRR ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte} 215a2dab3c8SSivas SRR ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00 216a2dab3c8SSivas SRR ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte} 217a2dab3c8SSivas SRR# To Check scenario for smaller IPMI raw commands with only 2 arguments 218a2dab3c8SSivas SRR# instead of usual 12 arguments. 219a2dab3c8SSivas SRR# Sample small IPMI raw command: Run IPMI command 0x06 0x36 220a2dab3c8SSivas SRR# If IPMI raw argument length is only 9 then return value in bytes without 221a2dab3c8SSivas SRR# array population. 222a2dab3c8SSivas SRR# Equivalent dbus-send argument for smaller IPMI raw command: 223a2dab3c8SSivas SRR# byte:0x00 byte:0x06 byte:0x00 byte:0x36 224a2dab3c8SSivas SRR Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray} 225c9ea9368SGunnar Mills [Return] ${valueinBytesWithArray} 226a2dab3c8SSivas SRR 227a2dab3c8SSivas SRR 228a2dab3c8SSivas SRRSet NetFn Byte 229*f4a807bfSJoy Onyerikwu [Documentation] Set the network function byte. 23038032805SGunnar Mills [Arguments] ${word} 231a2dab3c8SSivas SRR ${netfnByteLocal}= Catenate byte:${word} 232a2dab3c8SSivas SRR Set Global Variable ${netfnByte} ${netfnByteLocal} 233a2dab3c8SSivas SRR 234a2dab3c8SSivas SRRSet Cmd Byte 235*f4a807bfSJoy Onyerikwu [Documentation] Set the command byte. 23638032805SGunnar Mills [Arguments] ${word} 237a2dab3c8SSivas SRR ${cmdByteLocal}= Catenate byte:${word} 238a2dab3c8SSivas SRR Set Global Variable ${cmdByte} ${cmdByteLocal} 239a2dab3c8SSivas SRR 240a2dab3c8SSivas SRRSet Array Byte 241*f4a807bfSJoy Onyerikwu [Documentation] Set the array byte. 24238032805SGunnar Mills [Arguments] ${word} 243a2dab3c8SSivas SRR ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word} 244a2dab3c8SSivas SRR ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} , 245a2dab3c8SSivas SRR Set Global Variable ${arrayByte} ${arrayByteLocal} 246a2dab3c8SSivas SRR 247b29d2e84SChris AustenCopy ipmitool 248*f4a807bfSJoy Onyerikwu [Documentation] Copy the ipmitool to the BMC. 249*f4a807bfSJoy Onyerikwu ${ipmitool_error}= Catenate The ipmitool program could not be found in the tools directory. 250*f4a807bfSJoy Onyerikwu ... It is not part of the automation code by default. You must manually copy or link the correct openbmc 251*f4a807bfSJoy Onyerikwu ... version of the tool in to the tools directory in order to run this test suite. 252*f4a807bfSJoy Onyerikwu 253*f4a807bfSJoy Onyerikwu OperatingSystem.File Should Exist tools/ipmitool msg=${ipmitool_error} 254b29d2e84SChris Austen 255b29d2e84SChris Austen Import Library SCPLibrary WITH NAME scp 256b29d2e84SChris Austen scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD} 257b29d2e84SChris Austen scp.Put File tools/ipmitool /tmp 258b29d2e84SChris Austen SSHLibrary.Open Connection ${OPENBMC_HOST} 259b29d2e84SChris Austen Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} 260b29d2e84SChris Austen Execute Command chmod +x /tmp/ipmitool 2610c34f69cSSridevi Ramesh 2620c34f69cSSridevi RameshInitiate Host Boot Via External IPMI 2630c34f69cSSridevi Ramesh [Documentation] Initiate host power on using external IPMI. 264982fee42SRahul Maheshwari [Arguments] ${wait}=${1} 265982fee42SRahul Maheshwari # Description of argument(s): 266982fee42SRahul Maheshwari # wait Indicates that this keyword should wait for host running state. 267982fee42SRahul Maheshwari 2680c34f69cSSridevi Ramesh ${output}= Run External IPMI Standard Command chassis power on 2690c34f69cSSridevi Ramesh Should Not Contain ${output} Error 270982fee42SRahul Maheshwari 271982fee42SRahul Maheshwari Run Keyword If '${wait}' == '${0}' Return From Keyword 272982fee42SRahul Maheshwari Wait Until Keyword Succeeds 10 min 10 sec Is Host Running 2730c34f69cSSridevi Ramesh 2740c34f69cSSridevi RameshInitiate Host PowerOff Via External IPMI 2750c34f69cSSridevi Ramesh [Documentation] Initiate host power off using external IPMI. 276982fee42SRahul Maheshwari [Arguments] ${wait}=${1} 277982fee42SRahul Maheshwari # Description of argument(s): 278982fee42SRahul Maheshwari # wait Indicates that this keyword should wait for host off state. 279982fee42SRahul Maheshwari 2800c34f69cSSridevi Ramesh ${output}= Run External IPMI Standard Command chassis power off 2810c34f69cSSridevi Ramesh Should Not Contain ${output} Error 282982fee42SRahul Maheshwari 283982fee42SRahul Maheshwari Run Keyword If '${wait}' == '${0}' Return From Keyword 284982fee42SRahul Maheshwari Wait Until Keyword Succeeds 3 min 10 sec Is Host Off 285982fee42SRahul Maheshwari 286982fee42SRahul MaheshwariGet Host State Via External IPMI 287982fee42SRahul Maheshwari [Documentation] Returns host state using external IPMI. 288982fee42SRahul Maheshwari 289982fee42SRahul Maheshwari ${output}= Run External IPMI Standard Command chassis power status 290982fee42SRahul Maheshwari Should Not Contain ${output} Error 291982fee42SRahul Maheshwari ${output}= Fetch From Right ${output} ${SPACE} 292982fee42SRahul Maheshwari 293982fee42SRahul Maheshwari [Return] ${output} 294