Please review pull request #659: (#13888) Fix self.instances for systemd service provider opened by (bodepd)

Description:

Previously, attempting to run puppet resource service
on Fedora 16 resulted in a stack trace.

This commit resolves the issue so that self.instances should
work for systemd providers. The issue was that the instances
method was returning an Array of strings. This commit updates the
method to correctly return an Array of Provider instances.

  • Opened: Wed Apr 11 22:22:33 UTC 2012
  • Based on: puppetlabs:master (42c8526aca72a4205358f8e8fdab20f48417106b)
  • Requested merge: bodepd:bug/master/13888_systemd_self_instances_fix (471057e432cc1b688c2ea10550d85fdd23c55670)

Diff follows:

diff --git a/lib/puppet/provider/service/systemd.rb b/lib/puppet/provider/service/systemd.rb
index 33ff52d..e206b11 100755
--- a/lib/puppet/provider/service/systemd.rb
+++ b/lib/puppet/provider/service/systemd.rb
@@ -9,9 +9,9 @@
 
   def self.instances
     i = []
-    output = `systemctl list-units --full --all --no-pager`
+    output = systemctl('list-units', '--full', '--all',  '--no-pager')
     output.scan(/^(\S+)\s+(loaded|error)\s+(active|inactive)\s+(active|waiting|running|plugged|mounted|dead|exited|listening|elapsed)\s*?(\S.*?)?$/i).each do |m|
-      i << m[0]
+      i << new(:name => m[0])
     end
     return i
   rescue Puppet::ExecutionFailure
diff --git a/spec/unit/provider/service/systemd_spec.rb b/spec/unit/provider/service/systemd_spec.rb
index 8480c01..184b4ad 100755
--- a/spec/unit/provider/service/systemd_spec.rb
+++ b/spec/unit/provider/service/systemd_spec.rb
@@ -30,4 +30,13 @@
       @provider.should respond_to(method)
     end
   end
+
+
+  it 'should return resources from self.instances' do
+    provider_class.expects(:systemctl).with('list-units', '--full', '--all',  '--no-pager').returns(
+      "my_service loaded active running\nmy_other_service loaded active running"
+    )
+    provider_class.instances.map {|provider| provider.name}.should =~ ["my_service","my_other_service"]
+  end
+
 end

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to