Skip to content
Open
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
26 changes: 23 additions & 3 deletions lib/puppet/provider/windowsfeature/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
def self.instances
# an array to store feature hashes
features = []
result = ps(%($ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Get-WindowsFeature | Select-Object -Property Name, Installed | ConvertTo-XML -As String -Depth 4 -NoTypeInformation))
result = ps(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Get-WindowsFeature | Select-Object -Property Name, Installed | ConvertTo-Xml -As String -Depth 4 -NoTypeInformation"
)
# create the XML document and parse the objects
xml = Document.new result
xml.root.each_element do |object|
Expand Down Expand Up @@ -81,7 +87,14 @@ def create
array << '-IncludeManagementTools' if @resource[:installmanagementtools] == true && win2008 == false
# show the created ps string, get the result, show the result (debug)
Puppet.debug "Powershell create command is '#{array}'"
result = ps(array.join(' '))
result = ps(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command',
array.join(' ')
)
Puppet.debug "Powershell create response was '#{result}'"
end

Expand All @@ -100,7 +113,14 @@ def destroy
end
# show the created ps string, get the result, show the result (debug)
Puppet.debug "Powershell destroy command is '#{array}'"
result = ps(array.join(' '))
result = ps(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command',
array.join(' ')
)
Puppet.debug "Powershell destroy response was '#{result}'"
end
end
80 changes: 70 additions & 10 deletions spec/unit/puppet/provider/windowsfeature/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
before do
allow(Facter).to receive(:value).with(:kernel).and_return(:windows)
allow(Facter).to receive(:value).with(:kernelmajversion).and_return('6.2')
allow(provider.class).to receive(:ps).with(%($ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Get-WindowsFeature | Select-Object -Property Name, Installed | ConvertTo-XML -As String -Depth 4 -NoTypeInformation)).and_return(windows_feature_xml)
allow(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Get-WindowsFeature | Select-Object -Property Name, Installed | ConvertTo-Xml -As String -Depth 4 -NoTypeInformation"
).and_return(windows_feature_xml)
end

it 'supports resource discovery' do
Expand Down Expand Up @@ -63,15 +69,27 @@
context 'on Windows 6.1' do
it 'runs Import-Module ServerManager; Add-WindowsFeature' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.1')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with('Import-Module ServerManager; Add-WindowsFeature feature-name').and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', 'Import-Module ServerManager; Add-WindowsFeature feature-name'
).and_return('')
provider.create
end
end

context 'on Windows 6.2 onward' do
it 'runs Install-WindowsFeature' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.2')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with("$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name").and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name"
).and_return('')
provider.create
end
end
Expand All @@ -92,7 +110,13 @@

it 'runs Install-WindowsFeature with -IncludeManagementTools' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.2')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with("$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name -IncludeManagementTools").and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name -IncludeManagementTools"
).and_return('')
provider.create
end
end
Expand All @@ -108,7 +132,13 @@

it 'runs Install-WindowsFeature with -IncludeAllSubFeature' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.2')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with("$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name -IncludeAllSubFeature").and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name -IncludeAllSubFeature"
).and_return('')
provider.create
end
end
Expand All @@ -124,7 +154,13 @@

it 'runs Install-WindowsFeature with -Source C:\Windows\sxs' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.2')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with("$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name -Source C:\\Windows\\sxs").and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name -Source C:\\Windows\\sxs"
).and_return('')
provider.create
end
end
Expand All @@ -140,7 +176,13 @@

it 'runs Install-WindowsFeature with -Restart' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.2')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with("$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name -Restart").and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Install-WindowsFeature feature-name -Restart"
).and_return('')
provider.create
end
end
Expand All @@ -150,15 +192,27 @@
context 'on Windows 6.1' do
it 'runs Import-Module ServerManager; Remove-WindowsFeature' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.1')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with('Import-Module ServerManager; Remove-WindowsFeature feature-name').and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', 'Import-Module ServerManager; Remove-WindowsFeature feature-name'
).and_return('')
provider.destroy
end
end

context 'on Windows 6.2 onward' do
it 'runs Uninstall-WindowsFeature' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.2')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with("$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Uninstall-WindowsFeature feature-name").and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Uninstall-WindowsFeature feature-name"
).and_return('')
provider.destroy
end
end
Expand All @@ -174,7 +228,13 @@

it 'runs Uninstall-WindowsFeature with -Restart' do
expect(Facter).to receive(:value).with(:kernelmajversion).and_return('6.2')
expect(Puppet::Type::Windowsfeature::ProviderDefault).to receive(:ps).with("$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Uninstall-WindowsFeature feature-name -Restart").and_return('')
expect(provider.class).to receive(:ps).with(
'-NoProfile',
'-NonInteractive',
'-NoLogo',
'-ExecutionPolicy', 'Bypass',
'-Command', "$ProgressPreference='SilentlyContinue'; Import-Module ServerManager; Uninstall-WindowsFeature feature-name -Restart"
).and_return('')
provider.destroy
end
end
Expand Down