1*** Settings *** 2Documentation This module is for IPMI client for copying ipmitool to 3... openbmc box and execute ipmitool IPMI standard 4... command. IPMI raw command will use dbus-send command 5Resource ../lib/resource.txt 6Resource ../lib/connection_client.robot 7Resource ../lib/utils.robot 8Resource ../lib/state_manager.robot 9 10Library String 11 12*** Variables *** 13${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1 14${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage 15${netfnByte}= ${EMPTY} 16${cmdByte}= ${EMPTY} 17${arrayByte}= array:byte: 18${IPMI_EXT_CMD}= ipmitool -I lanplus -C 3 -P 19${IPMI_INBAND_CMD}= ipmitool -C 3 20${HOST}= -H 21${RAW}= raw 22 23*** Keywords *** 24 25Run IPMI Command 26 [Arguments] ${args} 27 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External' 28 ... Run External IPMI RAW Command ${args} 29 ... ELSE IF '${IPMI_COMMAND}' == 'Inband' 30 ... Run Inband IPMI RAW Command ${args} 31 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus' 32 ... Run Dbus IPMI RAW Command ${args} 33 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND} 34 [Return] ${resp} 35 36Run IPMI Standard Command 37 [Arguments] ${args} 38 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External' 39 ... Run External IPMI Standard Command ${args} 40 ... ELSE IF '${IPMI_COMMAND}' == 'Inband' 41 ... Run Inband IPMI Standard Command ${args} 42 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus' 43 ... Run Dbus IPMI Standard Command ${args} 44 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND} 45 46 [Return] ${resp} 47 48Run Dbus IPMI RAW Command 49 [Arguments] ${args} 50 ${valueinBytes}= Byte Conversion ${args} 51 ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg} 52 ${cmd}= Catenate ${cmd} ${valueinBytes} 53 ${output} ${stderr}= Execute Command ${cmd} return_stderr=True 54 Should Be Empty ${stderr} 55 set test variable ${OUTPUT} "${output}" 56 57Run Dbus IPMI Standard Command 58 [Arguments] ${args} 59 Copy ipmitool 60 ${stdout} ${stderr} ${output}= Execute Command 61 ... /tmp/ipmitool -I dbus ${args} return_stdout=True 62 ... return_stderr= True return_rc=True 63 Should Be Equal ${output} ${0} msg=${stderr} 64 [Return] ${stdout} 65 66Run Inband IPMI Raw Command 67 [Documentation] Run Inband IPMI raw command. 68 [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 69 ... ${os_password}=${OS_PASSWORD} 70 71 # Desription of arguments: 72 # ${args} parameters to IPMI command. 73 # ${os_host} IP address of the OS Host. 74 # ${os_username} OS Host Login user name. 75 # ${os_password} OS Host Login passwrd. 76 77 Login To OS Host ${os_host} ${os_username} ${os_password} 78 Check If IPMI Tool Exist 79 80 ${inband_raw_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${args} 81 ${stdout} ${stderr}= Execute Command ${inband_raw_cmd} return_stderr=True 82 Should Be Empty ${stderr} msg=${stdout} 83 [Return] ${stdout} 84 85Run Inband IPMI Standard Command 86 [Documentation] Run Inband IPMI standard command. 87 [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 88 ... ${os_password}=${OS_PASSWORD} 89 90 # Desription of arguments: 91 # ${args} parameters to IPMI command. 92 # ${os_host} IP address of the OS Host. 93 # ${os_username} OS Host Login user name. 94 # ${os_password} OS Host Login passwrd. 95 96 Login To OS Host ${os_host} ${os_username} ${os_password} 97 Check If IPMI Tool Exist 98 99 ${inband_std_cmd}= Catenate ${IPMI_INBAND_CMD} ${args} 100 ${stdout} ${stderr}= Execute Command ${inband_std_cmd} return_stderr=True 101 Should Be Empty ${stderr} msg=${stdout} 102 [Return] ${stdout} 103 104Run External IPMI RAW Command 105 [Arguments] ${args} 106 ${ipmi_raw_cmd}= Catenate SEPARATOR= 107 ... ${IPMI_EXT_CMD}${SPACE}${IPMI_PASSWORD}${SPACE} 108 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${RAW}${SPACE}${args} 109 ${rc} ${output}= Run and Return RC and Output ${ipmi_raw_cmd} 110 Should Be Equal ${rc} ${0} msg=${output} 111 [Return] ${output} 112 113Run External IPMI Standard Command 114 [Arguments] ${args} 115 ${ipmi_cmd}= Catenate SEPARATOR= 116 ... ${IPMI_EXT_CMD}${SPACE}${IPMI_PASSWORD}${SPACE} 117 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${args} 118 ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd} 119 Should Be Equal ${rc} ${0} msg=${output} 120 [Return] ${output} 121 122Check If IPMI Tool Exist 123 [Documentation] Check if IPMI Tool installed or not. 124 ${output}= Execute Command which ipmitool 125 Should Not Be Empty ${output} msg=ipmitool not installed. 126 127Byte Conversion 128 [Documentation] Byte Conversion method receives IPMI RAW commands as 129 ... argument in string format. 130 ... Sample argument is as follows 131 ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00 132 ... 0x00" 133 ... IPMI RAW command format is as follows 134 ... <netfn Byte> <cmd Byte> <Data Bytes..> 135 ... This method converts IPMI command format into 136 ... dbus command format as follows 137 ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd> 138 ... <array:byte:data> 139 ... Sample dbus Host IPMI Received Message argument 140 ... byte:0x00 byte:0x04 byte:0x00 byte:0x30 141 ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00 142 [Arguments] ${args} 143 ${argLength}= Get Length ${args} 144 Set Global Variable ${arrayByte} array:byte: 145 @{listargs}= Split String ${args} 146 ${index}= Set Variable ${0} 147 :FOR ${word} in @{listargs} 148 \ Run Keyword if ${index} == 0 Set NetFn Byte ${word} 149 \ Run Keyword if ${index} == 1 Set Cmd Byte ${word} 150 \ Run Keyword if ${index} > 1 Set Array Byte ${word} 151 \ ${index}= Set Variable ${index + 1} 152 ${length}= Get Length ${arrayByte} 153 ${length}= Evaluate ${length} - 1 154 ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length} 155 Set Global Variable ${arrayByte} ${arrayByteLocal} 156 ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00 157 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte} 158 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte} 159 ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00 160 ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte} 161# To Check scenario for smaller IPMI raw commands with only 2 arguments 162# instead of usual 12 arguments. 163# Sample small IPMI raw command: Run IPMI command 0x06 0x36 164# If IPMI raw argument length is only 9 then return value in bytes without 165# array population. 166# Equivalent dbus-send argument for smaller IPMI raw command: 167# byte:0x00 byte:0x06 byte:0x00 byte:0x36 168 Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray} 169 [Return] ${valueinBytesWithArray} 170 171 172Set NetFn Byte 173 [Arguments] ${word} 174 ${netfnByteLocal}= Catenate byte:${word} 175 Set Global Variable ${netfnByte} ${netfnByteLocal} 176 177Set Cmd Byte 178 [Arguments] ${word} 179 ${cmdByteLocal}= Catenate byte:${word} 180 Set Global Variable ${cmdByte} ${cmdByteLocal} 181 182Set Array Byte 183 [Arguments] ${word} 184 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word} 185 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} , 186 Set Global Variable ${arrayByte} ${arrayByteLocal} 187 188Copy ipmitool 189 OperatingSystem.File Should Exist tools/ipmitool msg=The ipmitool program could not be found in the tools directory. It is not part of the automation code by default. You must manually copy or link the correct openbmc version of the tool in to the tools directory in order to run this test suite. 190 191 Import Library SCPLibrary WITH NAME scp 192 scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD} 193 scp.Put File tools/ipmitool /tmp 194 SSHLibrary.Open Connection ${OPENBMC_HOST} 195 Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} 196 Execute Command chmod +x /tmp/ipmitool 197