blob: accfdbb96e89252ce077371d90154b5cda39402d [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
2Resource ../lib/resource.txt
3Resource ../lib/rest_client.robot
George Keishing5e870cd2016-08-24 10:05:47 -05004Resource ../lib/connection_client.robot
Chris Austenb29d2e82016-06-07 12:25:35 -05005
6Library OperatingSystem
7
8*** Variables ***
9${SYSTEM_SHUTDOWN_TIME} ${5}
Sivas SRRe1143ae2016-08-26 22:31:02 -050010${dbuscmdBase} = dbus-send --system --print-reply --dest=org.openbmc.settings.Host
11${dbuscmdGet} = /org/openbmc/settings/host0 org.freedesktop.DBus.Properties.Get
12${dbuscmdString} = string:"org.openbmc.settings.Host" string:
Chris Austenb29d2e82016-06-07 12:25:35 -050013
14*** Keywords ***
Chris Austenb29d2e82016-06-07 12:25:35 -050015Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000016 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
17 ... ${interval}=5 sec
18
19 # host The DNS name or IP of the host to ping.
20 # timeout The amount of time after which attempts to ping cease.
21 # interval The amount of time in between attempts to ping.
22
23 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050024
25Ping Host
26 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050027 Should Not Be Empty ${host} msg=No host provided
Chris Austenb29d2e82016-06-07 12:25:35 -050028 ${RC} ${output} = Run and return RC and Output ping -c 4 ${host}
29 Log RC: ${RC}\nOutput:\n${output}
30 Should be equal ${RC} ${0}
31
32Get Boot Progress
33 ${state} = Read Attribute /org/openbmc/sensors/host/BootProgress value
34 [return] ${state}
35
36Is Power On
root442f0ef2016-08-04 20:23:05 +000037 ${state}= Get Power State
38 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050039
40Is Power Off
root442f0ef2016-08-04 20:23:05 +000041 ${state}= Get Power State
42 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050043
root442f0ef2016-08-04 20:23:05 +000044Initiate Power On
45 [Documentation] Initiates the power on and waits until the Is Power On
46 ... keyword returns that the power state has switched to on.
Chris Austenb29d2e82016-06-07 12:25:35 -050047 @{arglist}= Create List
48 ${args}= Create Dictionary data=@{arglist}
49 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOn data=${args}
50 should be equal as strings ${resp.status_code} ${HTTP_OK}
51 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
52
root442f0ef2016-08-04 20:23:05 +000053Initiate Power Off
54 [Documentation] Initiates the power off and waits until the Is Power Off
55 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -050056 @{arglist}= Create List
57 ${args}= Create Dictionary data=@{arglist}
58 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOff data=${args}
59 should be equal as strings ${resp.status_code} ${HTTP_OK}
60 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
61
62Trigger Warm Reset
63 log to console "Triggering warm reset"
64 ${data} = create dictionary data=@{EMPTY}
65 ${resp} = openbmc post request /org/openbmc/control/bmc0/action/warmReset data=${data}
66 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -050067 ${session_active}= Check If warmReset is Initiated
68 Run Keyword If '${session_active}' == '${True}'
69 ... Fail msg=warm reset didn't occur
70
Chris Austenb29d2e82016-06-07 12:25:35 -050071 Sleep ${SYSTEM_SHUTDOWN_TIME}min
72 Wait For Host To Ping ${OPENBMC_HOST}
Michael Walsh49ab0f42016-07-20 11:44:33 -050073
74Check OS
root442f0ef2016-08-04 20:23:05 +000075 [Documentation] Attempts to ping the host OS and then checks that the host
76 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -050077
78 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
79 ... ${os_password}=${OS_PASSWORD}
80 [Teardown] Close Connection
81
82 # os_host The DNS name/IP of the OS host associated with our BMC.
83 # os_username The username to be used to sign on to the OS host.
84 # os_password The password to be used to sign on to the OS host.
85
root442f0ef2016-08-04 20:23:05 +000086 # Attempt to ping the OS. Store the return code to check later.
87 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
88
Michael Walsh49ab0f42016-07-20 11:44:33 -050089 Open connection ${os_host}
90 Login ${os_username} ${os_password}
91
92 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
93 ... return_rc=True
94
95 # If the return code returned by "Execute Command" is non-zero, this keyword
96 # will fail.
97 Should Be Equal ${rc} ${0}
98 # We will likewise fail if there is any stderr data.
99 Should Be Empty ${stderr}
100
root442f0ef2016-08-04 20:23:05 +0000101 # We will likewise fail if the OS did not ping, as we could SSH but not ping
102 Should Be Equal As Strings ${ping_rc} ${TRUE}
103
Michael Walsh49ab0f42016-07-20 11:44:33 -0500104Wait for OS
105 [Documentation] Waits for the host OS to come up via calls to "Check OS".
106 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
107 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
108
109 # os_host The DNS name or IP of the OS host associated with our
110 # BMC.
111 # os_username The username to be used to sign on to the OS host.
112 # os_password The password to be used to sign on to the OS host.
113 # timeout The timeout in seconds indicating how long you're
114 # willing to wait for the OS to respond.
115
116 # The interval to be used between calls to "Check OS".
117 ${interval}= Set Variable 5
118
119 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
120 ... ${os_host} ${os_username} ${os_password}
root442f0ef2016-08-04 20:23:05 +0000121
122Get BMC State
123 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
124 @{arglist}= Create List
125 ${args}= Create Dictionary data=@{arglist}
126 ${resp}= Call Method /org/openbmc/managers/System/ getSystemState
127 ... data=${args}
128 Should be equal as strings ${resp.status_code} ${HTTP_OK}
129 ${content}= to json ${resp.content}
130 [return] ${content["data"]}
131
132Get Power State
133 [Documentation] Returns the power state as an integer. Either 0 or 1.
134 @{arglist}= Create List
135 ${args}= Create Dictionary data=@{arglist}
136 ${resp}= Call Method /org/openbmc/control/chassis0/ getPowerState
137 ... data=${args}
138 Should be equal as strings ${resp.status_code} ${HTTP_OK}
139 ${content}= to json ${resp.content}
140 [return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500141
142Clear BMC Record Log
143 [Documentation] Clears all the event logs on the BMC. This would be
144 ... equivalent to ipmitool sel clear.
145 @{arglist}= Create List
146 ${args}= Create Dictionary data=@{arglist}
147 ${resp}= Call Method /org/openbmc/records/events/ clear data=${args}
148 should be equal as strings ${resp.status_code} ${HTTP_OK}
149
150Copy PNOR to BMC
151 Import Library SCPLibrary WITH NAME scp
152 Open Connection for SCP
153 Log Copying ${PNOR_IMAGE_PATH} to /tmp
154 scp.Put File ${PNOR_IMAGE_PATH} /tmp
155
156Flash PNOR
157 [Documentation] Calls flash bios update method to flash PNOR image
158 [arguments] ${pnor_image}
159 @{arglist}= Create List ${pnor_image}
160 ${args}= Create Dictionary data=@{arglist}
161 ${resp}= Call Method /org/openbmc/control/flash/bios/ update data=${args}
162 should be equal as strings ${resp.status_code} ${HTTP_OK}
163 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
164
165Get Flash BIOS Status
166 [Documentation] Returns the status of the flash BIOS API as a string. For
167 ... example 'Flashing', 'Flash Done', etc
168 ${data}= Read Properties /org/openbmc/control/flash/bios
169 [return] ${data['status']}
170
171Is PNOR Flashing
172 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
173 ... flashing has started.
174 ${status}= Get Flash BIOS Status
175 should be equal as strings ${status} Flashing
176
177Is PNOR Flash Done
178 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
179 ... PNOR flashing has completed.
180 ${status}= Get Flash BIOS Status
181 should be equal as strings ${status} Flash Done
182
183Is System State Host Booted
184 [Documentation] Checks whether system state is HOST_BOOTED.
185 ${state}= Get BMC State
186 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500187
188Verify Ping and REST Authentication
189 ${l_ping} = Run Keyword And Return Status
190 ... Ping Host ${OPENBMC_HOST}
191 Return From Keyword If '${l_ping}' == '${False}' ${False}
192
193 ${l_rest} = Run Keyword And Return Status
194 ... Initialize OpenBMC
195 Return From Keyword If '${l_rest}' == '${False}' ${False}
196
197 # Just to make sure the SSH is working for SCP
198 Open Connection And Log In
199 ${system} ${stderr}= Execute Command hostname return_stderr=True
200 Should Be Empty ${stderr}
201
202 [return] ${True}
George Keishingb3700812016-08-31 03:03:30 -0500203
204Check If warmReset is Initiated
205 [Documentation] Ping would be still alive, so try SSH to connect
206 ... if fails the ports are down indicating reboot
207 ... is in progress
208 ${alive}= Run Keyword and Return Status
209 ... Open Connection And Log In
210 Return From Keyword If '${alive}' == '${False}' ${False}
211 [return] ${True}
212
George Keishing06ae4aa2016-08-30 01:41:28 -0500213Flush REST Sessions
214 [Documentation] Removes all the active session objects
215 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500216
Sivas SRRe1143ae2016-08-26 22:31:02 -0500217Initialize DBUS cmd
218 [Documentation] Initialize dbus string with property string to extract
219 [arguments] ${boot_property}
220 ${cmd} = Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
221 ${cmd} = Catenate ${cmd}${boot_property}
222 Set Global Variable ${dbuscmd} ${cmd}
223