Skip to content

Commit

Permalink
add Import-Module ServerManager for win2012r2 PS commands (#110)
Browse files Browse the repository at this point in the history
Import ServerManager module so the `*-WindowsFeature` cmdlets are available.
  • Loading branch information
devcfgc authored and vinzent committed Dec 16, 2017
1 parent d9c4576 commit ef7bd75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/puppet/provider/windowsfeature/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.instances
result = if win2008 == true
ps('Import-Module ServerManager; Get-WindowsFeature | Select Name,Installed | ConvertTo-XML -As String -Depth 4 -NoTypeInformation')
else
ps('Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation')
ps('Import-Module ServerManager; Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation')
end
# create the XML document and parse the objects
xml = Document.new result
Expand Down Expand Up @@ -70,7 +70,7 @@ def create
win2008 = Facter.value(:kernelmajversion) == '6.1'
# set the install line
array << "Import-Module ServerManager; Add-WindowsFeature #{resource[:name]}" if win2008 == true
array << "Install-WindowsFeature #{resource[:name]}" if win2008 == false
array << "Import-Module ServerManager; Install-WindowsFeature #{resource[:name]}" if win2008 == false
# add restart, subfeatures and a source optionally
array << '-IncludeAllSubFeature' if @resource[:installsubfeatures] == true
array << '-Restart' if @resource[:restart] == true
Expand All @@ -94,7 +94,7 @@ def destroy
win2008 = Facter.value(:kernelmajversion) == '6.1'
# set the uninstall line
array << "Import-Module ServerManager; Remove-WindowsFeature #{resource[:name]}" if win2008 == true
array << "Uninstall-WindowsFeature #{resource[:name]}" if win2008 == false
array << "Import-Module ServerManager; Uninstall-WindowsFeature #{resource[:name]}" if win2008 == false
# add the restart flag optionally
array << '-Restart' if @resource[:restart] == true
# show the created ps string, get the result, show the result (debug)
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/puppet/provider/windowsfeature/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
before do
Facter.stubs(:value).with(:kernel).returns(:windows)
Facter.stubs(:value).with(:kernelmajversion).returns('6.2')
provider.class.stubs(:ps).with('Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation').returns(windows_feature_xml)
provider.class.stubs(:ps).with('Import-Module ServerManager; Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation').returns(windows_feature_xml)
end

it 'supports resource discovery' do
Expand Down Expand Up @@ -68,7 +68,7 @@
context 'on Windows 6.2 onward' do
it 'runs Install-WindowsFeature' do
Facter.expects(:value).with(:kernelmajversion).returns('6.2')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Install-WindowsFeature feature-name').returns('')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Import-Module ServerManager; Install-WindowsFeature feature-name').returns('')
provider.create
end
end
Expand All @@ -88,7 +88,7 @@

it 'runs Install-WindowsFeature with -IncludeManagementTools' do
Facter.expects(:value).with(:kernelmajversion).returns('6.2')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Install-WindowsFeature feature-name -IncludeManagementTools').returns('')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Import-Module ServerManager; Install-WindowsFeature feature-name -IncludeManagementTools').returns('')
provider.create
end
end
Expand All @@ -104,7 +104,7 @@

it 'runs Install-WindowsFeature with -IncludeAllSubFeature' do
Facter.expects(:value).with(:kernelmajversion).returns('6.2')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Install-WindowsFeature feature-name -IncludeAllSubFeature').returns('')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Import-Module ServerManager; Install-WindowsFeature feature-name -IncludeAllSubFeature').returns('')
provider.create
end
end
Expand All @@ -120,7 +120,7 @@

it 'runs Install-WindowsFeature with -Source C:\Windows\sxs' do
Facter.expects(:value).with(:kernelmajversion).returns('6.2')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Install-WindowsFeature feature-name -Source C:\Windows\sxs').returns('')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Import-Module ServerManager; Install-WindowsFeature feature-name -Source C:\Windows\sxs').returns('')
provider.create
end
end
Expand All @@ -136,7 +136,7 @@

it 'runs Install-WindowsFeature with -Restart' do
Facter.expects(:value).with(:kernelmajversion).returns('6.2')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Install-WindowsFeature feature-name -Restart').returns('')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Import-Module ServerManager; Install-WindowsFeature feature-name -Restart').returns('')
provider.create
end
end
Expand All @@ -153,7 +153,7 @@
context 'on Windows 6.2 onward' do
it 'runs Uninstall-WindowsFeature' do
Facter.expects(:value).with(:kernelmajversion).returns('6.2')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Uninstall-WindowsFeature feature-name').returns('')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Import-Module ServerManager; Uninstall-WindowsFeature feature-name').returns('')
provider.destroy
end
end
Expand All @@ -168,7 +168,7 @@

it 'runs Uninstall-WindowsFeature with -Restart' do
Facter.expects(:value).with(:kernelmajversion).returns('6.2')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Uninstall-WindowsFeature feature-name -Restart').returns('')
Puppet::Type::Windowsfeature::ProviderDefault.expects('ps').with('Import-Module ServerManager; Uninstall-WindowsFeature feature-name -Restart').returns('')
provider.destroy
end
end
Expand Down

0 comments on commit ef7bd75

Please # to comment.