1*** Settings ***
2Documentation   This suite verifies the power restore policy supported by
3...             REST Interfaces.
4...             Refer here for documentation on the REST interfaces
5...             https://github.com/openbmc/docs/blob/master/rest-api.md
6
7Resource        ../../lib/rest_client.robot
8Resource        ../../lib/utils.robot
9Resource        ../../lib/openbmc_ffdc.robot
10Resource        ../../lib/state_manager.robot
11Resource        ../../lib/boot_utils.robot
12Resource        ../../lib/bmc_redfish_resource.robot
13Resource        ../../lib/bmc_redfish_utils.robot
14Resource        ../../lib/pdu/pdu.robot
15Library         ../../lib/state_map.py
16
17Test Teardown   Test Teardown Execution
18Suite Teardown  Suite Teardown Execution
19
20Force Tags      power_restore
21
22*** Variables ***
23
24*** Test Cases ***
25
26Test Restore Policy ALWAYS_POWER_OFF With Host Off
27    [Documentation]  Validate ALWAYS_POWER_OFF restore policy functionality.
28    ...              Policy:
29    ...                    System policy set to ALWAYS_POWER_OFF.
30    ...              Initial Host State:
31    ...                    State where system should be before running the
32    ...                    test case.
33    ...              Expected Host State:
34    ...                    After BMC reset, system should reach this
35    ...                    specific state.
36    [Tags]  Test_Restore_Policy_ALWAYS_POWER_OFF_With_Host_Off
37    [Template]  Verify Restore Policy
38
39    # Policy                Initial Host State     Expected Host State
40    AlwaysOff               Off                    Off
41
42
43
44Test Restore Policy ALWAYS_POWER_OFF With Host Running
45    [Documentation]  Verify that the BMC restore policy is ALWAYS_POWER_OFF while the Host is running.
46    [Tags]  Test_Restore_Policy_ALWAYS_POWER_OFF_With_Host_Running
47    [Template]  Verify Restore Policy
48
49    # Policy                Initial Host State     Expected Host State
50    AlwaysOff               Running                Running
51
52
53Test Restore Policy ALWAYS_POWER_ON With Host Off
54    [Documentation]  Validate ALWAYS_POWER_ON restore policy functionality.
55    ...              Policy:
56    ...                    System policy set to ALWAYS_POWER_OFF.
57    ...              Initial Host State:
58    ...                    State where system should be before running the
59    ...                    test case.
60    ...              Expected Host State:
61    ...                    After BMC reset, system should reach this
62    ...                    specific state.
63    [Tags]  Test_Restore_Policy_ALWAYS_POWER_ON_With_Host_Off
64    [Template]  Verify Restore Policy
65
66    # Policy                Initial Host State     Expected Host State
67    AlwaysOn                Off                    Running
68
69
70
71Test Restore Policy ALWAYS_POWER_ON With Host Running
72    [Documentation]  Verify the BMC restore policy is ALWAYS_POWER_ON while the Host is running.
73    [Tags]  Test_Restore_Policy_ALWAYS_POWER_ON_With_Host_Running
74    [Template]  Verify Restore Policy
75
76    # Policy                Initial Host State     Expected Host State
77    AlwaysOn                Running                Running
78
79
80
81Test Restore Policy Restore Last State With Host Running
82    [Documentation]  Validate RESTORE_LAST_STATE restore policy functionality.
83    ...              Policy:
84    ...                    System policy set to RESTORE_LAST_STATE.
85    ...              Initial Host State:
86    ...                    State where system should be before running the
87    ...                    test case.
88    ...              Expected Host State:
89    ...                    After BMC reset, system should reach this
90    ...                    specific state.
91    [Tags]  Test_Restore_Policy_Restore_Last_State_With_Host_Running
92    [Template]  Verify Restore Policy
93
94    # Policy                Initial Host State     Expected Host State
95    LastState               Running                Running
96
97
98
99Test Restore Policy Restore Last State With Host Off
100    [Documentation]  Verify the RESTORE_LAST_STATE restore policy functionality while the Host is off.
101    [Tags]  Test_Restore_Policy_Restore_Last_State_With_Host_Off
102    [Template]  Verify Restore Policy
103
104    # Policy                Initial Host State     Expected Host State
105    LastState               Off                    Off
106
107
108*** Keywords ***
109
110Verify Restore Policy
111    [Documentation]  Set given policy, reset BMC and expect specified end
112    ...              state.
113    [Arguments]  ${policy}  ${expectedState}  ${nextState}
114
115    # Description of argument(s):
116    # policy           System policy state string.
117    # expectedState    Test initial host state.
118    # nextState        Test end host state.
119
120    Set Initial Test State  ${expectedState}
121
122    Redfish Set Power Restore Policy  ${policy}
123
124    PDU Power Cycle
125    Sleep  20s
126    Wait For BMC Online
127
128    Wait Until Keyword Succeeds
129    ...  10 min  20 sec  Valid Boot States  ${nextState}
130
131
132Valid Boot States
133    [Documentation]  Verify boot states for a given system state.
134    [Arguments]  ${sys_state}
135
136    # Description of argument(s):
137    # sys_state    system state list
138    #              (e.g. "Off", "On", "Reboot", etc.).
139
140    ${current_state}=  Redfish Get States
141    Redfish Valid Boot State  ${sys_state}  ${current_state}
142
143
144Set Initial Test State
145    [Documentation]  Poweron if ON expected, Poweroff if OFF expected
146    ...              to initial state of the test.
147
148    [Arguments]  ${expectedState}
149    # Description of argument(s):
150    # expectedState    Test initial host state.
151
152    Redfish.Login
153
154    Run Keyword If  '${expectedState}' == 'Running'
155    ...  Redfish Power On  stack_mode=skip
156
157    Run Keyword If  '${expectedState}' == 'Off'
158    ...  Redfish Power Off  stack_mode=skip
159
160
161Test Teardown Execution
162    [Documentation]  Do the post test teardown.
163    # 1. Capture FFDC on test failure.
164    # 2. Close all open SSH connections.
165
166    FFDC On Test Case Fail
167    Close All Connections
168
169
170Suite Teardown Execution
171    [Documentation]  Do the post suite teardown.
172    # 1. Set policy to default.
173
174    Run Keyword And Ignore Error  Redfish Set Power Restore Policy  AlwaysOff
175    Redfish.Logout
176
177
178Wait For BMC Online
179    [Documentation]  Wait for Host to be online. Checks every X seconds
180    ...              interval for Y minutes and fails if timed out.
181    ...              Default MAX timedout is 10 min, interval 10 seconds.
182    [Arguments]      ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
183    ...              ${interval}=10 sec
184
185    # Description of argument(s):
186    # max_timeout   Maximum time to wait.
187    #               This should be expressed in Robot Framework's time format
188    #               (e.g. "10 minutes").
189    # interval      Interval to wait between status checks.
190    #               This should be expressed in Robot Framework's time format
191    #               (e.g. "5 seconds").
192
193    Wait Until Keyword Succeeds
194    ...   ${max_timeout}  ${interval}  Verify Ping SSH And Redfish Authentication
195