blob: 52bd89790d6e1290a4435d43f58ad946ada58bd0 [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:
Rahul Maheshwarif7b8a6c2017-03-07 08:22:07 -060018${IPMI_EXT_CMD}= ipmitool -I lanplus -C 3 -P
Prashanth Kattiae7c2282017-03-15 07:43:46 -050019${IPMI_INBAND_CMD}= ipmitool -C 3
Gunnar Mills59204d22016-12-06 11:05:19 -060020${HOST}= -H
21${RAW}= raw
Chris Austenb29d2e82016-06-07 12:25:35 -050022
23*** Keywords ***
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050024
Chris Austenb29d2e82016-06-07 12:25:35 -050025Run IPMI Command
Prashanth Kattiae7c2282017-03-15 07:43:46 -050026 [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}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050035
36Run IPMI Standard Command
Prashanth Kattiae7c2282017-03-15 07:43:46 -050037 [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}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050045
Prashanth Kattiae7c2282017-03-15 07:43:46 -050046 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050047
48Run Dbus IPMI RAW Command
Gunnar Mills38032802016-12-12 13:43:40 -060049 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -060050 ${valueinBytes}= Byte Conversion ${args}
51 ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
52 ${cmd}= Catenate ${cmd} ${valueinBytes}
Sivas SRRa2dab3c2016-07-25 05:08:18 -050053 ${output} ${stderr}= Execute Command ${cmd} return_stderr=True
54 Should Be Empty ${stderr}
Chris Austenb29d2e82016-06-07 12:25:35 -050055 set test variable ${OUTPUT} "${output}"
56
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050057Run Dbus IPMI Standard Command
Gunnar Mills38032802016-12-12 13:43:40 -060058 [Arguments] ${args}
George Keishing4d6c1da2016-07-15 05:51:22 -050059 Copy ipmitool
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050060 ${stdout} ${stderr} ${output}= Execute Command
61 ... /tmp/ipmitool -I dbus ${args} return_stdout=True
62 ... return_stderr= True return_rc=True
Chris Austenb29d2e82016-06-07 12:25:35 -050063 Should Be Equal ${output} ${0} msg=${stderr}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060064 [Return] ${stdout}
Chris Austenb29d2e82016-06-07 12:25:35 -050065
Prashanth Kattiae7c2282017-03-15 07:43:46 -050066Run 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
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500104Run External IPMI RAW Command
Gunnar Mills38032802016-12-12 13:43:40 -0600105 [Arguments] ${args}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500106 ${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}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600111 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500112
113Run External IPMI Standard Command
Gunnar Mills38032802016-12-12 13:43:40 -0600114 [Arguments] ${args}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500115 ${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}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600120 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500121
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500122Check 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.
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500126
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500127Byte 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
Gunnar Mills38032802016-12-12 13:43:40 -0600142 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -0600143 ${argLength}= Get Length ${args}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500144 Set Global Variable ${arrayByte} array:byte:
Gunnar Mills59204d22016-12-06 11:05:19 -0600145 @{listargs}= Split String ${args}
146 ${index}= Set Variable ${0}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500147 :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}
Gunnar Mills59204d22016-12-06 11:05:19 -0600151 \ ${index}= Set Variable ${index + 1}
152 ${length}= Get Length ${arrayByte}
153 ${length}= Evaluate ${length} - 1
154 ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500155 Set Global Variable ${arrayByte} ${arrayByteLocal}
Gunnar Mills59204d22016-12-06 11:05:19 -0600156 ${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}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500161# 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}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600169 [Return] ${valueinBytesWithArray}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500170
171
172Set NetFn Byte
Gunnar Mills38032802016-12-12 13:43:40 -0600173 [Arguments] ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600174 ${netfnByteLocal}= Catenate byte:${word}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500175 Set Global Variable ${netfnByte} ${netfnByteLocal}
176
177Set Cmd Byte
Gunnar Mills38032802016-12-12 13:43:40 -0600178 [Arguments] ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600179 ${cmdByteLocal}= Catenate byte:${word}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500180 Set Global Variable ${cmdByte} ${cmdByteLocal}
181
182Set Array Byte
Gunnar Mills38032802016-12-12 13:43:40 -0600183 [Arguments] ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600184 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word}
185 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} ,
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500186 Set Global Variable ${arrayByte} ${arrayByteLocal}
187
Chris Austenb29d2e82016-06-07 12:25:35 -0500188Copy 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