186 changes: 87 additions & 99 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,171 +1,159 @@
## 2017-03-29 - Supported Release 2.1.4
# Changelog

### Summary
All notable changes to this project will be documented in this file.

Small release with bug fixes
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

### Bug Fixes
## [Unreleased]

- Unabled to start pipes server in PowerShell process on some Windows 2008r2 images ([MODULES-6927](https://tickets.puppetlabs.com/browse/MODULES-6927))
- Minor updates to PowerShell syntax in README examples.
## [2.1.5] - 2018-05-08

## 2017-12-08 - Supported Release 2.1.3
### Added

### Summary
- Metadata for supporting Windows Server 2016 ([MODULES-4271](https://tickets.puppetlabs.com/browse/MODULES-4271))

Small release with bug fixes.
### Fixed

### Bug Fixes
- Upgraded message to make .NET Framework requirements clearer when running PowerShell 2.0 ([MODULES-7011](https://tickets.puppetlabs.com/browse/MODULES-7011))
- Fixed timeout handling when the user specifies a timeout parameter value of `0` to substitute the default of 300 seconds ([MODULES-7018](https://tickets.puppetlabs.com/browse/MODULES-7018))

- Fix timeouts and zombie process creation ([MODULES-4748](https://tickets.puppetlabs.com/browse/MODULES-4748))
- Update PowerShell executable name for experimental cross-platform / PowerShell 6 support ([MODULES-6081](https://tickets.puppetlabs.com/browse/MODULES-6081))
## [2.1.4] - 2017-03-29

## 2017-07-27 - Supported Release 2.1.2
### Fixed

### Summary
- Ensured that the code is able to start the pipes server in a PowerShell process on Windows 2008R2 images ([MODULES-6927](https://tickets.puppetlabs.com/browse/MODULES-6927))
- Updated PowerShell syntax in README examples

Small release with bugs fixes.
## [2.1.3] - 2017-12-08

### Bug Fixes
### Fixed

- Fix Global Warning variable ([MODULES-5224](https://tickets.puppetlabs.com/browse/MODULES-5224))
- Move PowerShell template file to stop conflicts with DSC Module ([MODULES-5228](https://tickets.puppetlabs.com/browse/MODULES-5228))
- Fixed timeouts and zombie process creation ([MODULES-4748](https://tickets.puppetlabs.com/browse/MODULES-4748))
- Corrected PowerShell executable name for experimental cross-platform / PowerShell 6 support ([MODULES-6081](https://tickets.puppetlabs.com/browse/MODULES-6081))

## 2017-07-07 - Supported Release 2.1.1
## [2.1.2] - 2017-07-27

### Summary
### Fixed

Small release with bugs fixes and experimental support for non-Windows Operating Systems (CentOS and Ubuntu).
- Fixed Global Warning variable ([MODULES-5224](https://tickets.puppetlabs.com/browse/MODULES-5224))
- Moved the PowerShell template file to stop it conflicting with the DSC module ([MODULES-5228](https://tickets.puppetlabs.com/browse/MODULES-5228))

### Features
## [2.1.1] - 2017-07-07

- Added rake tasks for release automation
- Added experimental support for non-Windows Support (CentOS, Ubuntu) ([MODULES-3945](https://tickets.puppetlabs.com/browse/MODULES-3945))
### Added

### Bug Fixes
- Rake tasks for release automation
- Experimental support for non-Windows Support (CentOS, Ubuntu) ([MODULES-3945](https://tickets.puppetlabs.com/browse/MODULES-3945))

- Documentation Update ([DOC-2960](https://tickets.puppetlabs.com/browse/DOC-2960))
- Update metadata for Puppet 4 and Puppet 5 ([MODULES-4528](https://tickets.puppetlabs.com/browse/MODULES-4528), [MODULES-4822](https://tickets.puppetlabs.com/browse/MODULES-4822), [MODULES-5144](https://tickets.puppetlabs.com/browse/MODULES-5144))
### Fixed

- Updated documentation ([DOC-2960](https://tickets.puppetlabs.com/browse/DOC-2960))
- Updated metadata for Puppet 4 and Puppet 5 ([MODULES-4528](https://tickets.puppetlabs.com/browse/MODULES-4528), [MODULES-4822](https://tickets.puppetlabs.com/browse/MODULES-4822), [MODULES-5144](https://tickets.puppetlabs.com/browse/MODULES-5144))
- Dispose runspace on pipe close ([MODULES-4754](https://tickets.puppetlabs.com/browse/MODULES-4754))
- Removed rspec configuration for win32_console ([MODULES-4976](https://tickets.puppetlabs.com/browse/MODULES-4976))
- Provider will now respect the environment parameter ([MODULES-4138](https://tickets.puppetlabs.com/browse/MODULES-4138))
- Return available UI Output on error ([MODULES-5145](https://tickets.puppetlabs.com/browse/MODULES-5145))

## 2016-11-17 - Supported Release 2.1.0

### Summary

Small release with bugs fixes and another speed improvement.

### Bug Fixes
## [2.1.0] - 2016-11-17

- Support Windows 2016/WMF 5.1 using named pipes ([MODULES-3690](https://tickets.puppetlabs.com/browse/MODULES-3690))
### Fixed

### Documentation updates
- Support for Windows 2016/WMF 5.1 using named pipes ([MODULES-3690](https://tickets.puppetlabs.com/browse/MODULES-3690))
- Fixed documentation for herestring ([DOC-2960](https://tickets.puppetlabs.com/browse/DOC-2960))

- Document herestring ([DOC-2960](https://tickets.puppetlabs.com/browse/DOC-2960))
### Added

## 2016-10-05 - Supported Release 2.0.3
- Speed improvements to the PowerShell manager ([MODULES-3690](https://tickets.puppetlabs.com/browse/MODULES-3690))

### Summary
## [2.0.3] - 2016-10-05

Small release with bugs fixes and another speed improvement.
### Added

### Bug Fixes
- The ability to set the current working directory ([MODULES-3565](https://tickets.puppetlabs.com/browse/MODULES-3565))

- Miscellaneous fixes which improve reliability
- Capture exit codes when executing external scripts ([MODULES-3399](https://tickets.puppetlabs.com/browse/MODULES-3399))
- Add ability to set current working directory ([MODULES-3565](https://tickets.puppetlabs.com/browse/MODULES-3565))
- Respect user specified timeout ([MODULES-3709](https://tickets.puppetlabs.com/browse/MODULES-3709))
- Improve handling of user code exceptions ([MODULES-3443](https://tickets.puppetlabs.com/browse/MODULES-3443))
- Output line and stacktrace of user code exception ([MODULES-3839](https://tickets.puppetlabs.com/browse/MODULES-3839))
- Improve resilience to failure of PowerShell host ([MODULES-3875](https://tickets.puppetlabs.com/browse/MODULES-3875))
- Fix race condition in threading with PowerShell host ([MODULES-3144](https://tickets.puppetlabs.com/browse/MODULES-3144))
- Modify tests to detect differences in PowerShell error text ([MODULES-3442](https://tickets.puppetlabs.com/browse/MODULES-3442))
### Fixed

### Documentation updates
- Miscellaneous fixes to improve reliability
- Fixed capture exit codes when executing external scripts ([MODULES-3399](https://tickets.puppetlabs.com/browse/MODULES-3399))
- Fixed respect user specified timeout ([MODULES-3709](https://tickets.puppetlabs.com/browse/MODULES-3709))
- Improved handling of user code exceptions ([MODULES-3443](https://tickets.puppetlabs.com/browse/MODULES-3443))
- Fixed output line and stacktrace of user code exception ([MODULES-3839](https://tickets.puppetlabs.com/browse/MODULES-3839))
- Improved the PowerShell host so that it is more resilient to failure ([MODULES-3875](https://tickets.puppetlabs.com/browse/MODULES-3875))
- Fixed race condition in threading with the PowerShell host ([MODULES-3144](https://tickets.puppetlabs.com/browse/MODULES-3144))
- Modified tests to detect differences in PowerShell error text ([MODULES-3443](https://tickets.puppetlabs.com/browse/MODULES-3443))
- Documented how to handle exit codes ([MODULES-3588](https://tickets.puppetlabs.com/browse/MODULES-3588))

- Document how to handle exit codes ([MODULES-3588](https://tickets.puppetlabs.com/browse/MODULES-3588))
## [2.0.2] - 2016-07-12

## 2016-07-12 - Supported Release 2.0.2
### Added

### Summary
- Noticable speed increase by reducing the time start for a PowerShell command ([MODULES-3406](https://tickets.puppetlabs.com/browse/MODULES-3406))
- Tests for try/catch ([MODULES-2634](https://tickets.puppetlabs.com/browse/MODULES-2634))

Small release with bugs fixes and another speed improvement.

### Features

- Noticable speed increase by reducing the time start a PowerShell command ([MODULES-3406](https://tickets.puppetlabs.com/browse/MODULES-3406))

### Bug Fixes
### Fixed

- Fixed minor bugs in tests ([MODULES-3347](https://tickets.puppetlabs.com/browse/MODULES-3347))
- Added tests for try/catch ([MODULES-2634](https://tickets.puppetlabs.com/browse/MODULES-2634))
- Fixed bug with older ruby (1.8)

## 2016-05-24 - Supported Release 2.0.1

### Bug Fixes
## [2.0.1] - 2016-05-24

- Updated the powershell manager in this module in order to not conflict with the Powershell Manager in the Puppet DSC module
### Fixed

## 2016-05-17 - Supported Release 2.0.0
- Updated the PowerShell manager so that it does not conflict with the PowerShell Manager in the Puppet DSC module ([FM-5240](https://tickets.puppetlabs.com/browse/FM-5240))

### Summary
## [2.0.0] - 2016-05-17

Major release with performance improvements
### Changed

Removed support for Windows Server 2003
- Major performance improvement by sharing a single PowerShell session, instead of creating a new PowerShell session per command. This change no longer writes temporary scripts to file system. ([MODULES-2962](https://tickets.puppetlabs.com/browse/MODULES-2962))

### Features
### Fixed

- Major performance improvement by sharing a single powershell session instead of creating a new powershell session per command
- Security improvement as scripts are not stored on the filesystem temporarily
- Updated test suites with later versions ([MODULES-2452](https://tickets.puppetlabs.com/browse/MODULES-2452), [MODULES-3011](https://tickets.puppetlabs.com/browse/MODULES-3011))
- Cleaned up documentation ([MODULES-3192](https://tickets.puppetlabs.com/browse/MODULES-3192))
- Removed extra verbose output

### Bug Fixes
## [1.0.6] - 2015-12-08

- Updated test suites with later versions
- Documentation cleanup
### Fixed

## 2015-12-08 - Supported Release 1.0.6
- Fixed testing bug when testing on Puppet 3+ on Windows Server 2003 ([MODULES-2443](https://tickets.puppetlabs.com/browse/MODULES-2443))

### Summary
## [1.0.5] - 2015-07-28

Small release for support of newer PE versions.
### Added

## 2015-07-28 - Supported Release 1.0.5
- Metadata for Puppet 4 and PE 2015.2.0 ([FM-2752](https://tickets.puppetlabs.com/browse/FM-2752))

### Summary
### Fixed

Add metadata for Puppet 4 and PE 2015.2.0
- Minor testing bug fixes ([MODULES-2207](https://tickets.puppetlabs.com/browse/MODULES-2207))
- Readme cleanup ([DOC-1497](https://tickets.puppetlabs.com/browse/DOC-1497))

### Bug Fixes
## [1.0.4] 2014-11-04

- Minor testing bug fixes
- Readme cleanup
### Fixed

## 2014-11-04 - Supported Release 1.0.4
- Fixed issues URL in metadata.json

### Summary
### Added

Fix Issues URL
Add Future Parser testing support
- Future Parser testing support ([FM-1519](https://tickets.puppetlabs.com/browse/FM-1519))

## 2014-08-25 - Supported Release 1.0.3
## [1.0.3] - 2014-08-25

### Summary
### Fixed

This release updates the tests to verify that powershell continues to function on x64-native ruby.
- Updated tests to verify that PowerShell continues to function on x64-native ruby

## 2014-07-15 - Supported Release 1.0.2
## [1.0.2] - 2014-07-15

### Summary
### Fixed

This release merely updates metadata.json so the module can be uninstalled and
upgraded via the puppet module command.
- Updated metadata.json so that the module can be uninstalled and upgraded via the puppet module command

## 2014-07-09 - Release 1.0.1
## [1.0.1]

### Summary
### Fixed

Fix issue with metadata and PE version requirement
- Fixed issue with metadata and PE version requirement
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Lists the expected return code(s). If the executed command returns something els

##### `timeout`

Sets the maximum time in seconds that the command should take. Valid options: Number or string representation of a number. Default: 300.
Sets the maximum time in seconds that the command should take. Valid options: Number or string representation of a number. Default: 300. A value of `0` for this property will result in using the default timeout of 300. Inifinite timeout is not supported in this module, but large timeouts are allowed if needed.

##### `tries`

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/exec/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
- PowerShell v2 with .NET Framework 2.0
PowerShell v2 works with both .NET Framework 2.0 and .NET Framework 3.5.
To be able to use the enhancements, we require at least .NET Framework 3.5.
To be able to use the enhancements, we require .NET Framework 3.5.
Typically you will only see this on a base Windows Server 2008 (and R2)
install.
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 .NET Framework 3.5 installed.
have .NET Framework 3.5 installed.
UPGRADE

def self.upgrade_message
Expand Down
8 changes: 8 additions & 0 deletions lib/puppet_x/puppetlabs/powershell/powershell_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ def self.init_path

def make_ps_code(powershell_code, timeout_ms = nil, working_dir = nil, environment_variables = [])
begin

# Zero timeout is a special case. Other modules sometimes treat this
# as an infinite timeout. We don't support infinite, so for the case
# of a user specifying zero, we sub in the default value of 300
# seconds.
if (timeout_ms == 0) then timeout_ms = 300 * 1000 end

timeout_ms = Integer(timeout_ms)

# Lower bound protection. The polling resolution is only 50ms
if (timeout_ms < 50) then timeout_ms = 50 end
rescue
Expand Down
3 changes: 2 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-powershell",
"version": "2.1.4",
"version": "2.1.5",
"author": "Puppet Inc",
"summary": "Adds a new exec provider for executing PowerShell commands.",
"license": "Apache-2.0",
Expand All @@ -15,6 +15,7 @@
"Server 2008 R2",
"Server 2012",
"Server 2012 R2",
"Server 2016",
"7",
"8",
"10"
Expand Down
1 change: 0 additions & 1 deletion spec/acceptance/exec_powershell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ def platform_string(host, windows, posix)
$pr = New-Object Security.Principal.WindowsPrincipal $id
if(!($pr.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))){Write-Error "Not in admin"}
PS1
#require 'pry'; binding.pry
it_should_behave_like 'standard exec', ps1, windows_agents
end

Expand Down
26 changes: 26 additions & 0 deletions spec/integration/puppet_x/puppetlabs/powershell_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def create_manager()
expected_error = /Failure waiting for PowerShell process (\d+) to start pipe server/
expect(e.message).to match expected_error
pid = expected_error.match(e.message)[1].to_i

# We want to make sure that enough time has elapsed since the manager called kill
# for the OS to finish killing the process and doing all of it's cleanup.
# We have found that without an appropriate wait period, the kill call below
# can return unexpected results and fail the test.
sleep(1)
expect{Process.kill(0, pid)}.to raise_error(Errno::ESRCH)
end
end
Expand Down Expand Up @@ -564,6 +570,26 @@ def output_cmdlet
expect(result[:stdout]).to end_with("404 Craig Not Found\r\n + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException\r\n + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException\r\n \r\n")
end

it "should use a default timeout of 300 seconds if the user specified a timeout of 0" do
timeout_ms = 0
command = 'return $true'
code = manager.make_ps_code(command, timeout_ms)
expect(code).to match(/TimeoutMilliseconds = 300000/)
end

it "Should use the correct correct timeout if a small value is specified" do

# Zero timeout is not supported, and a timeout less than 50ms is not supported.
# This test is to ensure that the code that inserts the default timeout when
# the user specified zero, does not interfere with the other default of 50ms
# if the user specifies a value less than that.

timeout_ms = 20
command = 'return $true'
code = manager.make_ps_code(command, timeout_ms)
expect(code).to match(/TimeoutMilliseconds = 50/)
end

it "should not deadlock and return a valid response given invalid unparseable PowerShell code" do
result = manager.execute(<<-CODE
{
Expand Down