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 "BMC_READY" or "HOST_POWERED_OFF"
9...                  - Boot policy is "RESTORE_LAST_STATE"
10...               Power cycle system via PDU if specified
11
12Resource          ../lib/boot/boot_resource_master.robot
13Resource          ../lib/utils.robot
14Resource          ../lib/pdu/pdu.robot
15
16*** Variables ***
17${HOST_SETTING}      /org/openbmc/settings/host0
18
19*** Test cases ***
20
21Get to Stable State
22    [Documentation]    BMC cleanup drive to stable state
23    ...                1. PDU powercycle if specified
24    ...                1. Ping Test
25    ...                2. SSH Connection session Test
26    ...                3. REST Connection session Test
27    ...                4. Reboot BMC if REST Test failed
28    ...                5. Check BMC state for standby
29    ...                6. Issue poweroff if not already in
30    ...                   standby state
31    ...                7. Update restore policy
32    [Tags]  Get to Stable State
33
34    Run Keyword And Ignore Error   Powercycle System Via PDU
35
36    Wait For Host To Ping  ${OPENBMC_HOST}  1 mins
37    Open Connection And Log In   host=${OPENBMC_HOST}
38
39    ${l_rest}=   Run Keyword And Return Status
40    ...    Initialize OpenBMC
41    Run Keyword If  '${l_rest}' == '${False}'
42    ...    Reboot and Wait for BMC Online
43
44    ${l_ready}=   Run Keyword And Return Status
45    ...    Get BMC State and Expect Standby
46
47    Run Keyword If  '${l_ready}' == '${False}'
48    ...    Initiate Power Off
49
50    Update Policy Setting   RESTORE_LAST_STATE
51
52
53*** Keywords ***
54
55Reboot and Wait for BMC Online
56    [Documentation]    Reboot BMC and wait for it to come online
57    ...                and boot to standby
58
59    Trigger Warm Reset via Reboot
60    Wait Until Keyword Succeeds
61    ...    5 min   10 sec    BMC Online Test
62
63    Wait For BMC Standby
64
65
66BMC Online Test
67    [Documentation]   BMC ping, SSH, REST connection Test
68
69    ${l_status}=   Run Keyword and Return Status
70    ...   Verify Ping and REST Authentication
71    Run Keyword If  '${l_status}' == '${False}'
72    ...   Fail  msg=System not in ideal state to continue [ERROR]
73
74
75Wait For BMC Standby
76    [Documentation]   Wait Until BMC standby post BMC reboot
77
78    @{states}=   Create List   BMC_READY   HOST_POWERED_OFF
79    Wait Until Keyword Succeeds
80    ...    10 min   10 sec   Verify BMC State   ${states}
81
82
83Get BMC State and Expect Standby
84    [Documentation]   Get BMC state and should be at standby
85
86    @{states}=     Create List   BMC_READY   HOST_POWERED_OFF
87    ${bmc_state}=  Get BMC State
88    Should Contain  ${states}   ${bmc_state}
89
90
91Update Policy Setting
92    [Documentation]   Update the given restore policy
93    [arguments]   ${policy}
94
95    ${valueDict}=     create dictionary  data=${policy}
96    Write Attribute    ${HOST_SETTING}    power_policy   data=${valueDict}
97    ${currentPolicy}=  Read Attribute     ${HOST_SETTING}   power_policy
98    Should Be Equal    ${currentPolicy}   ${policy}
99
100
101Trigger Warm Reset via Reboot
102    [Documentation]    Execute reboot command on the remote BMC and
103    ...                returns immediately. This keyword "Start Command"
104    ...                returns nothing and does not wait for the command
105    ...                execution to be finished.
106    Open Connection And Log In
107
108    Start Command   /sbin/reboot
109
110
111Powercycle System Via PDU
112    [Documentation]   AC cycle the system via PDU
113
114    Validate Parameters
115    PDU Power Cycle
116    Check If BMC is Up   5 min    10 sec
117
118
119Validate Parameters
120    Should Not Be Empty   ${PDU_IP}
121    Should Not Be Empty   ${PDU_TYPE}
122    Should Not Be Empty   ${PDU_SLOT_NO}
123    Should Not Be Empty   ${PDU_USERNAME}
124    Should Not Be Empty   ${PDU_PASSWORD}
125