Skip to content

Commit

Permalink
Merge pull request #63 from yast/fix_check
Browse files Browse the repository at this point in the history
Fix check
  • Loading branch information
jreidinger committed Oct 19, 2016
2 parents 8b782d9 + 40b648d commit 0c5b818
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 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 @@
-------------------------------------------------------------------
Tue Oct 18 13:53:24 UTC 2016 - jreidinger@suse.com

- properly report that test failed if server without running ntp is
checked as ntp server (bsc#972842)
- 3.2.0

-------------------------------------------------------------------
Thu Aug 11 14:24:42 CEST 2016 - schubi@suse.de

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: 3.1.28
Version: 3.2.0
Release: 0
Summary: YaST2 - NTP Client Configuration
License: GPL-2.0+
Expand Down
14 changes: 9 additions & 5 deletions src/modules/NtpClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,17 @@ def sntp_test(server, ip_version = 4)

Builtins.y2milestone("sntp test response: #{output}")

return false if output["exit"] != 0
# sntp returns always 0 if not called with option -S or -s (set system time)
# so this is a workaround at least to return false in case server is not
# reachable. We could also take care of stdout checking if it includes
# "no (U|B)CST reponse", but it also implies be too dependent in the
# future and the ntp package should take care of it and aswer other exit
# code instead of 0
output["stderr"].include?("lookup error") ? false : output["exit"] == 0
# reachable.
return false if output["stderr"].include?("lookup error")
# this happens for valid address, but without ntp server. If it breaks in the
# future start complaining to sntp maintainer to not return 0 in this case.
# customer case: bsc#972842
return false if output["stdout"] =~ /no (U|B)CST/

true
end

# Handle UI of NTP server test answers
Expand Down
66 changes: 34 additions & 32 deletions test/ntp_client_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require_relative "test_helper"

require "fileutils"

Yast.import "NtpClient"
Yast.import "NetworkInterfaces"
Yast.import "PackageSystem"
Expand Down Expand Up @@ -414,44 +416,44 @@
let(:server) { "sntp.server.de" }
let(:output) { { "stdout" => "", "stderr" => "", "exit" => 0 } }

context "given a server" do
context "when no ip_version is passed as argument" do
let(:output) do
{
"stderr" => "server_name lookup error Name or service not known",
"stdout" => "sntp 4.2.8p7@1.3265-o Thu May 12 16:14:59 UTC 2016",
"exit" => 0
}
end
it "calls sntp command with ip version 4 by default" do
expect(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
.and_return(output)

it "calls sntp command with ip version 4 by default" do
expect(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
.and_return(output)
subject.sntp_test(server)
end

subject.sntp_test(server)
end
it "returns false if server is not reachable" do
output["stderr"] = "server_name lookup error Name or service not known"
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
.and_return(output)

it "returns false if server is not reachable" do
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
.and_return(output)
expect(subject.sntp_test(server)).to eql(false)
end

expect(subject.sntp_test(server)).to eql(false)
end
it "returns false if sntp response includes 'no UCST'" do
output["stdout"] = "sntp 4.2.8p8@1.3265-o Fri Sep 30 15:52:10 UTC 2016 (1)\n" \
"195.113.144.2 no UCST response after 5 seconds\n"
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
.and_return(output)

it "returns true if sntp command's exit code is 0" do
output["stderr"] = ""
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
.and_return(output)
expect(subject.sntp_test(server)).to eql(false)
end

expect(subject.sntp_test(server)).to eql(true)
end
end
it "returns true if sntp command's exit code is 0" do
output["stdout"] = "sntp 4.2.8p8@1.3265-o Fri Sep 30 15:52:10 UTC 2016 (1)\n"
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
.and_return(output)

expect(subject.sntp_test(server)).to eql(true)
end
end

Expand Down

0 comments on commit 0c5b818

Please sign in to comment.