Skip to content

Commit

Permalink
Merge 29cd52a into e9c7dde
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Sep 21, 2022
2 parents e9c7dde + 29cd52a commit e9d36d8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
7 changes: 7 additions & 0 deletions package/yast2-ntp-client.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Sep 21 13:10:17 UTC 2022 - Knut Anderssen <kanderssen@suse.com>

- Skip to write and update netconfig configuration when netconfig
executable does not exist (bsc#1198066, bsc#1202748)
- 4.5.1

-------------------------------------------------------------------
Wed Apr 06 13:24:58 UTC 2022 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-ntp-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-ntp-client
Version: 4.5.0
Version: 4.5.1
Release: 0
Summary: YaST2 - NTP Client Configuration
License: GPL-2.0-or-later
Expand Down
18 changes: 14 additions & 4 deletions src/modules/NtpClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class NtpClientClass < Module
# The file name of systemd timer for the synchronization.
TIMER_PATH = "/etc/systemd/system/#{TIMER_FILE}".freeze

# @return [String] Netconfig executable
NETCONFIG_PATH = "/usr/sbin/netconfig".freeze

UNSUPPORTED_AUTOYAST_OPTIONS = [
"configure_dhcp",
"peers",
Expand All @@ -62,7 +65,6 @@ def main
Yast.import "Language"
Yast.import "Message"
Yast.import "Mode"
Yast.import "NetworkInterfaces"
Yast.import "Package"
Yast.import "Popup"
Yast.import "Progress"
Expand Down Expand Up @@ -159,6 +161,11 @@ def progress?
Mode.normal
end

# return [Boolean] whether netconfig is present in the system or not
def netconfig?
FileUtils.Exists(NETCONFIG_PATH)
end

# Synchronize against specified server only one time and does not modify
# any configuration
# @param server [String] to sync against
Expand Down Expand Up @@ -338,7 +345,6 @@ def Read
return false if !go_next

progress_orig = Progress.set(false)
NetworkInterfaces.Read
Progress.set(progress_orig)

read_policy!
Expand Down Expand Up @@ -389,7 +395,11 @@ def Write

Report.Error(Message.CannotWriteSettingsTo("/etc/chrony.conf")) if !write_ntp_conf

write_and_update_policy
if netconfig?
write_and_update_policy
else
log.info("There is no netconfig, skipping policy write")
end

# restart daemon
return false if !go_next
Expand Down Expand Up @@ -818,7 +828,7 @@ def write_policy
# Calls netconfig to update ntp
# @return [Boolean] true on success
def update_netconfig
SCR.Execute(path(".target.bash"), "/sbin/netconfig update -m ntp") == 0
SCR.Execute(path(".target.bash"), "#{NETCONFIG_PATH} update -m ntp") == 0
end

# Writes sysconfig ntp policy and calls netconfig to update ntp. Report an
Expand Down
29 changes: 17 additions & 12 deletions test/ntp_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require "cfa/memory_file"

Yast.import "NtpClient"
Yast.import "NetworkInterfaces"
Yast.import "Package"
Yast.import "Service"

Expand Down Expand Up @@ -32,7 +31,6 @@
allow(subject).to receive(:go_next).and_return(true)
allow(subject).to receive(:progress?).and_return(false)
allow(Yast::Service).to receive(:Enabled).with("chronyd").and_return(true)
allow(Yast::NetworkInterfaces).to receive(:Read)
allow(Yast::Progress)
allow(Yast::Package).to receive(:CheckAndInstallPackagesInteractive)
.with(["chrony"]).and_return(true)
Expand Down Expand Up @@ -137,7 +135,6 @@
allow(subject).to receive(:ReadSynchronization)
allow(subject).to receive(:read_policy!)
allow(Yast::Service).to receive(:Enabled).with("chronyd").and_return(true)
allow(Yast::NetworkInterfaces).to receive(:Read)
allow(Yast::Progress)
allow(Yast::Package).to receive(:CheckAndInstallPackagesInteractive)
.with(["chrony"]).and_return(true)
Expand Down Expand Up @@ -169,12 +166,6 @@
subject.Read
end

it "reads network interfaces config" do
expect(Yast::NetworkInterfaces).to receive(:Read)

subject.Read
end

it "reads ntp policy" do
expect(subject).to receive(:read_policy!)

Expand Down Expand Up @@ -231,13 +222,16 @@
end

describe "#Write" do
let(:netconfig) { true }

before do
allow(subject).to receive(:Abort).and_return(false)
allow(subject).to receive(:go_next).and_return(true)
allow(subject).to receive(:progress?).and_return(false)
allow(subject).to receive(:write_ntp_conf).and_return(true)
allow(subject).to receive(:write_and_update_policy).and_return(true)
allow(subject).to receive(:check_service)
allow(subject).to receive(:netconfig?).and_return(netconfig)

allow(Yast::Report)
end
Expand Down Expand Up @@ -268,10 +262,21 @@
expect(lines.lines).to include("pool tik.cesnet.cz iburst\n")
end

it "writes ntp policy and updates ntp with netconfig" do
expect(subject).to receive(:write_and_update_policy)
context "when netconfig is available" do
it "writes ntp policy and updates ntp with netconfig" do
expect(subject).to receive(:write_and_update_policy)

subject.Write
subject.Write
end
end

context "when netconfig is not available" do
let(:netconfig) { false }
it "skips netconfig configuration" do
expect(subject).to_not receive(:write_and_update_policy)

subject.Write
end
end

context "services will be started" do
Expand Down
1 change: 0 additions & 1 deletion test/y2ntp_client/client/auto_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

before do
allow(Yast::Service).to receive(:Enabled).with("chronyd").and_return(true)
allow(Yast::NetworkInterfaces).to receive(:Read)
allow(Yast::Package).to receive(:CheckAndInstallPackagesInteractive)
.with(["chrony"]).and_return(true)
Yast::NtpClient.Read
Expand Down

0 comments on commit e9d36d8

Please sign in to comment.