Showing with 115 additions and 45 deletions.
  1. +42 −0 .github/workflows/weekly.yml
  2. +4 −0 .sync.yml
  3. +3 −1 .travis.yml
  4. +8 −0 CHANGELOG.md
  5. +4 −4 Gemfile
  6. +23 −19 README.md
  7. +1 −1 REFERENCE.md
  8. +2 −0 Rakefile
  9. +2 −0 appveyor.yml
  10. +3 −3 metadata.json
  11. +8 −8 plans/init.pp
  12. +13 −9 spec/plans/init_spec.rb
  13. +2 −0 spec/spec_helper.rb
42 changes: 42 additions & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "weekly"

on:
schedule:
- cron: '0 0 * * 6'

jobs:
LitmusAcceptance:
runs-on: self-hosted
strategy:
matrix:
ruby_version: [2.5.x]
puppet_gem_version: [~> 6.0]
platform: [release_checks]
agent_family: ['puppet5', 'puppet6']

steps:
- uses: actions/checkout@v1
- name: Litmus Parallel
uses: puppetlabs/action-litmus_parallel@master
with:
platform: ${{ matrix.platform }}
agent_family: ${{ matrix.agent_family }}
Spec:
runs-on: self-hosted
strategy:
matrix:
check: [spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop']
ruby_version: [2.5.x]
puppet_gem_version: [~> 5.0, ~> 6.0]
exclude:
- puppet_gem_version: ~> 5.0
check: 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'
- ruby_version: 2.5.x
puppet_gem_version: ~> 5.0
steps:
- uses: actions/checkout@v1
- name: Spec Tests
uses: puppetlabs/action-litmus_spec@master
with:
puppet_gem_version: ${{ matrix.puppet_gem_version }}
check: ${{ matrix.check }}
4 changes: 4 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
enabled: false
global_env:
- GEM_BOLT=true
- HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests"
simplecov: true
notifications:
slack:
secure: OviSgQ0iGIHgjC8eiiRrqDV958sNSE0te+Q8IdPgxJZwMYYeP3hCW6e8ngl5op1GTIUoiMZwMfcXTHJmq71BkBUkRQlfmFw5onTlqs2xitCA8nQvo0PKLWcgr9X9R6A1NZCiPg0BTy6JDApIYq1WfVCWLuoRQyJCT07V6mpYjCI=
appveyor.yml:
environment:
HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6
HONEYCOMB_DATASET: litmus tests
matrix_extras:
- PUPPET_GEM_VERSION: "~> 6.0"
RUBY_VERSION: 25
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ before_install:
- rm -f Gemfile.lock
- "# 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'
- "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set"
- '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION'
- gem --version
- bundle -v
script:
Expand All @@ -18,6 +19,7 @@ rvm:
env:
global:
- GEM_BOLT=true
- HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests"
stages:
- static
- spec
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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).

## [v3.0.0](https://github.com/puppetlabs/puppetlabs-reboot/tree/v3.0.0) (2020-02-25)

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

### Changed

- \(GH-1376\) Change `$nodes` parameter for `reboot` plan to `$targets` [\#223](https://github.com/puppetlabs/puppetlabs-reboot/pull/223) ([beechtom](https://github.com/beechtom))

## [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)
Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ group :development do
gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-posix-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby]
gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby]
gem "puppet-module-win-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-win-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby]
gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby]
gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "bolt", '~> 1.3', require: false if ENV['GEM_BOLT'] and ENV['PUPPET_GEM_VERSION'] != "~> 5.0"
gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')
end
Expand Down
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@

## Overview

This module adds a type, and both Windows and generic POSIX providers, for managing node reboots.
This module adds a type, and both Windows and generic POSIX providers, for managing target reboots.

## Module Description

Some packages require a reboot of the node to complete their installation. Until that reboot is completed, the package might not be fully functional, and other installs might fail. This module provides a resource type to let Puppet perform that reboot, and providers to support Windows and POSIX systems. HP-UX is not supported.
Some packages require a reboot of the target to complete their installation. Until that reboot is completed, the package might not be fully functional, and other installs might fail. This module provides a resource type to let Puppet perform that reboot, and providers to support Windows and POSIX systems. HP-UX is not supported.

By default, this module only reboots a node in response to another resource being applied --- e.g., after a package install. On Windows nodes, you can also have Puppet check for pending reboots and complete them *before* applying the next resource in the catalog, by specifying `when => pending`.
By default, this module only reboots a target in response to another resource being applied --- e.g., after a package install. On Windows targets, you can also have Puppet check for pending reboots and complete them *before* applying the next resource in the catalog, by specifying `when => pending`.

## Setup

### Setup Requirements

On Windows nodes, the 'shutdown.exe' command must be in the `PATH`.
On Windows targets, the 'shutdown.exe' command must be in the `PATH`.

On Windows 2003 (non-R2) x64 nodes, [KB942589](http://support.microsoft.com/kb/942589) must be installed.
On Windows 2003 (non-R2) x64 targets, [KB942589](http://support.microsoft.com/kb/942589) must be installed.

### Beginning with reboot

Expand Down Expand Up @@ -114,7 +114,7 @@ The main type of the module, responsible for all its functionality.

#### Features

* `manages_reboot_pending`: Detects whether a reboot is pending due to a prior change. If so, reboot the node. (Available with the `windows` provider.)
* `manages_reboot_pending`: Detects whether a reboot is pending due to a prior change. If so, reboot the target. (Available with the `windows` provider.)

#### Parameters

Expand All @@ -140,9 +140,9 @@ The main type of the module, responsible for all its functionality.

##### `when`

*Optional.* Specifies how reboots are triggered. If set to 'refreshed', the provider only reboots the node in response to a refresh event from another resource, e.g., installing a package. If set to 'pending', Puppet checks for signs of any pending reboots and completes them before applying the next resource in the catalog. Valid options: 'refreshed' and 'pending'. Default value: 'refreshed'.
*Optional.* Specifies how reboots are triggered. If set to 'refreshed', the provider only reboots the target in response to a refresh event from another resource, e.g., installing a package. If set to 'pending', Puppet checks for signs of any pending reboots and completes them before applying the next resource in the catalog. Valid options: 'refreshed' and 'pending'. Default value: 'refreshed'.

**Note:** For `when => pending` reboots, Puppet can normally detect a pending reboot based on some specific system conditions (such as the existence of the PendingFileRenameOperations registry key). However, if those conditions aren't resolved after the node reboots, Puppet triggers another reboot. This can lead to a reboot loop.
**Note:** For `when => pending` reboots, Puppet can normally detect a pending reboot based on some specific system conditions (such as the existence of the PendingFileRenameOperations registry key). However, if those conditions aren't resolved after the target reboots, Puppet triggers another reboot. This can lead to a reboot loop.

#### `onlyif`

Expand All @@ -160,14 +160,18 @@ See the [Reboot when certain conditions are met](#reboot-when-certain-conditions

### Plan: `reboot`

This plan is intended to be used as part of other [plans](https://puppet.com/docs/bolt/latest/writing_plans.html) and allows Bolt to wait for a server to reboot before continuing. It requires Bolt 1.0+ and/or PE 2019.0+.
This plan is intended to be used as part of other [plans](https://puppet.com/docs/bolt/latest/writing_plans.html) and allows Bolt to wait for a server to reboot before continuing. It requires Bolt 1.0+ and/or PE 2019.0+.

**NOTE**: The `nodes` parameters is deprecated in Bolt 2.0, and has been updated here to `targets`.
This breaks plans or workflows that explicitly call the `nodes` parameter, however this module is
still compatible with Bolt 1.x specifying the `targets` parameter instead.

Here is an example of using this module to reboot servers, wait for them to come back, then check the status of a service:

```puppet
plan myapp::patch (
$servers,
$version,
TargetSpec $servers,
TargetSpec $version,
) {
# Upgrade the application
run_task('myapp::upgrade', $servers, { 'version' => $version })
Expand All @@ -176,7 +180,7 @@ plan myapp::patch (
run_plan('reboot', $servers, reconnect_timeout => 300)
# Check the status of the service
return run_task('service', $nodes, {
return run_task('service', $servers, {
'name' => 'myapp',
'action' => 'status',
})
Expand All @@ -190,7 +194,7 @@ The `reboot` plan returns a ResultSet on success. It also returns a ResultSet if
The plan may raise an Error if any targets fail to reboot and `fail_plan_on_errors` is set to true. In that circumstance, the error raised will contain the ResultSet in its details key.

```
$plan_result = run_plan('reboot', nodes => $targets)
$plan_result = run_plan('reboot', targets => $targets)
$results = case $plan_result {
Error: { $plan_result.details['result_set'] }
default: { $plan_result }
Expand All @@ -202,9 +206,9 @@ $results.error_set.targets # Targets that did not successfully reboot

#### Parameters

##### `nodes`
##### `targets`

A `TargetSpec` object containing all nodes to wait for.
A `TargetSpec` object containing all targets to wait for.

##### `message`

Expand Down Expand Up @@ -234,19 +238,19 @@ Setting this value to false allows the return value of a plan to be treated the

```puppet
plan myapp::patch (
TargetSpec $nodes,
TargetSpec $targets,
String $version,
) {
$targets = get_targets($nodes)
$target_objects = get_targets($targets)
# Upgrade the application
$step1_results = run_task('myapp::upgrade', $targets,
$step1_results = run_task('myapp::upgrade', $target_objects,
version => $version,
_catch_errors => true,
)
# Reboot the servers. This app is slow to shut down so give them 5 minutes to reboot.
$step2_results = run_plan('reboot', nodes => $step1_results.ok_set.targets,
$step2_results = run_plan('reboot', targets => $step1_results.ok_set.targets,
reconnect_timeout => 300
fail_plan_on_errors => false,
)
Expand Down
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Reboots targets and waits for them to be available again.

The following parameters are available in the `reboot` plan.

##### `nodes`
##### `targets`

Data type: `TargetSpec`

Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any?
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-syntax/tasks/puppet-syntax'
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ init:
- 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0'
- 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0'
environment:
HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6
HONEYCOMB_DATASET: litmus tests
SIMPLECOV: yes
matrix:
-
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.4.0",
"version": "3.0.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.15.0",
"pdk-version": "1.16.0",
"template-url": "https://github.com/puppetlabs/pdk-templates#master",
"template-ref": "heads/master-0-gcaed9d7"
"template-ref": "heads/master-0-g5d52853"
}
16 changes: 8 additions & 8 deletions plans/init.pp
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Reboots targets and waits for them to be available again.
#
# @param nodes Targets to reboot.
# @param targets Targets to reboot.
# @param message Message to log with the reboot (for platforms that support it).
# @param reboot_delay How long (in seconds) to wait before rebooting. Defaults to 1.
# @param disconnect_wait How long (in seconds) to wait before checking whether the server has rebooted. Defaults to 10.
# @param reconnect_timeout How long (in seconds) to attempt to reconnect before giving up. Defaults to 180.
# @param retry_interval How long (in seconds) to wait between retries. Defaults to 1.
# @param fail_plan_on_errors Raise an error if any targets do not successfully reboot. Defaults to true.
plan reboot (
TargetSpec $nodes,
TargetSpec $targets,
Optional[String] $message = undef,
Integer[1] $reboot_delay = 1,
Integer[0] $disconnect_wait = 10,
Integer[0] $reconnect_timeout = 180,
Integer[0] $retry_interval = 1,
Boolean $fail_plan_on_errors = true,
) {
$targets = get_targets($nodes)
$target_objects = get_targets($targets)

# Short-circuit the plan if the TargetSpec given was empty
if $targets.empty { return ResultSet.new([]) }
if $target_objects.empty { return ResultSet.new([]) }

# Get last boot time
$begin_boot_time_results = without_default_logging() || {
run_task('reboot::last_boot_time', $targets)
run_task('reboot::last_boot_time', $target_objects)
}

# Reboot; catch errors here because the connection may get cut out from underneath
$reboot_result = run_task('reboot', $nodes, timeout => $reboot_delay, message => $message)
$reboot_result = run_task('reboot', $targets, timeout => $reboot_delay, message => $message)

# Wait long enough for all targets to trigger reboot, plus disconnect_wait to allow for shutdown time.
$timeouts = $reboot_result.map |$result| { $result['timeout'] }
Expand All @@ -40,13 +40,13 @@
## Mark finished for targets with a new last boot time.
## If we still have targets check for timeout, sleep if not done.
$wait_results = without_default_logging() || {
$reconnect_timeout.reduce({'pending' => $targets, 'ok' => []}) |$memo, $_| {
$reconnect_timeout.reduce({'pending' => $target_objects, 'ok' => []}) |$memo, $_| {
if ($memo['pending'].empty() or $memo['timed_out']) {
break()
}

$plural = if $memo['pending'].size() > 1 { 's' }
notice("Waiting: ${$memo['pending'].size()} target${plural} rebooting")
out::message("Waiting: ${$memo['pending'].size()} target${plural} rebooting")
$current_boot_time_results = run_task('reboot::last_boot_time', $memo['pending'], _catch_errors => true)
# Compare boot times
Expand Down
Loading