Skip to content

Commit

Permalink
adapt to use NtpClient API instead of direct ntp call (replaced by ch…
Browse files Browse the repository at this point in the history
…rony FATE#323432)
  • Loading branch information
jreidinger committed Nov 28, 2017
1 parent d421e89 commit a66813b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/modules/AutoinstGeneral.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def main
Yast.import "Language"
Yast.import "Timezone"
Yast.import "Misc"
Yast.import "NtpClient"
Yast.import "Profile"
Yast.import "ProductFeatures"

Expand Down Expand Up @@ -417,7 +418,7 @@ def NtpSync
# TRANSLATORS: %s is the name of the ntp server
_("Syncing time with %s.") % ntp_server
)
ret = SCR.Execute(path(".target.bash"), "/usr/sbin/ntpdate -b #{ntp_server}")
ret = NtpClient.sync_once(ntp_server)
if ret > 0
Report.Error(_("Time syncing failed."))
else
Expand Down
23 changes: 20 additions & 3 deletions test/AutoinstGeneral_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/usr/bin/env rspec

# stub to avoid ntpclient build dependency
module Yast
class NtpClient
def self.sync_once(server)
0
end
end
end

require_relative "test_helper"

Yast.import "AutoinstGeneral"
Expand All @@ -26,15 +35,23 @@
it "syncs hardware time" do
subject.Import(profile)

expect(Yast::SCR).to receive(:Execute).with(
path(".target.bash"), "/usr/sbin/ntpdate -b ntp.suse.de"
).and_return(0)
expect(Yast::NtpClient).to receive(:sync_once).with("ntp.suse.de").and_return(0)

expect(Yast::SCR).to receive(:Execute).with(path(".target.bash"), "/sbin/hwclock --systohc")
.and_return(0)

subject.Write()
end

it "does not sync hardware time if ntp sync failed" do
subject.Import(profile)

expect(Yast::NtpClient).to receive(:sync_once).with("ntp.suse.de").and_return(1)

expect(Yast::SCR).to_not receive(:Execute).with(path(".target.bash"), "/sbin/hwclock --systohc")

subject.Write()
end
end

context "when no NTP server is set" do
Expand Down

0 comments on commit a66813b

Please sign in to comment.