1*** Settings ***
2
3Documentation    Module to test IPMI chassis functionality.
4Resource         ../lib/ipmi_client.robot
5Resource         ../lib/openbmc_ffdc.robot
6Resource         ../lib/boot_utils.robot
7Library          ../lib/ipmi_utils.py
8Variables        ../data/ipmi_raw_cmd_table.py
9
10Suite Setup      Redfish.Login
11Suite Teardown   Redfish.Logout
12Test Teardown    Test Teardown Execution
13
14
15*** Test Cases ***
16
17IPMI Chassis Status On
18    [Documentation]  This test case verfies system power on status
19    ...               using IPMI Get Chassis status command.
20    [Tags]  IPMI_Chassis_Status_On
21
22    Redfish Power On  stack_mode=skip  quiet=1
23    ${resp}=  Run IPMI Standard Command  chassis status
24    ${power_status}=  Get Lines Containing String  ${resp}  System Power
25    Should Contain  ${power_status}  on
26
27IPMI Chassis Status Off
28    [Documentation]  This test case verfies system power off status
29    ...               using IPMI Get Chassis status command.
30    [Tags]  IPMI_Chassis_Status_Off
31
32    Redfish Power Off  stack_mode=skip  quiet=1
33    ${resp}=  Run IPMI Standard Command  chassis status
34    ${power_status}=  Get Lines Containing String  ${resp}  System Power
35    Should Contain  ${power_status}  off
36
37Verify Host PowerOff Via IPMI
38    [Documentation]   Verify host power off operation using external IPMI command.
39    [Tags]  Verify_Host_PowerOff_Via_IPMI
40
41    IPMI Power Off
42    ${ipmi_state}=  Get Host State Via External IPMI
43    Valid Value  ipmi_state  ['off']
44
45Verify Host PowerOn Via IPMI
46    [Documentation]   Verify host power on operation using external IPMI command.
47    [Tags]  Verify_Host_PowerOn_Via_IPMI
48
49    IPMI Power On
50    ${ipmi_state}=  Get Host State Via External IPMI
51    Valid Value  ipmi_state  ['on']
52
53
54Verify Soft Shutdown
55    [Documentation]  Verify host OS shutdown softly via IPMI command.
56    [Tags]  Verify_Soft_Shutdown
57
58    Redfish Power On  stack_mode=skip
59    Run IPMI Standard Command  chassis power soft
60    Wait Until Keyword Succeeds  3 min  10 sec  Is Host Off Via IPMI
61
62
63Verify Chassis Power Cycle And Check Chassis Status Via IPMI
64    [Documentation]   Verify chassis power Cycle operation and check the Chassis Power Status using external IPMI command.
65    [Tags]  Verify_Chassis_Power_Cycle_And_Check_Chassis_Status_Via_IPMI
66
67    # Chassis power cycle command via IPMI
68    IPMI Power Cycle
69    ${ipmi_state}=  Get Host State Via External IPMI
70    Valid Value  ipmi_state  ['on']
71
72
73Verify Chassis Power Reset And Check Chassis Status Via IPMI
74    [Documentation]   Verify chassis power Reset operation and check the Chassis Power Status using external IPMI command.
75    [Tags]  Verify_Chassis_Power_Reset_And_Check_Chassis_Status_Via_IPMI
76
77    # Chassis power reset command via IPMI
78    IPMI Power Reset
79    ${ipmi_state}=  Get Host State Via External IPMI
80    Valid Value  ipmi_state  ['on']
81
82
83Verify Chassis Power Policy
84    [Documentation]  Verify setting chassis power policy via IPMI command.
85    [Tags]  Verify_Chassis_Power_Policy
86    [Setup]  Test Setup Execution
87    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
88    ...  Run IPMI Standard Command  chassis policy ${initial_power_policy}
89    [Template]  Set Chassis Power Policy Via IPMI And Verify
90
91    # power_policy
92    always-off
93    always-on
94    previous
95
96
97Verify Chassis Status Via IPMI
98    [Documentation]  Verify Chassis Status via IPMI command.
99    [Tags]  Verify_Chassis_Status_Via_IPMI
100    [Setup]  Test Setup Execution
101    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
102    ...  Run IPMI Standard Command  chassis policy ${initial_power_policy}
103    [Template]  Check Chassis Status Via IPMI
104
105    # power_policy
106    always-off
107    always-on
108    previous
109
110
111*** Keywords ***
112
113Set Chassis Power Policy Via IPMI And Verify
114    [Documentation]  Set chasiss power policy via IPMI and verify.
115    [Arguments]  ${power_policy}
116
117    # Description of argument(s):
118    # power_policy    Chassis power policy to be set(e.g. "always-off", "always-on").
119
120    Run IPMI Standard Command  chassis policy ${power_policy}
121    ${resp}=  Get Chassis Status
122    Valid Value  resp['power_restore_policy']  ['${power_policy}']
123
124
125Check Chassis Status Via IPMI
126    [Documentation]  Set Chassis Status via IPMI and verify and verify chassis status.
127    [Arguments]  ${power_policy}
128
129    # Sets power policy according to requested policy
130    Set Chassis Power Policy Via IPMI And Verify  ${power_policy}
131
132    # Gets chassis status via IPMI raw command and validate byte 1
133    ${status}=  Run External IPMI Raw Command  ${IPMI_RAW_CMD['Chassis_status']['get'][0]}
134    ${status}=  Split String  ${status}
135    ${state}=  Convert To Binary  ${status[0]}  base=16
136    ${state}=  Zfill Data  ${state}  8
137
138    # Last bit corresponds whether Power is on
139    Should Be Equal As Strings  ${state[-1]}  1
140    # bit 1-2 corresponds to power restore policy
141    ${policy}=  Set Variable  ${state[1:3]}
142
143    # condition to verify each power policy
144    IF  '${power_policy}' == 'always-off'
145        Should Be Equal As Strings  ${policy}  00
146    ELSE IF  '${power_policy}' == 'always-on'
147        Should Be Equal As Strings  ${policy}  10
148    ELSE IF  '${power_policy}' == 'previous'
149        Should Be Equal As Strings  ${policy}  01
150    ELSE
151        Log  Power Restore Policy is Unknown
152        Should Be Equal As Strings  ${policy}  11
153    END
154
155    # Last Power Event - 4th bit should be 1b i.e, last ‘Power is on’ state was entered via IPMI command
156    ${last_power_event}=  Convert To Binary  ${status[1]}  base=16
157    ${last_power_event}=  Zfill Data  ${last_power_event}  8
158    Should Be Equal As Strings  ${last_power_event[3]}  1
159
160
161Test Setup Execution
162    [Documentation]  Do test setup tasks.
163
164    ${chassis_status}=  Get Chassis Status
165    Set Test Variable  ${initial_power_policy}  ${chassis_status['power_restore_policy']}
166
167
168Test Teardown Execution
169    [Documentation]  Do Test Teardown tasks.
170
171    ${resp}=  Run IPMI Standard Command  chassis status
172    ${power_status}=  Get Lines Containing String  ${resp}  System Power
173    @{powertolist}=  Split String  ${power_status}   :
174    ${status}=  Get From List  ${powertolist}  1
175    # Chassis Power ON if status is off
176    Run Keyword If    '${status.strip()}' != 'on'
177    ...  Redfish Power On
178    FFDC On Test Case Fail
179