xref: /openbmc/openbmc-test-automation/extended/standby_bmc.robot (revision feb79d60e26d78a6e91521ee41b1af5b8ba71f4c)
1*** Settings ***
2Documentation     This module will take whatever action is necessary
3...               to bring the BMC to a stable, standby state.  For our
4...               purposes, a stable state is defined as:
5...                  - BMC is communicating
6...                   (pinging, sshing and REST commands working)
7...                  - Power state is 0 (off)
8...                  - BMC state is "Ready"
9...                  - HOST state is "Off"
10...                  - Boot policy is "ALWAYS_POWER_OFF"
11...               Power cycle system via PDU if specified
12...               Prune archived journal logs
13
14Resource          ../lib/utils.robot
15Resource          ../lib/pdu/pdu.robot
16Resource          ../lib/state_manager.robot
17Resource          ../lib/bmc_network_utils.robot
18Resource          ../lib/bmc_cleanup.robot
19Resource          ../lib/dump_utils.robot
20Resource          ../lib/bmc_redfish_resource.robot
21Resource          ../lib/bmc_redfish_utils.robot
22Library           ../lib/gen_misc.py
23
24# Force the test to timedout to prevent test hanging.
25Test Timeout      10 minutes
26
27Test Tags         Standby_BMC
28
29*** Variables ***
30${HOST_SETTING}      /org/openbmc/settings/host0
31
32${ERROR_REGEX}  xyz.openbmc_project.Software.BMC.Updater.service: Failed with result 'core-dump'
33
34*** Test Cases ***
35
36Get To Stable State
37    [Documentation]  BMC cleanup drive to stable state
38    ...              1. PDU powercycle if specified
39    ...              1. Ping Test
40    ...              2. SSH Connection session Test
41    ...              3. REST Connection session Test
42    ...              4. Reboot BMC if REST Test failed
43    ...              5. Get BMC in Ready state if its not in this state
44    ...              6. Get Host in Off state if its not in this state
45    ...              7. Update restore policy
46    ...              8. Verify and Update MAC address.
47    [Tags]  Get_To_Stable_State
48
49    Run Keyword And Ignore Error  Powercycle System Via PDU
50
51    ${ping_status}=  Run Keyword And Return Status
52    ...  Wait For Host To Ping  ${OPENBMC_HOST}  2 mins
53
54    # Check if the ping works using 1400 MTU.
55    #IF  ${ping_status} == ${True}  MTU Ping Test
56
57    IF  ${ping_status} == ${False}  Fail  ${OPENBMC_HOST} ping test failed.
58
59    Open Connection And Log In  host=${OPENBMC_HOST}
60
61    IF  ${REDFISH_SUPPORTED}
62        Redfish Clean Up
63    ELSE
64        REST Clean Up
65    END
66
67
68    Prune Journal Log
69    Check For Current Boot Application Failures
70
71*** Keywords ***
72
73
74REST Clean Up
75    [Documentation]  Check states, reboot if needed and poweroff.
76
77    Wait Until Keyword Succeeds  1 min  30 sec  Initialize OpenBMC
78
79    ${ready_status}=  Run Keyword And Return Status  Is BMC Ready
80    IF  '${ready_status}' == '${False}'
81        Put BMC State  Ready
82    ELSE
83        REST Power Off  stack_mode=skip
84    END
85
86    Run Keyword And Ignore Error  Set BMC Power Policy  ${ALWAYS_POWER_OFF}
87    Run Keyword And Ignore Error  Delete All Error Logs
88    Run Keyword And Ignore Error  Delete All Dumps
89
90
91Redfish Clean Up
92    [Documentation]  Check states, reboot if needed and poweroff.
93
94    Wait Until Keyword Succeeds  1 min  30 sec  Redfish.Login
95
96    Redfish Power Off  stack_mode=skip
97
98    Run Keyword And Ignore Error  Redfish Set Power Restore Policy  AlwaysOff
99    Run Keyword And Ignore Error  Redfish Purge Event Log
100    Run Keyword And Ignore Error  Redfish Delete All BMC Dumps
101    Run Keyword And Ignore Error  Redfish Delete All System Dumps
102    Run Keyword And Ignore Error  Clear All Subscriptions
103    Run Keyword And Ignore Error  Delete All Redfish Sessions
104
105
106BMC Online Test
107    [Documentation]   BMC ping, SSH, REST connection Test
108
109    ${l_status}=   Run Keyword and Return Status
110    ...   Verify Ping and REST Authentication
111    IF  '${l_status}' == '${False}'
112        Fail  msg=System not in ideal state to continue [ERROR]
113    END
114
115
116Update Policy Setting
117    [Documentation]   Update the given restore policy
118    [Arguments]   ${policy}
119
120    # Description of argument(s):
121    # policy      Restore policy.
122
123    ${valueDict}=     create dictionary  data=${policy}
124    Write Attribute    ${HOST_SETTING}    power_policy   data=${valueDict}
125    ${currentPolicy}=  Read Attribute     ${HOST_SETTING}   power_policy
126    Should Be Equal    ${currentPolicy}   ${policy}
127
128
129Trigger Warm Reset via Reboot
130    [Documentation]    Execute reboot command on the remote BMC and
131    ...                returns immediately. This keyword "Start Command"
132    ...                returns nothing and does not wait for the command
133    ...                execution to be finished.
134    Open Connection And Log In
135
136    Start Command   /sbin/reboot
137
138
139Powercycle System Via PDU
140    [Documentation]   AC cycle the system via PDU.
141
142    Validate Parameters
143    PDU Power Cycle
144    Check If BMC is Up   5 min    10 sec
145
146
147Check For Current Boot Application Failures
148    [Documentation]  Parse the journal log and check for failures.
149    [Arguments]  ${error_regex}=${ERROR_REGEX}
150
151    # Description of argument(s):
152    # error_regex    Regex error pattern to be checked in the journal log.
153
154    ${error_regex}=  Escape Bash Quotes  ${error_regex}
155    ${journal_log}  ${stderr}  ${rc}=  BMC Execute Command
156    ...  journalctl -b --no-pager | egrep '${error_regex}'  ignore_err=1
157
158    Should Be Empty  ${journal_log}
159
160
161Validate Parameters
162    [Documentation]  Validate PDU parameters.
163
164    Should Not Be Empty   ${PDU_IP}
165    Should Not Be Empty   ${PDU_TYPE}
166    Should Not Be Empty   ${PDU_SLOT_NO}
167    Should Not Be Empty   ${PDU_USERNAME}
168    Should Not Be Empty   ${PDU_PASSWORD}
169
170
171MTU Ping Test
172    [Documentation]  Ping test using MTU.
173    [Arguments]  ${mtu}=${1400}
174
175    # Description of argument(s):
176    # mtu   The maximum transmission unit (MTU) of a network interface.
177
178    ${rc}  ${output}=  Run And Return RC And Output
179    ...  ping -M do -s ${mtu} -c 10 ${OPENBMC_HOST}
180    Should Be Equal As Integers  ${rc}  0
181    Should Not Contain  ${output}  100% packet loss
182
183
184Clear All Subscriptions
185    [Documentation]  Delete all subscriptions.
186
187    ${subscriptions}=  Redfish.Get Attribute  /redfish/v1/EventService/Subscriptions  Members
188    FOR  ${subscription}  IN  @{subscriptions}
189        Redfish.Delete  ${subscription['@odata.id']}
190    END
191