Skip to content

Commit

Permalink
Do not write if only synchronization is requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Nov 8, 2018
1 parent cbfda15 commit e99bab5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
21 changes: 9 additions & 12 deletions src/clients/ntp-client_proposal.rb
@@ -1,13 +1,13 @@
# encoding: utf-8

# File: clients/ntp-client_proposal.ycp
# Summary: Installation client for ntp configuration
# Author: Bubli <kmachalkova@suse.cz>
#
# This is used as the general interface between yast2-country
# (time,timezone) and yast2-ntp-client.
require "yast"

module Yast
# This is used as the general interface between yast2-country
# (time,timezone) and yast2-ntp-client.
class NtpClientProposalClient < Client
include Logger

def main
Yast.import "UI"
textdomain "ntp-client"
Expand Down Expand Up @@ -366,11 +366,11 @@ def Write(params)

return :invalid_hostname unless ValidateSingleServer(ntp_server)

WriteNtpSettings(ntp_servers, ntp_server, run_service)
add_or_install_required_package unless params["write_only"]

return :success if params["write_only"]
WriteNtpSettings(ntp_servers, ntp_server, run_service) unless params["ntpdate_only"]

add_or_install_required_package
return :success if params["write_only"]

# Only if network is running try to synchronize the ntp server
if NetworkService.isNetworkRunning
Expand All @@ -381,9 +381,6 @@ def Write(params)
return :ntpdate_failed unless exit_code.zero?
end

# User wants more than running one time sync (synchronize on boot)
WriteNtpSettings(ntp_servers, ntp_server, run_service) unless params["ntpdate_only"]

:success
end

Expand Down
3 changes: 3 additions & 0 deletions src/modules/NtpClient.rb
Expand Up @@ -37,6 +37,9 @@ class NtpClientClass < Module

NTP_FILE = "/etc/ntp.conf".freeze

# Package which is needed for saving NTP configuration into system
REQUIRED_PACKAGE = "ntp".freeze

def main
Yast.import "UI"
textdomain "ntp-client"
Expand Down
14 changes: 7 additions & 7 deletions test/ntp_client_proposal_test.rb
Expand Up @@ -14,7 +14,7 @@
describe "#Write" do
let(:ntp_server) { "fake.pool.ntp.org" }
let(:write_only) { false }
let(:ntpdate_only) { true }
let(:ntpdate_only) { false }
let(:params) do
{
"server" => ntp_server,
Expand Down Expand Up @@ -148,18 +148,18 @@
end

context "and user only wants to syncronize date" do
it "writes settings only once" do
expect(subject).to receive(:WriteNtpSettings).once
let(:ntpdate_only) { true }

it "does not write settings" do
expect(subject).to_not receive(:WriteNtpSettings)

subject.Write(params)
end
end

context "and user wants to syncronize on boot" do
let(:ntpdate_only) { false }

it "writes settings again?" do
expect(subject).to receive(:WriteNtpSettings).twice
it "writes settings only once" do
expect(subject).to receive(:WriteNtpSettings).once

subject.Write(params)
end
Expand Down

0 comments on commit e99bab5

Please sign in to comment.