From df4c43a65d0aa35fcb4b73160150e959fc45ad9c Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 20 Nov 2017 17:51:53 +0100 Subject: [PATCH] add label if there is hardware clock defined --- src/lib/cfa/chrony_conf.rb | 8 +++++++- src/lib/y2ntp_client/dialog/main.rb | 13 +++++++++++++ test/cfa/chrony_conf_test.rb | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/lib/cfa/chrony_conf.rb b/src/lib/cfa/chrony_conf.rb index 4b67a76f..86f73274 100644 --- a/src/lib/cfa/chrony_conf.rb +++ b/src/lib/cfa/chrony_conf.rb @@ -76,10 +76,16 @@ def pools Hash[pools_map] end + # Is there any hardware clock settings? + def hardware_clock? + !data.select(Matcher.new(collection: "refclock")).empty? + end + private COLLECTION_KEYS = [ - "pool" + "pool", + "refclock" ].freeze # if there is only one element of collection, augeas does not add [], # so fix it here for known keys which we modify ( and can be hitted with it ) diff --git a/src/lib/y2ntp_client/dialog/main.rb b/src/lib/y2ntp_client/dialog/main.rb index bb399469..df0c9515 100644 --- a/src/lib/y2ntp_client/dialog/main.rb +++ b/src/lib/y2ntp_client/dialog/main.rb @@ -4,6 +4,7 @@ require "y2ntp_client/widgets" Yast.import "Label" +Yast.import "NtpClient" Yast.import "Stage" module Y2NtpClient @@ -29,6 +30,7 @@ def contents VSpacing(1), Left(Y2NtpClient::PolicyCombo.new), VSpacing(1), + *hardware_clock_widgets, Y2NtpClient::ServersTable.new ) end @@ -37,6 +39,17 @@ def abort_button Yast::Label.CancelButton end + def hardware_clock_widgets + if Yast::NtpClient.ntp_conf.hardware_clock? + [ + Label(_("Hardware clock configured as source. YaST will keep it untouched.")), + VSpacing(1), + ] + else + [ Empty() ] + end + end + def back_button # no back button "" diff --git a/test/cfa/chrony_conf_test.rb b/test/cfa/chrony_conf_test.rb index 4a5d191b..7b07c28f 100644 --- a/test/cfa/chrony_conf_test.rb +++ b/test/cfa/chrony_conf_test.rb @@ -98,4 +98,27 @@ def ntp_conf(file) end end end + + describe "hardware_clock?" do + context "hardware clock defined" do + let(:content) do + "refclock PPS /dev/pps0 lock NMEA refid GPS\n" + end + + it "return true" do + expect(subject.hardware_clock?).to eq true + end + end + + context "no hardware clock defined" do + let(:content) do + "rtcsync\n" \ + "pool ntp.suse.cz offline\n" + end + + it "return true" do + expect(subject.hardware_clock?).to eq false + end + end + end end