Showing with 325 additions and 92 deletions.
  1. +5 −0 .sync.yml
  2. +5 −7 .travis.yml
  3. +11 −2 CHANGELOG.md
  4. +0 −6 MAINTAINERS.md
  5. +1 −1 README.md
  6. +18 −0 REFERENCE.md
  7. +8 −0 lib/puppet/provider/reboot/windows.rb
  8. +2 −2 lib/puppet/type/reboot.rb
  9. +3 −3 metadata.json
  10. +19 −0 spec/unit/provider/reboot/windows_spec.rb
  11. +131 −0 spec/unit/task/init_spec.rb
  12. +4 −0 tasks/init.json
  13. +87 −64 tasks/init.rb
  14. +4 −0 tasks/nix.json
  15. +14 −2 tasks/nix.sh
  16. +4 −0 tasks/win.json
  17. +9 −5 tasks/win.ps1
5 changes: 5 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
include_todos: true
selected_profile: false
".travis.yml":
deploy_to_forge:
enabled: false
global_env:
- GEM_BOLT=true
simplecov: true
notifications:
slack:
secure: OviSgQ0iGIHgjC8eiiRrqDV958sNSE0te+Q8IdPgxJZwMYYeP3hCW6e8ngl5op1GTIUoiMZwMfcXTHJmq71BkBUkRQlfmFw5onTlqs2xitCA8nQvo0PKLWcgr9X9R6A1NZCiPg0BTy6JDApIYq1WfVCWLuoRQyJCT07V6mpYjCI=
appveyor.yml:
matrix_extras:
- PUPPET_GEM_VERSION: "~> 6.0"
Expand Down
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ cache: bundler
before_install:
- bundle -v
- rm -f Gemfile.lock
- gem update --system $RUBYGEMS_VERSION
- "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner"
- "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used"
- '[ -z "$RUBYGEMS_VERSION" ] || gem update --system $RUBYGEMS_VERSION'
- gem --version
- bundle -v
script:
Expand All @@ -20,9 +22,6 @@ stages:
- static
- spec
- acceptance
-
if: tag =~ ^v\d
name: deploy
matrix:
fast_finish: true
include:
Expand All @@ -37,12 +36,11 @@ matrix:
env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
rvm: 2.5.3
stage: spec
-
env: DEPLOY_TO_FORGE=yes
stage: deploy
branches:
only:
- master
- /^v\d/
notifications:
email: false
slack:
secure: OviSgQ0iGIHgjC8eiiRrqDV958sNSE0te+Q8IdPgxJZwMYYeP3hCW6e8ngl5op1GTIUoiMZwMfcXTHJmq71BkBUkRQlfmFw5onTlqs2xitCA8nQvo0PKLWcgr9X9R6A1NZCiPg0BTy6JDApIYq1WfVCWLuoRQyJCT07V6mpYjCI=
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file. 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).

## [v2.4.0](https://github.com/puppetlabs/puppetlabs-reboot/tree/v2.4.0) (2020-02-03)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-reboot/compare/v2.3.0...v2.4.0)

### Added

- Add `shutdown\_only` parameter to tasks [\#224](https://github.com/puppetlabs/puppetlabs-reboot/pull/224) ([MikaelSmith](https://github.com/MikaelSmith))
- \(MODULES-8201\) Add pending reboot due to domain join for windows. [\#179](https://github.com/puppetlabs/puppetlabs-reboot/pull/179) ([razorbladex401](https://github.com/razorbladex401))

## [v2.3.0](https://github.com/puppetlabs/puppetlabs-reboot/tree/v2.3.0) (2019-12-06)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-reboot/compare/2.2.0...v2.3.0)
Expand All @@ -10,11 +19,11 @@ All notable changes to this project will be documented in this file. The format

- \(FM-8700\) - Addition of Support for CentOs 8 [\#221](https://github.com/puppetlabs/puppetlabs-reboot/pull/221) ([david22swan](https://github.com/david22swan))
- pdksync - Add support on Debian10 [\#218](https://github.com/puppetlabs/puppetlabs-reboot/pull/218) ([lionce](https://github.com/lionce))
- Fix plan return value [\#209](https://github.com/puppetlabs/puppetlabs-reboot/pull/209) ([reidmv](https://github.com/reidmv))

### Fixed

- Fix reboot message for linux hosts [\#213](https://github.com/puppetlabs/puppetlabs-reboot/pull/213) ([nmaludy](https://github.com/nmaludy))
- \[MODULES-8718\] Check for root or sudo in the reboot task nix.sh script [\#203](https://github.com/puppetlabs/puppetlabs-reboot/pull/203) ([thilinapiy](https://github.com/thilinapiy))

## [2.2.0](https://github.com/puppetlabs/puppetlabs-reboot/tree/2.2.0) (2019-07-24)

Expand All @@ -26,14 +35,14 @@ All notable changes to this project will be documented in this file. The format

### Added

- Fix plan return value [\#209](https://github.com/puppetlabs/puppetlabs-reboot/pull/209) ([reidmv](https://github.com/reidmv))
- \(FM-8051\) Add RedHat 8 support [\#207](https://github.com/puppetlabs/puppetlabs-reboot/pull/207) ([eimlav](https://github.com/eimlav))
- MODULES-8726: Ensure sbin is in the path [\#205](https://github.com/puppetlabs/puppetlabs-reboot/pull/205) ([xalimar](https://github.com/xalimar))
- \(MODULES-8148\) - Add SLES 15 support [\#191](https://github.com/puppetlabs/puppetlabs-reboot/pull/191) ([eimlav](https://github.com/eimlav))

### Fixed

- Add additional guards for nix process detach [\#210](https://github.com/puppetlabs/puppetlabs-reboot/pull/210) ([reidmv](https://github.com/reidmv))
- \[MODULES-8718\] Check for root or sudo in the reboot task nix.sh script [\#203](https://github.com/puppetlabs/puppetlabs-reboot/pull/203) ([thilinapiy](https://github.com/thilinapiy))
- \(MODULES-8717\) Fix dependency issue on boltspec [\#202](https://github.com/puppetlabs/puppetlabs-reboot/pull/202) ([HelenCampbell](https://github.com/HelenCampbell))

# Changelog
Expand Down
6 changes: 0 additions & 6 deletions MAINTAINERS.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ The possible reasons for rebooting are:
* pending_computer_rename: The computer needs to be renamed.
* pending_dsc_reboot: DSC has requested a reboot.
* pending_ccm_reboot: CCM has requested a reboot.

* pending_domain_join: System has joined domain and is pending a reboot.

## Reference

Expand Down
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ Data type: `Optional[Pattern[/^[^|&]*$/]]`

Shutdown message for systems that support it

##### `shutdown_only`

Data type: `Optional[Boolean]`

Only shut the machine down, do not reboot

### last_boot_time

Gets the last boot time of a Linux or Windows system
Expand Down Expand Up @@ -172,6 +178,12 @@ Data type: `Optional[Pattern[/^[^|&]*$/]]`

Shutdown message for systems that support it

##### `shutdown_only`

Data type: `Optional[Boolean]`

Only shut the machine down, do not reboot

### win

Reboots a machine
Expand All @@ -192,6 +204,12 @@ Data type: `Optional[Pattern[/^[^|&]*$/]]`

Shutdown message for systems that support it

##### `shutdown_only`

Data type: `Optional[Boolean]`

Only shut the machine down, do not reboot

## Plans

### reboot
Expand Down
8 changes: 8 additions & 0 deletions lib/puppet/provider/reboot/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def reboot_pending?
:pending_computer_rename,
:pending_dsc_reboot,
:pending_ccm_reboot,
:pending_domain_join,
]

if @resource[:onlyif] && @resource[:unless]
Expand Down Expand Up @@ -219,6 +220,13 @@ def pending_ccm_reboot?
reboot
end

def pending_domain_join?
path = 'SYSTEM\CurrentControlSet\Services\Netlogon\JoinDomain'
pending = key_exists?(path)
Puppet.debug("Pending reboot: HKLM\\#{path}") if pending
pending
end

private

def with_key(name)
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/reboot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def insync?(is)
possible_values = [
:reboot_required, :component_based_servicing, :windows_auto_update,
:pending_file_rename_operations, :package_installer,
:pending_computer_rename, :pending_dsc_reboot, :pending_ccm_reboot
:pending_computer_rename, :pending_dsc_reboot, :pending_ccm_reboot, :pending_domain_join
]

validate do |values|
Expand Down Expand Up @@ -130,7 +130,7 @@ def insync?(is)
possible_values = [
:reboot_required, :component_based_servicing, :windows_auto_update,
:pending_file_rename_operations, :package_installer,
:pending_computer_rename, :pending_dsc_reboot, :pending_ccm_reboot
:pending_computer_rename, :pending_dsc_reboot, :pending_ccm_reboot, :pending_domain_join
]

validate do |values|
Expand Down
6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-reboot",
"version": "2.3.0",
"version": "2.4.0",
"author": "Puppet Inc",
"summary": "Adds a type and provider for managing system reboots.",
"license": "Apache-2.0",
Expand Down Expand Up @@ -96,7 +96,7 @@
}
],
"description": "This module provides a facility for managing reboots across nodes.",
"pdk-version": "1.14.1",
"pdk-version": "1.15.0",
"template-url": "https://github.com/puppetlabs/pdk-templates#master",
"template-ref": "heads/master-0-gfaf9e8b"
"template-ref": "heads/master-0-gcaed9d7"
}
19 changes: 19 additions & 0 deletions spec/unit/provider/reboot/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,22 @@ def expects_registry_value_not_found(path, name)
end
end

context 'Domain Join' do
let(:path) { 'SYSTEM\CurrentControlSet\Services\Netlogon\JoinDomain' }

it 'reboots if the JoinDomain key is present' do
expects_registry_key(path).yields(stub('reg'))

provider.should be_pending_domain_join
end

it 'ignores if the JoinDomain key is absent' do
expects_registry_key_not_found(path)

provider.should_not be_pending_domain_join
end
end

context 'with reboot_required provider property' do
it 'does not indicate a reboot by default' do
expect(provider.reboot_required).to be_falsey
Expand All @@ -488,6 +504,7 @@ def expects_registry_value_not_found(path, name)
provider.expects(:pending_computer_rename?).returns(false)
provider.expects(:pending_dsc_reboot?).returns(false)
provider.expects(:pending_ccm_reboot?).returns(false)
provider.expects(:pending_domain_join?).returns(false)

expect(provider).not_to be_reboot_pending
end
Expand All @@ -506,6 +523,7 @@ def expects_registry_value_not_found(path, name)
# provider.expects(:pending_computer_rename?).returns(true)
provider.expects(:pending_dsc_reboot?).returns(false)
# provider.expects(:pending_ccm_reboot?).returns(true)
# provider.expects(:pending_domain_join?).returns(true)

expect(provider).not_to be_reboot_pending
end
Expand All @@ -524,6 +542,7 @@ def expects_registry_value_not_found(path, name)
provider.expects(:pending_computer_rename?).returns(false)
# provider.expects(:pending_dsc_reboot?).returns(true)
provider.expects(:pending_ccm_reboot?).returns(false)
provider.expects(:pending_domain_join?).returns(false)

expect(provider).not_to be_reboot_pending
end
Expand Down
131 changes: 131 additions & 0 deletions spec/unit/task/init_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
require 'spec_helper'
require_relative '../../../tasks/init'

describe Reboot::Task do # rubocop:disable RSpec/FilePath
context 'on Windows' do
before(:each) { Facter.stubs(:value).with(:kernel).returns('windows') }

context 'when rebooting' do
let(:reboot) { described_class.new }

it 'runs the correct command' do
command = 'shutdown.exe /r /t 3 /d p:4:1 '
reboot.expects(:shutdown_executable_windows).returns('shutdown.exe')
reboot.expects(:async_command).with(command).returns(nil)
reboot.execute!
end

context 'with a timeout' do
let(:reboot) { described_class.new('timeout' => 20) }

it 'handles the timeout' do
command = 'shutdown.exe /r /t 20 /d p:4:1 '
reboot.expects(:shutdown_executable_windows).returns('shutdown.exe')
reboot.expects(:async_command).with(command).returns(nil)
reboot.execute!
end

it 'does not allow timeouts < 3' do
reboot = described_class.new('timeout' => 0)
command = 'shutdown.exe /r /t 3 /d p:4:1 '
reboot.expects(:shutdown_executable_windows).returns('shutdown.exe')
reboot.expects(:async_command).with(command).returns(nil)
reboot.execute!
end
end
end

context 'when shutting down' do
let(:reboot) { described_class.new('shutdown_only' => true) }

it 'runs the correct command' do
command = 'shutdown.exe /s /t 3 /d p:4:1 '
reboot.expects(:shutdown_executable_windows).returns('shutdown.exe')
reboot.expects(:async_command).with(command).returns(nil)
reboot.execute!
end
end
end

context 'on Solaris' do
before(:each) { Facter.stubs(:value).with(:kernel).returns('SunOS') }

context 'when rebooting' do
let(:reboot) { described_class.new }

it 'runs the correct command' do
# Enforces minimum 3s timeout.
command = ['shutdown', '-y', '-i', '6', '-g', 3, "''", '</dev/null', '>/dev/null', '2>&1', '&']
reboot.expects(:async_command).with(command).returns(nil)
reboot.execute!
end

context 'with a timeout' do
let(:reboot) { described_class.new('timeout' => 20) }

it 'handles the timeout' do
command = ['shutdown', '-y', '-i', '6', '-g', 20, "''", '</dev/null', '>/dev/null', '2>&1', '&']
reboot.expects(:async_command).with(command).returns(nil)
reboot.execute!
end
end
end

context 'when shutting down' do
let(:reboot) { described_class.new('shutdown_only' => true) }

it 'runs the correct command' do
# Enforces minimum 3s timeout.
command = ['shutdown', '-y', '-i', '5', '-g', 3, "''", '</dev/null', '>/dev/null', '2>&1', '&']
reboot.expects(:async_command).with(command).returns(nil)
reboot.execute!
end
end
end

context 'on Linux' do
before(:each) { Facter.stubs(:value).with(:kernel).returns('Linux') }

context 'when rebooting' do
let(:reboot) { described_class.new }

it 'runs the correct command' do
command = ['shutdown', '-r', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&']
# Enforces minimum 3s timeout.
reboot.expects(:async_command).with(command, 3).returns(nil)
reboot.execute!
end

context 'with a small timeout' do
let(:reboot) { described_class.new('timeout' => 20) }

it 'handles the timeout by sleeping' do
command = ['shutdown', '-r', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&']
reboot.expects(:async_command).with(command, 20).returns(nil)
reboot.execute!
end
end

context 'with a large timeout' do
let(:reboot) { described_class.new('timeout' => 90) }

it 'handles the timeout by sleeping' do
command = ['shutdown', '-r', '+1', "''", '</dev/null', '>/dev/null', '2>&1', '&']
reboot.expects(:async_command).with(command, 30).returns(nil)
reboot.execute!
end
end
end

context 'when shutting down' do
let(:reboot) { described_class.new('shutdown_only' => true) }

it 'runs the correct command' do
# Enforces minimum 3s timeout.
command = ['shutdown', '-P', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&']
reboot.expects(:async_command).with(command, 3).returns(nil)
reboot.execute!
end
end
end
end
4 changes: 4 additions & 0 deletions tasks/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"message": {
"description": "Shutdown message for systems that support it",
"type": "Optional[Pattern[/^[^|&]*$/]]"
},
"shutdown_only": {
"description": "Only shut the machine down, do not reboot",
"type": "Optional[Boolean]"
}
},
"implementations": [
Expand Down
Loading