Skip to content

Commit

Permalink
adapted suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Jun 14, 2019
1 parent 4d0263e commit 3537f67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
21 changes: 12 additions & 9 deletions src/modules/NtpClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def main

# Service names of the NTP daemon
@service_name = "chronyd"

# "chrony-wait" service has also to be handled in order to ensure that
# "chronyd" is working correctly and do not depend on the network status.
# bsc#1137196, bsc#1129730
@wait_service_name = "chrony-wait"

# Netconfig policy: for merging and prioritizing static and DHCP config.
Expand Down Expand Up @@ -595,7 +599,6 @@ def dhcp_ntp_servers
publish variable: :synchronize_time, type: "boolean"
publish variable: :sync_interval, type: "integer"
publish variable: :service_name, type: "string"
publish variable: :wait_service_name, type: "string"
publish variable: :ntp_policy, type: "string"
publish variable: :ntp_selected, type: "boolean"
publish variable: :ad_controller, type: "string"
Expand Down Expand Up @@ -806,26 +809,26 @@ def write_and_update_policy
# only mode.
def check_service
if @run_service
# Enable and run services
if !Service.Enable(@service_name)
Report.Error(Message.CannotAdjustService(@service_name))
elsif !Service.Enable(@wait_service_name)
Report.Error(Message.CannotAdjustService(@wait_service_name))
end
elsif !Service.Disable(@service_name)
Report.Error(Message.CannotAdjustService(@service_name))
elsif !Service.Disable(@wait_service_name)
Report.Error(Message.CannotAdjustService(@wait_service_name))
end

if @run_service
unless @write_only
if !@write_only
if !Service.Restart(@service_name)
Report.Error(_("Cannot restart \"%s\" service.") % @service_name)
elsif !Service.Restart(@wait_service_name)
Report.Error(_("Cannot restart \"%s\" service.") % @wait_service_name)
end
end
else
# Disable and stop services
if !Service.Disable(@service_name)
Report.Error(Message.CannotAdjustService(@service_name))
elsif !Service.Disable(@wait_service_name)
Report.Error(Message.CannotAdjustService(@wait_service_name))
end
Service.Stop(@service_name)
Service.Stop(@wait_service_name)
end
Expand Down
16 changes: 8 additions & 8 deletions test/ntp_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@

it "enables and restarts services" do
allow(subject).to receive(:check_service).and_call_original
expect(Yast::Service).to receive(:Enable).with(subject.service_name).and_return(true)
expect(Yast::Service).to receive(:Enable).with(subject.wait_service_name).and_return(true)
expect(Yast::Service).to receive(:Restart).with(subject.service_name).and_return(true)
expect(Yast::Service).to receive(:Restart).with(subject.wait_service_name).and_return(true)
expect(Yast::Service).to receive(:Enable).with("chronyd").and_return(true)
expect(Yast::Service).to receive(:Enable).with("chrony-wait").and_return(true)
expect(Yast::Service).to receive(:Restart).with("chronyd").and_return(true)
expect(Yast::Service).to receive(:Restart).with("chrony-wait").and_return(true)

subject.Write
end
Expand All @@ -307,10 +307,10 @@

it "disables and stops services" do
allow(subject).to receive(:check_service).and_call_original
expect(Yast::Service).to receive(:Disable).with(subject.service_name).and_return(true)
expect(Yast::Service).to receive(:Disable).with(subject.wait_service_name).and_return(true)
expect(Yast::Service).to receive(:Stop).with(subject.service_name).and_return(true)
expect(Yast::Service).to receive(:Stop).with(subject.wait_service_name).and_return(true)
expect(Yast::Service).to receive(:Disable).with("chronyd").and_return(true)
expect(Yast::Service).to receive(:Disable).with("chrony-wait").and_return(true)
expect(Yast::Service).to receive(:Stop).with("chronyd").and_return(true)
expect(Yast::Service).to receive(:Stop).with("chrony-wait").and_return(true)

subject.Write
end
Expand Down

0 comments on commit 3537f67

Please sign in to comment.