1*** Settings ***
2Documentation    This suite tests Redfish Host power operations.
3
4Resource         ../../lib/boot_utils.robot
5Resource         ../../lib/common_utils.robot
6Resource         ../../lib/open_power_utils.robot
7
8Test Setup       Test Setup Execution
9Test Teardown    Test Teardown Execution
10
11*** Variables ***
12
13# Extended code to check OCC state, power metric and others.
14${additional_power_check}      ${1}
15${additional_occ_check}        ${1}
16
17*** Test Cases ***
18
19Verify Redfish Host GracefulShutdown
20    [Documentation]  Verify Redfish host graceful shutdown operation.
21    [Tags]  Verify_Redfish_Host_GracefulShutdown
22
23    Redfish Power Off
24
25
26Verify Redfish BMC PowerOn With OCC State
27    [Documentation]  Verify Redfish host power on operation.
28    [Tags]  Verify_Redfish_BMC_PowerOn_With_OCC_State
29
30    Redfish Power On
31
32    # TODO: Replace OCC state check with redfish property when available.
33    Verify OCC State
34
35
36Verify Redfish Host PowerOn
37    [Documentation]  Verify Redfish host power on operation.
38    [Tags]  Verify_Redfish_Host_PowerOn
39
40    Redfish Power On
41
42    Run Keyword If  ${additional_occ_check} == ${1}
43    ...  Wait Until Keyword Succeeds  3 mins  30 secs  Match OCC And CPU State Count
44
45    Run Keyword If  ${additional_power_check} == ${1}  Power Check
46
47
48Verify Redfish Host GracefulRestart
49    [Documentation]  Verify Redfish host graceful restart operation.
50    [Tags]  Verify_Redfish_Host_GracefulRestart
51
52    RF SYS GracefulRestart
53
54
55Verify Redfish Host PowerOff
56    [Documentation]  Verify Redfish host power off operation.
57    [Tags]  Verify_Redfish_Host_PowerOff
58
59    Redfish Hard Power Off
60
61*** Keywords ***
62
63Test Setup Execution
64    [Documentation]  Do test case setup tasks.
65
66    Printn
67    Start SOL Console Logging
68    Redfish.Login
69
70
71Test Teardown Execution
72    [Documentation]  Collect FFDC and SOL log.
73
74    FFDC On Test Case Fail
75    ${sol_log}=    Stop SOL Console Logging
76    Log   ${sol_log}
77
78    Run Keyword If  ${REDFISH_SUPPORTED}
79    ...    Redfish Set Auto Reboot  RetryAttempts
80    ...  ELSE
81    ...    Set Auto Reboot  ${1}
82    Redfish.Logout
83
84
85Power Check
86    [Documentation]  Verify PowerConsumedWatts property.
87
88    ${power_uri_list}=  redfish_utils.Get Members URI  /redfish/v1/Chassis/  PowerControl
89    Log List  ${power_uri_list}
90
91    # Power entries could be seen across different redfish path, remove the URI
92    # where the attribute is non-existent.
93    # Example:
94    #     ['/redfish/v1/Chassis/chassis/Power',
95    #      '/redfish/v1/Chassis/motherboard/Power']
96    FOR  ${idx}  IN  @{power_uri_list}
97        ${power_control}=  redfish_utils.Get Attribute  ${idx}  PowerControl
98        Log Dictionary  ${power_control[0]}
99
100        # Ensure the path does have the attribute else set to EMPTY as default to skip.
101        ${value}=  Get Variable Value  ${power_control[0]['PowerConsumedWatts']}  ${EMPTY}
102        Run Keyword If  "${value}" == "${EMPTY}"
103        ...  Remove Values From List  ${power_uri_list}  ${idx}
104
105        # Check the next available element in the list.
106        Continue For Loop If  "${value}" == "${EMPTY}"
107
108        Valid Dict  power_control[${0}]  ['PowerConsumedWatts']
109
110    END
111
112    # Double check, the validation has at least one valid path.
113    Should Not Be Empty  ${power_uri_list}
114    ...  msg=Should contain at least one element in the list.
115