blob: f7bae9ca033ea26e9a6e1f6be782a9662a94d765 [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
2Resource ../lib/resource.txt
3Resource ../lib/rest_client.robot
4
5Library OperatingSystem
6
7*** Variables ***
8${SYSTEM_SHUTDOWN_TIME} ${5}
9
10*** Keywords ***
Chris Austenb29d2e82016-06-07 12:25:35 -050011Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000012 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
13 ... ${interval}=5 sec
14
15 # host The DNS name or IP of the host to ping.
16 # timeout The amount of time after which attempts to ping cease.
17 # interval The amount of time in between attempts to ping.
18
19 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050020
21Ping Host
22 [Arguments] ${host}
23 ${RC} ${output} = Run and return RC and Output ping -c 4 ${host}
24 Log RC: ${RC}\nOutput:\n${output}
25 Should be equal ${RC} ${0}
26
27Get Boot Progress
28 ${state} = Read Attribute /org/openbmc/sensors/host/BootProgress value
29 [return] ${state}
30
31Is Power On
root442f0ef2016-08-04 20:23:05 +000032 ${state}= Get Power State
33 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050034
35Is Power Off
root442f0ef2016-08-04 20:23:05 +000036 ${state}= Get Power State
37 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050038
root442f0ef2016-08-04 20:23:05 +000039Initiate Power On
40 [Documentation] Initiates the power on and waits until the Is Power On
41 ... keyword returns that the power state has switched to on.
Chris Austenb29d2e82016-06-07 12:25:35 -050042 @{arglist}= Create List
43 ${args}= Create Dictionary data=@{arglist}
44 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOn data=${args}
45 should be equal as strings ${resp.status_code} ${HTTP_OK}
46 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
47
root442f0ef2016-08-04 20:23:05 +000048Initiate Power Off
49 [Documentation] Initiates the power off and waits until the Is Power Off
50 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -050051 @{arglist}= Create List
52 ${args}= Create Dictionary data=@{arglist}
53 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOff data=${args}
54 should be equal as strings ${resp.status_code} ${HTTP_OK}
55 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
56
57Trigger Warm Reset
58 log to console "Triggering warm reset"
59 ${data} = create dictionary data=@{EMPTY}
60 ${resp} = openbmc post request /org/openbmc/control/bmc0/action/warmReset data=${data}
61 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
62 Sleep ${SYSTEM_SHUTDOWN_TIME}min
63 Wait For Host To Ping ${OPENBMC_HOST}
Michael Walsh49ab0f42016-07-20 11:44:33 -050064
65Check OS
root442f0ef2016-08-04 20:23:05 +000066 [Documentation] Attempts to ping the host OS and then checks that the host
67 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -050068
69 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
70 ... ${os_password}=${OS_PASSWORD}
71 [Teardown] Close Connection
72
73 # os_host The DNS name/IP of the OS host associated with our BMC.
74 # os_username The username to be used to sign on to the OS host.
75 # os_password The password to be used to sign on to the OS host.
76
root442f0ef2016-08-04 20:23:05 +000077 # Attempt to ping the OS. Store the return code to check later.
78 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
79
Michael Walsh49ab0f42016-07-20 11:44:33 -050080 Open connection ${os_host}
81 Login ${os_username} ${os_password}
82
83 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
84 ... return_rc=True
85
86 # If the return code returned by "Execute Command" is non-zero, this keyword
87 # will fail.
88 Should Be Equal ${rc} ${0}
89 # We will likewise fail if there is any stderr data.
90 Should Be Empty ${stderr}
91
root442f0ef2016-08-04 20:23:05 +000092 # We will likewise fail if the OS did not ping, as we could SSH but not ping
93 Should Be Equal As Strings ${ping_rc} ${TRUE}
94
Michael Walsh49ab0f42016-07-20 11:44:33 -050095Wait for OS
96 [Documentation] Waits for the host OS to come up via calls to "Check OS".
97 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
98 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
99
100 # os_host The DNS name or IP of the OS host associated with our
101 # BMC.
102 # os_username The username to be used to sign on to the OS host.
103 # os_password The password to be used to sign on to the OS host.
104 # timeout The timeout in seconds indicating how long you're
105 # willing to wait for the OS to respond.
106
107 # The interval to be used between calls to "Check OS".
108 ${interval}= Set Variable 5
109
110 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
111 ... ${os_host} ${os_username} ${os_password}
root442f0ef2016-08-04 20:23:05 +0000112
113Get BMC State
114 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
115 @{arglist}= Create List
116 ${args}= Create Dictionary data=@{arglist}
117 ${resp}= Call Method /org/openbmc/managers/System/ getSystemState
118 ... data=${args}
119 Should be equal as strings ${resp.status_code} ${HTTP_OK}
120 ${content}= to json ${resp.content}
121 [return] ${content["data"]}
122
123Get Power State
124 [Documentation] Returns the power state as an integer. Either 0 or 1.
125 @{arglist}= Create List
126 ${args}= Create Dictionary data=@{arglist}
127 ${resp}= Call Method /org/openbmc/control/chassis0/ getPowerState
128 ... data=${args}
129 Should be equal as strings ${resp.status_code} ${HTTP_OK}
130 ${content}= to json ${resp.content}
131 [return] ${content["data"]}