ref: refs/heads/network
commit 333c9549c4918b4b0b8a68993fc2888eb4de7b80
Author: Josef Reidinger
Date: Tue Sep 8 09:24:03 2009 +0200
use new yapi call for ntp synchronization
---
plugins/time/app/models/systemtime.rb | 40 +++++++++++++----
plugins/time/test/unit/systemtime_test.rb | 67 ++++++++++++++++++++--------
2 files changed, 78 insertions(+), 29 deletions(-)
diff --git a/plugins/time/app/models/systemtime.rb b/plugins/time/app/models/systemtime.rb
index f14ad69..0163395 100644
--- a/plugins/time/app/models/systemtime.rb
+++ b/plugins/time/app/models/systemtime.rb
@@ -14,6 +14,16 @@ class Systemtime
attr_accessor :timezone
# Utc status possible values is UTCOnly, UTC and localtime see yast2-country doc
attr_accessor :utcstatus
+ # define how time will be set
+ attr_accessor :time_setter
+
+ # constants for time_setter
+ #don't set time on machine
+ NONE = "none"
+ # set time manually by values
+ MANUAL = "manual"
+ # set regular ntp synchronization
+ NTP = "ntp"
private
@@ -58,6 +68,7 @@ class Systemtime
systemtime.date = xmlroot[:date]
systemtime.timezone = xmlroot[:timezone]
systemtime.utcstatus = xmlroot[:utcstatus]
+ systemtime.time_setter = xmlroot[:time_setter]
return systemtime
end
@@ -84,13 +95,22 @@ class Systemtime
settings[:utcstatus] = @utcstatus
end
need_rescue = false
- if (@date and !@date.empty?) and
+ case @time_setter
+ when MANUAL then
+ if (@date and !@date.empty?) and
(@time and !@time.empty?)
date = @date.split("/")
datetime = "#{date[2]}-#{date[0]}-#{date[1]} - "+@time
settings[:currenttime] = datetime
need_rescue = true
+ else
+ #TODO some exception that time is not set
+ end
+ when NTP then
+ #TODO if routes became configurable ten provide ntp synchronization via separated vie
+ YastService.Call("YaPI::NTP::Synchronize")
end
+
begin
YastService.Call("YaPI::TIME::Write",settings)
rescue Exception => e
@@ -98,7 +118,6 @@ class Systemtime
unless need_rescue
raise
end
-
end
end
@@ -107,21 +126,22 @@ class Systemtime
xml.instruct! unless options[:skip_instruct]
xml.systemtime do
- xml.tag!(:time, @time )
- xml.tag!(:date, @date )
- xml.tag!(:timezone, @timezone )
- xml.tag!(:utcstatus, @utcstatus )
+ xml.time @time
+ xml.date @date
+ xml.timezone @timezone
+ xml.utcstatus @utcstatus
+ xml.time_setter "NONE"
xml.timezones({:type => "array"}) do
@@timezones.each do |region|
if not region.empty?
xml.region do
- xml.tag!(:name, region["name"])
- xml.tag!(:central, region["central"])
+ xml.name region["name"]
+ xml.central region["central"]
xml.entries({:type => "array"}) do
region["entries"].each do |id,name|
xml.timezone do
- xml.tag!(:id, id)
- xml.tag!(:name, name)
+ xml.id id
+ xml.name name
end
end
end
diff --git a/plugins/time/test/unit/systemtime_test.rb b/plugins/time/test/unit/systemtime_test.rb
index e69e8ae..9161501 100644
--- a/plugins/time/test/unit/systemtime_test.rb
+++ b/plugins/time/test/unit/systemtime_test.rb
@@ -21,39 +21,43 @@ class SystemtimeTest < ActiveSupport::TestCase
}
]
- def read_arguments
- return {
+ READ_ARGUMENTS = {
"zones"=> "true",
"timezone"=> "true",
"utcstatus"=> "true",
"currenttime" => "true"
}
- end
- def read_response
- return {
+ READ_RESPONSE = {
"zones"=> TEST_TIMEZONES,
"timezone"=> "Europe/Prague",
"utcstatus"=> "true",
"time" => "2009-07-02 - 12:18:00"
+ }
+
+ WRITE_ARGUMENTS_NONE = {
+ :timezone=> "America/Kentucky/Monticello",
+ :utcstatus=> "false"
}
- end
- def write_arguments
- return {
- "timezone"=> "America/Kentucky/Monticello",
- "utcstatus"=> "false"
+ WRITE_ARGUMENTS_TIME = {
+ :timezone=> "America/Kentucky/Monticello",
+ :utcstatus=> "false",
+ :time => "2009-07-02 - 12:18:00"
+ }
+
+ WRITE_ARGUMENTS_NTP = {
+ :timezone=> "America/Kentucky/Monticello",
+ :utcstatus=> "false",
}
- end
def setup
@model = Systemtime.new
end
- def test_getter
- result = read_response
- YastService.stubs(:Call).with("YaPI::TIME::Read",read_arguments).returns(result)
+ def test_getter
+ YastService.stubs(:Call).with("YaPI::TIME::Read",READ_ARGUMENTS).returns(READ_RESPONSE)
@model = Systemtime.find
assert_equal("02/07/2009", @model.date)
@@ -63,12 +67,37 @@ class SystemtimeTest < ActiveSupport::TestCase
assert_equal(TEST_TIMEZONES,Systemtime.timezones)
end
- def test_setter
- YastService.stubs(:Call).with("YaPI::TIME::Write",write_arguments).returns(true)
+ def test_setter_none
+ YastService.stubs(:Call).with("YaPI::TIME::Write",WRITE_ARGUMENTS_NONE).returns(true)
YastService.expects(:Call).once
+ YastService.expects(:Call).with("YaPI::NTP::Synchronize").never
+
+ @model.timezone = "America/Kentucky/Monticello"
+ @model.utcstatus = "false"
+ @model.time_setter = Systemtime.const_get "NONE"
+ @model.save
+ end
+
+ def test_setter_manual
+ YastService.stubs(:Call).with("YaPI::TIME::Write",WRITE_ARGUMENTS_TIME).returns(true)
+ YastService.expects(:Call).once
+ YastService.expects(:Call).with("YaPI::NTP::Synchronize").never
+
+ @model.timezone = "America/Kentucky/Monticello"
+ @model.utcstatus = "false"
+ @model.date = "02/07/2009"
+ @model.time = "12:18:00"
+ @model.time_setter = Systemtime.const_get "MANUAL"
+ @model.save
+ end
+
+ def test_setter_ntp
+ YastService.stubs(:Call).with("YaPI::TIME::Write",WRITE_ARGUMENTS_NTP).returns(true)
+ YastService.expects(:Call).with("YaPI::NTP::Synchronize").once
- @model.timezone = "Europe/Prague"
+ @model.timezone = "America/Kentucky/Monticello"
@model.utcstatus = "false"
+ @model.time_setter = Systemtime.const_get "NTP"
@model.save
end
@@ -78,7 +107,7 @@ class SystemtimeTest < ActiveSupport::TestCase
@@timezones=val
end
- data = read_response
+ data = READ_RESPONSE
@model.timezone = data["timezone"]
@model.utcstatus = data["utcstatus"]
@model.date = "02/07/2009"
@@ -113,7 +142,7 @@ class SystemtimeTest < ActiveSupport::TestCase
end
- data = read_response
+ data = READ_RESPONSE
@model.timezone = data["timezone"]
@model.utcstatus = data["utcstatus"]
@model.date = "02/07/2009"
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org