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 5839a0c27SSandhya SomashekarResource ../lib/resource.robot 64d6c1dabSGeorge KeishingResource ../lib/connection_client.robot 7ae7c2281SPrashanth KattiResource ../lib/utils.robot 8ae7c2281SPrashanth KattiResource ../lib/state_manager.robot 9ae7c2281SPrashanth Katti 10a2dab3c8SSivas SRRLibrary String 1134c79af0SMichael WalshLibrary var_funcs.py 1219621bacSMichael WalshLibrary ipmi_client.py 13b9a29a6bSleetLibrary ../lib/bmc_ssh_utils.py 14a2dab3c8SSivas SRR 15a2dab3c8SSivas SRR*** Variables *** 16d7f11f70SGeorge Keishing${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1 17d7f11f70SGeorge Keishing${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage 18a2dab3c8SSivas SRR${netfnByte}= ${EMPTY} 19a2dab3c8SSivas SRR${cmdByte}= ${EMPTY} 20a2dab3c8SSivas SRR${arrayByte}= array:byte: 21a7913898SMichael Walsh${IPMI_USER_OPTIONS} ${EMPTY} 2275f55dc7SGeorge Keishing${IPMI_INBAND_CMD}= ipmitool -C ${IPMI_CIPHER_LEVEL} -N ${IPMI_TIMEOUT} -p ${IPMI_PORT} 237a212a09SRahul Maheshwari${HOST}= -H 247a212a09SRahul Maheshwari${RAW}= raw 25b9a29a6bSleet${IPMITOOL_PATH} /tmp/ipmitool 26b29d2e84SChris Austen 27b29d2e84SChris Austen*** Keywords *** 287a212a09SRahul Maheshwari 29b29d2e84SChris AustenRun IPMI Command 303ef2e92cSMichael Walsh [Documentation] Run the raw IPMI command. 313ef2e92cSMichael Walsh [Arguments] ${command} ${fail_on_err}=${1} &{options} 323ef2e92cSMichael Walsh 333ef2e92cSMichael Walsh # Description of argument(s): 343ef2e92cSMichael Walsh # command The IPMI command string to be executed 353ef2e92cSMichael Walsh # (e.g. "power status"). 363ef2e92cSMichael Walsh # fail_on_err Fail if the IPMI command execution fails. 373ef2e92cSMichael Walsh # options Additional ipmitool command options (e.g. 383ef2e92cSMichael Walsh # -C=3, -I=lanplus, etc.). Currently, only 393ef2e92cSMichael Walsh # used for external IPMI commands. 403ef2e92cSMichael Walsh 417a212a09SRahul Maheshwari ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External' 423ef2e92cSMichael Walsh ... Run External IPMI Raw Command ${command} ${fail_on_err} &{options} 43ae7c2281SPrashanth Katti ... ELSE IF '${IPMI_COMMAND}' == 'Inband' 443ef2e92cSMichael Walsh ... Run Inband IPMI Raw Command ${command} 457a212a09SRahul Maheshwari ... ELSE IF '${IPMI_COMMAND}' == 'Dbus' 463ef2e92cSMichael Walsh ... Run Dbus IPMI RAW Command ${command} 47ae7c2281SPrashanth Katti ... ELSE Fail msg=Invalid IPMI Command type provided: ${IPMI_COMMAND} 48c9ea9368SGunnar Mills [Return] ${resp} 497a212a09SRahul Maheshwari 503ef2e92cSMichael Walsh 517a212a09SRahul MaheshwariRun IPMI Standard Command 52f4a807bfSJoy Onyerikwu [Documentation] Run the standard IPMI command. 53d0e58e73SMichael Walsh [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options} 5420f3bf73SRahul Maheshwari 5520f3bf73SRahul Maheshwari # Description of argument(s): 563ef2e92cSMichael Walsh # command The IPMI command string to be executed 573ef2e92cSMichael Walsh # (e.g. "0x06 0x36"). 583ef2e92cSMichael Walsh # fail_on_err Fail if the IPMI command execution fails. 59d0e58e73SMichael Walsh # expected_rc The expected return code from the ipmi 60d0e58e73SMichael Walsh # command (e.g. ${0}, ${1}, etc.). 613ef2e92cSMichael Walsh # options Additional ipmitool command options (e.g. 623ef2e92cSMichael Walsh # -C=3, -I=lanplus, etc.). Currently, only 633ef2e92cSMichael Walsh # used for external IPMI commands. 6420f3bf73SRahul Maheshwari 657a212a09SRahul Maheshwari ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External' 66d0e58e73SMichael Walsh ... Run External IPMI Standard Command ${command} ${fail_on_err} ${expected_rc} &{options} 67ae7c2281SPrashanth Katti ... ELSE IF '${IPMI_COMMAND}' == 'Inband' 683ef2e92cSMichael Walsh ... Run Inband IPMI Standard Command ${command} ${fail_on_err} 697a212a09SRahul Maheshwari ... ELSE IF '${IPMI_COMMAND}' == 'Dbus' 703ef2e92cSMichael Walsh ... Run Dbus IPMI Standard Command ${command} 71ae7c2281SPrashanth Katti ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND} 72c9ea9368SGunnar Mills [Return] ${resp} 737a212a09SRahul Maheshwari 743ef2e92cSMichael Walsh 757a212a09SRahul MaheshwariRun Dbus IPMI RAW Command 76f4a807bfSJoy Onyerikwu [Documentation] Run the raw IPMI command through dbus. 773ef2e92cSMichael Walsh [Arguments] ${command} 783ef2e92cSMichael Walsh ${valueinBytes}= Byte Conversion ${command} 79a2dab3c8SSivas SRR ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg} 80a2dab3c8SSivas SRR ${cmd}= Catenate ${cmd} ${valueinBytes} 81a2dab3c8SSivas SRR ${output} ${stderr}= Execute Command ${cmd} return_stderr=True 82b29d2e84SChris Austen Should Be Empty ${stderr} 83b29d2e84SChris Austen set test variable ${OUTPUT} "${output}" 84b29d2e84SChris Austen 853ef2e92cSMichael Walsh 867a212a09SRahul MaheshwariRun Dbus IPMI Standard Command 87f4a807bfSJoy Onyerikwu [Documentation] Run the standard IPMI command through dbus. 883ef2e92cSMichael Walsh [Arguments] ${command} 894d6c1dabSGeorge Keishing Copy ipmitool 907a212a09SRahul Maheshwari ${stdout} ${stderr} ${output}= Execute Command 91b9a29a6bSleet ... ${IPMITOOL_PATH} -I dbus ${command} return_stdout=True 927a212a09SRahul Maheshwari ... return_stderr= True return_rc=True 93b29d2e84SChris Austen Should Be Equal ${output} ${0} msg=${stderr} 94c9ea9368SGunnar Mills [Return] ${stdout} 95b29d2e84SChris Austen 963ef2e92cSMichael Walsh 97ae7c2281SPrashanth KattiRun Inband IPMI Raw Command 98f4a807bfSJoy Onyerikwu [Documentation] Run the raw IPMI command in-band. 994ad123acSchithrag [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 100ae7c2281SPrashanth Katti ... ${os_password}=${OS_PASSWORD} 101ae7c2281SPrashanth Katti 1023ef2e92cSMichael Walsh # Description of argument(s): 1033ef2e92cSMichael Walsh # command The IPMI command string to be executed 1043ef2e92cSMichael Walsh # (e.g. "0x06 0x36"). 1053ef2e92cSMichael Walsh # os_host The host name or IP address of the OS Host. 1063ef2e92cSMichael Walsh # os_username The OS host user name. 1073ef2e92cSMichael Walsh # os_password The OS host passwrd. 108ae7c2281SPrashanth Katti 109ae7c2281SPrashanth Katti Login To OS Host ${os_host} ${os_username} ${os_password} 110ae7c2281SPrashanth Katti Check If IPMI Tool Exist 111ae7c2281SPrashanth Katti 1123ef2e92cSMichael Walsh ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${command} 1133ef2e92cSMichael Walsh Qprint Issuing ${ipmi_cmd} 1143ef2e92cSMichael Walsh ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True 1154ad123acSchithrag Return From Keyword If ${fail_on_err} == ${0} ${stderr} 116ae7c2281SPrashanth Katti Should Be Empty ${stderr} msg=${stdout} 117ae7c2281SPrashanth Katti [Return] ${stdout} 118ae7c2281SPrashanth Katti 1193ef2e92cSMichael Walsh 120ae7c2281SPrashanth KattiRun Inband IPMI Standard Command 121f4a807bfSJoy Onyerikwu [Documentation] Run the standard IPMI command in-band. 1223ef2e92cSMichael Walsh [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST} 12320f3bf73SRahul Maheshwari ... ${os_username}=${OS_USERNAME} ${os_password}=${OS_PASSWORD} 1249e8c0d88SNaman Navin Hegde ... ${login_host}=${1} 125ae7c2281SPrashanth Katti 1263ef2e92cSMichael Walsh # Description of argument(s): 1273ef2e92cSMichael Walsh # command The IPMI command string to be executed 1283ef2e92cSMichael Walsh # (e.g. "power status"). 1293ef2e92cSMichael Walsh # os_host The host name or IP address of the OS Host. 1303ef2e92cSMichael Walsh # os_username The OS host user name. 1313ef2e92cSMichael Walsh # os_password The OS host passwrd. 1329e8c0d88SNaman Navin Hegde # login_host Indicates that this keyword should login to host OS. 133ae7c2281SPrashanth Katti 1349e8c0d88SNaman Navin Hegde Run Keyword If ${login_host} == ${1} 1359e8c0d88SNaman Navin Hegde ... Login To OS Host ${os_host} ${os_username} ${os_password} 136ae7c2281SPrashanth Katti Check If IPMI Tool Exist 137ae7c2281SPrashanth Katti 1383ef2e92cSMichael Walsh ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${command} 1393ef2e92cSMichael Walsh Qprint Issuing ${ipmi_cmd} 1403ef2e92cSMichael Walsh ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True 14120f3bf73SRahul Maheshwari Return From Keyword If ${fail_on_err} == ${0} ${stderr} 142ae7c2281SPrashanth Katti Should Be Empty ${stderr} msg=${stdout} 143ae7c2281SPrashanth Katti [Return] ${stdout} 144ae7c2281SPrashanth Katti 1457a212a09SRahul Maheshwari 1467a212a09SRahul MaheshwariRun External IPMI Standard Command 1473ef2e92cSMichael Walsh [Documentation] Run the external IPMI standard command. 148d0e58e73SMichael Walsh [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options} 14902651f0cSGeorge Keishing 15002651f0cSGeorge Keishing # Description of argument(s): 1513ef2e92cSMichael Walsh # command The IPMI command string to be executed 1523ef2e92cSMichael Walsh # (e.g. "power status"). Note that if 1533ef2e92cSMichael Walsh # ${IPMI_USER_OPTIONS} has a value (e.g. 1543ef2e92cSMichael Walsh # "-vvv"), it will be pre-pended to this 1553ef2e92cSMichael Walsh # command string. 1563ef2e92cSMichael Walsh # fail_on_err Fail if the IPMI command execution fails. 157d0e58e73SMichael Walsh # expected_rc The expected return code from the ipmi 158d0e58e73SMichael Walsh # command (e.g. ${0}, ${1}, etc.). 1593ef2e92cSMichael Walsh # options Additional ipmitool command options (e.g. 1603ef2e92cSMichael Walsh # -C=3, -I=lanplus, etc.). 161a7913898SMichael Walsh 1623ef2e92cSMichael Walsh ${command_string}= Process IPMI User Options ${command} 1633ef2e92cSMichael Walsh ${ipmi_cmd}= Create IPMI Ext Command String ${command_string} &{options} 1643ef2e92cSMichael Walsh Qprint Issuing ${ipmi_cmd} 16504a2204bSRahul Maheshwari ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd} 16602651f0cSGeorge Keishing Return From Keyword If ${fail_on_err} == ${0} ${output} 167d0e58e73SMichael Walsh Should Be Equal ${rc} ${expected_rc} msg=${output} 168c9ea9368SGunnar Mills [Return] ${output} 1697a212a09SRahul Maheshwari 1703ef2e92cSMichael Walsh 1713ef2e92cSMichael WalshRun External IPMI Raw Command 1723ef2e92cSMichael Walsh [Documentation] Run the external IPMI raw command. 1733ef2e92cSMichael Walsh [Arguments] ${command} ${fail_on_err}=${1} &{options} 1743ef2e92cSMichael Walsh 1753ef2e92cSMichael Walsh # This keyword is a wrapper for 'Run External IPMI Standard Command'. See 1763ef2e92cSMichael Walsh # that keyword's prolog for argument details. This keyword will pre-pend 1773ef2e92cSMichael Walsh # the word "raw" plus a space to command prior to calling 'Run External 1783ef2e92cSMichael Walsh # IPMI Standard Command'. 1793ef2e92cSMichael Walsh 1803ef2e92cSMichael Walsh ${output}= Run External IPMI Standard Command 1813ef2e92cSMichael Walsh ... raw ${command} ${fail_on_err} &{options} 1823ef2e92cSMichael Walsh [Return] ${output} 1833ef2e92cSMichael Walsh 1843ef2e92cSMichael Walsh 185ae7c2281SPrashanth KattiCheck If IPMI Tool Exist 186ae7c2281SPrashanth Katti [Documentation] Check if IPMI Tool installed or not. 187ae7c2281SPrashanth Katti ${output}= Execute Command which ipmitool 188ae7c2281SPrashanth Katti Should Not Be Empty ${output} msg=ipmitool not installed. 1897a212a09SRahul Maheshwari 19004a2204bSRahul Maheshwari 19104a2204bSRahul MaheshwariActivate SOL Via IPMI 19204a2204bSRahul Maheshwari [Documentation] Start SOL using IPMI and route output to a file. 19326206721SGeorge Keishing [Arguments] ${file_path}=${IPMI_SOL_LOG_FILE} 1943ef2e92cSMichael Walsh 19504a2204bSRahul Maheshwari # Description of argument(s): 1963ef2e92cSMichael Walsh # file_path The file path on the local machine (vs. 1973ef2e92cSMichael Walsh # OBMC) to collect SOL output. By default 1983ef2e92cSMichael Walsh # SOL output is collected at 19926206721SGeorge Keishing # logs/sol_<BMC_IP> else user input location. 20004a2204bSRahul Maheshwari 2013ef2e92cSMichael Walsh ${ipmi_cmd}= Create IPMI Ext Command String sol activate usesolkeepalive 2023ef2e92cSMichael Walsh Qprint Issuing ${ipmi_cmd} 2032102f6bfSGeorge Keishing Start Process ${ipmi_cmd} shell=True stdout=${file_path} 2044f360843SRahul Maheshwari ... alias=sol_proc 20504a2204bSRahul Maheshwari 20604a2204bSRahul Maheshwari 20704a2204bSRahul MaheshwariDeactivate SOL Via IPMI 20804a2204bSRahul Maheshwari [Documentation] Stop SOL using IPMI and return SOL output. 20926206721SGeorge Keishing [Arguments] ${file_path}=${IPMI_SOL_LOG_FILE} 2103ef2e92cSMichael Walsh 21104a2204bSRahul Maheshwari # Description of argument(s): 2123ef2e92cSMichael Walsh # file_path The file path on the local machine to copy 2133ef2e92cSMichael Walsh # SOL output collected by above "Activate 2143ef2e92cSMichael Walsh # SOL Via IPMI" keyword. By default it 21526206721SGeorge Keishing # copies log from logs/sol_<BMC_IP>. 21604a2204bSRahul Maheshwari 2173ef2e92cSMichael Walsh ${ipmi_cmd}= Create IPMI Ext Command String sol deactivate 2183ef2e92cSMichael Walsh Qprint Issuing ${ipmi_cmd} 21904a2204bSRahul Maheshwari ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd} 2204f360843SRahul Maheshwari Run Keyword If ${rc} > 0 Run Keywords 2217f48a2c6SRahul Maheshwari ... Run Keyword And Ignore Error Terminate Process sol_proc 2227f48a2c6SRahul Maheshwari ... AND Return From Keyword ${output} 22304a2204bSRahul Maheshwari 224aec8b879SGeorge Keishing ${output}= OperatingSystem.Get File ${file_path} encoding_errors=ignore 22504a2204bSRahul Maheshwari 22604a2204bSRahul Maheshwari # Logging SOL output for debug purpose. 22704a2204bSRahul Maheshwari Log ${output} 22804a2204bSRahul Maheshwari 22904a2204bSRahul Maheshwari [Return] ${output} 23004a2204bSRahul Maheshwari 23104a2204bSRahul Maheshwari 232a2dab3c8SSivas SRRByte Conversion 233a2dab3c8SSivas SRR [Documentation] Byte Conversion method receives IPMI RAW commands as 234a2dab3c8SSivas SRR ... argument in string format. 235a2dab3c8SSivas SRR ... Sample argument is as follows 236a2dab3c8SSivas SRR ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00 237a2dab3c8SSivas SRR ... 0x00" 238a2dab3c8SSivas SRR ... IPMI RAW command format is as follows 239a2dab3c8SSivas SRR ... <netfn Byte> <cmd Byte> <Data Bytes..> 240a2dab3c8SSivas SRR ... This method converts IPMI command format into 241a2dab3c8SSivas SRR ... dbus command format as follows 242a2dab3c8SSivas SRR ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd> 243a2dab3c8SSivas SRR ... <array:byte:data> 244a2dab3c8SSivas SRR ... Sample dbus Host IPMI Received Message argument 245a2dab3c8SSivas SRR ... byte:0x00 byte:0x04 byte:0x00 byte:0x30 246a2dab3c8SSivas SRR ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00 24738032805SGunnar Mills [Arguments] ${args} 248a2dab3c8SSivas SRR ${argLength}= Get Length ${args} 249a2dab3c8SSivas SRR Set Global Variable ${arrayByte} array:byte: 250a2dab3c8SSivas SRR @{listargs}= Split String ${args} 251a2dab3c8SSivas SRR ${index}= Set Variable ${0} 25220ccfc71SMarissa Garza FOR ${word} IN @{listargs} 25320ccfc71SMarissa Garza Run Keyword if ${index} == 0 Set NetFn Byte ${word} 25420ccfc71SMarissa Garza Run Keyword if ${index} == 1 Set Cmd Byte ${word} 25520ccfc71SMarissa Garza Run Keyword if ${index} > 1 Set Array Byte ${word} 25620ccfc71SMarissa Garza ${index}= Set Variable ${index + 1} 25720ccfc71SMarissa Garza END 258a2dab3c8SSivas SRR ${length}= Get Length ${arrayByte} 259a2dab3c8SSivas SRR ${length}= Evaluate ${length} - 1 260a2dab3c8SSivas SRR ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length} 261a2dab3c8SSivas SRR Set Global Variable ${arrayByte} ${arrayByteLocal} 262a2dab3c8SSivas SRR ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00 263a2dab3c8SSivas SRR ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte} 264a2dab3c8SSivas SRR ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte} 265a2dab3c8SSivas SRR ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00 266a2dab3c8SSivas SRR ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte} 267a2dab3c8SSivas SRR # To Check scenario for smaller IPMI raw commands with only 2 arguments 268a2dab3c8SSivas SRR # instead of usual 12 arguments. 269a2dab3c8SSivas SRR # Sample small IPMI raw command: Run IPMI command 0x06 0x36 270a2dab3c8SSivas SRR # If IPMI raw argument length is only 9 then return value in bytes without 271a2dab3c8SSivas SRR # array population. 272a2dab3c8SSivas SRR # Equivalent dbus-send argument for smaller IPMI raw command: 273a2dab3c8SSivas SRR # byte:0x00 byte:0x06 byte:0x00 byte:0x36 274a2dab3c8SSivas SRR Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray} 275c9ea9368SGunnar Mills [Return] ${valueinBytesWithArray} 276a2dab3c8SSivas SRR 277a2dab3c8SSivas SRR 278a2dab3c8SSivas SRRSet NetFn Byte 279f4a807bfSJoy Onyerikwu [Documentation] Set the network function byte. 28038032805SGunnar Mills [Arguments] ${word} 281a2dab3c8SSivas SRR ${netfnByteLocal}= Catenate byte:${word} 282a2dab3c8SSivas SRR Set Global Variable ${netfnByte} ${netfnByteLocal} 283a2dab3c8SSivas SRR 2843ef2e92cSMichael Walsh 285a2dab3c8SSivas SRRSet Cmd Byte 286f4a807bfSJoy Onyerikwu [Documentation] Set the command byte. 28738032805SGunnar Mills [Arguments] ${word} 288a2dab3c8SSivas SRR ${cmdByteLocal}= Catenate byte:${word} 289a2dab3c8SSivas SRR Set Global Variable ${cmdByte} ${cmdByteLocal} 290a2dab3c8SSivas SRR 2913ef2e92cSMichael Walsh 292a2dab3c8SSivas SRRSet Array Byte 293f4a807bfSJoy Onyerikwu [Documentation] Set the array byte. 29438032805SGunnar Mills [Arguments] ${word} 295a2dab3c8SSivas SRR ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word} 296a2dab3c8SSivas SRR ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} , 297a2dab3c8SSivas SRR Set Global Variable ${arrayByte} ${arrayByteLocal} 298a2dab3c8SSivas SRR 2993ef2e92cSMichael Walsh 300b29d2e84SChris AustenCopy ipmitool 301f4a807bfSJoy Onyerikwu [Documentation] Copy the ipmitool to the BMC. 302f4a807bfSJoy Onyerikwu ${ipmitool_error}= Catenate The ipmitool program could not be found in the tools directory. 303f4a807bfSJoy Onyerikwu ... It is not part of the automation code by default. You must manually copy or link the correct openbmc 304f4a807bfSJoy Onyerikwu ... version of the tool in to the tools directory in order to run this test suite. 305f4a807bfSJoy Onyerikwu 306b9a29a6bSleet ${response} ${stderr} ${rc}= BMC Execute Command 307b9a29a6bSleet ... which ipmitool ignore_err=${1} 308b9a29a6bSleet ${installed}= Get Regexp Matches ${response} ipmitool 309b9a29a6bSleet Run Keyword If ${installed} == ['ipmitool'] 310b9a29a6bSleet ... Run Keywords Set Suite Variable ${IPMITOOL_PATH} ${response} 311b9a29a6bSleet ... AND SSHLibrary.Open Connection ${OPENBMC_HOST} 312b9a29a6bSleet ... AND SSHLibrary.Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} 313b9a29a6bSleet ... AND Return From Keyword 314b29d2e84SChris Austen 315b9a29a6bSleet OperatingSystem.File Should Exist tools/ipmitool msg=${ipmitool_error} 316b29d2e84SChris Austen Import Library SCPLibrary WITH NAME scp 317b29d2e84SChris Austen scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD} 318b29d2e84SChris Austen scp.Put File tools/ipmitool /tmp 319b29d2e84SChris Austen SSHLibrary.Open Connection ${OPENBMC_HOST} 320f94de719SGeorge Keishing SSHLibrary.Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} 321b9a29a6bSleet Execute Command chmod +x ${IPMITOOL_PATH} 3220c34f69cSSridevi Ramesh 3233ef2e92cSMichael Walsh 3240c34f69cSSridevi RameshInitiate Host Boot Via External IPMI 3250c34f69cSSridevi Ramesh [Documentation] Initiate host power on using external IPMI. 326982fee42SRahul Maheshwari [Arguments] ${wait}=${1} 3273ef2e92cSMichael Walsh 328982fee42SRahul Maheshwari # Description of argument(s): 3293ef2e92cSMichael Walsh # wait Indicates that this keyword should wait 3303ef2e92cSMichael Walsh # for host running state. 331982fee42SRahul Maheshwari 3320c34f69cSSridevi Ramesh ${output}= Run External IPMI Standard Command chassis power on 3330c34f69cSSridevi Ramesh Should Not Contain ${output} Error 334982fee42SRahul Maheshwari 335982fee42SRahul Maheshwari Run Keyword If '${wait}' == '${0}' Return From Keyword 336982fee42SRahul Maheshwari Wait Until Keyword Succeeds 10 min 10 sec Is Host Running 3370c34f69cSSridevi Ramesh 3383ef2e92cSMichael Walsh 3390c34f69cSSridevi RameshInitiate Host PowerOff Via External IPMI 3400c34f69cSSridevi Ramesh [Documentation] Initiate host power off using external IPMI. 341982fee42SRahul Maheshwari [Arguments] ${wait}=${1} 3423ef2e92cSMichael Walsh 343982fee42SRahul Maheshwari # Description of argument(s): 3443ef2e92cSMichael Walsh # wait Indicates that this keyword should wait 3453ef2e92cSMichael Walsh # for host off state. 346982fee42SRahul Maheshwari 3470c34f69cSSridevi Ramesh ${output}= Run External IPMI Standard Command chassis power off 3480c34f69cSSridevi Ramesh Should Not Contain ${output} Error 349982fee42SRahul Maheshwari 350982fee42SRahul Maheshwari Run Keyword If '${wait}' == '${0}' Return From Keyword 351982fee42SRahul Maheshwari Wait Until Keyword Succeeds 3 min 10 sec Is Host Off 352982fee42SRahul Maheshwari 3533ef2e92cSMichael Walsh 354460778dcSRahul MaheshwariIs Host Off Via IPMI 355460778dcSRahul Maheshwari [Documentation] Verify if the Host is off using IPMI command. 356460778dcSRahul Maheshwari 357460778dcSRahul Maheshwari ${status}= Run External IPMI Standard Command chassis power status 358460778dcSRahul Maheshwari Should Contain ${status} off 359460778dcSRahul Maheshwari 360460778dcSRahul Maheshwari 361982fee42SRahul MaheshwariGet Host State Via External IPMI 362982fee42SRahul Maheshwari [Documentation] Returns host state using external IPMI. 363982fee42SRahul Maheshwari 364982fee42SRahul Maheshwari ${output}= Run External IPMI Standard Command chassis power status 365982fee42SRahul Maheshwari Should Not Contain ${output} Error 366982fee42SRahul Maheshwari ${output}= Fetch From Right ${output} ${SPACE} 367982fee42SRahul Maheshwari 368982fee42SRahul Maheshwari [Return] ${output} 369b4d4a4aeSGeorge Keishing 370b4d4a4aeSGeorge Keishing 371b4d4a4aeSGeorge KeishingSet BMC Network From Host 372b4d4a4aeSGeorge Keishing [Documentation] Set BMC network from host. 373b4d4a4aeSGeorge Keishing [Arguments] ${nw_info} 374b4d4a4aeSGeorge Keishing 375b4d4a4aeSGeorge Keishing # Description of argument(s): 3763ef2e92cSMichael Walsh # nw_info A dictionary containing the network 3773ef2e92cSMichael Walsh # information to apply. 378b4d4a4aeSGeorge Keishing 379b4d4a4aeSGeorge Keishing Run Inband IPMI Standard Command 380b4d4a4aeSGeorge Keishing ... lan set 1 ipaddr ${nw_info['IP Address']} 381b4d4a4aeSGeorge Keishing 382b4d4a4aeSGeorge Keishing Run Inband IPMI Standard Command 383b4d4a4aeSGeorge Keishing ... lan set 1 netmask ${nw_info['Subnet Mask']} 384b4d4a4aeSGeorge Keishing 385b4d4a4aeSGeorge Keishing Run Inband IPMI Standard Command 386b4d4a4aeSGeorge Keishing ... lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']} 387c3d1e968SRahul Maheshwari 388c3d1e968SRahul Maheshwari 389c3d1e968SRahul MaheshwariVerify IPMI Username And Password 390c3d1e968SRahul Maheshwari [Documentation] Verify that user is able to run IPMI command 391c3d1e968SRahul Maheshwari ... with given username and password. 392c3d1e968SRahul Maheshwari [Arguments] ${username} ${password} 393c3d1e968SRahul Maheshwari 394c3d1e968SRahul Maheshwari # Description of argument(s): 395c3d1e968SRahul Maheshwari # username The user name (e.g. "root", "robert", etc.). 396*7ac1f56fSGeorge Keishing # password The user password. 397c3d1e968SRahul Maheshwari 398f9379e88STony Lee ${output}= Wait Until Keyword Succeeds 15 sec 5 sec Run External IPMI Standard Command 399c3d1e968SRahul Maheshwari ... sel info U=${username} P=${password} 400c3d1e968SRahul Maheshwari Should Contain ${output} SEL Information msg=SEL information not present 40175e91feaSRahul Maheshwari 40275e91feaSRahul Maheshwari 40375e91feaSRahul MaheshwariIPMI Create User 40475e91feaSRahul Maheshwari [Documentation] Create IPMI user with given userid and username. 40575e91feaSRahul Maheshwari [Arguments] ${userid} ${username} 40675e91feaSRahul Maheshwari 40775e91feaSRahul Maheshwari # Description of argument(s): 40875e91feaSRahul Maheshwari # userid The user ID (e.g. "1", "2", etc.). 40975e91feaSRahul Maheshwari # username The user name (e.g. "root", "robert", etc.). 41075e91feaSRahul Maheshwari 41175e91feaSRahul Maheshwari ${ipmi_cmd}= Catenate user set name ${userid} ${username} 41275e91feaSRahul Maheshwari ${resp}= Run IPMI Standard Command ${ipmi_cmd} 41326499145SNagarjun B ${user_info}= Get User Info ${userid} ${CHANNEL_NUMBER} 41475e91feaSRahul Maheshwari Should Be Equal ${user_info['user_name']} ${username} 41575e91feaSRahul Maheshwari 41675e91feaSRahul Maheshwari 417a2255de5Snagarjunb22Enable IPMI User And Verify 418a2255de5Snagarjunb22 [Documentation] Enable the userid and verify that it has been enabled. 419a2255de5Snagarjunb22 [Arguments] ${userid} 420a2255de5Snagarjunb22 421a2255de5Snagarjunb22 # Description of argument(s): 422a2255de5Snagarjunb22 # userid A numeric userid (e.g. "4"). 423a2255de5Snagarjunb22 424a2255de5Snagarjunb22 Run IPMI Standard Command user enable ${userid} 42526499145SNagarjun B ${user_info}= Get User Info ${userid} ${CHANNEL_NUMBER} 426a2255de5Snagarjunb22 Valid Value user_info['enable_status'] ['enabled'] 427a2255de5Snagarjunb22 428a2255de5Snagarjunb22 429a2255de5Snagarjunb22Create Random IPMI User 430a2255de5Snagarjunb22 [Documentation] Create IPMI user with random username and userid and return those fields. 431a2255de5Snagarjunb22 432a2255de5Snagarjunb22 ${random_username}= Generate Random String 8 [LETTERS] 433a2255de5Snagarjunb22 ${random_userid}= Evaluate random.randint(2, 15) modules=random 434a2255de5Snagarjunb22 IPMI Create User ${random_userid} ${random_username} 435a2255de5Snagarjunb22 [Return] ${random_userid} ${random_username} 436a2255de5Snagarjunb22 437a2255de5Snagarjunb22 438a2255de5Snagarjunb22Delete Created User 439a2255de5Snagarjunb22 [Documentation] Delete created IPMI user. 440a2255de5Snagarjunb22 [Arguments] ${userid} 441a2255de5Snagarjunb22 # Description of argument(s): 442a2255de5Snagarjunb22 # userid The user ID (e.g. "1", "2", etc.). 443a2255de5Snagarjunb22 444a2255de5Snagarjunb22 Run IPMI Standard Command user set name ${userid} "" 445a2255de5Snagarjunb22 Sleep 5s 446a2255de5Snagarjunb22 447a2255de5Snagarjunb22 44875e91feaSRahul MaheshwariSet Channel Access 44975e91feaSRahul Maheshwari [Documentation] Verify that user is able to run IPMI command 45075e91feaSRahul Maheshwari ... with given username and password. 4517c5f4b28STony Lee [Arguments] ${userid} ${options} ${channel_number}=${CHANNEL_NUMBER} 45275e91feaSRahul Maheshwari 45375e91feaSRahul Maheshwari # Description of argument(s): 45475e91feaSRahul Maheshwari # userid The user ID (e.g. "1", "2", etc.). 45575e91feaSRahul Maheshwari # options Set channel command options (e.g. 45675e91feaSRahul Maheshwari # "link=on", "ipmi=on", etc.). 45775e91feaSRahul Maheshwari # channel_number The user's channel number (e.g. "1"). 45875e91feaSRahul Maheshwari 45975e91feaSRahul Maheshwari ${ipmi_cmd}= Catenate SEPARATOR= 4607c5f4b28STony Lee ... channel setaccess${SPACE}${channel_number}${SPACE}${userid} 46175e91feaSRahul Maheshwari ... ${SPACE}${options} 46275e91feaSRahul Maheshwari Run IPMI Standard Command ${ipmi_cmd} 4633e61ce66SRahul Maheshwari 4643e61ce66SRahul Maheshwari 4653e61ce66SRahul MaheshwariDelete All Non Root IPMI User 4663e61ce66SRahul Maheshwari [Documentation] Delete all non-root IPMI user. 4673e61ce66SRahul Maheshwari 46834c79af0SMichael Walsh # Get complete list of user info records. 46926499145SNagarjun B ${user_info}= Get User Info ${EMPTY} ${CHANNEL_NUMBER} 47034c79af0SMichael Walsh # Remove header record. 47134c79af0SMichael Walsh ${user_info}= Filter Struct ${user_info} [('user_name', None)] invert=1 47234c79af0SMichael Walsh ${non_empty_user_info}= Filter Struct ${user_info} [('user_name', '')] invert=1 47334c79af0SMichael Walsh ${non_root_user_info}= Filter Struct ${non_empty_user_info} [('user_name', 'root')] invert=1 47434c79af0SMichael Walsh 47534c79af0SMichael Walsh FOR ${user_record} IN @{non_root_user_info} 47634c79af0SMichael Walsh Run IPMI Standard Command user set name ${user_record['user_id']} "" 477bb3d21c0SRahul Maheshwari Sleep 5s 4783e61ce66SRahul Maheshwari END 4790a8c8787Schithrag 4800a8c8787Schithrag 4810a8c8787SchithragCreate SEL 4820a8c8787Schithrag [Documentation] Create a SEL. 4830a8c8787Schithrag [Arguments] ${sensor_type} ${sensor_number} 4840a8c8787Schithrag 4850a8c8787Schithrag # Create a SEL. 4860a8c8787Schithrag # Example: 4870a8c8787Schithrag # a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 | | Asserted 4880a8c8787Schithrag # Description of argument(s): 4890a8c8787Schithrag # ${sensor_type} Type of the sensor used in hexadecimal (can be fan, temp etc.,), 4900a8c8787Schithrag # obtained from Sensor Type field in - ipmitool sdr get "sensor_name". 4910a8c8787Schithrag # Example: Sensor Type (Threshold) : Fan (0x04), here 0xHH is sensor type. 4920a8c8787Schithrag 4930a8c8787Schithrag # ${sensor_number} Sensor number of the sensor in hexadecimal. 4940a8c8787Schithrag # obtained from Sensor ID field in - ipmitool sdr get "sensor_name". 4950a8c8787Schithrag # Example: Sensor ID : SENSOR_1 (0xHH), here 0xHH is sensor number. 4960a8c8787Schithrag 497a8aee234Sganesanb ${cmd}= Catenate ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][0]} 0x${GEN_ID_BYTE_1} 0x${GEN_ID_BYTE_2} 498a8aee234Sganesanb ... ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][1]} 0x${sensor_type} 0x${sensor_number} 499a8aee234Sganesanb ... ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][2]} 500a8aee234Sganesanb 501a8aee234Sganesanb ${resp}= Run IPMI Command ${cmd} 5020a8c8787Schithrag 503d7e009b6Schithrag Should Not Contain ${resp} 00 00 msg=SEL not created. 504d7e009b6Schithrag 50575379c97Smanimozhik Sleep 5s 50675379c97Smanimozhik 5070a8c8787Schithrag [Return] ${resp} 5080a8c8787Schithrag 5090a8c8787Schithrag 510ebea55fdSganesanbFetch One Threshold Sensor From Sensor List 511ebea55fdSganesanb [Documentation] Fetch one threshold sensor randomly from Sensor list. 512d282b56bSganesanb 513ebea55fdSganesanb @{sensor_name_list}= Create List 5140a8c8787Schithrag 5150a8c8787Schithrag ${resp}= Run IPMI Standard Command sensor 516ebea55fdSganesanb @{sensor_list}= Split To Lines ${resp} 5170a8c8787Schithrag 518d282b56bSganesanb # Omit the discrete sensor and create an threshold sensor name list 519ebea55fdSganesanb FOR ${sensor} IN @{sensor_list} 520d282b56bSganesanb ${discrete_sensor_status}= Run Keyword And Return Status Should Contain ${sensor} discrete 521d282b56bSganesanb Continue For Loop If '${discrete_sensor_status}' == 'True' 522d282b56bSganesanb ${sensor_details}= Split String ${sensor} | 523d282b56bSganesanb ${get_sensor_name}= Get From List ${sensor_details} 0 524d282b56bSganesanb ${sensor_name}= Set Variable ${get_sensor_name.strip()} 525ebea55fdSganesanb Append To List ${sensor_name_list} ${sensor_name} 526d282b56bSganesanb END 5270a8c8787Schithrag 528ebea55fdSganesanb ${random_sensor_name}= Evaluate random.choice(${sensor_name_list}) random 5290a8c8787Schithrag 530d282b56bSganesanb [Return] ${random_sensor_name} 5310a8c8787Schithrag 5320a8c8787SchithragFetch Sensor Details From SDR 5330a8c8787Schithrag [Documentation] Identify the sensors from sdr get and fetch sensor details required. 5340a8c8787Schithrag [Arguments] ${sensor_name} ${setting} 5350a8c8787Schithrag 5360a8c8787Schithrag # Description of argument(s): 5370a8c8787Schithrag # ${sensor_number} Sensor number of the sensor in hexadecimal. 5380a8c8787Schithrag # obtained sensor name from - 'ipmitool sensor' command. 5390a8c8787Schithrag # Example: a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 | | Asserted 5400a8c8787Schithrag # here, a is the sensor name. 5410a8c8787Schithrag 5420a8c8787Schithrag # ${setting} Field to fetch data. Example : Sensor ID, Sensor Type (Threshold), etc,. 5430a8c8787Schithrag 5440a8c8787Schithrag ${resp}= Run IPMI Standard Command sdr get "${sensor_name}" 5450a8c8787Schithrag 5460a8c8787Schithrag ${setting_line}= Get Lines Containing String ${resp} ${setting} 5470a8c8787Schithrag ... case-insensitive 5480a8c8787Schithrag ${setting_status}= Fetch From Right ${setting_line} :${SPACE} 5490a8c8787Schithrag 5500a8c8787Schithrag [Return] ${setting_status} 5510a8c8787Schithrag 5520a8c8787Schithrag 55311fe27f3SganesanbGet Bytes From SDR Sensor 5540a8c8787Schithrag [Documentation] Fetch the Field Data and hexadecimal values from given details. 5550a8c8787Schithrag [Arguments] ${sensor_detail} 5560a8c8787Schithrag 5570a8c8787Schithrag # Description of argument(s): 5580a8c8787Schithrag # ${sensor_detail} Requested field and the value from the sdr get ipmi command. 5590a8c8787Schithrag # Example : if Sensor ID is the requesting setting, then, 5600a8c8787Schithrag # ${sensor_detail} will be "Sensor ID : SENSOR_1 (0xHH)" 5610a8c8787Schithrag 5620a8c8787Schithrag ${sensor_detail}= Split String ${sensor_detail} (0x 5630a8c8787Schithrag ${sensor_hex}= Replace String ${sensor_detail[1]} ) ${EMPTY} 5640a8c8787Schithrag ${sensor_hex}= Zfill Data ${sensor_hex} 2 5650a8c8787Schithrag 56611fe27f3Sganesanb [Return] ${sensor_hex} 5670a8c8787Schithrag 5680a8c8787Schithrag 5690a8c8787SchithragGet Current Date from BMC 5700a8c8787Schithrag [Documentation] Runs the date command from BMC and returns current date and time 5710a8c8787Schithrag 5720a8c8787Schithrag # Get Current Date from BMC 5730a8c8787Schithrag ${date} ${stderr} ${rc}= BMC Execute Command date 5740a8c8787Schithrag 5750a8c8787Schithrag # Split the string and remove first and 2nd last value from the list and join to form %d %b %H:%M:%S %Y date format 5760a8c8787Schithrag ${date}= Split String ${date} 5770a8c8787Schithrag Remove From List ${date} 0 5780a8c8787Schithrag Remove From List ${date} -2 5790a8c8787Schithrag ${date}= Evaluate " ".join(${date}) 5800a8c8787Schithrag 5810a8c8787Schithrag # Convert the date format to %m/%d/%Y %H:%M:%S 5820a8c8787Schithrag ${date}= Convert Date ${date} date_format=%b %d %H:%M:%S %Y result_format=%m/%d/%Y %H:%M:%S exclude_millis=True 5830a8c8787Schithrag 5840a8c8787Schithrag [Return] ${date} 585d7e009b6Schithrag 586d7e009b6Schithrag 587d7e009b6SchithragGet SEL Info Via IPMI 588d7e009b6Schithrag [Documentation] Get the SEL Info via IPMI raw command 589d7e009b6Schithrag 590d7e009b6Schithrag # Get SEL Info response consist of 14 bytes of hexadecimal data. 591d7e009b6Schithrag 592d7e009b6Schithrag # Byte 1 - SEL Version, 593d7e009b6Schithrag # Byte 2 & 3 - Entry bytes - LSB MSB, 594d7e009b6Schithrag # Byte 4 & 5 - Free Space in bytes, LS Byte first. 595d7e009b6Schithrag # Byte 6 - 9 - Most recent addition timestamp, 596d7e009b6Schithrag # Byte 10-13 - Most recent erase timestamp, 597d7e009b6Schithrag # Byte 14 - Operation Support 598d7e009b6Schithrag 599d7e009b6Schithrag # Example: ${resp} will be "51 XX XX XX XX ff ff ff ff ff ff ff ff XX" 600d7e009b6Schithrag 601d7e009b6Schithrag ${resp}= Run IPMI Standard Command 602d7e009b6Schithrag ... raw ${IPMI_RAW_CMD['SEL_entry']['SEL_info'][0]} 603d7e009b6Schithrag ${resp}= Split String ${resp} 604d7e009b6Schithrag 605d7e009b6Schithrag [Return] ${resp} 6067fabf794Snagarjunb22 6077fabf794Snagarjunb22 6087fabf794Snagarjunb22Verify Invalid IPMI Command 6097fabf794Snagarjunb22 [Documentation] Execute invalid IPMI command and verify with given response code. 6107fabf794Snagarjunb22 [Arguments] ${ipmi_cmd} ${error_code}=0xc9 6117fabf794Snagarjunb22 6127fabf794Snagarjunb22 # Description Of Arguments. 6137fabf794Snagarjunb22 # ${ipmi_cmd} - IPMI raw cmd with invalid data length. 6147fabf794Snagarjunb22 # ${error_code} - Expected error code e.g 0xc7, 0xcc. 6157fabf794Snagarjunb22 6167fabf794Snagarjunb22 ${resp}= Run External IPMI Raw Command ${ipmi_cmd} fail_on_err=0 6177fabf794Snagarjunb22 6187fabf794Snagarjunb22 Should Contain ${resp} rsp=${error_code} 619c288affeSganesanb 620c288affeSganesanb 621c288affeSganesanbIdentify Request Data 622c288affeSganesanb [Documentation] Convert text from variable declared to request data. 623c288affeSganesanb [Arguments] ${string} 624c288affeSganesanb 625c288affeSganesanb # Convert string to hexadecimal data for each character. 626c288affeSganesanb # Return the hex data with prefix of 0x as string and list of hex data. 627c288affeSganesanb # Description of argument(s): 628c288affeSganesanb # string Any string to be converted to hex. 629c288affeSganesanb 630c288affeSganesanb # Given a string, convert to hexadecimal and prefix with 0x 631c288affeSganesanb ${hex1}= Create List 632c288affeSganesanb ${hex2}= Create List 633c288affeSganesanb ${resp_data}= Split String With Index ${string} 1 634c288affeSganesanb FOR ${data} IN @{resp_data} 635c288affeSganesanb # prefixes 0x by default 636c288affeSganesanb ${hex_value}= Evaluate hex(ord("${data}")) 637c288affeSganesanb # prefixes string with bytes prefixed 0x by default 638c288affeSganesanb Append To List ${hex1} ${hex_value} 639c288affeSganesanb # provides only hexadecimal bytes 640c288affeSganesanb ${hex}= Evaluate hex(ord("${data}"))[2:] 641c288affeSganesanb # provides string with only hexadecimal bytes 642c288affeSganesanb Append To List ${hex2} ${hex} 643c288affeSganesanb END 644c288affeSganesanb ${hex1}= Evaluate " ".join(${hex1}) 645c288affeSganesanb 646c288affeSganesanb # ${hex1} will contains the data to write for fru in list. 647c288affeSganesanb # ${hex2} will contains the data to verify fru after write operation completed. 648c288affeSganesanb 649c288affeSganesanb [Return] ${hex1} ${hex2} 650