[yast-commit] <rest-service> master : allow synchronize action only if ntp is available (bnc#552071)
ref: refs/heads/master commit 9861053de05483497cbe628ab08ce3b584201a9a Author: Josef Reidinger <jreidinger@suse.cz> Date: Mon Nov 30 11:33:50 2009 +0100 allow synchronize action only if ntp is available (bnc#552071) --- plugins/ntp/app/models/ntp.rb | 6 ++++-- plugins/ntp/package/NTP.pm | 9 +++++++++ plugins/ntp/test/functional/ntp_controller_test.rb | 1 + plugins/ntp/test/unit/ntp_test.rb | 8 +++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/ntp/app/models/ntp.rb b/plugins/ntp/app/models/ntp.rb index c57115f..64c2b25 100644 --- a/plugins/ntp/app/models/ntp.rb +++ b/plugins/ntp/app/models/ntp.rb @@ -4,11 +4,13 @@ class Ntp public def initialize - @actions = { :synchronize => false } + @actions = Hash.new end def self.find - Ntp.new + ret =Ntp.new + ret.actions[:synchronize] = false if YastService.Call("YaPI::NTP::Available") + return ret end def save diff --git a/plugins/ntp/package/NTP.pm b/plugins/ntp/package/NTP.pm index e71acea..332a606 100644 --- a/plugins/ntp/package/NTP.pm +++ b/plugins/ntp/package/NTP.pm @@ -32,6 +32,15 @@ sub Synchronize { return $out.$ret; } +BEGIN{$TYPEINFO{Synchronize} = ["function", + "boolean"]; +} +sub Available { + my $self = shift; + return ((scalar @{getServers()}) != 0) && (getServers()->[0] ne "") +} + + sub getServers { my $servers = `grep "^[:space:]*NETCONFIG_NTP_STATIC_SERVERS" /etc/sysconfig/network/config | sed 's/.*="\\(.*\\)"/\\1/'`; my @serv = split(/\s+/,$servers); diff --git a/plugins/ntp/test/functional/ntp_controller_test.rb b/plugins/ntp/test/functional/ntp_controller_test.rb index 9709de5..db010eb 100644 --- a/plugins/ntp/test/functional/ntp_controller_test.rb +++ b/plugins/ntp/test/functional/ntp_controller_test.rb @@ -12,6 +12,7 @@ class SystemControllerTest < ActionController::TestCase @request = ActionController::TestRequest.new # http://railsforum.com/viewtopic.php?id=1719 @request.session[:account_id] = 1 # defined in fixtures + YastService.stubs(:Call).with("YaPI::NTP::Available").returns(true) end diff --git a/plugins/ntp/test/unit/ntp_test.rb b/plugins/ntp/test/unit/ntp_test.rb index 2783e1f..e17c3fb 100644 --- a/plugins/ntp/test/unit/ntp_test.rb +++ b/plugins/ntp/test/unit/ntp_test.rb @@ -5,7 +5,8 @@ require 'system' class NtpTest < ActiveSupport::TestCase def setup - @model = Ntp.find + YastService.stubs(:Call).with("YaPI::NTP::Available").once.returns(true) + @model = Ntp.find end def test_actions @@ -40,4 +41,9 @@ class NtpTest < ActiveSupport::TestCase @model.save end end + + def test_unavailable_NTP + YastService.stubs(:Call).with("YaPI::NTP::Available").once.returns(false) + assert_equal nil, Ntp.find.actions[:synchronize] + end end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
Josef Reidinger