blob: cfc83c60e3ae710a482b67a97bd6790157f1497b [file] [log] [blame]
Sivas SRR0e3bc6d2019-04-23 08:36:35 -05001*** Settings ***
2Documentation Test BMC manager time functionality.
3Resource ../../lib/resource.robot
4Resource ../../lib/bmc_redfish_resource.robot
5Resource ../../lib/common_utils.robot
6Resource ../../lib/openbmc_ffdc.robot
7Resource ../../lib/utils.robot
Sushil Singh79b04aa2019-06-18 05:25:34 -05008Resource ../../lib/rest_client.robot
Sivas SRR20fe0322019-06-17 04:24:18 -05009Library ../../lib/gen_robot_valid.py
Sivas SRR0e3bc6d2019-04-23 08:36:35 -050010
Michael Walsh09083a82019-08-01 12:46:16 -050011Test Setup Printn
Sivas SRR0e3bc6d2019-04-23 08:36:35 -050012Test Teardown Test Teardown Execution
Sivas SRR20fe0322019-06-17 04:24:18 -050013Suite Setup Suite Setup Execution
George Keishingade5f6e2019-07-12 11:42:42 -050014Suite Teardown Suite Teardown Execution
Sivas SRR0e3bc6d2019-04-23 08:36:35 -050015
16*** Variables ***
17${max_time_diff_in_seconds} 6
Sivas SRR9e00ff32019-07-18 10:38:44 -050018# The "offset" consists of the value "26" specified for hours. Redfish will
19# convert that to the next day + 2 hours.
20${date_time_with_offset} 2019-04-25T26:24:46+00:00
21${expected_date_time} 2019-04-26T02:24:46+00:00
Sivas SRR3f152ae2019-06-07 10:02:51 -050022${invalid_datetime} "2019-04-251T12:24:46+00:00"
George Keishing5c7318d2022-07-07 12:46:00 -050023${ntp_server_1} 9.9.9.9
24${ntp_server_2} 2.2.3.3
Sivas SRR20fe0322019-06-17 04:24:18 -050025&{original_ntp} &{EMPTY}
Sivas SRR0e3bc6d2019-04-23 08:36:35 -050026
27*** Test Cases ***
28
29Verify Redfish BMC Time
30 [Documentation] Verify that date/time obtained via redfish matches
31 ... date/time obtained via BMC command line.
32 [Tags] Verify_Redfish_BMC_Time
33
34 ${redfish_date_time}= Redfish Get DateTime
35 ${cli_date_time}= CLI Get BMC DateTime
36 ${time_diff}= Subtract Date From Date ${cli_date_time}
37 ... ${redfish_date_time}
38 ${time_diff}= Evaluate abs(${time_diff})
39 Rprint Vars redfish_date_time cli_date_time time_diff
40 Should Be True ${time_diff} < ${max_time_diff_in_seconds}
41 ... The difference between Redfish time and CLI time exceeds the allowed time difference.
42
43
Sivas SRR8a53dad2019-05-16 08:56:14 -050044Verify Set Time Using Redfish
45 [Documentation] Verify set time using redfish API.
46 [Tags] Verify_Set_Time_Using_Redfish
47
Anusha Dathatri87e4e552020-05-28 07:02:42 -050048 Set Time To Manual Mode
Sushil Singh79b04aa2019-06-18 05:25:34 -050049
Sivas SRR8a53dad2019-05-16 08:56:14 -050050 ${old_bmc_time}= CLI Get BMC DateTime
51 # Add 3 days to current date.
52 ${new_bmc_time}= Add Time to Date ${old_bmc_time} 3 Days
53 Redfish Set DateTime ${new_bmc_time}
54 ${cli_bmc_time}= CLI Get BMC DateTime
55 ${time_diff}= Subtract Date From Date ${cli_bmc_time}
56 ... ${new_bmc_time}
57 ${time_diff}= Evaluate abs(${time_diff})
58 Rprint Vars old_bmc_time new_bmc_time cli_bmc_time time_diff max_time_diff_in_seconds
59 Should Be True ${time_diff} < ${max_time_diff_in_seconds}
60 ... The difference between Redfish time and CLI time exceeds the allowed time difference.
61 # Setting back to old bmc time.
62 Redfish Set DateTime ${old_bmc_time}
63
64
Sivas SRR9e00ff32019-07-18 10:38:44 -050065Verify Set DateTime With Offset Using Redfish
66 [Documentation] Verify set DateTime with offset using redfish API.
67 [Tags] Verify_Set_DateTime_With_Offset_Using_Redfish
68 [Teardown] Run Keywords Redfish Set DateTime AND FFDC On Test Case Fail
69
70 Redfish Set DateTime ${date_time_with_offset}
71 ${cli_bmc_time}= CLI Get BMC DateTime
72
73 ${date_time_diff}= Subtract Date From Date ${cli_bmc_time}
74 ... ${expected_date_time} exclude_millis=yes
75 ${date_time_diff}= Convert to Integer ${date_time_diff}
Michael Walsh09083a82019-08-01 12:46:16 -050076 Rprint Vars date_time_with_offset expected_date_time cli_bmc_time
Sivas SRR9e00ff32019-07-18 10:38:44 -050077 ... date_time_diff max_time_diff_in_seconds
Michael Walsh09083a82019-08-01 12:46:16 -050078 Valid Range date_time_diff 0 ${max_time_diff_in_seconds}
Sivas SRR9e00ff32019-07-18 10:38:44 -050079
80
Sivas SRR3f152ae2019-06-07 10:02:51 -050081Verify Set DateTime With Invalid Data Using Redfish
82 [Documentation] Verify error while setting invalid DateTime using Redfish.
83 [Tags] Verify_Set_DateTime_With_Invalid_Data_Using_Redfish
84
85 Redfish Set DateTime ${invalid_datetime} valid_status_codes=[${HTTP_BAD_REQUEST}]
86
87
Sivas SRR4d645992019-06-20 05:34:50 -050088Verify DateTime Persists After Reboot
89 [Documentation] Verify date persists after BMC reboot.
90 [Tags] Verify_DateTime_Persists_After_Reboot
91
92 # Synchronize BMC date/time to local system date/time.
93 ${local_system_time}= Get Current Date
94 Redfish Set DateTime ${local_system_time}
95 Redfish OBMC Reboot (off)
96 Redfish.Login
97 ${bmc_time}= CLI Get BMC DateTime
98 ${local_system_time}= Get Current Date
99 ${time_diff}= Subtract Date From Date ${bmc_time}
100 ... ${local_system_time}
101 ${time_diff}= Evaluate abs(${time_diff})
102 Rprint Vars local_system_time bmc_time time_diff max_time_diff_in_seconds
103 Should Be True ${time_diff} < ${max_time_diff_in_seconds}
104 ... The difference between Redfish time and CLI time exceeds the allowed time difference.
105
106
Sivas SRR62d22d02019-06-08 12:13:31 -0500107Verify NTP Server Set
George Keishing5c7318d2022-07-07 12:46:00 -0500108 [Documentation] Patch NTP servers and verify NTP servers is set.
Sivas SRR62d22d02019-06-08 12:13:31 -0500109 [Tags] Verify_NTP_Server_Set
George Keishing5c7318d2022-07-07 12:46:00 -0500110 [Setup] Set NTP state ${True}
Sivas SRR62d22d02019-06-08 12:13:31 -0500111
George Keishing093c1bd2020-02-10 09:47:34 -0600112 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI}
113 ... body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_2}']}}
George Keishingfa2840d2020-01-28 01:41:30 -0600114 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sivas SRR62d22d02019-06-08 12:13:31 -0500115
George Keishing5c7318d2022-07-07 12:46:00 -0500116 # NTP network take few seconds to reload.
117 Wait Until Keyword Succeeds 30 sec 10 sec Verify NTP Servers Are Populated
Sivas SRR62d22d02019-06-08 12:13:31 -0500118
119Verify NTP Server Value Not Duplicated
120 [Documentation] Verify NTP servers value not same for both primary and secondary server.
121 [Tags] Verify_NTP_Server_Value_Not_Duplicated
122
George Keishing093c1bd2020-02-10 09:47:34 -0600123 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI}
124 ... body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_1}']}}
George Keishingfa2840d2020-01-28 01:41:30 -0600125 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sivas SRR62d22d02019-06-08 12:13:31 -0500126 ${network_protocol}= Redfish.Get Properties ${REDFISH_NW_PROTOCOL_URI}
127 Should Contain X Times ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_1} 1
George Keishing1af70ef2019-06-11 09:31:10 -0500128 ... msg=NTP primary and secondary server values should not be same.
Sivas SRR62d22d02019-06-08 12:13:31 -0500129
130
Sivas SRRaac72b02019-06-11 08:56:10 -0500131Verify NTP Server Setting Persist After BMC Reboot
132 [Documentation] Verify NTP server setting persist after BMC reboot.
133 [Tags] Verify_NTP_Server_Setting_Persist_After_BMC_Reboot
George Keishing5c7318d2022-07-07 12:46:00 -0500134 [Setup] Set NTP state ${True}
Sivas SRRaac72b02019-06-11 08:56:10 -0500135
George Keishing093c1bd2020-02-10 09:47:34 -0600136 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI}
137 ... body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_2}']}}
George Keishingfa2840d2020-01-28 01:41:30 -0600138 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sivas SRRaac72b02019-06-11 08:56:10 -0500139 Redfish OBMC Reboot (off)
140 Redfish.Login
George Keishing5c7318d2022-07-07 12:46:00 -0500141
142 # NTP network take few seconds to reload.
143 Wait Until Keyword Succeeds 30 sec 10 sec Verify NTP Servers Are Populated
Sivas SRRaac72b02019-06-11 08:56:10 -0500144
145
Sivas SRR20fe0322019-06-17 04:24:18 -0500146Verify Enable NTP
147 [Documentation] Verify NTP protocol mode can be enabled.
148 [Teardown] Restore NTP Mode
149 [Tags] Verify_Enable_NTP
150
151 ${original_ntp}= Redfish.Get Attribute ${REDFISH_NW_PROTOCOL_URI} NTP
152 Set Suite Variable ${original_ntp}
Michael Walsh39c00512019-07-17 10:54:06 -0500153 Rprint Vars original_ntp
Sivas SRR20fe0322019-06-17 04:24:18 -0500154 # The following patch command should set the ["NTP"]["ProtocolEnabled"] property to "True".
George Keishingfa2840d2020-01-28 01:41:30 -0600155 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'ProtocolEnabled': ${True}}}
156 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sivas SRR20fe0322019-06-17 04:24:18 -0500157 ${ntp}= Redfish.Get Attribute ${REDFISH_NW_PROTOCOL_URI} NTP
Michael Walsh39c00512019-07-17 10:54:06 -0500158 Rprint Vars ntp
Michael Walshe7edb222019-08-19 17:39:38 -0500159 Valid Value ntp["ProtocolEnabled"] valid_values=[True]
Sivas SRR20fe0322019-06-17 04:24:18 -0500160
161
Anusha Dathatri4ad9f432020-06-29 05:18:29 -0500162Verify Immediate Consumption Of BMC Date
163 [Documentation] Verify immediate change in BMC date time.
164 [Tags] Verify_Immediate_Consumption_Of_BMC_Date
165 [Setup] Run Keywords Set Time To Manual Mode AND
Anusha Dathatriad6a3df2020-07-22 05:20:18 -0500166 ... Redfish Set DateTime valid_status_codes=[${HTTP_OK}]
Anusha Dathatri4ad9f432020-06-29 05:18:29 -0500167 [Teardown] Run Keywords FFDC On Test Case Fail AND
168 ... Redfish Set DateTime valid_status_codes=[${HTTP_OK}]
169 [Template] Set BMC Date And Verify
170
171 # host_state
172 on
173 off
174
175
Sivas SRR0e3bc6d2019-04-23 08:36:35 -0500176*** Keywords ***
177
Sivas SRR4d645992019-06-20 05:34:50 -0500178
Sivas SRR0e3bc6d2019-04-23 08:36:35 -0500179Test Teardown Execution
180 [Documentation] Do the post test teardown.
181
182 FFDC On Test Case Fail
Sivas SRR0e3bc6d2019-04-23 08:36:35 -0500183
184
185Redfish Get DateTime
186 [Documentation] Returns BMC Datetime value from Redfish.
187
188 ${date_time}= Redfish.Get Attribute ${REDFISH_BASE_URI}Managers/bmc DateTime
189 [Return] ${date_time}
Sivas SRR8a53dad2019-05-16 08:56:14 -0500190
191
192Redfish Set DateTime
193 [Documentation] Set DateTime using Redfish.
Sivas SRR9e00ff32019-07-18 10:38:44 -0500194 [Arguments] ${date_time}=${EMPTY} &{kwargs}
Sivas SRR8a53dad2019-05-16 08:56:14 -0500195 # Description of argument(s):
Sivas SRR3f152ae2019-06-07 10:02:51 -0500196 # date_time New time to set for BMC (eg.
Sivas SRR9e00ff32019-07-18 10:38:44 -0500197 # "2019-06-30 09:21:28"). If this value is
198 # empty, it will be set to the UTC current
199 # date time of the local system.
George Keishing7bc01e92021-06-15 11:07:14 -0500200 # kwargs Additional parameters to be passed directly to
Sivas SRR3f152ae2019-06-07 10:02:51 -0500201 # th Redfish.Patch function. A good use for
202 # this is when testing a bad date-time, the
203 # caller can specify
204 # valid_status_codes=[${HTTP_BAD_REQUEST}].
Sivas SRR8a53dad2019-05-16 08:56:14 -0500205
Sivas SRR9e00ff32019-07-18 10:38:44 -0500206 # Assign default value of UTC current date time if date_time is empty.
207 ${date_time}= Run Keyword If
208 ... '${date_time}' == '${EMPTY}' Get Current Date time_zone=UTC
209 ... ELSE
210 ... Set Variable ${date_time}
Anusha Dathatriad6a3df2020-07-22 05:20:18 -0500211 Wait Until Keyword Succeeds 1min 5sec
212 ... Redfish.Patch ${REDFISH_BASE_URI}Managers/bmc body={'DateTime': '${date_time}'} &{kwargs}
Sushil Singh79b04aa2019-06-18 05:25:34 -0500213
214
Anusha Dathatri87e4e552020-05-28 07:02:42 -0500215Set Time To Manual Mode
Anusha Dathatrid1a7bf02021-09-15 03:04:45 -0500216 [Documentation] Set date time to manual mode via Redfish.
Sushil Singh79b04aa2019-06-18 05:25:34 -0500217
Anusha Dathatrid1a7bf02021-09-15 03:04:45 -0500218 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'ProtocolEnabled': ${False}}}
219 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sushil Singh79b04aa2019-06-18 05:25:34 -0500220
Sivas SRR9e00ff32019-07-18 10:38:44 -0500221
Sivas SRR20fe0322019-06-17 04:24:18 -0500222Restore NTP Mode
223 [Documentation] Restore the original NTP mode.
224
225
226 Return From Keyword If &{original_ntp} == &{EMPTY}
227 Print Timen Restore NTP Mode.
228 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI}
George Keishingfa2840d2020-01-28 01:41:30 -0600229 ... body={'NTP':{'ProtocolEnabled': ${original_ntp["ProtocolEnabled"]}}}
230 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sivas SRR20fe0322019-06-17 04:24:18 -0500231
232
233Suite Setup Execution
234 [Documentation] Do the suite level setup.
235
236 Printn
237 Redfish.Login
Tony Lee10822662020-05-12 14:53:35 +0800238 Get NTP Initial Status
Anusha Dathatri87e4e552020-05-28 07:02:42 -0500239 Set Time To Manual Mode
Tony Lee10822662020-05-12 14:53:35 +0800240
George Keishingade5f6e2019-07-12 11:42:42 -0500241
242Suite Teardown Execution
243 [Documentation] Do the suite level teardown.
Sivas SRR9e00ff32019-07-18 10:38:44 -0500244
Sivas SRR64613ff2019-07-13 03:06:33 -0500245 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI}
George Keishingf05a1032020-01-27 11:08:51 -0600246 ... body={'NTP':{'NTPServers': ['${EMPTY}', '${EMPTY}']}}
247 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Anusha Dathatri87e4e552020-05-28 07:02:42 -0500248 Set Time To Manual Mode
Tony Lee10822662020-05-12 14:53:35 +0800249 Restore NTP Status
George Keishingade5f6e2019-07-12 11:42:42 -0500250 Redfish.Logout
Tony Lee10822662020-05-12 14:53:35 +0800251
252
253Set NTP state
254 [Documentation] Set NTP service inactive.
255 [Arguments] ${state}
256
257 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'ProtocolEnabled': ${state}}}
258 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
259
260
261Get NTP Initial Status
262 [Documentation] Get NTP service Status.
263
264 ${original_ntp}= Redfish.Get Attribute ${REDFISH_NW_PROTOCOL_URI} NTP
265 Set Suite Variable ${original_ntp}
266
267
268Restore NTP Status
269 [Documentation] Restore NTP Status.
270
271 Run Keyword If '${original_ntp["ProtocolEnabled"]}' == 'True'
272 ... Set NTP state ${TRUE}
Anusha Dathatri4ad9f432020-06-29 05:18:29 -0500273 ... ELSE Set NTP state ${FALSE}
274
275
276Set BMC Date And Verify
277 [Documentation] Set BMC Date Time at a given host state and verify.
278 [Arguments] ${host_state}
279 # Description of argument(s):
280 # host_state Host state at which date time will be updated for verification
281 # (eg. on, off).
282
283 Run Keyword If '${host_state}' == 'on'
284 ... Redfish Power On stack_mode=skip
285 ... ELSE
286 ... Redfish Power off stack_mode=skip
287 ${current_date}= Get Current Date time_zone=UTC
288 ${new_value}= Subtract Time From Date ${current_date} 1 day
289 Redfish Set DateTime ${new_value} valid_status_codes=[${HTTP_OK}]
290 ${current_value}= Redfish Get DateTime
291 ${time_diff}= Subtract Date From Date ${current_value} ${new_value}
292 Should Be True '${time_diff}'<='3'
George Keishing5c7318d2022-07-07 12:46:00 -0500293
294Verify NTP Servers Are Populated
295 [Documentation] Redfish GET request /redfish/v1/Managers/bmc/NetworkProtocol response
296 ... and verify if NTP servers are populated.
297
298 ${network_protocol}= Redfish.Get Properties ${REDFISH_NW_PROTOCOL_URI}
299 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_1}
300 ... msg=NTP server value ${ntp_server_1} not stored.
301 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_2}
302 ... msg=NTP server value ${ntp_server_2} not stored.
303