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*** Variables ***
25${HOST_SETTING}      /org/openbmc/settings/host0
26
27${ERROR_REGEX}  xyz.openbmc_project.Software.BMC.Updater.service: Failed with result 'core-dump'
28
29*** Test Cases ***
30
31Get To Stable State
32    [Documentation]  BMC cleanup drive to stable state
33    ...              1. PDU powercycle if specified
34    ...              1. Ping Test
35    ...              2. SSH Connection session Test
36    ...              3. REST Connection session Test
37    ...              4. Reboot BMC if REST Test failed
38    ...              5. Get BMC in Ready state if its not in this state
39    ...              6. Get Host in Off state if its not in this state
40    ...              7. Update restore policy
41    ...              8. Verify and Update MAC address.
42    [Tags]  Get_To_Stable_State
43
44    Run Keyword And Ignore Error  Powercycle System Via PDU
45
46    ${ping_status}=  Run Keyword And Return Status
47    ...  Wait For Host To Ping  ${OPENBMC_HOST}  2 mins
48
49    # Check if the ping works using 1400 MTU.
50    Run Keyword if  ${ping_status} == ${True}  MTU Ping Test
51
52    Run Keyword if  ${ping_status} == ${False}
53    ...  Fail  ${OPENBMC_HOST} ping test failed.
54
55    Open Connection And Log In  host=${OPENBMC_HOST}
56
57    Wait Until Keyword Succeeds
58    ...  1 min  30 sec  Initialize OpenBMC
59
60    ${ready_status}=  Run Keyword And Return Status  Is BMC Ready
61    Run Keyword If  '${ready_status}' == '${False}'  Put BMC State  Ready
62
63    ${host_off_status}=  Run Keyword And Return Status  Is Host Off
64    Run Keyword If  '${host_off_status}' == '${False}'  Initiate Host PowerOff
65
66    Prune Journal Log
67
68    Run Keyword And Ignore Error  Set BMC Power Policy  ${ALWAYS_POWER_OFF}
69
70    # TODO: Enable MAC AES check latter.
71    # Reference : openbmc/openbmc-test-automation#998
72    #Run Keyword If  '${MAC_ADDRESS}' != '${EMPTY}'
73    #...  Check And Reset MAC
74
75    # TODO: Add new UBI File system cleanup.
76    # Reference : openbmc/openbmc-test-automation#998
77    #${rc}=  Execute Command  find ${CLEANUP_DIR_PATH}
78    #...  return_stdout=False  return_rc=True
79    #Run Keyword If  '${CLEANUP_DIR_PATH}' != '${EMPTY}' and ${rc} == 0
80    #...  Cleanup Dir
81
82    Run Keyword And Ignore Error  Delete All Error Logs
83    Run Keyword And Ignore Error  Delete All Dumps
84    Run Keyword And Ignore Error  Delete All Redfish Sessions
85    Check For Current Boot Application Failures
86
87*** Keywords ***
88
89BMC Online Test
90    [Documentation]   BMC ping, SSH, REST connection Test
91
92    ${l_status}=   Run Keyword and Return Status
93    ...   Verify Ping and REST Authentication
94    Run Keyword If  '${l_status}' == '${False}'
95    ...   Fail  msg=System not in ideal state to continue [ERROR]
96
97
98Update Policy Setting
99    [Documentation]   Update the given restore policy
100    [Arguments]   ${policy}
101
102    ${valueDict}=     create dictionary  data=${policy}
103    Write Attribute    ${HOST_SETTING}    power_policy   data=${valueDict}
104    ${currentPolicy}=  Read Attribute     ${HOST_SETTING}   power_policy
105    Should Be Equal    ${currentPolicy}   ${policy}
106
107
108Trigger Warm Reset via Reboot
109    [Documentation]    Execute reboot command on the remote BMC and
110    ...                returns immediately. This keyword "Start Command"
111    ...                returns nothing and does not wait for the command
112    ...                execution to be finished.
113    Open Connection And Log In
114
115    Start Command   /sbin/reboot
116
117
118Powercycle System Via PDU
119    [Documentation]   AC cycle the system via PDU.
120
121    Validate Parameters
122    PDU Power Cycle
123    Check If BMC is Up   5 min    10 sec
124
125
126Check For Current Boot Application Failures
127    [Documentation]  Parse the journal log and check for failures.
128    [Arguments]  ${error_regex}=${ERROR_REGEX}
129
130    ${error_regex}=  Escape Bash Quotes  ${error_regex}
131    ${journal_log}  ${stderr}  ${rc}=  BMC Execute Command
132    ...  journalctl -b --no-pager | egrep '${error_regex}'  ignore_err=1
133
134    Should Be Empty  ${journal_log}
135
136
137Validate Parameters
138    [Documentation]  Validate PDU parameters.
139    Should Not Be Empty   ${PDU_IP}
140    Should Not Be Empty   ${PDU_TYPE}
141    Should Not Be Empty   ${PDU_SLOT_NO}
142    Should Not Be Empty   ${PDU_USERNAME}
143    Should Not Be Empty   ${PDU_PASSWORD}
144
145
146MTU Ping Test
147    [Documentation]  Ping test using MTU.
148    [Arguments]  ${mtu}=${1400}
149
150    # Description of argument(s):
151    # mtu   The maximum transmission unit (MTU) of a network interface.
152
153    ${rc}  ${output}=  Run And Return RC And Output
154    ...  ping -M do -s ${mtu} -c 10 ${OPENBMC_HOST}
155    Should Be Equal As Integers  ${rc}  0
156    Should Not Contain  ${output}  100% packet loss
157