Skip to content

Commit

Permalink
add label if there is hardware clock defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 20, 2017
1 parent a4872d1 commit df4c43a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/cfa/chrony_conf.rb
Expand Up @@ -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 )
Expand Down
13 changes: 13 additions & 0 deletions src/lib/y2ntp_client/dialog/main.rb
Expand Up @@ -4,6 +4,7 @@
require "y2ntp_client/widgets"

Yast.import "Label"
Yast.import "NtpClient"
Yast.import "Stage"

module Y2NtpClient
Expand All @@ -29,6 +30,7 @@ def contents
VSpacing(1),
Left(Y2NtpClient::PolicyCombo.new),
VSpacing(1),
*hardware_clock_widgets,
Y2NtpClient::ServersTable.new
)
end
Expand All @@ -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
""
Expand Down
23 changes: 23 additions & 0 deletions test/cfa/chrony_conf_test.rb
Expand Up @@ -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

0 comments on commit df4c43a

Please sign in to comment.