blob: 1b019450a32158b6f9dcfb5a292c0dc22c3a5095 [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.
28 [Arguments] ${date_time}=${EMPTY} &{kwargs}
29 # 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.
34 # kwargs Additional parameters to be passed directly to
35 # th Redfish.Patch function. A good use for
36 # this is when testing a bad date-time, the
37 # caller can specify
38 # valid_status_codes=[${HTTP_BAD_REQUEST}].
39
40 # Assign default value of UTC current date time if date_time is empty.
41 ${date_time}= Run Keyword If
42 ... '${date_time}' == '${EMPTY}' Get Current Date time_zone=UTC
43 ... ELSE
44 ... Set Variable ${date_time}
sarandev35e5f5972024-09-05 02:25:53 -050045 # Change date format to 2024-03-07T07:58:50+00:00 from 2024-03-07 07:58:50.000.
46 IF "T" in "${date_time}"
47 Wait Until Keyword Succeeds 1min 5sec
sarandev33d500892025-01-21 01:45:16 -060048 ... Redfish.Patch ${REDFISH_BASE_URI}Managers/${MANAGER_ID}
49 ... body={'DateTime': '${date_time}'} &{kwargs}
Sweta Potthurid12a3472025-03-11 00:25:33 -050050 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
sarandev35e5f5972024-09-05 02:25:53 -050051 ELSE
52 ${date_time_formatted}= Convert Date ${date_time} result_format=%Y-%m-%dT%H:%M:%S+00:00
53 Wait Until Keyword Succeeds 1min 5sec
54 ... Redfish.Patch ${REDFISH_BASE_URI}Managers/${MANAGER_ID} body={'DateTime': '${date_time_formatted}'}
55 ... &{kwargs} valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
56 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
73 Run Keyword If '${host_state}' == 'on'
74 ... Redfish Power On stack_mode=skip
75 ... ELSE
76 ... Redfish Power off stack_mode=skip
77 ${current_date}= Get Current Date time_zone=UTC
78 ${new_value}= Subtract Time From Date ${current_date} 1 day
79 Redfish Set DateTime ${new_value} valid_status_codes=[${HTTP_OK}]
80 ${current_value}= Redfish Get DateTime
81 ${time_diff}= Subtract Date From Date ${current_value} ${new_value}
82 Should Be True '${time_diff}'<='3'
83
84
85Set NTP state
86 [Documentation] Set NTP service inactive.
87 [Arguments] ${state}
88
89 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'ProtocolEnabled': ${state}}}
90 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
91
92
93Get NTP Initial Status
94 [Documentation] Get NTP service Status.
95
96 ${original_ntp}= Redfish.Get Attribute ${REDFISH_NW_PROTOCOL_URI} NTP
97 Set Suite Variable ${original_ntp}
98
99
100Restore NTP Status
101 [Documentation] Restore NTP Status.
102
103 Run Keyword If '${original_ntp["ProtocolEnabled"]}' == 'True'
104 ... Set NTP state ${TRUE}
105 ... ELSE Set NTP state ${FALSE}
106
107
108Verify NTP Servers Are Populated
109 [Documentation] Redfish GET request /redfish/v1/Managers/${MANAGER_ID}/NetworkProtocol response
110 ... and verify if NTP servers are populated.
111
112 ${network_protocol}= Redfish.Get Properties ${REDFISH_NW_PROTOCOL_URI}
113 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_1}
114 ... msg=NTP server value ${ntp_server_1} not stored.
115 Should Contain ${network_protocol["NTP"]["NTPServers"]} ${ntp_server_2}
116 ... msg=NTP server value ${ntp_server_2} not stored.
117
118
119Verify System Time Sync Status
120 [Documentation] Verify the status of service systemd-timesyncd matches the NTP protocol enabled state.
121 [Arguments] ${expected_sync_status}=${True}
122
123 # Description of argument(s):
124 # expected_sync_status expected status at which NTP protocol enabled will be updated for verification
125 # (eg. True, False).
126
127 ${resp}= BMC Execute Command
128 ... systemctl status systemd-timesyncd
129 ... ignore_err=${1}
130 ${sync_status}= Get Lines Matching Regexp ${resp[0]} .*Active.*
131 Run Keyword If ${expected_sync_status}==${True}
132 ... Should Contain ${sync_status} active (running)
133 Run Keyword If ${expected_sync_status}==${False}
134 ... Should Contain ${sync_status} inactive (dead)
135
136
137Enable NTP And Add NTP Address
138 [Documentation] Enable NTP Protocol and Add NTP Address.
139
140 Set NTP state ${TRUE}
141
142 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} body={'NTP':{'NTPServers': ${NTP_SERVER_ADDRESSES}}}
143 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
144
145 Wait Until Keyword Succeeds 1 min 10 sec Check Date And Time Was Changed
146
147
148Check Date And Time Was Changed
149 [Documentation] Verify date was current date and time.
150
151 ${new_date_time}= CLI Get BMC DateTime
152 Should Not Contain ${new_date_time} ${year_without_ntp}
153
154
155Restore NTP Mode
156 [Documentation] Restore the original NTP mode.
157
Anvesh-Kumar_Rayankula365b8f92024-08-04 00:07:19 -0500158 Return From Keyword If &{original_ntp} == &{EMPTY}
159 Print Timen Restore NTP Mode.
160 Redfish.Patch ${REDFISH_NW_PROTOCOL_URI}
161 ... body={'NTP':{'ProtocolEnabled': ${original_ntp["ProtocolEnabled"]}}}
162 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]