Mailinglist Archive: yast-commit (1771 mails)

< Previous Next >
[yast-commit] <rest-service> network : added more tests, handle missing command in vendor config
  • From: Ladislav Slezak <lslezak@xxxxxxxxxx>
  • Date: Mon, 24 Aug 2009 17:18:49 +0200
  • Message-id: <E1MiTqL-0006dH-2w@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit eeb20ba5409c5ab7efde93fe517d859f186f6fc4
Author: Ladislav Slezak <lslezak@xxxxxxxxxx>
Date: Mon Aug 24 17:08:28 2009 +0200

added more tests, handle missing command in vendor config
---
plugins/services/app/models/service.rb | 12 ++++--
plugins/services/test/unit/services_test.rb | 41 +++++++++++++++++---
.../unit/vendor_config/invalid/custom_services.yml | 3 +
.../unit/vendor_config/valid/custom_services.yml | 6 +++
4 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/plugins/services/app/models/service.rb
b/plugins/services/app/models/service.rb
index 184ee0a..e57334c 100644
--- a/plugins/services/app/models/service.rb
+++ b/plugins/services/app/models/service.rb
@@ -88,13 +88,17 @@ class Service
return { :stderr => e }
end

- if custom_service.blank? or not custom_service.has_key?(cmd)
+ if custom_service.blank?
Rails.logger.debug "no custom command found, calling YaPI..."
ret = YastService.Call("YaPI::SERVICES::Execute", self.name, cmd)
else
- command = custom_service[cmd]
- Rails.logger.debug "Service commmand #{command}"
- ret = Scr.instance.execute([command])
+ if custom_service.has_key?(cmd) and !custom_service[cmd].blank?
+ command = custom_service[cmd]
+ Rails.logger.debug "Service commmand #{command}"
+ ret = Scr.instance.execute([command])
+ else
+ raise Exception.new("Missing custom command to '#{cmd}' command")
+ end
end

Rails.logger.debug "Command returns: #{ret.inspect}"
diff --git a/plugins/services/test/unit/services_test.rb
b/plugins/services/test/unit/services_test.rb
index 4df006c..2620195 100644
--- a/plugins/services/test/unit/services_test.rb
+++ b/plugins/services/test/unit/services_test.rb
@@ -7,6 +7,10 @@ class ServiceTest < ActiveSupport::TestCase
def setup
end

+ def vendor_config(name)
+ File.join(File.dirname(__FILE__), 'vendor_config', name)
+ end
+
test "read current runlevel" do
Service.stubs(:run_runlevel).returns("N 5")

@@ -53,17 +57,31 @@ class ServiceTest < ActiveSupport::TestCase
assert ret.map {|s| s.name} == ['acpid', 'dbus']
end

-
test "find custom service" do
-# TODO
+ Service.stubs(:run_runlevel).returns("N 5")
+
YaST::ConfigFile.stubs(:config_default_location).returns(vendor_config('valid'))
+
+ ret = Service.find_all({"custom" => true})
+ assert ret.map {|s| s.name} == ['vendor_service']
end

- test "check invalid custom service" do
-# TODO
+ test "missing custom service" do
+ Service.stubs(:run_runlevel).returns("N 5")
+
YaST::ConfigFile.stubs(:config_default_location).returns(vendor_config('missing'))
+ YastService.stubs(:Call).returns({})
+
+ ret = Service.find_all({"custom" => true})
+ assert ret.map {|s| s.name} == []
end

- test "missing command is custom service" do
-# TODO
+ test "missing command in custom service" do
+
YaST::ConfigFile.stubs(:config_default_location).returns(vendor_config('invalid'))
+ YastService.stubs(:Call).returns({})
+
+ s = Service.new('vendor_service')
+ assert_raise Exception do
+ s.save('status')
+ end
end

test "check missing LSB service" do
@@ -82,7 +100,18 @@ class ServiceTest < ActiveSupport::TestCase
assert s.save('status') == ret
end

+
test "check custom service status" do
+
YaST::ConfigFile.stubs(:config_default_location).returns(vendor_config('valid'))
+
+ # do not call introspection in the Scr constructor
+ DBus::SystemBus.instance.stubs(:introspect).returns('<node><interface
name="org.opensuse.yast.SCR.Methods"></interface></node>')
+
+ ret = {:exit => 0, :stderr => "", :stdout => "Checking for service
collectd ..running\n"}
+ Scr.instance.stubs(:execute).with(['/usr/sbin/rccollectd
status']).returns(ret)
+
+ s = Service.new('vendor_service')
+ assert s.save("status") == ret
end


diff --git
a/plugins/services/test/unit/vendor_config/invalid/custom_services.yml
b/plugins/services/test/unit/vendor_config/invalid/custom_services.yml
new file mode 100644
index 0000000..755c63e
--- /dev/null
+++ b/plugins/services/test/unit/vendor_config/invalid/custom_services.yml
@@ -0,0 +1,3 @@
+# This an invalid example of vendor config (missing commands)
+vendor_service:
+ description: Statistics Collection Daemon for filling RRD Files
diff --git a/plugins/services/test/unit/vendor_config/valid/custom_services.yml
b/plugins/services/test/unit/vendor_config/valid/custom_services.yml
new file mode 100644
index 0000000..1b91373
--- /dev/null
+++ b/plugins/services/test/unit/vendor_config/valid/custom_services.yml
@@ -0,0 +1,6 @@
+# This a valid example of vendor config
+vendor_service:
+ description: Statistics Collection Daemon for filling RRD Files
+ start: "/usr/sbin/rccollectd start"
+ stop: "/usr/sbin/rccollectd stop"
+ status: "/usr/sbin/rccollectd status"
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages