blob: e1a386b851b96fe41cafc5135aeba2e32f5f1436 [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
George Keishing4d6c1da2016-07-15 05:51:22 -05002Documentation This module is for IPMI client for copying ipmitool to
Sivas SRRa2dab3c2016-07-25 05:08:18 -05003... openbmc box and execute ipmitool IPMI standard
4... command. IPMI raw command will use dbus-send command
Chris Austenb29d2e82016-06-07 12:25:35 -05005Resource ../lib/resource.txt
George Keishing4d6c1da2016-07-15 05:51:22 -05006Resource ../lib/connection_client.robot
Prashanth Kattiae7c2282017-03-15 07:43:46 -05007Resource ../lib/utils.robot
8Resource ../lib/state_manager.robot
9
Sivas SRRa2dab3c2016-07-25 05:08:18 -050010Library String
11
12*** Variables ***
George Keishingd7f11f72017-01-04 10:58:19 -060013${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1
14${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage
Gunnar Mills59204d22016-12-06 11:05:19 -060015${netfnByte}= ${EMPTY}
George Keishingd7f11f72017-01-04 10:58:19 -060016${cmdByte}= ${EMPTY}
Gunnar Mills59204d22016-12-06 11:05:19 -060017${arrayByte}= array:byte:
Michael Walsha7913892017-04-20 16:29:01 -050018${IPMI_EXT_CMD}= ipmitool -I lanplus -C 3
19${IPMI_USER_OPTIONS} ${EMPTY}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050020${IPMI_INBAND_CMD}= ipmitool -C 3
Gunnar Mills59204d22016-12-06 11:05:19 -060021${HOST}= -H
22${RAW}= raw
Chris Austenb29d2e82016-06-07 12:25:35 -050023
24*** Keywords ***
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050025
Chris Austenb29d2e82016-06-07 12:25:35 -050026Run IPMI Command
Prashanth Kattiae7c2282017-03-15 07:43:46 -050027 [Arguments] ${args}
28 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
29 ... Run External IPMI RAW Command ${args}
30 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
31 ... Run Inband IPMI RAW Command ${args}
32 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
33 ... Run Dbus IPMI RAW Command ${args}
34 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
35 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050036
37Run IPMI Standard Command
Prashanth Kattiae7c2282017-03-15 07:43:46 -050038 [Arguments] ${args}
39 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
40 ... Run External IPMI Standard Command ${args}
41 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
42 ... Run Inband IPMI Standard Command ${args}
43 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
44 ... Run Dbus IPMI Standard Command ${args}
45 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050046
Prashanth Kattiae7c2282017-03-15 07:43:46 -050047 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050048
49Run Dbus IPMI RAW Command
Gunnar Mills38032802016-12-12 13:43:40 -060050 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -060051 ${valueinBytes}= Byte Conversion ${args}
52 ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
53 ${cmd}= Catenate ${cmd} ${valueinBytes}
Sivas SRRa2dab3c2016-07-25 05:08:18 -050054 ${output} ${stderr}= Execute Command ${cmd} return_stderr=True
55 Should Be Empty ${stderr}
Chris Austenb29d2e82016-06-07 12:25:35 -050056 set test variable ${OUTPUT} "${output}"
57
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050058Run Dbus IPMI Standard Command
Gunnar Mills38032802016-12-12 13:43:40 -060059 [Arguments] ${args}
George Keishing4d6c1da2016-07-15 05:51:22 -050060 Copy ipmitool
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050061 ${stdout} ${stderr} ${output}= Execute Command
62 ... /tmp/ipmitool -I dbus ${args} return_stdout=True
63 ... return_stderr= True return_rc=True
Chris Austenb29d2e82016-06-07 12:25:35 -050064 Should Be Equal ${output} ${0} msg=${stderr}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060065 [Return] ${stdout}
Chris Austenb29d2e82016-06-07 12:25:35 -050066
Prashanth Kattiae7c2282017-03-15 07:43:46 -050067Run Inband IPMI Raw Command
68 [Documentation] Run Inband IPMI raw command.
69 [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
70 ... ${os_password}=${OS_PASSWORD}
71
72 # Desription of arguments:
73 # ${args} parameters to IPMI command.
74 # ${os_host} IP address of the OS Host.
75 # ${os_username} OS Host Login user name.
76 # ${os_password} OS Host Login passwrd.
77
78 Login To OS Host ${os_host} ${os_username} ${os_password}
79 Check If IPMI Tool Exist
80
81 ${inband_raw_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${args}
82 ${stdout} ${stderr}= Execute Command ${inband_raw_cmd} return_stderr=True
83 Should Be Empty ${stderr} msg=${stdout}
84 [Return] ${stdout}
85
86Run Inband IPMI Standard Command
87 [Documentation] Run Inband IPMI standard command.
88 [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
89 ... ${os_password}=${OS_PASSWORD}
90
91 # Desription of arguments:
92 # ${args} parameters to IPMI command.
93 # ${os_host} IP address of the OS Host.
94 # ${os_username} OS Host Login user name.
95 # ${os_password} OS Host Login passwrd.
96
97 Login To OS Host ${os_host} ${os_username} ${os_password}
98 Check If IPMI Tool Exist
99
100 ${inband_std_cmd}= Catenate ${IPMI_INBAND_CMD} ${args}
101 ${stdout} ${stderr}= Execute Command ${inband_std_cmd} return_stderr=True
102 Should Be Empty ${stderr} msg=${stdout}
103 [Return] ${stdout}
104
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500105Run External IPMI RAW Command
Gunnar Mills38032802016-12-12 13:43:40 -0600106 [Arguments] ${args}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500107 ${ipmi_raw_cmd}= Catenate SEPARATOR=
Michael Walsha7913892017-04-20 16:29:01 -0500108 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500109 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${RAW}${SPACE}${args}
110 ${rc} ${output}= Run and Return RC and Output ${ipmi_raw_cmd}
111 Should Be Equal ${rc} ${0} msg=${output}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600112 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500113
114Run External IPMI Standard Command
Gunnar Mills38032802016-12-12 13:43:40 -0600115 [Arguments] ${args}
Michael Walsha7913892017-04-20 16:29:01 -0500116
117 ${ipmi_cmd}= Catenate SEPARATOR=
118 ... ${IPMI_EXT_CMD} ${IPMI_USER_OPTIONS} -P${SPACE}${IPMI_PASSWORD}
119 ... ${SPACE}${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${args}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500120 ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd}
Michael Walsha7913892017-04-20 16:29:01 -0500121 Should Be Equal ${rc} ${0} msg=${output}
122 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500123
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500124Check If IPMI Tool Exist
125 [Documentation] Check if IPMI Tool installed or not.
126 ${output}= Execute Command which ipmitool
127 Should Not Be Empty ${output} msg=ipmitool not installed.
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500128
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500129
130Activate SOL Via IPMI
131 [Documentation] Start SOL using IPMI and route output to a file.
132 [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST}
133 # Description of argument(s):
134 # file_path The file path on the local machine (vs OBMC) to collect SOL
135 # output. By default SOL output is collected at
136 # /tmp/sol_<BMC_IP> else user input location.
137
138 ${ipmi_cmd}= Catenate SEPARATOR=
139 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}
140 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}sol activate
141
George Keishing2102f6b2017-06-06 08:30:10 -0500142 Start Process ${ipmi_cmd} shell=True stdout=${file_path}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500143
144
145Deactivate SOL Via IPMI
146 [Documentation] Stop SOL using IPMI and return SOL output.
147 [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST}
148 # Description of argument(s):
149 # file_path The file path on the local machine to copy SOL output
150 # collected by above "Activate SOL Via IPMI" keyword.
151 # By default it copies log from /tmp/sol_<BMC_IP>.
152
153 ${ipmi_cmd}= Catenate SEPARATOR=
154 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}
155 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}sol deactivate
156
157 ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd}
158 Run Keyword If ${rc} > 0 Return From Keyword ${output}
159
160 ${rc} ${output}= Run and Return RC and Output cat ${file_path}
161 Should Be Equal ${rc} ${0} msg=${output}
162
163 # Logging SOL output for debug purpose.
164 Log ${output}
165
166 [Return] ${output}
167
168
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500169Byte Conversion
170 [Documentation] Byte Conversion method receives IPMI RAW commands as
171 ... argument in string format.
172 ... Sample argument is as follows
173 ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
174 ... 0x00"
175 ... IPMI RAW command format is as follows
176 ... <netfn Byte> <cmd Byte> <Data Bytes..>
177 ... This method converts IPMI command format into
178 ... dbus command format as follows
179 ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
180 ... <array:byte:data>
181 ... Sample dbus Host IPMI Received Message argument
182 ... byte:0x00 byte:0x04 byte:0x00 byte:0x30
183 ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
Gunnar Mills38032802016-12-12 13:43:40 -0600184 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -0600185 ${argLength}= Get Length ${args}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500186 Set Global Variable ${arrayByte} array:byte:
Gunnar Mills59204d22016-12-06 11:05:19 -0600187 @{listargs}= Split String ${args}
188 ${index}= Set Variable ${0}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500189 :FOR ${word} in @{listargs}
190 \ Run Keyword if ${index} == 0 Set NetFn Byte ${word}
191 \ Run Keyword if ${index} == 1 Set Cmd Byte ${word}
192 \ Run Keyword if ${index} > 1 Set Array Byte ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600193 \ ${index}= Set Variable ${index + 1}
194 ${length}= Get Length ${arrayByte}
195 ${length}= Evaluate ${length} - 1
196 ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500197 Set Global Variable ${arrayByte} ${arrayByteLocal}
Gunnar Mills59204d22016-12-06 11:05:19 -0600198 ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
199 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte}
200 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte}
201 ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
202 ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500203# To Check scenario for smaller IPMI raw commands with only 2 arguments
204# instead of usual 12 arguments.
205# Sample small IPMI raw command: Run IPMI command 0x06 0x36
206# If IPMI raw argument length is only 9 then return value in bytes without
207# array population.
208# Equivalent dbus-send argument for smaller IPMI raw command:
209# byte:0x00 byte:0x06 byte:0x00 byte:0x36
210 Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600211 [Return] ${valueinBytesWithArray}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500212
213
214Set NetFn Byte
Gunnar Mills38032802016-12-12 13:43:40 -0600215 [Arguments] ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600216 ${netfnByteLocal}= Catenate byte:${word}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500217 Set Global Variable ${netfnByte} ${netfnByteLocal}
218
219Set Cmd Byte
Gunnar Mills38032802016-12-12 13:43:40 -0600220 [Arguments] ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600221 ${cmdByteLocal}= Catenate byte:${word}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500222 Set Global Variable ${cmdByte} ${cmdByteLocal}
223
224Set Array Byte
Gunnar Mills38032802016-12-12 13:43:40 -0600225 [Arguments] ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600226 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word}
227 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} ,
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500228 Set Global Variable ${arrayByte} ${arrayByteLocal}
229
Chris Austenb29d2e82016-06-07 12:25:35 -0500230Copy ipmitool
231 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.
232
233 Import Library SCPLibrary WITH NAME scp
234 scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD}
235 scp.Put File tools/ipmitool /tmp
236 SSHLibrary.Open Connection ${OPENBMC_HOST}
237 Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
238 Execute Command chmod +x /tmp/ipmitool
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500239
240Initiate Host Boot Via External IPMI
241 [Documentation] Initiate host power on using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500242 [Arguments] ${wait}=${1}
243 # Description of argument(s):
244 # wait Indicates that this keyword should wait for host running state.
245
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500246 ${output}= Run External IPMI Standard Command chassis power on
247 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500248
249 Run Keyword If '${wait}' == '${0}' Return From Keyword
250 Wait Until Keyword Succeeds 10 min 10 sec Is Host Running
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500251
252Initiate Host PowerOff Via External IPMI
253 [Documentation] Initiate host power off using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500254 [Arguments] ${wait}=${1}
255 # Description of argument(s):
256 # wait Indicates that this keyword should wait for host off state.
257
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500258 ${output}= Run External IPMI Standard Command chassis power off
259 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500260
261 Run Keyword If '${wait}' == '${0}' Return From Keyword
262 Wait Until Keyword Succeeds 3 min 10 sec Is Host Off
263
264Get Host State Via External IPMI
265 [Documentation] Returns host state using external IPMI.
266
267 ${output}= Run External IPMI Standard Command chassis power status
268 Should Not Contain ${output} Error
269 ${output}= Fetch From Right ${output} ${SPACE}
270
271 [Return] ${output}