blob: 6dde95cc24b77df222cf4082d3311d3423dc2d1d [file] [log] [blame]
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -05001*** Settings ***
2Documentation This module provides general keywords for date time and ntp.
3
4Resource ../../lib/resource.robot
5Resource ../../lib/bmc_redfish_resource.robot
6Resource ../../lib/common_utils.robot
7Resource ../../lib/openbmc_ffdc.robot
8Resource ../../lib/utils.robot
9Resource ../../lib/rest_client.robot
10Library ../../lib/gen_robot_valid.py
11
12*** Variables ***
13
14${year_without_ntp} 1970
15
16*** Keywords ***
17
18
19Redfish Get DateTime
20 [Documentation] Returns BMC Datetime value from Redfish.
21
22 ${date_time}= Redfish.Get Attribute ${REDFISH_BASE_URI}Managers/${MANAGER_ID} DateTime
23 RETURN ${date_time}
24
25
26Redfish Set DateTime
27 [Documentation] Set DateTime using Redfish.
sarandev34055c962025-03-25 00:49:55 -050028 [Arguments] ${date_time}=${EMPTY} ${request_type}=valid
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -050029 # Description of argument(s):
30 # date_time New time to set for BMC (eg.
31 # "2019-06-30 09:21:28"). If this value is
32 # empty, it will be set to the UTC current
33 # date time of the local system.
sarandev34055c962025-03-25 00:49:55 -050034 # request_type By default user request is valid.
35 # User can pass invalid to identify the user
36 # date time input will result in failure as
37 # expected.
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -050038
39 # Assign default value of UTC current date time if date_time is empty.
Sridevi Ramesh9f9edcc2025-05-16 01:27:01 -050040 ${current_date_time}= Get Current Date time_zone=UTC
41 ${date_time}= Set Variable If '${date_time}' == '${EMPTY}'
42 ... ${current_date_time} ${date_time}
43
sarandev34055c962025-03-25 00:49:55 -050044 # Patch date_time based on type of ${request_type}.
45 IF '${request_type}' == 'valid'
46 ${date_time}= Convert Date ${date_time} result_format=%Y-%m-%dT%H:%M:%S+00:00
sarandev35e5f5972024-09-05 02:25:53 -050047 Wait Until Keyword Succeeds 1min 5sec
sarandev33d500892025-01-21 01:45:16 -060048 ... Redfish.Patch ${REDFISH_BASE_URI}Managers/${MANAGER_ID}
sarandev34055c962025-03-25 00:49:55 -050049 ... body={'DateTime': '${date_time}'}
Sweta Potthurid12a3472025-03-11 00:25:33 -050050 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
sarandev35e5f5972024-09-05 02:25:53 -050051 ELSE
sarandev35e5f5972024-09-05 02:25:53 -050052 Wait Until Keyword Succeeds 1min 5sec
sarandev34055c962025-03-25 00:49:55 -050053 ... Redfish.Patch ${REDFISH_BASE_URI}Managers/${MANAGER_ID}
54 ... body={'DateTime': '${date_time}'}
55 ... valid_status_codes=[${HTTP_BAD_REQUEST}]
sarandev35e5f5972024-09-05 02:25:53 -050056 END
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -050057
58
59Set Time To Manual Mode
60 [Documentation] Set date time to manual mode via Redfish.
61
62 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'ProtocolEnabled': ${False}}}
63 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
64
65
66Set BMC Date And Verify
67 [Documentation] Set BMC Date Time at a given host state and verify.
68 [Arguments] ${host_state}
69 # Description of argument(s):
70 # host_state Host state at which date time will be updated for verification
71 # (eg. on, off).
72
Sridevi Ramesh9f9edcc2025-05-16 01:27:01 -050073 IF '${host_state}' == 'on'
74 Redfish Power On stack_mode=skip
75 ELSE
76 Redfish Power off stack_mode=skip
77 END
78
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -050079 ${current_date}= Get Current Date time_zone=UTC
80 ${new_value}= Subtract Time From Date ${current_date} 1 day
sarandev34055c962025-03-25 00:49:55 -050081 Redfish Set DateTime ${new_value}
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -050082 ${current_value}= Redfish Get DateTime
83 ${time_diff}= Subtract Date From Date ${current_value} ${new_value}
84 Should Be True '${time_diff}'<='3'
85
86
87Set NTP state
88 [Documentation] Set NTP service inactive.
89 [Arguments] ${state}
Sridevi Ramesh89242292025-07-20 02:36:56 -050090 # Description of argument(s):
91 # state NTP protocol state (True/False).
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -050092
93 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'ProtocolEnabled': ${state}}}
94 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
95
96
97Get NTP Initial Status
98 [Documentation] Get NTP service Status.
99
100 ${original_ntp}= Redfish.Get Attribute ${REDFISH_NW_PROTOCOL_URI} NTP
101 Set Suite Variable ${original_ntp}
102
103
104Restore NTP Status
105 [Documentation] Restore NTP Status.
106
Sridevi Ramesh9f9edcc2025-05-16 01:27:01 -0500107 IF '${original_ntp["ProtocolEnabled"]}' == 'True'
108 Set NTP state ${TRUE}
109 ELSE
110 Set NTP state ${FALSE}
111 END
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -0500112
113
114Verify NTP Servers Are Populated
115 [Documentation] Redfish GET request /redfish/v1/Managers/${MANAGER_ID}/NetworkProtocol response
116 ... and verify if NTP servers are populated.
117
118 ${network_protocol}= Redfish.Get Properties ${REDFISH_NW_PROTOCOL_URI}
119 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_1}
120 ... msg=NTP server value ${ntp_server_1} not stored.
121 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_2}
122 ... msg=NTP server value ${ntp_server_2} not stored.
123
124
125Verify System Time Sync Status
126 [Documentation] Verify the status of service systemd-timesyncd matches the NTP protocol enabled state.
127 [Arguments] ${expected_sync_status}=${True}
128
129 # Description of argument(s):
130 # expected_sync_status expected status at which NTP protocol enabled will be updated for verification
131 # (eg. True, False).
132
133 ${resp}= BMC Execute Command
134 ... systemctl status systemd-timesyncd
135 ... ignore_err=${1}
136 ${sync_status}= Get Lines Matching Regexp ${resp[0]} .*Active.*
Sridevi Ramesh9f9edcc2025-05-16 01:27:01 -0500137 IF ${expected_sync_status}==${True}
138 Should Contain ${sync_status} active (running)
139 END
140 IF ${expected_sync_status}==${False}
141 Should Contain ${sync_status} inactive (dead)
142 END
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -0500143
144
145Enable NTP And Add NTP Address
146 [Documentation] Enable NTP Protocol and Add NTP Address.
147
148 Set NTP state ${TRUE}
149
150 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'NTPServers': ${NTP_SERVER_ADDRESSES}}}
151 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
152
153 Wait Until Keyword Succeeds 1 min 10 sec Check Date And Time Was Changed
154
155
156Check Date And Time Was Changed
157 [Documentation] Verify date was current date and time.
158
159 ${new_date_time}= CLI Get BMC DateTime
160 Should Not Contain ${new_date_time} ${year_without_ntp}
161
162
163Restore NTP Mode
164 [Documentation] Restore the original NTP mode.
165
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -0500166 Return From Keyword If &{original_ntp} == &{EMPTY}
167 Print Timen Restore NTP Mode.
168 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI}
169 ... body={'NTP':{'ProtocolEnabled': ${original_ntp["ProtocolEnabled"]}}}
170 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]