18197420 pkg publisher provider should handle set/disable combination
authorDrew Fisher <drew.fisher@oracle.com>
Wed, 06 Aug 2014 10:27:03 -0600
changeset 2031 5b9a9cd91149
parent 2030 bdc5bb5c4f99
child 2032 916ced318d1e
18197420 pkg publisher provider should handle set/disable combination 19278382 svccfg provider doesn't verify properties correctly 19308306 puppet verify fails on file:/ pkg publisher
components/puppet/files/solaris/lib/puppet/provider/pkg_publisher/solaris.rb
components/puppet/files/solaris/lib/puppet/provider/svccfg/solaris.rb
components/puppet/files/solaris/lib/puppet/type/pkg_publisher.rb
components/puppet/files/solaris/lib/puppet/type/svccfg.rb
--- a/components/puppet/files/solaris/lib/puppet/provider/pkg_publisher/solaris.rb	Tue Aug 05 18:00:26 2014 -0700
+++ b/components/puppet/files/solaris/lib/puppet/provider/pkg_publisher/solaris.rb	Wed Aug 06 10:27:03 2014 -0600
@@ -134,13 +134,6 @@
 
     def build_flags
         flags = []
-        if enable = @resource[:enable] and enable != nil
-            if enable == :true
-                flags << "--enable"
-            elsif enable == :false
-                flags << "--disable"
-            end
-        end
 
         if searchfirst = @resource[:searchfirst] and searchfirst != ""
             if searchfirst == :true
@@ -236,6 +229,13 @@
     # required puppet functions
     def create
         pkg("set-publisher", build_flags, build_origin, @resource[:name])
+        # pkg(5) does not allow for a new publisher to be set with the disabled
+        # flag, so check for it after setting the publisher
+        if enable = @resource[:enable] and enable != nil
+            if enable == :false
+                pkg("set-publisher", "--disable", @resource[:name])
+            end
+        end
     end
 
     def destroy
--- a/components/puppet/files/solaris/lib/puppet/provider/svccfg/solaris.rb	Tue Aug 05 18:00:26 2014 -0700
+++ b/components/puppet/files/solaris/lib/puppet/provider/svccfg/solaris.rb	Wed Aug 06 10:27:03 2014 -0600
@@ -20,7 +20,7 @@
 #
 
 #
-# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
 #
 
 Puppet::Type.type(:svccfg).provide(:svccfg) do
@@ -35,20 +35,23 @@
             # only test for the existance of the property and not the value
             return p[:exit] == 0
         elsif @resource[:ensure] == :present
-            # if the property doesn't exist at all, the exit code will be 1
+            # if the property group or property doesn't exist at all, the exit
+            # code will be 1
             return false if p[:exit] != 0
 
-            # strip the leading and trailing parens if resource[:property]
-            # contains a slash as this indicates that a value is associated
-            # with it.
+            # turn @resource[:value] into a simple string by dropping the first
+            # and last array elements (the parens) and removing all double
+            # quotes
+            simple = @resource[:value][1..-2].join(" ")[1..-2].gsub(/\"/, "")
+
+            # For properties, check the value against what's in SMF.  For
+            # property groups, svcprop already verified the PG exists by not
+            # failing
             if @resource[:property].include? "/"
-                return p[:out].strip == \
-                    @resource[:value][1..-2].join(" ")[1..-2]
+                return p[:out].strip == simple
+            else
+                return p[:exit] == 0
             end
-            # resource[:property] is a property group, not a property.
-            # There is no value to manipulate, but the property needs to be
-            # created, so return true.
-            return p[:exit] == 0
         end
     end
 
@@ -57,26 +60,32 @@
         cmd = Array[command(:svccfg), "select", @resource[:fmri]]
         svc_exist = exec_cmd(cmd)
 
-        # Create the service instance if it doesn't exist
+        # Raise an error if the entity does not exist
         if svc_exist[:exit] != 0
-            service, instance = \
-                @resource[:fmri].split(":").reject{|n| n == "svc"}
-            svccfg("-s", service, "add", instance)
+            raise Puppet::Error, "SMF entity #{@resource[:fmri]} does not exist"
         end
+        
+        args = ["-s", @resource[:fmri]]
 
-        # Add the property
         if @resource[:property].include? "/"
-            svccfg("-s", @resource[:fmri], "setprop", @resource[:property],
-                   "=", @resource[:type] + ":", @resource[:value])
+            args << "setprop" << @resource[:property] << "="
+            if type = @resource[:type] and type != nil
+                args << @resource[:type] + ":"
+            end
+            args << @resource[:value]
         else
-            svccfg("-s", @resource[:fmri], "addpg", @resource[:property],
-                   @resource[:type])
+            args << "addpg" << @resource[:property] << @resource[:type]
         end
+        svccfg(args)
         svccfg("-s", @resource[:fmri], "refresh")
     end
 
     def destroy
-        svccfg("-s", @resource[:fmri], "delprop", @resource[:property])
+        if @resource[:property].include? "/"
+            svccfg("-s", @resource[:fmri], "delprop", @resource[:property])
+        else
+            svccfg("-s", @resource[:fmri], "delpg", @resource[:property])
+        end
         svccfg("-s", @resource[:fmri], "refresh")
     end
 
--- a/components/puppet/files/solaris/lib/puppet/type/pkg_publisher.rb	Tue Aug 05 18:00:26 2014 -0700
+++ b/components/puppet/files/solaris/lib/puppet/type/pkg_publisher.rb	Wed Aug 06 10:27:03 2014 -0600
@@ -20,7 +20,7 @@
 #
 
 #
-# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
 #
 
 require 'puppet/property/list'
@@ -51,6 +51,15 @@
         def retrieve
             provider.origin
         end
+
+        # for origins with a file:// URI, strip any trailing / character
+        munge do |value|
+            if value.start_with? "file" and value.end_with? "/"
+                value = value.chomp("/")
+            else
+                value
+            end
+        end
     end
 
     newproperty(:enable) do
--- a/components/puppet/files/solaris/lib/puppet/type/svccfg.rb	Tue Aug 05 18:00:26 2014 -0700
+++ b/components/puppet/files/solaris/lib/puppet/type/svccfg.rb	Wed Aug 06 10:27:03 2014 -0600
@@ -20,7 +20,7 @@
 #
 
 #
-# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
 #
 
 Puppet::Type.newtype(:svccfg) do
@@ -42,7 +42,8 @@
 
     newparam(:name) do
         desc "The symbolic name for properties to manipulate.  This name is
-              used for human reference only"
+              meaningful only within Puppet manifests and not expressed to
+              SMF in any way."
         isnamevar
     end
 
@@ -51,7 +52,9 @@
     end
 
     newparam(:property) do
-        desc "Name of property - includes Property Group and Propery"
+        desc "Name of property - includes Property Group and Property.  If
+              the service, instance, or property group does not exist, they
+              will be created."
     end
 
     newparam(:type) do
@@ -61,7 +64,9 @@
     newparam(:value) do
         desc "Value of the property"
         munge do |value|
-            # cast the value to an array
+            # cast the value to an array.  This is done for the case where a
+            # property needs to be set.  exists? will undo all of this and
+            # revert the value into a simple string for comparisons.
             if not value.is_a? Array
                 value = Array[value]
             end