blob: 728ce834856016fac4cee5ca397be964e77244b5 [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 Maheshwarif486ae82017-10-24 06:10:14 -050084 #Operation Owner Mode Status BMC Time Host Time
85 Set BMC Time ${BMC_OWNER} ${MANUAL_MODE} ok Set Change
Rahul Maheshwari93f68092016-10-24 02:42:12 -050086
Rahul Maheshwarif8785902016-12-12 01:23:13 -060087 [Documentation] Set BMC time when time owner is BMC and time mode is
88 ... manual.
89 [Tags] Set_BMC_Time_With_BMC_And_Manual
90 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -050091
Rahul Maheshwarif8785902016-12-12 01:23:13 -060092Set BMC Time With Both And Manual
Rahul Maheshwarif486ae82017-10-24 06:10:14 -050093 #Operation Owner Mode Status BMC Time Host Time
94 Set BMC Time ${BOTH_OWNER} ${MANUAL_MODE} ok Set Change
Rahul Maheshwari93f68092016-10-24 02:42:12 -050095
Rahul Maheshwarif8785902016-12-12 01:23:13 -060096 [Documentation] Set BMC time when time owner is Both and time mode is
97 ... manual.
98 [Tags] Set_BMC_Time_With_Both_And_Manual
99 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500100
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500101
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600102Set BMC Time With Split And Manual
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500103 #Operation Owner Mode Status BMC Time Host Time
104 Set BMC Time ${SPLIT_OWNER} ${MANUAL_MODE} ok Set No Change
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500105
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600106 [Documentation] Set BMC time when time owner is Split and time mode is
107 ... manual.
108 [Tags] Set_BMC_Time_With_Split_And_Manual
109 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500110
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600111Set BMC Time With BMC And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500112 #Operation Owner Mode Status BMC Time Host Time
113 Set BMC Time ${BMC_OWNER} ${NTP_MODE} ok Not Set No Change
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500114
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600115 [Documentation] Set BMC time when time owner is BMC and time mode is
116 ... NTP.
117 [Tags] Set_BMC_Time_With_BMC_And_NTP
118 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500119
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600120Set BMC Time With Host And Manual
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500121 #Operation Owner Mode Status BMC Time Host Time
122 Set BMC Time ${HOST_OWNER} ${MANUAL_MODE} ok Not Set No Change
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600123 [Documentation] Set BMC time when time owner is Host and time mode is
124 ... Manual.
125 [Tags] Set_BMC_Time_With_Host_And_Manual
126 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500127
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600128Set BMC Time With Both And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500129 #Operation Owner Mode Status BMC Time Host Time
130 Set BMC Time ${BOTH_OWNER} ${NTP_MODE} ok Not Set No Change
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600131
132 [Documentation] Set BMC time when time owner is Both and time mode is
133 ... NTP.
134 [Tags] Set_BMC_Time_With_Both_And_NTP
135 [Template] Set Time Using REST
136
137Set BMC Time With Split And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500138 #Operation Owner Mode Status BMC Time Host Time
139 Set BMC Time ${SPLIT_OWNER} ${NTP_MODE} ok Not Set No Change
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600140
141 [Documentation] Set BMC time when time owner is Split and time mode is
142 ... NTP.
143 [Tags] Set_BMC_Time_With_Split_And_NTP
144 [Template] Set Time Using REST
145
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500146Set BMC Time With Host And NTP
147 #Operation Owner Mode Status BMC Time Host Time
148 Set BMC Time ${HOST_OWNER} ${NTP_MODE} ok Not Set No Change
149
150 [Documentation] Set BMC time when time owner is Host and time mode is
151 ... NTP.
152 [Tags] Set_BMC_Time_With_Host_And_NTP
153 [Template] Set Time Using REST
154
155
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600156Set Host Time With Host And Manual
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500157 #Operation Owner Mode Status BMC Time Host Time
158 Set Host Time ${HOST_OWNER} ${MANUAL_MODE} ok Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600159
160 [Documentation] Set host time when time owner is host and time mode is
161 ... manual.
162 [Tags] Set_Host_Time_With_Host_And_Manual
163 [Template] Set Time Using REST
164
165Set Host Time With Both And Manual
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500166 #Operation Owner Mode Status BMC Time Host Time
167 Set Host Time ${BOTH_OWNER} ${MANUAL_MODE} ok Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600168
169 [Documentation] Set host time when time owner is both and time mode is
170 ... manual.
171 [Tags] Set_Host_Time_With_Both_And_Manual
172 [Template] Set Time Using REST
173
174Set Host Time With Both And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500175 #Operation Owner Mode Status BMC Time Host Time
176 Set Host Time ${BOTH_OWNER} ${NTP_MODE} ok No Change Not Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600177
178 [Documentation] Set host time when time owner is both and time mode is
179 ... NTP.
180 [Tags] Set_Host_Time_With_Both_And_NTP
181 [Template] Set Time Using REST
182
183Set Host Time With Split And Manual
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500184 #Operation Owner Mode Status BMC Time Host Time
185 Set Host Time ${SPLIT_OWNER} ${MANUAL_MODE} ok No Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600186
187 [Documentation] Set host time when time owner is split and time mode is
188 ... manual.
189 [Tags] Set_Host_Time_With_Split_And_Manual
190 [Template] Set Time Using REST
191
192Set Host Time With Split And NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500193 #Operation Owner Mode Status BMC Time HOST Time
194 Set Host Time ${SPLIT_OWNER} ${NTP_MODE} ok No Change Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600195
196 [Documentation] Set host time when time owner is split and time mode is
197 ... NTP.
198 [Tags] Set_Host_Time_With_Split_And_NTP
199 [Template] Set Time Using REST
200
201Set Host Time With BMC And Manual
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500202 #Operation Owner Mode Status BMC Time HOST Time
203 Set Host Time ${BMC_OWNER} ${MANUAL_MODE} ok No Change Not Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600204 [Documentation] Set host time when time owner is BMC and time mode is
205 ... Manual.
206 [Tags] Set_Host_Time_With_BMC_And_Manual
207 [Template] Set Time Using REST
208
209Set Host Time With BMC Owner NTP
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500210 #Operation Owner Mode Status BMC Time HOST Time
211 Set Host Time ${BMC_OWNER} ${NTP_MODE} ok No Change Not Set
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600212 [Documentation] Set host time when time owner is BMC and time mode is
213 ... NTP.
214 [Tags] Set_Host_Time_With_BMC_And_NTP
215 [Template] Set Time Using REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500216
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500217Set Host Time With Host And NTP
218 #Operation Owner Mode Status BMC Time Host Time
219 Set Host Time ${HOST_OWNER} ${NTP_MODE} ok Not Change No Set
220
221 [Documentation] Set host time when time owner is Host and time mode is
222 ... NTP.
223 [Tags] Set_Host_Time_With_Host_And_NTP
224 [Template] Set Time Using REST
225
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500226Set Invalid Time Mode
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600227 [Documentation] Set time mode with invalid value using REST and verify
228 ... that it should throw error.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500229 [Tags] Set_Invalid_Time_Mode
230
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500231 ${timemode}=
232 ... Set Variable xyz.openbmc_project.Time.Synchronization.Method.abc
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600233 ${valueDict}= Create Dictionary data=${timemode}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500234
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600235 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500236 ... ${TIME_MANAGER_URI}sync_method/attr/TimeSyncMethod data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600237 ${jsondata}= to JSON ${resp.content}
238 Should Be Equal ${jsondata['status']} error
239
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500240 ${mode}= Read Attribute ${TIME_MANAGER_URI}sync_method TimeSyncMethod
241 Should Not Be Equal ${mode}
242 ... xyz.openbmc_project.Time.Synchronization.Method.abc
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500243
244Set Invalid Time Owner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600245 [Documentation] Set time owner with invalid value using REST and verify
246 ... that it should throw error.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500247 [Tags] Set_Invalid_Time_Owner
248
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500249 ${timeowner}= Set Variable xyz.openbmc_project.Time.Owner.Owners.xyz
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600250 ${valueDict}= Create Dictionary data=${timeowner}
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}owner/attr/TimeOwner 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 ${owner}= Read Attribute ${TIME_MANAGER_URI}owner TimeOwner
258 Should Not Be Equal ${owner} xyz.openbmc_project.Time.Owner.Owners.xyz
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500259
260
Chris Austenb29d2e82016-06-07 12:25:35 -0500261*** Keywords ***
262
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600263Get BMC Time Using IPMI
264 [Documentation] Returns BMC time of the system via IPMI
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500265
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600266 ${stdout} ${stderr} ${output}=
267 ... Execute Command date "+%m/%d/%Y %H:%M:%S"
268 ... return_stdout=True return_stderr= True return_rc=True
269 Should Be Equal ${output} ${0} msg=${stderr}
270
271 ${resp}= Convert Date ${stdout} date_format=%m/%d/%Y %H:%M:%S
272 ... exclude_millis=yes
273 Should Not Be Empty ${resp}
274 [Return] ${resp}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500275
276Set Time Owner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600277 [Arguments] ${args}
278 [Documentation] Set time owner of the system via REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500279
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600280 ${timeowner}= Set Variable ${args}
281 ${valueDict}= Create Dictionary data=${timeowner}
282
283 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500284 ... ${TIME_MANAGER_URI}owner/attr/TimeOwner data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600285 ${jsondata}= to JSON ${resp.content}
286
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600287 ${host_state}= Get Host State
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600288
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600289 Run Keyword If '${host_state}' == 'Off'
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600290 ... Log System is in off state so owner change will get applied.
291 ... ELSE Run keyword
Rahul Maheshwari2c725042017-01-29 22:55:28 -0600292 ... Initiate Host PowerOff
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600293
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500294 ${owner}= Read Attribute ${TIME_MANAGER_URI}owner TimeOwner
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600295 Should Be Equal ${owner} ${args}
296
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600297 [Return] ${jsondata['status']}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500298
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500299
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500300Set Time Mode
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600301 [Arguments] ${args}
302 [Documentation] Set time mode of the system via REST
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500303
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600304 ${timemode}= Set Variable ${args}
305 ${valueDict}= Create Dictionary data=${timemode}
306
307 ${resp}= OpenBMC Put Request
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500308 ... ${TIME_MANAGER_URI}sync_method/attr/TimeSyncMethod data=${valueDict}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600309 ${jsondata}= to JSON ${resp.content}
310 Sleep 5s
311
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500312 ${mode}= Read Attribute ${TIME_MANAGER_URI}sync_method TimeSyncMethod
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600313 Should Be Equal ${mode} ${args}
314
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600315
316Get BMC Time Using REST
317 [Documentation] Returns BMC time of the system via REST
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500318 ... Time Format : epoch time in microseconds
319 ... e.g 1507809604687329
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600320
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500321 ${resp}= Read Attribute ${TIME_MANAGER_URI}/bmc Elapsed
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600322 [Return] ${resp}
323
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500324
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600325Get HOST Time Using REST
326 [Documentation] Returns HOST time of the system via REST
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500327 ... Time Format : epoch time in microseconds
328 ... e.g 1507809604687329
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600329
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500330 ${resp}= Read Attribute ${TIME_MANAGER_URI}/host Elapsed
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600331 [Return] ${resp}
332
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500333
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600334Set Time Using REST
335 [Arguments] ${operation} ${owner} ${mode} ${status} ${bmc_time}
336 ... ${host_time}
337 [Documentation] Set BMC or Host time on system via REST.
338 ... Description of arguments:
339 ... operation : Set BMC/Host time
340 ... owner: Time owner
341 ... mode: Time mode
342 ... status: Expected status of set BMC time URI
343 ... bmc_time: Status of BMC time after operation
344 ... host_time: Status of HOST time after operation
345 ... Set - Given time is set
346 ... Not Set - Given time is not set
347 ... Change - time is change
348 ... No Change - time is not change
349
350 Set Time Owner ${owner}
351 Set Time Mode ${mode}
352
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500353 ${setdate}= Set Variable ${SYSTEM_TIME_VALID_EPOCH}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600354
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500355 ${time_owner_url}= Set Variable If
356 ... '${operation}' == 'Set BMC Time' ${TIME_MANAGER_URI}bmc
357 ... '${operation}' == 'Set Host Time' ${TIME_MANAGER_URI}host
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600358
Sridevi Rameshae444822017-02-13 05:51:52 -0600359 ${start_time}= Get Current Date
360
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600361 ${old_bmc_time}= Get BMC Time Using REST
362 ${old_host_time}= Get HOST Time Using REST
363
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500364 ${valueDict}= Create Dictionary data=${SYSTEM_TIME_VALID_EPOCH}
365 ${resp}= OpenBMC Put Request
366 ... ${time_owner_url}/attr/Elapsed data=${valueDict}
367 ${jsondata}= to JSON ${resp.content}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600368 Should Be Equal As Strings ${jsondata['status']} ${status}
369
370 ${new_bmc_time}= Get BMC Time Using REST
371 ${new_host_time}= Get HOST Time Using REST
372
Sridevi Rameshae444822017-02-13 05:51:52 -0600373 ${end_time}= Get Current Date
374 ${time_duration}= Subtract Date From Date ${start_time} ${end_time}
375 ${time_duration} Evaluate abs(${time_duration})
376
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500377 # Convert epoch to date format: YYYY-MM-DD hh:mm:ss.mil
378 ${setdate}= Convert epoch to date ${setdate}
379 ${new_bmc_time}= Convert epoch to date ${new_bmc_time}
380 ${old_bmc_time}= Convert epoch to date ${old_bmc_time}
381 ${new_host_time}= Convert epoch to date ${new_host_time}
382 ${old_host_time}= Convert epoch to date ${old_host_time}
383
384
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600385 ${bmc_diff_set_new}=
386 ... Subtract Date From Date ${setdate} ${new_bmc_time}
387 ${bmc_diff_set_new}= Evaluate abs(${bmc_diff_set_new})
388 ${bmc_diff_old_new}=
389 ... Subtract Date From Date ${old_bmc_time} ${new_bmc_time}
390 ${bmc_diff_old_new}= Evaluate abs(${bmc_diff_old_new})
391
392 ${host_diff_set_new}=
393 ... Subtract Date From Date ${setdate} ${new_host_time}
394 ${host_diff_set_new}= Evaluate abs(${host_diff_set_new})
395 ${host_diff_old_new}=
396 ... Subtract Date From Date ${old_host_time} ${new_host_time}
397 ${host_diff_old_new}= Evaluate abs(${host_diff_old_new})
398
399 Run Keyword If '${bmc_time}' == 'Not Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600400 ... Should Be True ${bmc_diff_set_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600401 ... ELSE IF '${bmc_time}' == 'Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600402 ... Should Be True ${bmc_diff_set_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600403 ... ELSE IF '${bmc_time}' == 'No Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600404 ... Should Be True ${bmc_diff_old_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600405 ... ELSE IF '${bmc_time}' == 'Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600406 ... Should Be True ${bmc_diff_old_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600407
408 Run Keyword If '${host_time}' == 'No Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600409 ... Should Be True ${host_diff_old_new} <= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600410 ... ELSE IF '${host_time}' == 'Change'
Sridevi Rameshae444822017-02-13 05:51:52 -0600411 ... Should Be True ${host_diff_old_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600412 ... ELSE IF '${host_time}' == 'Not Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600413 ... Should Be True ${host_diff_set_new} >= ${time_duration}
Rahul Maheshwarif8785902016-12-12 01:23:13 -0600414 ... ELSE IF '${host_time}' == 'Set'
Sridevi Rameshae444822017-02-13 05:51:52 -0600415 ... Should Be True ${host_diff_set_new} <= ${time_duration}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500416
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500417Convert epoch to date
418 [Documentation] Convert epoch time to date format.
419 [Arguments] ${epoch_time}
420 # Description of argument(s):
Rahul Maheshwari7e863322018-02-02 06:03:06 -0600421 # epoch_time epoch time in milliseconds.
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500422 # (e.g. 1487304700000000)
423
Rahul Maheshwari7e863322018-02-02 06:03:06 -0600424 # Convert epoch_time into floating point number.
425 ${epoch_time}= Convert To Number ${epoch_time}
426
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500427 # Convert epoch time from microseconds to seconds
428 ${epoch_time_sec}= Evaluate ${epoch_time}/1000000
429
430 # Convert epoch time to date format: YYYY-MM-DD hh:mm:ss.mil
431 # e.g. 2017-02-16 22:14:11.000
432 ${date}= Convert Date ${epoch_time_sec}
433
434 [Return] ${date}
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500435
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600436Post Test Case Execution
437 [Documentation] Do the post test teardown.
438 ... 1. Capture FFDC on test failure.
439 ... 2. Sets defaults for time mode and owner.
440 ... 3. Close all open SSH connections.
Rahul Maheshwari93f68092016-10-24 02:42:12 -0500441
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600442 FFDC On Test Case Fail
Rahul Maheshwarif486ae82017-10-24 06:10:14 -0500443 Set Time Owner ${BMC_OWNER}
444 Set Time Mode ${NTP_MODE}
Rahul Maheshwari06174f22017-03-06 03:17:09 -0600445 Close All Connections