blob: 193c1e19bdaf85d8684ddb3850070c88fdc2fd57 [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
George Keishingab1bd922016-12-05 05:29:59 -06008Resource ../lib/resource.txt
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
41Set Valid System Time
Rahul Maheshwarif8785902016-12-12 01:23:13 -060042 [Documentation] Set system time using IPMI and verify that it is
43 ... correctly set in BMC.
George Keishing845fb822016-11-01 13:23:19 -050044 [Tags] Set_Valid_System_Time
Chris Austenb29d2e82016-06-07 12:25:35 -050045
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050046 Set Time Owner ${HOST_OWNER}
47 Set Time Mode ${MANUAL_MODE}
Rahul Maheshwari7588f872017-04-13 05:51:24 -050048
Rahul Maheshwarif8785902016-12-12 01:23:13 -060049 ${resp}= Run IPMI Standard Command sel time set "${SYSTEM_TIME_VALID}"
50 ${setdate}= Convert Date ${SYSTEM_TIME_VALID}
51 ... date_format=%m/%d/%Y %H:%M:%S exclude_millis=yes
52 ${bmcdate}= Get BMC Time Using IPMI
53 ${diff}= Subtract Date From Date ${bmcdate} ${setdate}
Sridevi Rameshae444822017-02-13 05:51:52 -060054 ${diff}= Convert To Number ${diff}
Rahul Maheshwarif8785902016-12-12 01:23:13 -060055 Should Be True ${diff} < ${ALLOWED_TIME_DIFF}
56 ... Open BMC time does not match with set time
Chris Austenb29d2e82016-06-07 12:25:35 -050057
58Set Invalid System Time
Rahul Maheshwarif8785902016-12-12 01:23:13 -060059 [Documentation] Set system time with invalid time using IPMI and verify
60 ... that it should throw error.
George Keishing845fb822016-11-01 13:23:19 -050061 [Tags] Set_Invalid_System_Time
Chris Austenb29d2e82016-06-07 12:25:35 -050062
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050063 Set Time Owner ${HOST_OWNER}
64 Set Time Mode ${MANUAL_MODE}
Rahul Maheshwari7588f872017-04-13 05:51:24 -050065
Rahul Maheshwarif8785902016-12-12 01:23:13 -060066 ${msg}= Run Keyword And Expect Error * Run IPMI Standard Command
67 ... sel time set "${SYSTEM_TIME_INVALID}"
68 Should Start With ${msg} Specified time could not be parsed
Chris Austenb29d2e82016-06-07 12:25:35 -050069
70Set System Time with no time
Rahul Maheshwarif8785902016-12-12 01:23:13 -060071 [Documentation] Set system time with no time using IPMI and verify
72 ... that it should throw error.
George Keishing845fb822016-11-01 13:23:19 -050073 [Tags] Set_System_Time_with_no_time
Chris Austenb29d2e82016-06-07 12:25:35 -050074
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050075 Set Time Owner ${HOST_OWNER}
76 Set Time Mode ${MANUAL_MODE}
Rahul Maheshwari7588f872017-04-13 05:51:24 -050077
Rahul Maheshwarif8785902016-12-12 01:23:13 -060078 ${msg}= Run Keyword And Expect Error * Run IPMI Standard Command
79 ... sel time set ""
80 Should Start With ${msg} Specified time could not be parsed
Chris Austenb29d2e82016-06-07 12:25:35 -050081
Rahul Maheshwari93f68092016-10-24 02:42:12 -050082
Rahul Maheshwarif8785902016-12-12 01:23:13 -060083Set BMC Time With BMC And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -060084 [Documentation] Set BMC time when time owner is BMC and time mode is
85 ... manual.
86 [Tags] Set_BMC_Time_With_BMC_And_Manual
87 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -050088
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050089 #Operation Owner Mode Status BMC Time Host Time
George Keishing5abfe602018-07-05 11:54:37 -050090 Set BMC Time ${BMC_OWNER} ${MANUAL_MODE} ok Set Change
Rahul Maheshwari93f68092016-10-24 02:42:12 -050091
George Keishing5abfe602018-07-05 11:54:37 -050092
93Set BMC Time With Both And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -060094 [Documentation] Set BMC time when time owner is Both and time mode is
95 ... manual.
96 [Tags] Set_BMC_Time_With_Both_And_Manual
97 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -050098
George Keishing5abfe602018-07-05 11:54:37 -050099 #Operation Owner Mode Status BMC Time Host Time
100 Set BMC Time ${BOTH_OWNER} ${MANUAL_MODE} ok Set Change
101
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500102
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600103Set BMC Time With Split And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600104 [Documentation] Set BMC time when time owner is Split and time mode is
105 ... manual.
106 [Tags] Set_BMC_Time_With_Split_And_Manual
107 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500108
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500109 #Operation Owner Mode Status BMC Time Host Time
George Keishing5abfe602018-07-05 11:54:37 -0500110 Set BMC Time ${SPLIT_OWNER} ${MANUAL_MODE} ok Set No Change
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500111
George Keishing5abfe602018-07-05 11:54:37 -0500112
113Set BMC Time With BMC And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600114 [Documentation] Set BMC time when time owner is BMC and time mode is
115 ... NTP.
116 [Tags] Set_BMC_Time_With_BMC_And_NTP
117 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500118
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500119 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500120 Set BMC Time ${BMC_OWNER} ${NTP_MODE} error Not Set No Change
George Keishing5abfe602018-07-05 11:54:37 -0500121
122
123Set BMC Time With Host And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600124 [Documentation] Set BMC time when time owner is Host and time mode is
125 ... Manual.
126 [Tags] Set_BMC_Time_With_Host_And_Manual
127 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500128
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500129 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500130 Set BMC Time ${HOST_OWNER} ${MANUAL_MODE} error Not Set No Change
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600131
George Keishing5abfe602018-07-05 11:54:37 -0500132
133Set BMC Time With Both And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600134 [Documentation] Set BMC time when time owner is Both and time mode is
135 ... NTP.
136 [Tags] Set_BMC_Time_With_Both_And_NTP
137 [Template] Set Time Using REST
138
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500139 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500140 Set BMC Time ${BOTH_OWNER} ${NTP_MODE} error Not Set No Change
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600141
George Keishing5abfe602018-07-05 11:54:37 -0500142
143Set BMC Time With Split And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600144 [Documentation] Set BMC time when time owner is Split and time mode is
145 ... NTP.
146 [Tags] Set_BMC_Time_With_Split_And_NTP
147 [Template] Set Time Using REST
148
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500149 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500150 Set BMC Time ${SPLIT_OWNER} ${NTP_MODE} error Not Set No Change
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500151
George Keishing5abfe602018-07-05 11:54:37 -0500152
153Set BMC Time With Host And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500154 [Documentation] Set BMC time when time owner is Host and time mode is
155 ... NTP.
156 [Tags] Set_BMC_Time_With_Host_And_NTP
157 [Template] Set Time Using REST
158
George Keishing5abfe602018-07-05 11:54:37 -0500159 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500160 Set BMC Time ${HOST_OWNER} ${NTP_MODE} error Not Set No Change
George Keishing5abfe602018-07-05 11:54:37 -0500161
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500162
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600163Set Host Time With Host And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600164 [Documentation] Set host time when time owner is host and time mode is
165 ... manual.
166 [Tags] Set_Host_Time_With_Host_And_Manual
167 [Template] Set Time Using REST
168
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500169 #Operation Owner Mode Status BMC Time Host Time
George Keishing5abfe602018-07-05 11:54:37 -0500170 Set Host Time ${HOST_OWNER} ${MANUAL_MODE} ok Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600171
George Keishing5abfe602018-07-05 11:54:37 -0500172
173Set Host Time With Both And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600174 [Documentation] Set host time when time owner is both and time mode is
175 ... manual.
176 [Tags] Set_Host_Time_With_Both_And_Manual
177 [Template] Set Time Using REST
178
George Keishing5abfe602018-07-05 11:54:37 -0500179 #Operation Owner Mode Status BMC Time Host Time
180 Set Host Time ${BOTH_OWNER} ${MANUAL_MODE} ok Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600181
George Keishing5abfe602018-07-05 11:54:37 -0500182
183Set Host Time With Both And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600184 [Documentation] Set host time when time owner is both and time mode is
185 ... NTP.
186 [Tags] Set_Host_Time_With_Both_And_NTP
187 [Template] Set Time Using REST
188
George Keishing5abfe602018-07-05 11:54:37 -0500189 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500190 Set Host Time ${BOTH_OWNER} ${NTP_MODE} error No Change Not Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600191
George Keishing5abfe602018-07-05 11:54:37 -0500192
193Set Host Time With Split And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600194 [Documentation] Set host time when time owner is split and time mode is
195 ... manual.
196 [Tags] Set_Host_Time_With_Split_And_Manual
197 [Template] Set Time Using REST
198
George Keishing5abfe602018-07-05 11:54:37 -0500199 #Operation Owner Mode Status BMC Time Host Time
200 Set Host Time ${SPLIT_OWNER} ${MANUAL_MODE} ok No Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600201
George Keishing5abfe602018-07-05 11:54:37 -0500202
203Set Host Time With Split And NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600204 [Documentation] Set host time when time owner is split and time mode is
205 ... NTP.
206 [Tags] Set_Host_Time_With_Split_And_NTP
207 [Template] Set Time Using REST
208
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500209 #Operation Owner Mode Status BMC Time HOST Time
George Keishing5abfe602018-07-05 11:54:37 -0500210 Set Host Time ${SPLIT_OWNER} ${NTP_MODE} ok No Change Set
211
212
213Set Host Time With BMC And Manual
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600214 [Documentation] Set host time when time owner is BMC and time mode is
215 ... Manual.
216 [Tags] Set_Host_Time_With_BMC_And_Manual
217 [Template] Set Time Using REST
218
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500219 #Operation Owner Mode Status BMC Time HOST Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500220 Set Host Time ${BMC_OWNER} ${MANUAL_MODE} error No Change Not Set
George Keishing5abfe602018-07-05 11:54:37 -0500221
222
223Set Host Time With BMC Owner NTP
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600224 [Documentation] Set host time when time owner is BMC and time mode is
225 ... NTP.
226 [Tags] Set_Host_Time_With_BMC_And_NTP
227 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500228
George Keishing5abfe602018-07-05 11:54:37 -0500229 #Operation Owner Mode Status BMC Time HOST Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500230 Set Host Time ${BMC_OWNER} ${NTP_MODE} error No Change Not Set
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500231
George Keishing5abfe602018-07-05 11:54:37 -0500232
233Set Host Time With Host And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500234 [Documentation] Set host time when time owner is Host and time mode is
235 ... NTP.
236 [Tags] Set_Host_Time_With_Host_And_NTP
237 [Template] Set Time Using REST
238
George Keishing5abfe602018-07-05 11:54:37 -0500239 #Operation Owner Mode Status BMC Time Host Time
Rahul Maheshwari8cc47172018-09-06 01:46:50 -0500240 Set Host Time ${HOST_OWNER} ${NTP_MODE} error Not Change No Set
George Keishing5abfe602018-07-05 11:54:37 -0500241
242
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500243Set Invalid Time Mode
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600244 [Documentation] Set time mode with invalid value using REST and verify
245 ... that it should throw error.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500246 [Tags] Set_Invalid_Time_Mode
247
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500248 ${timemode}=
249 ... Set Variable xyz.openbmc_project.Time.Synchronization.Method.abc
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600250 ${valueDict}= Create Dictionary data=${timemode}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500251
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600252 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500253 ... ${TIME_MANAGER_URI}sync_method/attr/TimeSyncMethod data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600254 ${jsondata}= to JSON ${resp.content}
255 Should Be Equal ${jsondata['status']} error
256
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500257 ${mode}= Read Attribute ${TIME_MANAGER_URI}sync_method TimeSyncMethod
258 Should Not Be Equal ${mode}
259 ... xyz.openbmc_project.Time.Synchronization.Method.abc
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500260
261Set Invalid Time Owner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600262 [Documentation] Set time owner with invalid value using REST and verify
263 ... that it should throw error.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500264 [Tags] Set_Invalid_Time_Owner
265
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500266 ${timeowner}= Set Variable xyz.openbmc_project.Time.Owner.Owners.xyz
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600267 ${valueDict}= Create Dictionary data=${timeowner}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500268
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600269 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500270 ... ${TIME_MANAGER_URI}owner/attr/TimeOwner data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600271 ${jsondata}= to JSON ${resp.content}
272 Should Be Equal ${jsondata['status']} error
273
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500274 ${owner}= Read Attribute ${TIME_MANAGER_URI}owner TimeOwner
275 Should Not Be Equal ${owner} xyz.openbmc_project.Time.Owner.Owners.xyz
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500276
277
Chris Austenb29d2e82016-06-07 12:25:35 -0500278*** Keywords ***
279
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600280Get BMC Time Using IPMI
281 [Documentation] Returns BMC time of the system via IPMI
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500282
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600283 ${stdout} ${stderr} ${output}=
284 ... Execute Command date "+%m/%d/%Y %H:%M:%S"
285 ... return_stdout=True return_stderr= True return_rc=True
286 Should Be Equal ${output} ${0} msg=${stderr}
287
288 ${resp}= Convert Date ${stdout} date_format=%m/%d/%Y %H:%M:%S
289 ... exclude_millis=yes
290 Should Not Be Empty ${resp}
291 [Return] ${resp}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500292
293Set Time Owner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600294 [Arguments] ${args}
295 [Documentation] Set time owner of the system via REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500296
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600297 ${timeowner}= Set Variable ${args}
298 ${valueDict}= Create Dictionary data=${timeowner}
299
300 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500301 ... ${TIME_MANAGER_URI}owner/attr/TimeOwner data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600302 ${jsondata}= to JSON ${resp.content}
303
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600304 ${host_state}= Get Host State
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600305
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600306 Run Keyword If '${host_state}' == 'Off'
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600307 ... Log System is in off state so owner change will get applied.
308 ... ELSE Run keyword
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600309 ... Initiate Host PowerOff
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600310
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500311 ${owner}= Read Attribute ${TIME_MANAGER_URI}owner TimeOwner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600312 Should Be Equal ${owner} ${args}
313
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600314 [Return] ${jsondata['status']}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500315
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500316
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500317Set Time Mode
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600318 [Arguments] ${args}
319 [Documentation] Set time mode of the system via REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500320
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600321 ${timemode}= Set Variable ${args}
322 ${valueDict}= Create Dictionary data=${timemode}
323
324 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500325 ... ${TIME_MANAGER_URI}sync_method/attr/TimeSyncMethod data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600326 ${jsondata}= to JSON ${resp.content}
327 Sleep 5s
328
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500329 ${mode}= Read Attribute ${TIME_MANAGER_URI}sync_method TimeSyncMethod
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600330 Should Be Equal ${mode} ${args}
331
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600332
333Get BMC Time Using REST
334 [Documentation] Returns BMC time of the system via REST
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500335 ... Time Format : epoch time in microseconds
336 ... e.g 1507809604687329
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600337
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500338 ${resp}= Read Attribute ${TIME_MANAGER_URI}/bmc Elapsed
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600339 [Return] ${resp}
340
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500341
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600342Get HOST Time Using REST
343 [Documentation] Returns HOST time of the system via REST
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500344 ... Time Format : epoch time in microseconds
345 ... e.g 1507809604687329
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600346
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500347 ${resp}= Read Attribute ${TIME_MANAGER_URI}/host Elapsed
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600348 [Return] ${resp}
349
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500350
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600351Set Time Using REST
352 [Arguments] ${operation} ${owner} ${mode} ${status} ${bmc_time}
353 ... ${host_time}
354 [Documentation] Set BMC or Host time on system via REST.
355 ... Description of arguments:
356 ... operation : Set BMC/Host time
357 ... owner: Time owner
358 ... mode: Time mode
359 ... status: Expected status of set BMC time URI
360 ... bmc_time: Status of BMC time after operation
361 ... host_time: Status of HOST time after operation
362 ... Set - Given time is set
363 ... Not Set - Given time is not set
364 ... Change - time is change
365 ... No Change - time is not change
366
367 Set Time Owner ${owner}
368 Set Time Mode ${mode}
369
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500370 ${setdate}= Set Variable ${SYSTEM_TIME_VALID_EPOCH}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600371
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500372 ${time_owner_url}= Set Variable If
373 ... '${operation}' == 'Set BMC Time' ${TIME_MANAGER_URI}bmc
374 ... '${operation}' == 'Set Host Time' ${TIME_MANAGER_URI}host
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600375
Sridevi Rameshae444822017-02-13 05:51:52 -0600376 ${start_time}= Get Current Date
377
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600378 ${old_bmc_time}= Get BMC Time Using REST
379 ${old_host_time}= Get HOST Time Using REST
380
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500381 ${valueDict}= Create Dictionary data=${SYSTEM_TIME_VALID_EPOCH}
382 ${resp}= OpenBMC Put Request
383 ... ${time_owner_url}/attr/Elapsed data=${valueDict}
384 ${jsondata}= to JSON ${resp.content}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600385 Should Be Equal As Strings ${jsondata['status']} ${status}
386
387 ${new_bmc_time}= Get BMC Time Using REST
388 ${new_host_time}= Get HOST Time Using REST
389
Sridevi Rameshae444822017-02-13 05:51:52 -0600390 ${end_time}= Get Current Date
391 ${time_duration}= Subtract Date From Date ${start_time} ${end_time}
392 ${time_duration} Evaluate abs(${time_duration})
393
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500394 # Convert epoch to date format: YYYY-MM-DD hh:mm:ss.mil
395 ${setdate}= Convert epoch to date ${setdate}
396 ${new_bmc_time}= Convert epoch to date ${new_bmc_time}
397 ${old_bmc_time}= Convert epoch to date ${old_bmc_time}
398 ${new_host_time}= Convert epoch to date ${new_host_time}
399 ${old_host_time}= Convert epoch to date ${old_host_time}
400
401
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600402 ${bmc_diff_set_new}=
403 ... Subtract Date From Date ${setdate} ${new_bmc_time}
404 ${bmc_diff_set_new}= Evaluate abs(${bmc_diff_set_new})
405 ${bmc_diff_old_new}=
406 ... Subtract Date From Date ${old_bmc_time} ${new_bmc_time}
407 ${bmc_diff_old_new}= Evaluate abs(${bmc_diff_old_new})
408
409 ${host_diff_set_new}=
410 ... Subtract Date From Date ${setdate} ${new_host_time}
411 ${host_diff_set_new}= Evaluate abs(${host_diff_set_new})
412 ${host_diff_old_new}=
413 ... Subtract Date From Date ${old_host_time} ${new_host_time}
414 ${host_diff_old_new}= Evaluate abs(${host_diff_old_new})
415
416 Run Keyword If '${bmc_time}' == 'Not Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600417 ... Should Be True ${bmc_diff_set_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600418 ... ELSE IF '${bmc_time}' == 'Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600419 ... Should Be True ${bmc_diff_set_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600420 ... ELSE IF '${bmc_time}' == 'No Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600421 ... Should Be True ${bmc_diff_old_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600422 ... ELSE IF '${bmc_time}' == 'Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600423 ... Should Be True ${bmc_diff_old_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600424
425 Run Keyword If '${host_time}' == 'No Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600426 ... Should Be True ${host_diff_old_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600427 ... ELSE IF '${host_time}' == 'Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600428 ... Should Be True ${host_diff_old_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600429 ... ELSE IF '${host_time}' == 'Not Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600430 ... Should Be True ${host_diff_set_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600431 ... ELSE IF '${host_time}' == 'Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600432 ... Should Be True ${host_diff_set_new} <= ${time_duration}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500433
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500434Convert epoch to date
435 [Documentation] Convert epoch time to date format.
436 [Arguments] ${epoch_time}
437 # Description of argument(s):
Rahul Maheshwari7e863322018-02-02 06:03:06 -0600438 # epoch_time epoch time in milliseconds.
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500439 # (e.g. 1487304700000000)
440
Rahul Maheshwari7e863322018-02-02 06:03:06 -0600441 # Convert epoch_time into floating point number.
442 ${epoch_time}= Convert To Number ${epoch_time}
443
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500444 # Convert epoch time from microseconds to seconds
445 ${epoch_time_sec}= Evaluate ${epoch_time}/1000000
446
447 # Convert epoch time to date format: YYYY-MM-DD hh:mm:ss.mil
448 # e.g. 2017-02-16 22:14:11.000
449 ${date}= Convert Date ${epoch_time_sec}
450
451 [Return] ${date}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500452
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600453Post Test Case Execution
454 [Documentation] Do the post test teardown.
455 ... 1. Capture FFDC on test failure.
456 ... 2. Sets defaults for time mode and owner.
457 ... 3. Close all open SSH connections.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500458
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600459 FFDC On Test Case Fail
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500460 Set Time Owner ${BMC_OWNER}
461 Set Time Mode ${NTP_MODE}
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600462 Close All Connections