1*** Settings ***
2Documentation                NTP configuration and verification
3                             ...  tests.
4
5Resource                     ../../lib/openbmc_ffdc.robot
6Resource                     ../../lib/bmc_date_and_time_utils.robot
7
8Test Setup                   Printn
9Test Teardown                FFDC On Test Case Fail
10Suite Setup                  Suite Setup Execution
11Suite Teardown               Suite Teardown Execution
12
13
14*** Variables ***
15
16${ntp_server_1}              9.9.9.9
17${ntp_server_2}              2.2.3.3
18&{original_ntp}              &{EMPTY}
19
20*** Test Cases ***
21
22Verify NTP Server Set
23    [Documentation]  Patch NTP servers and verify NTP servers is set.
24    [Tags]  Verify_NTP_Server_Set
25    [Setup]  Set NTP state  ${True}
26
27    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}
28    ...  body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_2}']}}
29    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
30
31    # NTP network take few seconds to reload.
32    Wait Until Keyword Succeeds  30 sec  10 sec  Verify NTP Servers Are Populated
33
34
35Verify NTP Server Value Not Duplicated
36    [Documentation]  Verify NTP servers value not same for both primary and secondary server.
37    [Tags]  Verify_NTP_Server_Value_Not_Duplicated
38
39    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}
40    ...  body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_1}']}}
41    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
42    ${network_protocol}=  Redfish.Get Properties  ${REDFISH_NW_PROTOCOL_URI}
43    Should Contain X Times  ${network_protocol["NTP"]["NTPServers"]}  ${ntp_server_1}  1
44    ...  msg=NTP primary and secondary server values should not be same.
45
46
47Verify NTP Server Setting Persist After BMC Reboot
48    [Documentation]  Verify NTP server setting persist after BMC reboot.
49    [Tags]  Verify_NTP_Server_Setting_Persist_After_BMC_Reboot
50    [Setup]  Set NTP state  ${True}
51
52    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}
53    ...  body={'NTP':{'NTPServers': ['${ntp_server_1}', '${ntp_server_2}']}}
54    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
55    Redfish OBMC Reboot (off)
56    Redfish.Login
57
58    # NTP network take few seconds to reload.
59    Wait Until Keyword Succeeds  30 sec  10 sec  Verify NTP Servers Are Populated
60
61
62Verify Enable NTP
63    [Documentation]  Verify NTP protocol mode can be enabled.
64    [Teardown]  Restore NTP Mode
65    [Tags]  Verify_Enable_NTP
66
67    # The following patch command should set the ["NTP"]["ProtocolEnabled"] property to "True".
68    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body={'NTP':{'ProtocolEnabled': ${True}}}
69    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
70    Wait Until Keyword Succeeds  1 min  5 sec
71    ...  Verify System Time Sync Status  ${True}
72    ${ntp}=  Redfish.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  NTP
73    Rprint Vars  ntp
74    Valid Value  ntp["ProtocolEnabled"]  valid_values=[True]
75
76Verify Disable NTP
77    [Documentation]  Verify NTP protocol mode can be disabled.
78    [Teardown]  Restore NTP Mode
79    [Tags]  Verify_Disable_NTP
80
81    # The following patch command should set the ["NTP"]["ProtocolEnabled"] property to "False".
82    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body={'NTP':{'ProtocolEnabled': ${False}}}
83    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
84    Wait Until Keyword Succeeds  1 min  5 sec
85    ...  Verify System Time Sync Status  ${False}
86    ${ntp}=  Redfish.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  NTP
87    Rprint Vars  ntp
88    Valid Value  ntp["ProtocolEnabled"]  valid_values=[False]
89
90Verify Set DateTime With NTP Enabled
91    [Documentation]  Verify whether set managers dateTime is restricted with NTP enabled.
92    [Tags]  Verify_Set_DateTime_With_NTP_Enabled
93
94    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body={'NTP':{'ProtocolEnabled': ${True}}}
95    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
96    ${ntp}=  Redfish.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  NTP
97    Valid Value  ntp["ProtocolEnabled"]  valid_values=[True]
98    ${local_system_time}=  Get Current Date
99    Redfish Set DateTime  ${local_system_time}
100    ...  valid_status_codes=[${HTTP_BAD_REQUEST}, ${HTTP_INTERNAL_SERVER_ERROR}]
101
102*** Keywords ***
103
104
105Suite Setup Execution
106    [Documentation]  Do the suite level setup.
107
108    Printn
109    Redfish.Login
110    Get NTP Initial Status
111    ${old_date_time}=  CLI Get BMC DateTime
112    ${year_status}=  Run Keyword And Return Status  Should Not Contain  ${old_date_time}  ${year_without_ntp}
113    Run Keyword If  ${year_status} == False
114    ...  Enable NTP And Add NTP Address
115
116Suite Teardown Execution
117    [Documentation]  Do the suite level teardown.
118
119    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}
120    ...  body={'NTP':{'NTPServers': ['${EMPTY}', '${EMPTY}']}}
121    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
122    Restore NTP Status
123    Redfish.Logout
124