chronyd doesn't change the time immediately because it wants to prevent time leaps. However this way it may look like if NTP was not running at all, so we need a manual sync first. --- pyanaconda/ntp.py | 48 ++++++++++++++++++++++++++++ pyanaconda/ui/gui/spokes/datetime_spoke.py | 8 ++++- 2 files changed, 55 insertions(+), 1 deletions(-) diff --git a/pyanaconda/ntp.py b/pyanaconda/ntp.py index 8e38ce3..b9a998c 100644 --- a/pyanaconda/ntp.py +++ b/pyanaconda/ntp.py @@ -25,6 +25,9 @@ Module facilitating the work with NTP servers and NTP daemon's configuration import re, os, tempfile +from pyanaconda import iutil +from pyanaconda.threads import threadMgr, AnacondaThread + NTP_CONFIG_FILE = "/etc/chrony.conf" #example line: @@ -149,3 +152,48 @@ def save_servers_to_config(servers, conf_file_path=NTP_CONFIG_FILE, old_conf_file.close() new_conf_file.close() + +def one_time_sync(server, callback=None): + """ + Synchronize the system time with a given NTP server. Note that this + function is blocking and will not return until the time gets synced or + querying server fails (may take some time before timeouting). + + @param server: NTP server + @param callback: callback function to run after sync or failure + @type callback: a function taking one boolean argument (success) + @return: True if the sync was successful, False otherwise + + """ + + ret = iutil.execWithRedirect("rdate", ["-s", server], stdout="/dev/tty5", + stderr="/dev/tty5") + + success = ret == 0 + + if callback is not None: + callback(success) + + return success + +def one_time_sync_async(server, callback=None): + """ + Asynchronously synchronize the system time with a given NTP server. This + function is non-blocking it starts a new thread for synchronization and + returns. Use callback argument to specify the function called when the + new thread finishes if needed. + + @param server: NTP server + @param callback: callback function to run after sync or failure + @type callback: a function taking one boolean argument (success) + + """ + + thread_name = "AnaSyncTime_%s" % server + if threadMgr.get(thread_name): + #syncing with the same server running + return + + threadMgr.add(AnacondaThread(name=thread_name, target=one_time_sync, + args=(server, callback))) + diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py index 6dfbfbd..5429c3f 100644 --- a/pyanaconda/ui/gui/spokes/datetime_spoke.py +++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py @@ -708,8 +708,14 @@ class DatetimeSpoke(NormalSpoke): return else: self.window.clear_info() - if self._config_dialog.working_server is None: + + working_server = self._config_dialog.working_server + if working_server is None: self._show_no_ntp_server_warning() + else: + #we need a one-time sync here, because chronyd would not change + #the time as drastically as we need + ntp.one_time_sync_async(working_server) ret = iutil.start_service("chronyd") self._set_date_time_setting_sensitive(False) -- 1.7.4.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list