summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Ford <ben.ford@puppetlabs.com>2015-08-19 08:31:36 -0700
committerBen Ford <ben.ford@puppetlabs.com>2015-08-19 15:05:47 -0700
commit66e118a92aa480739f62e4675ed80c79ef80619c (patch)
tree15d14d31a622c400c9734cecafeb0693480663fe
parent1d89df906e1ae1d09a862974181663caaf8012c6 (diff)
Add a service_provider fact
This returns the default provider Puppet will choose to manage services on this system by instantiating a dummy service resource type and returning the provider chosen. Co-Authored-By: Simon Fraser University <asa188@sfu.ca>
-rw-r--r--lib/facter/service_provider.rb14
-rw-r--r--spec/unit/facter/service_provider_spec.rb37
2 files changed, 51 insertions, 0 deletions
diff --git a/lib/facter/service_provider.rb b/lib/facter/service_provider.rb
new file mode 100644
index 0000000..54db937
--- /dev/null
+++ b/lib/facter/service_provider.rb
@@ -0,0 +1,14 @@
+# Fact: service_provider
+#
+# Purpose: Returns the default provider Puppet will choose to manage services
+# on this system
+#
+# Resolution: Instantiates a dummy service resource and return the provider
+#
+# Caveats:
+#
+Facter.add(:service_provider) do
+ setcode do
+ Puppet::Type.type(:service).newservice(:name => 'dummy')[:provider].to_s
+ end
+end
diff --git a/spec/unit/facter/service_provider_spec.rb b/spec/unit/facter/service_provider_spec.rb
new file mode 100644
index 0000000..ad8a5fc
--- /dev/null
+++ b/spec/unit/facter/service_provider_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+require 'puppet/type'
+require 'puppet/type/service'
+
+describe 'service_provider', :type => :fact do
+ before { Facter.clear }
+ after { Facter.clear }
+
+ context "macosx" do
+ it "should return launchd" do
+ provider = Puppet::Type.type(:service).provider(:launchd)
+ Puppet::Type.type(:service).stubs(:defaultprovider).returns provider
+
+ expect(Facter.fact(:service_provider).value).to eq('launchd')
+ end
+ end
+
+ context "systemd" do
+ it "should return systemd" do
+ provider = Puppet::Type.type(:service).provider(:systemd)
+ Puppet::Type.type(:service).stubs(:defaultprovider).returns provider
+
+ expect(Facter.fact(:service_provider).value).to eq('systemd')
+ end
+ end
+
+ context "redhat" do
+ it "should return redhat" do
+ provider = Puppet::Type.type(:service).provider(:redhat)
+ Puppet::Type.type(:service).stubs(:defaultprovider).returns provider
+
+ expect(Facter.fact(:service_provider).value).to eq('redhat')
+ end
+ end
+
+end