ref: refs/heads/master
commit 21308f1be9bf3f1c5123b45150e1bd0aea3c0ef8
Author: Josef Reidinger
Date: Fri Dec 4 15:22:38 2009 +0100
fix passing hardware clock settings to ntp (bnc#556467)
---
plugins/ntp/app/controllers/ntp_controller.rb | 1 +
plugins/ntp/app/models/ntp.rb | 6 ++++--
plugins/ntp/package/NTP.pm | 9 +++++++--
plugins/ntp/test/functional/ntp_controller_test.rb | 8 ++++----
plugins/ntp/test/unit/ntp_test.rb | 9 ++++++---
5 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/plugins/ntp/app/controllers/ntp_controller.rb b/plugins/ntp/app/controllers/ntp_controller.rb
index 8af3666..d7dd0fd 100644
--- a/plugins/ntp/app/controllers/ntp_controller.rb
+++ b/plugins/ntp/app/controllers/ntp_controller.rb
@@ -23,6 +23,7 @@ class NtpController < ApplicationController
if root["synchronize"]
yapi_perm_check "ntp.synchronize"
@ntp.actions[:synchronize] = true
+ @ntp.actions[:synchronize_utc] = root[:synchronize_utc]
end
@ntp.save
diff --git a/plugins/ntp/app/models/ntp.rb b/plugins/ntp/app/models/ntp.rb
index c57115f..4ae1d58 100644
--- a/plugins/ntp/app/models/ntp.rb
+++ b/plugins/ntp/app/models/ntp.rb
@@ -4,7 +4,9 @@ class Ntp
public
def initialize
- @actions = { :synchronize => false }
+ @actions = { :synchronize => false,
+ :synchronize_utc => true
+ }
end
def self.find
@@ -21,7 +23,7 @@ class Ntp
def synchronize
ret = "OK"
begin
- ret = YastService.Call("YaPI::NTP::Synchronize")
+ ret = YastService.Call("YaPI::NTP::Synchronize",@actions[:synchronize_utc])
rescue Exception => e
Rails.logger.info "ntp synchronization cause probably timeout #{e.inspect}"
end
diff --git a/plugins/ntp/package/NTP.pm b/plugins/ntp/package/NTP.pm
index e71acea..46276d7 100644
--- a/plugins/ntp/package/NTP.pm
+++ b/plugins/ntp/package/NTP.pm
@@ -6,11 +6,12 @@ use YaST::YCP qw(:LOGGING);
our %TYPEINFO;
-BEGIN{$TYPEINFO{Synchronize} = ["function",
+BEGIN{$TYPEINFO{Synchronize} = ["function","boolean"
"string"];
}
sub Synchronize {
my $self = shift;
+ my $use_utc = shift;
my $servers = getServers();
my $out = undef;
@@ -24,7 +25,11 @@ sub Synchronize {
y2warning($out);
}
return "NOSERVERS" unless (defined ($out));
- my $ret = `/sbin/hwclock --utc --systohc`;
+ my $local = "--utc"
+ unless $use_utc {
+ my $local = "--localtime"
+ }
+ my $ret = `/sbin/hwclock $local --systohc`;
y2milestone("hwclock returns $?: $ret");
if ($? == 0){
return "OK";
diff --git a/plugins/ntp/test/functional/ntp_controller_test.rb b/plugins/ntp/test/functional/ntp_controller_test.rb
index 9709de5..09951d5 100644
--- a/plugins/ntp/test/functional/ntp_controller_test.rb
+++ b/plugins/ntp/test/functional/ntp_controller_test.rb
@@ -23,14 +23,14 @@ class SystemControllerTest < ActionController::TestCase
end
def test_update
- YastService.stubs(:Call).with("YaPI::NTP::Synchronize").once.returns("OK")
- post :update, {"ntp"=>{"synchronize"=>true}}
+ YastService.stubs(:Call).with("YaPI::NTP::Synchronize",true).once.returns("OK")
+ post :update, {"ntp"=>{"synchronize"=>true,"synchronize_utc"=>true}}
assert_response :success
end
def test_update_failed
- YastService.stubs(:Call).with("YaPI::NTP::Synchronize").once.returns("Failed")
- post :update, {"ntp"=>{"synchronize"=>true}}
+ YastService.stubs(:Call).with("YaPI::NTP::Synchronize",false).once.returns("Failed")
+ post :update, {"ntp"=>{"synchronize"=>true,"synchronize_utc" => false}}
assert_response 503
end
diff --git a/plugins/ntp/test/unit/ntp_test.rb b/plugins/ntp/test/unit/ntp_test.rb
index 2783e1f..963ba50 100644
--- a/plugins/ntp/test/unit/ntp_test.rb
+++ b/plugins/ntp/test/unit/ntp_test.rb
@@ -15,7 +15,8 @@ class NtpTest < ActiveSupport::TestCase
def test_synchronize_ok
@model.actions[:synchronize] = true
- YastService.stubs(:Call).with("YaPI::NTP::Synchronize").once.returns("OK")
+ @model.actions[:synchronize_utc] = true
+ YastService.stubs(:Call).with("YaPI::NTP::Synchronize",true).once.returns("OK")
assert_nothing_raised do
@model.save
end
@@ -23,7 +24,8 @@ class NtpTest < ActiveSupport::TestCase
def test_synchronize_error
@model.actions[:synchronize] = true
- YastService.stubs(:Call).with("YaPI::NTP::Synchronize").once.returns("No server defined")
+ @model.actions[:synchronize_utc] = true
+ YastService.stubs(:Call).with("YaPI::NTP::Synchronize",true).once.returns("No server defined")
assert_raise(NtpError.new "No server defined") do
@model.save
end
@@ -31,10 +33,11 @@ class NtpTest < ActiveSupport::TestCase
def test_synchronize_error
@model.actions[:synchronize] = true
+ @model.actions[:synchronize_utc] = true
msg_mock = mock()
msg_mock.stubs(:error_name).returns("org.freedesktop.DBus.Error.NoReply")
msg_mock.stubs(:params).returns(["test","test"])
- YastService.stubs(:Call).with("YaPI::NTP::Synchronize").once.raises(DBus::Error,msg_mock)
+ YastService.stubs(:Call).with("YaPI::NTP::Synchronize",true).once.raises(DBus::Error,msg_mock)
assert_nothing_raised do
@model.save
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org