xref: /openbmc/openbmc-test-automation/redfish/managers/test_managers_bmc_time.robot (revision 4055c9658c29bb49cb783271af27ed8f69765753)
1*** Settings ***
2Documentation    Test BMC manager time functionality.
3Resource                     ../../lib/openbmc_ffdc.robot
4Resource                     ../../lib/bmc_date_and_time_utils.robot
5
6Test Setup                   Printn
7Test Teardown                Test Teardown Execution
8Suite Setup                  Suite Setup Execution
9Suite Teardown               Suite Teardown Execution
10
11Test Tags                   Managers_BMC_Time
12
13*** Variables ***
14
15${max_time_diff_in_seconds}  6
16${date_time_with_offset}     2019-04-25T26:24:46+00:00
17${invalid_datetime}          2019-04-251T12:24:46+00:00
18
19*** Test Cases ***
20
21Verify Redfish BMC Time
22    [Documentation]  Verify that date/time obtained via redfish matches
23    ...  date/time obtained via BMC command line.
24    [Tags]  Verify_Redfish_BMC_Time
25
26    ${redfish_date_time}=  Redfish Get DateTime
27    ${cli_date_time}=  CLI Get BMC DateTime
28    ${time_diff}=  Subtract Date From Date  ${cli_date_time}
29    ...  ${redfish_date_time}
30    ${time_diff}=  Evaluate  abs(${time_diff})
31    Rprint Vars  redfish_date_time  cli_date_time  time_diff
32    Should Be True  ${time_diff} < ${max_time_diff_in_seconds}
33    ...  The difference between Redfish time and CLI time exceeds the allowed time difference.
34
35
36Verify Set Time Using Redfish
37    [Documentation]  Verify set time using redfish API.
38    [Tags]  Verify_Set_Time_Using_Redfish
39
40    Set Time To Manual Mode
41
42    ${old_bmc_time}=  CLI Get BMC DateTime
43    # Add 3 days to current date.
44    ${new_bmc_time}=  Add Time to Date  ${old_bmc_time}  3 Days
45    Redfish Set DateTime  ${new_bmc_time}
46    ${cli_bmc_time}=  CLI Get BMC DateTime
47    ${time_diff}=  Subtract Date From Date  ${cli_bmc_time}
48    ...  ${new_bmc_time}
49    ${time_diff}=  Evaluate  abs(${time_diff})
50    Rprint Vars   old_bmc_time  new_bmc_time  cli_bmc_time  time_diff  max_time_diff_in_seconds
51    Should Be True  ${time_diff} < ${max_time_diff_in_seconds}
52    ...  The difference between Redfish time and CLI time exceeds the allowed time difference.
53    # Setting back to old bmc time.
54    Redfish Set DateTime  ${old_bmc_time}
55
56
57Verify Set DateTime With Offset Using Redfish
58    [Documentation]  Verify error while setting DateTime with offset using redfish API.
59    [Tags]  Verify_Set_DateTime_With_Offset_Using_Redfish
60    [Teardown]  Run Keywords  Redfish Set DateTime  AND  FFDC On Test Case Fail
61
62    Redfish Set DateTime  ${date_time_with_offset}  invalid
63
64
65Verify Set DateTime With Invalid Data Using Redfish
66    [Documentation]  Verify error while setting invalid DateTime using Redfish.
67    [Tags]  Verify_Set_DateTime_With_Invalid_Data_Using_Redfish
68
69    Redfish Set DateTime  ${invalid_datetime}  invalid
70
71
72Verify DateTime Persists After Reboot
73    [Documentation]  Verify date persists after BMC reboot.
74    [Tags]  Verify_DateTime_Persists_After_Reboot
75
76    # Synchronize BMC date/time to local system date/time.
77    ${local_system_time}=  Get Current Date
78    Redfish Set DateTime  ${local_system_time}
79    Redfish OBMC Reboot (off)
80    Redfish.Login
81    ${bmc_time}=  CLI Get BMC DateTime
82    ${local_system_time}=  Get Current Date
83    ${time_diff}=  Subtract Date From Date  ${bmc_time}
84    ...  ${local_system_time}
85    ${time_diff}=  Evaluate  abs(${time_diff})
86    Rprint Vars   local_system_time  bmc_time  time_diff  max_time_diff_in_seconds
87    Should Be True  ${time_diff} < ${max_time_diff_in_seconds}
88    ...  The difference between Redfish time and CLI time exceeds the allowed time difference.
89
90
91Verify Immediate Consumption Of BMC Date
92    [Documentation]  Verify immediate change in BMC date time.
93    [Tags]  Verify_Immediate_Consumption_Of_BMC_Date
94    [Setup]  Run Keywords  Set Time To Manual Mode  AND
95    ...  Redfish Set DateTime
96    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
97    ...  Redfish Set DateTime
98    [Template]  Set BMC Date And Verify
99
100    # host_state
101    on
102    off
103
104
105
106*** Keywords ***
107
108
109Test Teardown Execution
110    [Documentation]  Do the post test teardown.
111
112    FFDC On Test Case Fail
113
114
115Suite Setup Execution
116    [Documentation]  Do the suite level setup.
117
118    Printn
119    Redfish.Login
120    Get NTP Initial Status
121    ${old_date_time}=  CLI Get BMC DateTime
122    ${year_status}=  Run Keyword And Return Status  Should Not Contain  ${old_date_time}  ${year_without_ntp}
123    Run Keyword If  ${year_status} == False
124    ...  Enable NTP And Add NTP Address
125    Set Time To Manual Mode
126
127
128Suite Teardown Execution
129    [Documentation]  Do the suite level teardown.
130
131    Set Time To Manual Mode
132    Restore NTP Status
133    Redfish.Logout
134