1+ import datetime
12import logging
23import pytest
34import re
@@ -74,14 +75,14 @@ def server_exist_in_conf(duthost, server_pattern):
7475 return False
7576
7677
77- def ntp_service_restarted (duthost ):
78- """ Check if ntp.service is just restarted within 10 secs
78+ def ntp_service_restarted (duthost , start_time ):
79+ """ Check if ntp.service is just restarted after start_time
7980 """
8081 output = duthost .shell ("systemctl show ntp.service --property ActiveState --value" )
8182 if output ["stdout" ] != "active" :
8283 return False
8384 output = duthost .shell ("ps -o etimes -p $(systemctl show ntp.service --property ExecMainPID --value) | sed '1d'" )
84- if int (output ['stdout' ].strip ()) < 10 :
85+ if int (output ['stdout' ].strip ()) < ( datetime . datetime . now () - start_time ). seconds :
8586 return True
8687 return False
8788
@@ -103,11 +104,12 @@ def ntp_server_tc1_add_config(duthost):
103104 logger .info ("tmpfile {}" .format (tmpfile ))
104105
105106 try :
107+ start_time = datetime .datetime .now ()
106108 output = apply_patch (duthost , json_data = json_patch , dest_file = tmpfile )
107109 expect_op_success (duthost , output )
108110
109111 pytest_assert (
110- ntp_service_restarted (duthost ),
112+ ntp_service_restarted (duthost , start_time ),
111113 "ntp.service is not restarted after change"
112114 )
113115 pytest_assert (
@@ -170,11 +172,12 @@ def ntp_server_tc1_replace(duthost):
170172 logger .info ("tmpfile {}" .format (tmpfile ))
171173
172174 try :
175+ start_time = datetime .datetime .now ()
173176 output = apply_patch (duthost , json_data = json_patch , dest_file = tmpfile )
174177 expect_op_success (duthost , output )
175178
176179 pytest_assert (
177- ntp_service_restarted (duthost ),
180+ ntp_service_restarted (duthost , start_time ),
178181 "ntp.service is not restarted after change"
179182 )
180183 pytest_assert (
@@ -201,11 +204,12 @@ def ntp_server_tc1_remove(duthost):
201204 logger .info ("tmpfile {}" .format (tmpfile ))
202205
203206 try :
207+ start_time = datetime .datetime .now ()
204208 output = apply_patch (duthost , json_data = json_patch , dest_file = tmpfile )
205209 expect_op_success (duthost , output )
206210
207211 pytest_assert (
208- ntp_service_restarted (duthost ),
212+ ntp_service_restarted (duthost , start_time ),
209213 "ntp.service is not restarted after change"
210214 )
211215 pytest_assert (
0 commit comments