Skip to content

Commit

Permalink
(MODULES-6860) Add dsc_lite feature for confines
Browse files Browse the repository at this point in the history
 - Previously when a version of PowerShell older than 5.0.10586.117
   was installed, Puppet would return an error message like:

   Error: Could not find a suitable provider for dsc

   Unfortunately this message did not yield any useful information,
   even with --debug and --verbose turned on, because of the way the
   existing confine check was performed with a confine :true

   To produce a more useful message that is meaningful to users,
   introduce a new feature that performs the same check as the
   confine, but that also will issue an error message (only once)
   that indicates the installed version / required version constraints
   for the module, changing the output to:.

   Error: The dsc_lite module requires PowerShell version 5.0.10586.117 - current version 5.0.10514.6\n   (file & line not available)
   Error: Could not find a suitable provider for dsc

 - Note that DSC_LITE_MODULE_POWERSHELL_UPGRADE_MSG is never actually
   shown when the PowerShell version is < 5.0.10586.117 because the
   check occurs too late in the lifecycle of loading providers. The
   confine code has already evaluated, preventing the other messsages
   from being shown.
  • Loading branch information
Iristyle committed Mar 16, 2018
1 parent a05396e commit 995e089
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions lib/puppet/feature/dsc_lite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'puppet/util/feature'

if Puppet.features.microsoft_windows?
required_version = Gem::Version.new('5.0.10586.117')
installed_version = Gem::Version.new(Facter.value(:powershell_version))

if (installed_version >= required_version)
Puppet.features.add(:dsc_lite)
else
Puppet.warn_once(
'dsc_lite_unavailable',
:dsc_lite_unavailable,
_("The dsc_lite module requires PowerShell version %{required} - current version %{current}") %
{ :required => required_version, :current => installed_version},
nil,
nil,
:err
)
end
end
4 changes: 2 additions & 2 deletions lib/puppet/type/dsc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
fail("#{value} is not a valid #{self.name.to_s}") unless value =~ /^[a-zA-Z0-9\.\-\_\'\s]+$/
end
end

newparam(:dsc_resource_name) do
desc "DSC Resource Name"
isrequired
Expand Down Expand Up @@ -66,7 +66,7 @@
end

Puppet::Type.type(:dsc).provide :powershell, :parent => Puppet::Type.type(:base_dsc_lite).provider(:powershell) do
confine :true => (Gem::Version.new(Facter.value(:powershell_version)) >= Gem::Version.new('5.0.10586.117'))
confine :feature => :dsc_lite
defaultfor :operatingsystem => :windows

mk_resource_methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def builddepends
end

Puppet::Type.type(:dsc_puppetfakeresource).provide :powershell, :parent => Puppet::Type.type(:base_dsc_lite).provider(:powershell) do
confine :true => (Gem::Version.new(Facter.value(:powershell_version)) >= Gem::Version.new('5.0.10240.16384'))
confine :feature => :dsc_lite
defaultfor :operatingsystem => :windows

mk_resource_methods
Expand Down

0 comments on commit 995e089

Please sign in to comment.