Skip to content

Commit cd2bf2c

Browse files
committed
Merge branch 'master' into stable
* master: (FM-5240) Prevent powershell_manager DSC conflict (MODULES-2634) Verify try/catch with PowerShell module
2 parents 9276de6 + 9c63ccb commit cd2bf2c

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

lib/puppet/provider/exec/powershell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'puppet/provider/exec'
2-
require_relative '../../../puppet_x/puppetlabs/powershell_manager'
2+
require_relative '../../../puppet_x/puppetlabs/powershell/powershell_manager'
33

44
Puppet::Type.type(:exec).provide :powershell, :parent => Puppet::Provider::Exec do
55
confine :operatingsystem => :windows

lib/puppet_x/puppetlabs/powershell_manager.rb renamed to lib/puppet_x/puppetlabs/powershell/powershell_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def exit
8787
end
8888

8989
def template_path
90-
File.expand_path('../../templates', __FILE__)
90+
File.expand_path('../../../templates', __FILE__)
9191
end
9292

9393
def make_ps_code(powershell_code, output_ready_event_name, timeout_ms = 300 * 1000)

spec/acceptance/exec_powershell_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@
3434

3535
end
3636

37+
describe 'should handle a try/catch successfully' do
38+
39+
powershell_cmd = <<-CMD
40+
try{
41+
$foo = ls
42+
$count = $foo.count
43+
$count
44+
}catch{
45+
Write-Error "foo"
46+
}
47+
CMD
48+
49+
p1 = <<-MANIFEST
50+
exec{'TestPowershell':
51+
command => '#{powershell_cmd}',
52+
provider => powershell,
53+
}
54+
MANIFEST
55+
56+
it 'should not error' do
57+
apply_manifest(p1, :expect_changes => true, :future_parser => FUTURE_PARSER)
58+
end
59+
60+
end
61+
3762
describe 'should run commands that exit session' do
3863

3964
exit_pp = <<-MANIFEST

spec/integration/puppet_x/puppetlabs/powershell_manager_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper'
22
require 'puppet/type'
3-
require 'puppet_x/puppetlabs/powershell_manager'
3+
require 'puppet_x/puppetlabs/powershell/powershell_manager'
44

55
module PuppetX
66
module PowerShell
@@ -89,6 +89,22 @@ class PowerShellManager; end
8989
expect(result[:exitcode]).to eq(0)
9090
end
9191

92+
it "should execute code with a try/catch" do
93+
result = manager.execute(<<-CODE
94+
try{
95+
$foo = ls
96+
$count = $foo.count
97+
$count
98+
}catch{
99+
Write-Error "foo"
100+
}
101+
CODE
102+
)
103+
104+
expect(result[:stdout]).not_to eq(nil)
105+
expect(result[:exitcode]).to eq(0)
106+
end
107+
92108
it "should reuse the same PowerShell process for multiple calls" do
93109
first_pid = manager.execute('[Diagnostics.Process]::GetCurrentProcess().Id')[:stdout]
94110
second_pid = manager.execute('[Diagnostics.Process]::GetCurrentProcess().Id')[:stdout]

spec/unit/provider/exec/powershell_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env ruby
22
require 'spec_helper'
33
require 'puppet/util'
4-
require 'puppet_x/puppetlabs/powershell_manager'
4+
require 'puppet_x/puppetlabs/powershell/powershell_manager'
55

66
describe Puppet::Type.type(:exec).provider(:powershell) do
77

0 commit comments

Comments
 (0)