xref: /openbmc/openbmc-test-automation/openpower/test_timed_power_on.robot (revision f0e4d1f6c22b3ccec4b03e8f936086f56823b2a2)
1*** Settings ***
2Documentation   This suite tests Timed Power On(TPO) feature via busctl command
3...             and verify the power status of the system.
4...
5...             System can be scheduled to Power ON at a specified time by using this feature.
6
7
8Resource        ../lib/boot_utils.robot
9Resource        ../lib/openbmc_ffdc.robot
10Resource        ../lib/bmc_redfish_resource.robot
11
12
13Suite Setup     Redfish.Login
14Suite Teardown  Redfish.Logout
15Test Setup      Test Setup Execution
16Test Teardown   Test Teardown Execution
17
18Test Tags       Test_Timed_Power_On
19
20*** Variables ****
21
22${CMD_ENABLE_TPO}      busctl set-property xyz.openbmc_project.State.ScheduledHostTransition
23...   /xyz/openbmc_project/scheduled/host0 xyz.openbmc_project.State.ScheduledHostTransition
24...   ScheduledTransition s "xyz.openbmc_project.State.Host.Transition.On"
25
26${CMD_SET_TPO_TIME}    busctl set-property xyz.openbmc_project.State.ScheduledHostTransition
27...  /xyz/openbmc_project/scheduled/host0 xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t
28
29${CMD_GET_TPO_TIME}    busctl get-property xyz.openbmc_project.State.ScheduledHostTransition
30...  /xyz/openbmc_project/scheduled/host0 xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime
31
32# Time in seconds.
33${TIMER_POWER_ON}      100
34
35# All current versions of the following distributions:
36#  - Red Hat Enterprise Linux
37#  - SUSE Linux Enterprise Server
38# Tested on RHEL 8.4.
39
40# Shut down the system and schedule it to restart in 1 hour.
41# User can input -v HOST_TIMER_POWER_ON:h24  ( e.g. 24 hours )
42${HOST_TIMER_POWER_ON}            h1
43${HOST_TIMED_POWER_ON_REQUEST}    set_poweron_time -d ${HOST_TIMER_POWER_ON} -s
44
45*** Test Cases ***
46
47Test Timed Powered On Via BMC
48    [Documentation]  Set time to power on host attribute ScheduledTime and expect
49    ...              the system to boot on scheduled time.
50    [Tags]  Test_Timed_Powered_On_Via_BMC
51
52    # Make sure the host is powered off.
53    Redfish Power Off  stack_mode=skip
54
55    # Set Host transition to ON to enable TPO.
56    BMC Execute Command  ${CMD_ENABLE_TPO}
57
58    ${tpo_set_value}=  Set Timer For Power ON
59    ${new_tpo_value}=  Get Time Power ON Value
60
61    Should Be Equal  ${new_tpo_value}  ${tpo_set_value}
62    ...  msg=TPO time set mismatched.
63
64    # Check if the system BootProgress state changed. If changed, it implies the
65    # system is powering on. Though we have set system to power on in 100 seconds
66    # since, the system boot sometime to change.
67    Wait Until Keyword Succeeds  10 min  20 sec  Is Boot Progress Changed
68
69    Log To Console   BMC Scheduled Time Power on success.
70
71
72Test Timed Powered On Via Host OS
73    [Documentation]  Set time to power on host via service aids tool set_poweron_time
74    ...              and expect the system to boot on scheduled time.
75    [Tags]  Test_Timed_Powered_On_Via_Host_OS
76
77    # Make sure the host is powered on and booted to host OS partition.
78    Redfish Power On
79
80    ${stdout}  ${stderr}  ${rc}=  OS Execute Command  which set_poweron_time  ignore_err=${0}
81    # Skip the test if the tool does not exist or error getting the tool.
82    Skip If  ${rc} != ${0}  INFO: ${stdout} Skip the test since the tool does not. Install and re-run.
83
84    # Set Host transition to ON to enable TPO.
85    ${stdout}  ${stderr}  ${rc}=  OS Execute Command  ${HOST_TIMED_POWER_ON_REQUEST}  ignore_err=${0}
86
87    # Wait for host to Power off.
88    Wait Until Keyword Succeeds  45 min  30 sec  Is BMC Standby
89
90    Log To Console  Power Off completed.
91
92    # Note: The verification could more precise by checking date and set time.
93
94    # Check if the system BootProgress state changed. If changed, it implies the
95    # system is powering on after user timer set and delta time to update BootProgress
96    # state by the state manager.
97    # ${HOST_TIMER_POWER_ON} is in <m/h/d/><time> format
98    # Example:  h1 , logic to convert  x[1:] -> 1 and x[:1] ->h  to robot format 1 h.
99
100    Log To Console  Waiting for system to power on.
101    Wait Until Keyword Succeeds  ${HOST_TIMER_POWER_ON[1:]} ${HOST_TIMER_POWER_ON[:1]}  30 sec
102    ...  Is Boot Progress Changed
103
104    Log To Console   Host Scheduled Time Power on success.
105
106
107*** Keywords ***
108
109Test Setup Execution
110    [Documentation]  Do test case setup tasks.
111
112    Redfish.Login
113    Set Power Policy For TPO  Automatic
114
115
116Set Power Policy For TPO
117    [Documentation]   Change 'server power policy' option to automatic.
118    [Arguments]  ${power_policy_mode}
119
120    # Description of argument(s):
121    # power_policy_mode           BIOS attribute value. E.g. "Stay On", "Automatic".
122
123    Redfish.Patch  /redfish/v1/Systems/${SYSTEM_ID}/Bios/Settings
124    ...  body={"Attributes":{"pvm_system_power_off_policy": "${power_policy_mode}"}}
125    ...  valid_status_codes=[${HTTP_OK}]
126
127
128Test Teardown Execution
129    [Documentation]  Do the test teardown
130
131    FFDC On Test Case Fail
132
133
134Set Timer For Power ON
135    [Documentation]  Set the time for power ON with given value.
136
137    ${current_bmc_time}=  BMC Execute Command  date +%s
138    ${time_set}=  Evaluate  ${current_bmc_time[0]} + ${TIMER_POWER_ON}
139    BMC Execute Command  ${CMD_SET_TPO_TIME} ${time_set}
140
141    RETURN  ${time_set}
142
143
144Get Time Power ON Value
145    [Documentation]  Returns time power ON value.
146
147    ${timer_value}=  BMC Execute Command  ${CMD_GET_TPO_TIME}
148    @{return_value}=  Split String  ${timer_value[0]}
149    ${return_value}=  Evaluate  ${return_value}[1]
150
151    # BMC command returns integer value.
152    RETURN  ${return_value}
153