blob: cf8b04bfb7377783dc1a47a8da407e1133fa79e7 [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
2Documentation This suite is for testing System time in Open BMC.
3
Rahul Maheshwari93f68092016-10-24 02:42:12 -05004Resource ../lib/rest_client.robot
George Keishing4d6c1da2016-07-15 05:51:22 -05005Resource ../lib/ipmi_client.robot
George Keishingd55a4be2016-08-26 03:28:17 -05006Resource ../lib/openbmc_ffdc.robot
Rahul Maheshwari2c725042017-01-29 22:55:28 -06007Resource ../lib/state_manager.robot
Sandhya Somashekar839a0c22019-01-31 05:05:43 -06008Resource ../lib/resource.robot
Chris Austenb29d2e82016-06-07 12:25:35 -05009
George Keishing4d6c1da2016-07-15 05:51:22 -050010Library OperatingSystem
11Library DateTime
Chris Austenb29d2e82016-06-07 12:25:35 -050012
Rahul Maheshwari06174f22017-03-06 03:17:09 -060013Test Setup Open Connection And Log In
14Test Teardown Post Test Case Execution
Chris Austenb29d2e82016-06-07 12:25:35 -050015
Sweta Potthurib1631202017-08-28 04:11:34 -050016Force Tags Clock_Time
17
Chris Austenb29d2e82016-06-07 12:25:35 -050018*** Variables ***
Rahul Maheshwarif8785902016-12-12 01:23:13 -060019${SYSTEM_TIME_INVALID} 01/01/1969 00:00:00
20${SYSTEM_TIME_VALID} 02/29/2016 09:10:00
Rahul Maheshwarif8785902016-12-12 01:23:13 -060021${ALLOWED_TIME_DIFF} 3
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050022# Equivalent epoch time for 02/17/2017 04:11:40
23${SYSTEM_TIME_VALID_EPOCH} ${1487304700000000}
George Keishingab1bd922016-12-05 05:29:59 -060024
Chris Austenb29d2e82016-06-07 12:25:35 -050025*** Test Cases ***
26
27Get System Time
Rahul Maheshwarif8785902016-12-12 01:23:13 -060028 [Documentation] Get system time using IPMI and verify that it matches
29 ... with BMC date time.
George Keishing845fb822016-11-01 13:23:19 -050030 [Tags] Get_System_Time
Chris Austenb29d2e82016-06-07 12:25:35 -050031
Rahul Maheshwarif8785902016-12-12 01:23:13 -060032 ${resp}= Run IPMI Standard Command sel time get
33 ${ipmidate}= Convert Date ${resp} date_format=%m/%d/%Y %H:%M:%S
34 ... exclude_millis=yes
35 ${bmcdate}= Get BMC Time Using IPMI
36 ${diff}= Subtract Date From Date ${bmcdate} ${ipmidate}
Sridevi Rameshae444822017-02-13 05:51:52 -060037 ${diff}= Convert To Number ${diff}
Rahul Maheshwarif8785902016-12-12 01:23:13 -060038 Should Be True ${diff} < ${ALLOWED_TIME_DIFF}
39 ... Open BMC time does not match with IPMI sel time
Chris Austenb29d2e82016-06-07 12:25:35 -050040
Rahul Maheshwari52d92942019-01-21 10:54:52 -060041
Chris Austenb29d2e82016-06-07 12:25:35 -050042Set Valid System Time
Rahul Maheshwarif8785902016-12-12 01:23:13 -060043 [Documentation] Set system time using IPMI and verify that it is
44 ... correctly set in BMC.
George Keishing845fb822016-11-01 13:23:19 -050045 [Tags] Set_Valid_System_Time
Chris Austenb29d2e82016-06-07 12:25:35 -050046
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050047 Set Time Owner ${HOST_OWNER}
48 Set Time Mode ${MANUAL_MODE}
Rahul Maheshwari7588f872017-04-13 05:51:24 -050049
Rahul Maheshwari11a1cc32019-01-24 02:53:05 -060050 # Added delay for NTP mode to get disabled fully
51 Sleep 30s
52
Rahul Maheshwarif8785902016-12-12 01:23:13 -060053 ${resp}= Run IPMI Standard Command sel time set "${SYSTEM_TIME_VALID}"
54 ${setdate}= Convert Date ${SYSTEM_TIME_VALID}
55 ... date_format=%m/%d/%Y %H:%M:%S exclude_millis=yes
56 ${bmcdate}= Get BMC Time Using IPMI
57 ${diff}= Subtract Date From Date ${bmcdate} ${setdate}
Sridevi Rameshae444822017-02-13 05:51:52 -060058 ${diff}= Convert To Number ${diff}
Rahul Maheshwarif8785902016-12-12 01:23:13 -060059 Should Be True ${diff} < ${ALLOWED_TIME_DIFF}
60 ... Open BMC time does not match with set time
Chris Austenb29d2e82016-06-07 12:25:35 -050061
Rahul Maheshwari52d92942019-01-21 10:54:52 -060062
Chris Austenb29d2e82016-06-07 12:25:35 -050063Set Invalid System Time
Rahul Maheshwarif8785902016-12-12 01:23:13 -060064 [Documentation] Set system time with invalid time using IPMI and verify
65 ... that it should throw error.
George Keishing845fb822016-11-01 13:23:19 -050066 [Tags] Set_Invalid_System_Time
Chris Austenb29d2e82016-06-07 12:25:35 -050067
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050068 Set Time Owner ${HOST_OWNER}
69 Set Time Mode ${MANUAL_MODE}
Rahul Maheshwari7588f872017-04-13 05:51:24 -050070
Rahul Maheshwarif8785902016-12-12 01:23:13 -060071 ${msg}= Run Keyword And Expect Error * Run IPMI Standard Command
72 ... sel time set "${SYSTEM_TIME_INVALID}"
73 Should Start With ${msg} Specified time could not be parsed
Chris Austenb29d2e82016-06-07 12:25:35 -050074
75Set System Time with no time
Rahul Maheshwarif8785902016-12-12 01:23:13 -060076 [Documentation] Set system time with no time using IPMI and verify
77 ... that it should throw error.
George Keishing845fb822016-11-01 13:23:19 -050078 [Tags] Set_System_Time_with_no_time
Chris Austenb29d2e82016-06-07 12:25:35 -050079
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050080 Set Time Owner ${HOST_OWNER}
81 Set Time Mode ${MANUAL_MODE}
Rahul Maheshwari7588f872017-04-13 05:51:24 -050082
Rahul Maheshwarif8785902016-12-12 01:23:13 -060083 ${msg}= Run Keyword And Expect Error * Run IPMI Standard Command
84 ... sel time set ""
85 Should Start With ${msg} Specified time could not be parsed
Chris Austenb29d2e82016-06-07 12:25:35 -050086
Rahul Maheshwari93f68092016-10-24 02:42:12 -050087
Rahul Maheshwarif8785902016-12-12 01:23:13 -060088Set BMC Time With BMC And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -060089 [Documentation] Set BMC time when time owner is BMC and time mode is
90 ... manual.
91 [Tags] Set_BMC_Time_With_BMC_And_Manual
92 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -050093
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050094 #Operation Owner Mode Status BMC Time Host Time
George Keishing5abfe602018-07-05 11:54:37 -050095 Set BMC Time ${BMC_OWNER} ${MANUAL_MODE} ok Set Change
Rahul Maheshwari93f68092016-10-24 02:42:12 -050096
George Keishing5abfe602018-07-05 11:54:37 -050097
98Set BMC Time With Both And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -060099 [Documentation] Set BMC time when time owner is Both and time mode is
100 ... manual.
101 [Tags] Set_BMC_Time_With_Both_And_Manual
102 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500103
George Keishing5abfe602018-07-05 11:54:37 -0500104 #Operation Owner Mode Status BMC Time Host Time
105 Set BMC Time ${BOTH_OWNER} ${MANUAL_MODE} ok Set Change
106
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500107
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600108Set BMC Time With Split And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600109 [Documentation] Set BMC time when time owner is Split and time mode is
110 ... manual.
111 [Tags] Set_BMC_Time_With_Split_And_Manual
112 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500113
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500114 #Operation Owner Mode Status BMC Time Host Time
George Keishing5abfe602018-07-05 11:54:37 -0500115 Set BMC Time ${SPLIT_OWNER} ${MANUAL_MODE} ok Set No Change
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500116
George Keishing5abfe602018-07-05 11:54:37 -0500117
118Set BMC Time With BMC And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600119 [Documentation] Set BMC time when time owner is BMC and time mode is
120 ... NTP.
121 [Tags] Set_BMC_Time_With_BMC_And_NTP
122 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500123
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500124 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500125 Set BMC Time ${BMC_OWNER} ${NTP_MODE} error Not Set No Change
George Keishing5abfe602018-07-05 11:54:37 -0500126
127
128Set BMC Time With Host And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600129 [Documentation] Set BMC time when time owner is Host and time mode is
130 ... Manual.
131 [Tags] Set_BMC_Time_With_Host_And_Manual
132 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500133
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500134 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500135 Set BMC Time ${HOST_OWNER} ${MANUAL_MODE} error Not Set No Change
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600136
George Keishing5abfe602018-07-05 11:54:37 -0500137
138Set BMC Time With Both And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600139 [Documentation] Set BMC time when time owner is Both and time mode is
140 ... NTP.
141 [Tags] Set_BMC_Time_With_Both_And_NTP
142 [Template] Set Time Using REST
143
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500144 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500145 Set BMC Time ${BOTH_OWNER} ${NTP_MODE} error Not Set No Change
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600146
George Keishing5abfe602018-07-05 11:54:37 -0500147
148Set BMC Time With Split And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600149 [Documentation] Set BMC time when time owner is Split and time mode is
150 ... NTP.
151 [Tags] Set_BMC_Time_With_Split_And_NTP
152 [Template] Set Time Using REST
153
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500154 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500155 Set BMC Time ${SPLIT_OWNER} ${NTP_MODE} error Not Set No Change
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500156
George Keishing5abfe602018-07-05 11:54:37 -0500157
158Set BMC Time With Host And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500159 [Documentation] Set BMC time when time owner is Host and time mode is
160 ... NTP.
161 [Tags] Set_BMC_Time_With_Host_And_NTP
162 [Template] Set Time Using REST
163
George Keishing5abfe602018-07-05 11:54:37 -0500164 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500165 Set BMC Time ${HOST_OWNER} ${NTP_MODE} error Not Set No Change
George Keishing5abfe602018-07-05 11:54:37 -0500166
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500167
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600168Set Host Time With Host And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600169 [Documentation] Set host time when time owner is host and time mode is
170 ... manual.
171 [Tags] Set_Host_Time_With_Host_And_Manual
172 [Template] Set Time Using REST
173
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500174 #Operation Owner Mode Status BMC Time Host Time
George Keishing5abfe602018-07-05 11:54:37 -0500175 Set Host Time ${HOST_OWNER} ${MANUAL_MODE} ok Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600176
George Keishing5abfe602018-07-05 11:54:37 -0500177
George Keishing5abfe602018-07-05 11:54:37 -0500178Set Host Time With Both And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600179 [Documentation] Set host time when time owner is both and time mode is
180 ... NTP.
181 [Tags] Set_Host_Time_With_Both_And_NTP
182 [Template] Set Time Using REST
183
George Keishing5abfe602018-07-05 11:54:37 -0500184 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500185 Set Host Time ${BOTH_OWNER} ${NTP_MODE} error No Change Not Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600186
George Keishing5abfe602018-07-05 11:54:37 -0500187
188Set Host Time With Split And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600189 [Documentation] Set host time when time owner is split and time mode is
190 ... manual.
191 [Tags] Set_Host_Time_With_Split_And_Manual
192 [Template] Set Time Using REST
193
George Keishing5abfe602018-07-05 11:54:37 -0500194 #Operation Owner Mode Status BMC Time Host Time
195 Set Host Time ${SPLIT_OWNER} ${MANUAL_MODE} ok No Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600196
George Keishing5abfe602018-07-05 11:54:37 -0500197
198Set Host Time With Split And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600199 [Documentation] Set host time when time owner is split and time mode is
200 ... NTP.
201 [Tags] Set_Host_Time_With_Split_And_NTP
202 [Template] Set Time Using REST
203
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500204 #Operation Owner Mode Status BMC Time HOST Time
George Keishing5abfe602018-07-05 11:54:37 -0500205 Set Host Time ${SPLIT_OWNER} ${NTP_MODE} ok No Change Set
206
207
208Set Host Time With BMC And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600209 [Documentation] Set host time when time owner is BMC and time mode is
210 ... Manual.
211 [Tags] Set_Host_Time_With_BMC_And_Manual
212 [Template] Set Time Using REST
213
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500214 #Operation Owner Mode Status BMC Time HOST Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500215 Set Host Time ${BMC_OWNER} ${MANUAL_MODE} error No Change Not Set
George Keishing5abfe602018-07-05 11:54:37 -0500216
217
218Set Host Time With BMC Owner NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600219 [Documentation] Set host time when time owner is BMC and time mode is
220 ... NTP.
221 [Tags] Set_Host_Time_With_BMC_And_NTP
222 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500223
George Keishing5abfe602018-07-05 11:54:37 -0500224 #Operation Owner Mode Status BMC Time HOST Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500225 Set Host Time ${BMC_OWNER} ${NTP_MODE} error No Change Not Set
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500226
George Keishing5abfe602018-07-05 11:54:37 -0500227
228Set Host Time With Host And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500229 [Documentation] Set host time when time owner is Host and time mode is
230 ... NTP.
231 [Tags] Set_Host_Time_With_Host_And_NTP
232 [Template] Set Time Using REST
233
George Keishing5abfe602018-07-05 11:54:37 -0500234 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500235 Set Host Time ${HOST_OWNER} ${NTP_MODE} error Not Change No Set
George Keishing5abfe602018-07-05 11:54:37 -0500236
237
Rahul Maheshwari52d92942019-01-21 10:54:52 -0600238Set Host Time With Both And Manual
239 [Documentation] Set host time when time owner is both and time mode is
240 ... manual.
241 [Tags] Set_Host_Time_With_Both_And_Manual
242 [Template] Set Time Using REST
243
244 #Operation Owner Mode Status BMC Time Host Time
245 Set Host Time ${BOTH_OWNER} ${MANUAL_MODE} ok Change Set
246
247
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500248Set Invalid Time Mode
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600249 [Documentation] Set time mode with invalid value using REST and verify
250 ... that it should throw error.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500251 [Tags] Set_Invalid_Time_Mode
252
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500253 ${timemode}=
254 ... Set Variable xyz.openbmc_project.Time.Synchronization.Method.abc
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600255 ${valueDict}= Create Dictionary data=${timemode}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500256
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600257 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500258 ... ${TIME_MANAGER_URI}sync_method/attr/TimeSyncMethod data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600259 ${jsondata}= to JSON ${resp.content}
260 Should Be Equal ${jsondata['status']} error
261
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500262 ${mode}= Read Attribute ${TIME_MANAGER_URI}sync_method TimeSyncMethod
263 Should Not Be Equal ${mode}
264 ... xyz.openbmc_project.Time.Synchronization.Method.abc
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500265
266Set Invalid Time Owner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600267 [Documentation] Set time owner with invalid value using REST and verify
268 ... that it should throw error.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500269 [Tags] Set_Invalid_Time_Owner
270
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500271 ${timeowner}= Set Variable xyz.openbmc_project.Time.Owner.Owners.xyz
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600272 ${valueDict}= Create Dictionary data=${timeowner}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500273
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600274 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500275 ... ${TIME_MANAGER_URI}owner/attr/TimeOwner data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600276 ${jsondata}= to JSON ${resp.content}
277 Should Be Equal ${jsondata['status']} error
278
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500279 ${owner}= Read Attribute ${TIME_MANAGER_URI}owner TimeOwner
280 Should Not Be Equal ${owner} xyz.openbmc_project.Time.Owner.Owners.xyz
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500281
282
Chris Austenb29d2e82016-06-07 12:25:35 -0500283*** Keywords ***
284
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600285Get BMC Time Using IPMI
286 [Documentation] Returns BMC time of the system via IPMI
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500287
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600288 ${stdout} ${stderr} ${output}=
289 ... Execute Command date "+%m/%d/%Y %H:%M:%S"
290 ... return_stdout=True return_stderr= True return_rc=True
291 Should Be Equal ${output} ${0} msg=${stderr}
292
293 ${resp}= Convert Date ${stdout} date_format=%m/%d/%Y %H:%M:%S
294 ... exclude_millis=yes
295 Should Not Be Empty ${resp}
296 [Return] ${resp}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500297
Rahul Maheshwari52d92942019-01-21 10:54:52 -0600298
299Verify Set Time Via REST
300 [Documentation] Verify set time via REST.
301 [Arguments] ${target} ${expected_status}
302 # Description of argument(s):
303 # target The target of the set time operation: "bmc" or "host".
304 # expected_status Expected status of set time operation
305
306 ${time_owner_url}= Set Variable ${TIME_MANAGER_URI}${target}
307
308 ${args}= Create Dictionary data=${SYSTEM_TIME_VALID_EPOCH}
309 ${resp}= OpenBMC Put Request
310 ... ${time_owner_url}/attr/Elapsed data=${args}
311 ${jsondata}= to Json ${resp.content}
312 Run Keyword If "${expected_status}" == "ok"
313 ... Should Not Be Equal As Strings ${jsondata['message']} 403 Forbidden
314 Should Be Equal As Strings ${jsondata['status']} ${expected_status}
315
316
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500317Set Time Owner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600318 [Arguments] ${args}
319 [Documentation] Set time owner of the system via REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500320
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600321 ${timeowner}= Set Variable ${args}
322 ${valueDict}= Create Dictionary data=${timeowner}
323
324 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500325 ... ${TIME_MANAGER_URI}owner/attr/TimeOwner data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600326 ${jsondata}= to JSON ${resp.content}
327
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600328 ${host_state}= Get Host State
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600329
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600330 Run Keyword If '${host_state}' == 'Off'
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600331 ... Log System is in off state so owner change will get applied.
332 ... ELSE Run keyword
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600333 ... Initiate Host PowerOff
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600334
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500335 ${owner}= Read Attribute ${TIME_MANAGER_URI}owner TimeOwner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600336 Should Be Equal ${owner} ${args}
337
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600338 [Return] ${jsondata['status']}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500339
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500340
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500341Set Time Mode
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600342 [Arguments] ${args}
343 [Documentation] Set time mode of the system via REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500344
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600345 ${timemode}= Set Variable ${args}
346 ${valueDict}= Create Dictionary data=${timemode}
347
348 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500349 ... ${TIME_MANAGER_URI}sync_method/attr/TimeSyncMethod data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600350 ${jsondata}= to JSON ${resp.content}
351 Sleep 5s
352
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500353 ${mode}= Read Attribute ${TIME_MANAGER_URI}sync_method TimeSyncMethod
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600354 Should Be Equal ${mode} ${args}
355
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600356
357Get BMC Time Using REST
358 [Documentation] Returns BMC time of the system via REST
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500359 ... Time Format : epoch time in microseconds
360 ... e.g 1507809604687329
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600361
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500362 ${resp}= Read Attribute ${TIME_MANAGER_URI}/bmc Elapsed
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600363 [Return] ${resp}
364
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500365
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600366Get HOST Time Using REST
367 [Documentation] Returns HOST time of the system via REST
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500368 ... Time Format : epoch time in microseconds
369 ... e.g 1507809604687329
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600370
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500371 ${resp}= Read Attribute ${TIME_MANAGER_URI}/host Elapsed
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600372 [Return] ${resp}
373
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500374
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600375Set Time Using REST
376 [Arguments] ${operation} ${owner} ${mode} ${status} ${bmc_time}
377 ... ${host_time}
378 [Documentation] Set BMC or Host time on system via REST.
379 ... Description of arguments:
380 ... operation : Set BMC/Host time
381 ... owner: Time owner
382 ... mode: Time mode
383 ... status: Expected status of set BMC time URI
384 ... bmc_time: Status of BMC time after operation
385 ... host_time: Status of HOST time after operation
386 ... Set - Given time is set
387 ... Not Set - Given time is not set
388 ... Change - time is change
389 ... No Change - time is not change
390
391 Set Time Owner ${owner}
392 Set Time Mode ${mode}
393
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500394 ${setdate}= Set Variable ${SYSTEM_TIME_VALID_EPOCH}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600395
Sridevi Rameshae444822017-02-13 05:51:52 -0600396 ${start_time}= Get Current Date
397
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600398 ${old_bmc_time}= Get BMC Time Using REST
399 ${old_host_time}= Get HOST Time Using REST
400
Rahul Maheshwari52d92942019-01-21 10:54:52 -0600401 Run Keyword If '${operation}' == 'Set BMC Time'
402 ... Wait Until Keyword Succeeds 1 min 20 sec Verify Set Time Via REST
403 ... bmc ${status}
404 ... ELSE IF '${operation}' == 'Set Host Time'
405 ... Wait Until Keyword Succeeds 1 min 20 sec Verify Set Time Via REST
406 ... host ${status}
407
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600408
409 ${new_bmc_time}= Get BMC Time Using REST
410 ${new_host_time}= Get HOST Time Using REST
411
Sridevi Rameshae444822017-02-13 05:51:52 -0600412 ${end_time}= Get Current Date
413 ${time_duration}= Subtract Date From Date ${start_time} ${end_time}
414 ${time_duration} Evaluate abs(${time_duration})
415
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500416 # Convert epoch to date format: YYYY-MM-DD hh:mm:ss.mil
417 ${setdate}= Convert epoch to date ${setdate}
418 ${new_bmc_time}= Convert epoch to date ${new_bmc_time}
419 ${old_bmc_time}= Convert epoch to date ${old_bmc_time}
420 ${new_host_time}= Convert epoch to date ${new_host_time}
421 ${old_host_time}= Convert epoch to date ${old_host_time}
422
423
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600424 ${bmc_diff_set_new}=
425 ... Subtract Date From Date ${setdate} ${new_bmc_time}
426 ${bmc_diff_set_new}= Evaluate abs(${bmc_diff_set_new})
427 ${bmc_diff_old_new}=
428 ... Subtract Date From Date ${old_bmc_time} ${new_bmc_time}
429 ${bmc_diff_old_new}= Evaluate abs(${bmc_diff_old_new})
430
431 ${host_diff_set_new}=
432 ... Subtract Date From Date ${setdate} ${new_host_time}
433 ${host_diff_set_new}= Evaluate abs(${host_diff_set_new})
434 ${host_diff_old_new}=
435 ... Subtract Date From Date ${old_host_time} ${new_host_time}
436 ${host_diff_old_new}= Evaluate abs(${host_diff_old_new})
437
438 Run Keyword If '${bmc_time}' == 'Not Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600439 ... Should Be True ${bmc_diff_set_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600440 ... ELSE IF '${bmc_time}' == 'Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600441 ... Should Be True ${bmc_diff_set_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600442 ... ELSE IF '${bmc_time}' == 'No Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600443 ... Should Be True ${bmc_diff_old_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600444 ... ELSE IF '${bmc_time}' == 'Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600445 ... Should Be True ${bmc_diff_old_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600446
447 Run Keyword If '${host_time}' == 'No Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600448 ... Should Be True ${host_diff_old_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600449 ... ELSE IF '${host_time}' == 'Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600450 ... Should Be True ${host_diff_old_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600451 ... ELSE IF '${host_time}' == 'Not Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600452 ... Should Be True ${host_diff_set_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600453 ... ELSE IF '${host_time}' == 'Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600454 ... Should Be True ${host_diff_set_new} <= ${time_duration}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500455
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500456Convert epoch to date
457 [Documentation] Convert epoch time to date format.
458 [Arguments] ${epoch_time}
459 # Description of argument(s):
Rahul Maheshwari7e863322018-02-02 06:03:06 -0600460 # epoch_time epoch time in milliseconds.
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500461 # (e.g. 1487304700000000)
462
Rahul Maheshwari7e863322018-02-02 06:03:06 -0600463 # Convert epoch_time into floating point number.
464 ${epoch_time}= Convert To Number ${epoch_time}
465
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500466 # Convert epoch time from microseconds to seconds
467 ${epoch_time_sec}= Evaluate ${epoch_time}/1000000
468
469 # Convert epoch time to date format: YYYY-MM-DD hh:mm:ss.mil
470 # e.g. 2017-02-16 22:14:11.000
471 ${date}= Convert Date ${epoch_time_sec}
472
473 [Return] ${date}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500474
Rahul Maheshwari52d92942019-01-21 10:54:52 -0600475
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600476Post Test Case Execution
477 [Documentation] Do the post test teardown.
478 ... 1. Capture FFDC on test failure.
479 ... 2. Sets defaults for time mode and owner.
480 ... 3. Close all open SSH connections.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500481
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600482 FFDC On Test Case Fail
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500483 Set Time Owner ${BMC_OWNER}
484 Set Time Mode ${NTP_MODE}
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600485 Close All Connections