Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MODULES-6860) Add dsc_lite feature for confines #41

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/puppet/feature/dsc_lite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'puppet/util/feature'

if Puppet.features.microsoft_windows?

DSC_LITE_MODULE_POWERSHELL_UPGRADE_MSG = <<-UPGRADE
The dsc_lite module requires PowerShell version %{required} - current version %{current}

The cmdlet Invoke-DscResource was introduced in v5.0, and is necessary for the
dsc_lite module to function. Further bug fixes, first made available in version
%{required} are also necessary for this module to function.

To enable this module, please install the latest version of WMF 5+ from Microsoft.
UPGRADE

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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'dsc_lite_unavailable',
:dsc_lite_unavailable,
DSC_LITE_MODULE_POWERSHELL_UPGRADE_MSG %
{ :required => required_version, :current => installed_version},
nil,
nil,
:err
)
end
end
19 changes: 0 additions & 19 deletions lib/puppet/provider/base_dsc_lite/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'json'
if Puppet::Util::Platform.windows?
require_relative '../../../puppet_x/puppetlabs/dsc_lite/powershell_manager'
require_relative '../../../puppet_x/puppetlabs/dsc_lite/compatible_powershell_version'
require_relative '../../../puppet_x/puppetlabs/dsc_lite/powershell_hash_formatter'
end

Expand Down Expand Up @@ -35,18 +34,6 @@
Puppet (including 3.x), or to a Puppet version newer than 3.x.
UPGRADE

DSC_LITE_MODULE_POWERSHELL_UPGRADE_MSG = <<-UPGRADE
Currently, the dsc module has reduced functionality on this agent
due to one or more of the following conditions:
- A PowerShell less than 5.0
The dsc module requires PowerShell v5.0 or greater to function. THe cmdlet
Invoke-DscResource was introduced in v5.0, and is necessary for the dsc module
to work
To enable these improvements, it is suggested to upgrade to any x64 version of
Puppet (including 3.x), or to a Puppet version newer than 3.x and ensure you
have at least PowerShell v5.0 installed.
UPGRADE

def self.upgrade_message
Puppet.warning DSC_LITE_MODULE_PUPPET_UPGRADE_MSG if !@upgrade_warning_issued
@upgrade_warning_issued = true
Expand Down Expand Up @@ -92,8 +79,6 @@ def exists?
script_content = ps_script_content('test')
Puppet.debug "\n" + script_content

fail DSC_LITE_MODULE_POWERSHELL_UPGRADE_MSG if !PuppetX::DscLite::PowerShellManager.compatible_version_of_powershell?

if !PuppetX::DscLite::PowerShellManager.supported?
self.class.upgrade_message
output = powershell(self.class.powershell_args, script_content)
Expand All @@ -114,8 +99,6 @@ def create
script_content = ps_script_content('set')
Puppet.debug "\n" + script_content

fail DSC_LITE_MODULE_POWERSHELL_UPGRADE_MSG if !PuppetX::DscLite::PowerShellManager.compatible_version_of_powershell?

if !PuppetX::DscLite::PowerShellManager.supported?
self.class.upgrade_message
output = powershell(self.class.powershell_args, script_content)
Expand All @@ -136,8 +119,6 @@ def destroy
script_content = ps_script_content('set')
Puppet.debug "\n" + script_content

fail DSC_LITE_MODULE_POWERSHELL_UPGRADE_MSG if !PuppetX::DscLite::PowerShellManager.compatible_version_of_powershell?

if !PuppetX::DscLite::PowerShellManager.supported?
self.class.upgrade_message
output = powershell(self.class.powershell_args, script_content)
Expand Down
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
19 changes: 0 additions & 19 deletions lib/puppet_x/puppetlabs/dsc_lite/compatible_powershell_version.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/puppet_x/puppetlabs/dsc_lite/powershell_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'securerandom'
require 'open3'
require 'base64'
require File.join(File.dirname(__FILE__), 'compatible_powershell_version')
require 'puppet/feature/dsc_lite'

module PuppetX
module DscLite
Expand All @@ -29,7 +29,7 @@ def self.win32console_enabled?
end

def self.compatible_version_of_powershell?
@compatible_powershell_version ||= PuppetX::PuppetLabs::DscLite::CompatiblePowerShellVersion.compatible_version?
@compatible_powershell_version ||= Puppet.features.dsc_lite?
end

def self.supported?
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'spec_helper'
require 'puppet/type'
require 'puppet_x/puppetlabs/dsc_lite/powershell_manager'
require 'puppet_x/puppetlabs/dsc_lite/compatible_powershell_version'

module PuppetX
module DscLite
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