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