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
12Library         ../../lib/state_map.py
13
14Test Teardown   Test Teardown Execution
15Suite Teardown  Suite Teardown Execution
16
17Force Tags      power_restore
18
19*** Variables ***
20
21*** Test Cases ***
22
23Test Restore Policy ALWAYS_POWER_OFF With Host Off
24    [Documentation]  Validate ALWAYS_POWER_OFF restore policy functionality.
25    ...              Policy:
26    ...                    System policy set to ALWAYS_POWER_OFF.
27    ...              Initial Host State:
28    ...                    State where system should be before running the
29    ...                    test case.
30    ...              Expected Host State:
31    ...                    After BMC reset, system should reach this
32    ...                    specific state.
33    [Tags]  Test_Restore_Policy_ALWAYS_POWER_OFF_With_Host_Off
34    [Template]  Verify Restore Policy
35
36    # Policy                Initial Host State     Expected Host State
37    ${ALWAYS_POWER_OFF}     Off                    Off
38
39
40
41Test Restore Policy ALWAYS_POWER_OFF With Host Running
42    [Documentation]  Verify that the BMC restore policy is ALWAYS_POWER_OFF while the Host is running.
43    [Tags]  Test_Restore_Policy_ALWAYS_POWER_OFF_With_Host_Running
44    [Template]  Verify Restore Policy
45
46    # Policy                Initial Host State     Expected Host State
47    ${ALWAYS_POWER_OFF}     Running                Running
48
49
50Test Restore Policy ALWAYS_POWER_ON With Host Off
51    [Documentation]  Validate ALWAYS_POWER_ON restore policy functionality.
52    ...              Policy:
53    ...                    System policy set to ALWAYS_POWER_OFF.
54    ...              Initial Host State:
55    ...                    State where system should be before running the
56    ...                    test case.
57    ...              Expected Host State:
58    ...                    After BMC reset, system should reach this
59    ...                    specific state.
60    [Tags]  Test_Restore_Policy_ALWAYS_POWER_ON_With_Host_Off
61    [Template]  Verify Restore Policy
62
63    # Policy                Initial Host State     Expected Host State
64    ${ALWAYS_POWER_ON}      Off                    Running
65
66
67
68Test Restore Policy ALWAYS_POWER_ON With Host Running
69    [Documentation]  Verify the BMC restore policy is ALWAYS_POWER_ON while the Host is running.
70    [Tags]  Test_Restore_Policy_ALWAYS_POWER_ON_With_Host_Running
71    [Template]  Verify Restore Policy
72
73    # Policy                Initial Host State     Expected Host State
74    ${ALWAYS_POWER_ON}      Running                Running
75
76
77
78Test Restore Policy Restore Last State With Host Running
79    [Documentation]  Validate RESTORE_LAST_STATE restore policy functionality.
80    ...              Policy:
81    ...                    System policy set to RESTORE_LAST_STATE.
82    ...              Initial Host State:
83    ...                    State where system should be before running the
84    ...                    test case.
85    ...              Expected Host State:
86    ...                    After BMC reset, system should reach this
87    ...                    specific state.
88    [Tags]  Test_Restore_Policy_Restore_Last_State_With_Host_Running
89    [Template]  Verify Restore Policy
90
91    # Policy                Initial Host State     Expected Host State
92    ${RESTORE_LAST_STATE}   Running                Running
93
94
95
96Test Restore Policy Restore Last State With Host Off
97    [Documentation]  Verify the RESTORE_LAST_STATE restore policy functionality while the Host is off.
98    [Tags]  Test_Restore_Policy_Restore_Last_State_With_Host_Off
99    [Template]  Verify Restore Policy
100
101    # Policy                Initial Host State     Expected Host State
102    ${RESTORE_LAST_STATE}   Off                    Off
103
104
105*** Keywords ***
106
107Verify Restore Policy
108    [Documentation]  Set given policy, reset BMC and expect specified end
109    ...              state.
110    [Arguments]  ${policy}  ${expectedState}  ${nextState}
111
112    # Description of argument(s):
113    # policy           System policy state string.
114    # expectedState    Test initial host state.
115    # nextState        Test end host state.
116
117    Set BMC Power Policy  ${policy}
118
119    Set Initial Test State  ${expectedState}
120
121    Redfish Power Operation  reset_type=GracefulRestart
122
123    Wait Until Keyword Succeeds
124    ...  10 min  10 sec  Valid Boot States  ${nextState}
125
126
127Valid Boot States
128    [Documentation]  Verify boot states for a given system state.
129    [Arguments]  ${sys_state}
130
131    # Description of argument(s):
132    # sys_state    system state list
133    #              (e.g. "Off", "On", "Reboot", etc.).
134
135    ${current_state}=  Get Boot State
136    Valid Boot State  ${sys_state}  ${current_state}
137
138
139Set Initial Test State
140    [Documentation]  Poweron if ON expected, Poweroff if OFF expected
141    ...              to initial state of the test.
142
143    [Arguments]  ${expectedState}
144    # Description of argument(s):
145    # expectedState    Test initial host state.
146
147    Run Keyword If  '${expectedState}' == 'Running'
148    ...  Redfish Power On
149
150    Run Keyword If  '${expectedState}' == 'Off'
151    ...  Redfish Power Off
152
153
154Test Teardown Execution
155    [Documentation]  Do the post test teardown.
156    # 1. Capture FFDC on test failure.
157    # 2. Close all open SSH connections.
158
159    FFDC On Test Case Fail
160    Close All Connections
161
162
163Suite Teardown Execution
164    [Documentation]  Do the post suite teardown.
165    # 1. Set policy to default.
166
167    Run Keyword And Ignore Error  Set BMC Power Policy  ${ALWAYS_POWER_OFF}
168
169