1*** 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 8Resource ../../lib/rest_client.robot 9Library ../../lib/gen_robot_valid.py 10 11Test Setup Printn 12Test Teardown Test Teardown Execution 13Suite Setup Suite Setup Execution 14Suite Teardown Suite Teardown Execution 15 16*** Variables *** 17${max_time_diff_in_seconds} 6 18# 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 22${invalid_datetime} "2019-04-251T12:24:46+00:00" 23${ntp_server_1} "9.9.9.9" 24${ntp_server_2} "2.2.3.3" 25&{original_ntp} &{EMPTY} 26 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 44Verify Set Time Using Redfish 45 [Documentation] Verify set time using redfish API. 46 [Tags] Verify_Set_Time_Using_Redfish 47 48 Set Time To Manual Mode 49 50 ${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 65Verify 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} 76 Rprint Vars date_time_with_offset expected_date_time cli_bmc_time 77 ... date_time_diff max_time_diff_in_seconds 78 Valid Range date_time_diff 0 ${max_time_diff_in_seconds} 79 80 81Verify 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 88Verify 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 107Verify NTP Server Set 108 [Documentation] Verify NTP server set. 109 [Tags] Verify_NTP_Server_Set 110 111 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} 112 ... body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_2}']}} 113 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] 114 ${network_protocol}= Redfish.Get Properties ${REDFISH_NW_PROTOCOL_URI} 115 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_1} 116 ... msg=NTP server value ${ntp_server_1} not stored. 117 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_2} 118 ... msg=NTP server value ${ntp_server_2} not stored. 119 120 121Verify NTP Server Value Not Duplicated 122 [Documentation] Verify NTP servers value not same for both primary and secondary server. 123 [Tags] Verify_NTP_Server_Value_Not_Duplicated 124 125 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} 126 ... body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_1}']}} 127 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] 128 ${network_protocol}= Redfish.Get Properties ${REDFISH_NW_PROTOCOL_URI} 129 Should Contain X Times ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_1} 1 130 ... msg=NTP primary and secondary server values should not be same. 131 132 133Verify NTP Server Setting Persist After BMC Reboot 134 [Documentation] Verify NTP server setting persist after BMC reboot. 135 [Tags] Verify_NTP_Server_Setting_Persist_After_BMC_Reboot 136 137 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} 138 ... body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_2}']}} 139 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] 140 Redfish OBMC Reboot (off) 141 Redfish.Login 142 ${network_protocol}= Redfish.Get Properties ${REDFISH_NW_PROTOCOL_URI} 143 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_1} 144 ... msg=NTP server value ${ntp_server_1} not stored. 145 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_2} 146 ... msg=NTP server value ${ntp_server_2} not stored. 147 148 149Verify Enable NTP 150 [Documentation] Verify NTP protocol mode can be enabled. 151 [Teardown] Restore NTP Mode 152 [Tags] Verify_Enable_NTP 153 154 ${original_ntp}= Redfish.Get Attribute ${REDFISH_NW_PROTOCOL_URI} NTP 155 Set Suite Variable ${original_ntp} 156 Rprint Vars original_ntp 157 # The following patch command should set the ["NTP"]["ProtocolEnabled"] property to "True". 158 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'ProtocolEnabled': ${True}}} 159 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] 160 ${ntp}= Redfish.Get Attribute ${REDFISH_NW_PROTOCOL_URI} NTP 161 Rprint Vars ntp 162 Valid Value ntp["ProtocolEnabled"] valid_values=[True] 163 164 165Verify Immediate Consumption Of BMC Date 166 [Documentation] Verify immediate change in BMC date time. 167 [Tags] Verify_Immediate_Consumption_Of_BMC_Date 168 [Setup] Run Keywords Set Time To Manual Mode AND 169 ... Redfish Set DateTime valid_status_codes=[${HTTP_OK}] 170 [Teardown] Run Keywords FFDC On Test Case Fail AND 171 ... Redfish Set DateTime valid_status_codes=[${HTTP_OK}] 172 [Template] Set BMC Date And Verify 173 174 # host_state 175 on 176 off 177 178 179*** Keywords *** 180 181 182Test Teardown Execution 183 [Documentation] Do the post test teardown. 184 185 FFDC On Test Case Fail 186 187 188Redfish Get DateTime 189 [Documentation] Returns BMC Datetime value from Redfish. 190 191 ${date_time}= Redfish.Get Attribute ${REDFISH_BASE_URI}Managers/bmc DateTime 192 [Return] ${date_time} 193 194 195Redfish Set DateTime 196 [Documentation] Set DateTime using Redfish. 197 [Arguments] ${date_time}=${EMPTY} &{kwargs} 198 # Description of argument(s): 199 # date_time New time to set for BMC (eg. 200 # "2019-06-30 09:21:28"). If this value is 201 # empty, it will be set to the UTC current 202 # date time of the local system. 203 # kwargs Additional parms to be passed directly to 204 # th Redfish.Patch function. A good use for 205 # this is when testing a bad date-time, the 206 # caller can specify 207 # valid_status_codes=[${HTTP_BAD_REQUEST}]. 208 209 # Assign default value of UTC current date time if date_time is empty. 210 ${date_time}= Run Keyword If 211 ... '${date_time}' == '${EMPTY}' Get Current Date time_zone=UTC 212 ... ELSE 213 ... Set Variable ${date_time} 214 Wait Until Keyword Succeeds 1min 5sec 215 ... Redfish.Patch ${REDFISH_BASE_URI}Managers/bmc body={'DateTime': '${date_time}'} &{kwargs} 216 217 218Set Time To Manual Mode 219 [Documentation] Set date time to manual mode via REST. 220 221 ${data}= Create Dictionary data=${MANUAL_MODE} 222 Write Attribute ${TIME_MANAGER_URI}sync_method TimeSyncMethod data=${data} verify=${TRUE} 223 224 225Restore NTP Mode 226 [Documentation] Restore the original NTP mode. 227 228 229 Return From Keyword If &{original_ntp} == &{EMPTY} 230 Print Timen Restore NTP Mode. 231 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} 232 ... body={'NTP':{'ProtocolEnabled': ${original_ntp["ProtocolEnabled"]}}} 233 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] 234 235 236Suite Setup Execution 237 [Documentation] Do the suite level setup. 238 239 Printn 240 Redfish.Login 241 Get NTP Initial Status 242 Set Time To Manual Mode 243 Set NTP state ${FALSE} 244 245 246Suite Teardown Execution 247 [Documentation] Do the suite level teardown. 248 249 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} 250 ... body={'NTP':{'NTPServers': ['${EMPTY}', '${EMPTY}']}} 251 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] 252 Set Time To Manual Mode 253 Restore NTP Status 254 Redfish.Logout 255 256 257Set NTP state 258 [Documentation] Set NTP service inactive. 259 [Arguments] ${state} 260 261 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'ProtocolEnabled': ${state}}} 262 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] 263 264 265Get NTP Initial Status 266 [Documentation] Get NTP service Status. 267 268 ${original_ntp}= Redfish.Get Attribute ${REDFISH_NW_PROTOCOL_URI} NTP 269 Set Suite Variable ${original_ntp} 270 271 272Restore NTP Status 273 [Documentation] Restore NTP Status. 274 275 Run Keyword If '${original_ntp["ProtocolEnabled"]}' == 'True' 276 ... Set NTP state ${TRUE} 277 ... ELSE Set NTP state ${FALSE} 278 279 280Set BMC Date And Verify 281 [Documentation] Set BMC Date Time at a given host state and verify. 282 [Arguments] ${host_state} 283 # Description of argument(s): 284 # host_state Host state at which date time will be updated for verification 285 # (eg. on, off). 286 287 Run Keyword If '${host_state}' == 'on' 288 ... Redfish Power On stack_mode=skip 289 ... ELSE 290 ... Redfish Power off stack_mode=skip 291 ${current_date}= Get Current Date time_zone=UTC 292 ${new_value}= Subtract Time From Date ${current_date} 1 day 293 Redfish Set DateTime ${new_value} valid_status_codes=[${HTTP_OK}] 294 ${current_value}= Redfish Get DateTime 295 ${time_diff}= Subtract Date From Date ${current_value} ${new_value} 296 Should Be True '${time_diff}'<='3' 297