Showing with 426 additions and 185 deletions.
  1. +2 −0 .gitignore
  2. +2 −0 .pdkignore
  3. +28 −5 .sync.yml
  4. +4 −6 .travis.yml
  5. +18 −4 CHANGELOG.md
  6. +3 −4 Gemfile
  7. +4 −2 README.md
  8. +9 −3 Rakefile
  9. +0 −8 appveyor.yml
  10. +5 −5 metadata.json
  11. +46 −57 spec/acceptance/init_spec.rb
  12. +41 −27 spec/acceptance/linux_spec.rb
  13. +72 −0 spec/acceptance/windows_spec.rb
  14. +9 −1 spec/spec_helper.rb
  15. +2 −0 spec/spec_helper_acceptance.rb
  16. +28 −0 spec/spec_helper_local.rb
  17. +7 −1 tasks/init.json
  18. +3 −3 tasks/linux.json
  19. +92 −33 tasks/linux.sh
  20. +51 −26 tasks/windows.ps1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
/convert_report.txt
/update_report.txt
.DS_Store
.vscode/
.envrc
2 changes: 2 additions & 0 deletions .pdkignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
/convert_report.txt
/update_report.txt
.DS_Store
.vscode/
.envrc
/appveyor.yml
/.fixtures.yml
/Gemfile
Expand Down
33 changes: 28 additions & 5 deletions .sync.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
---
.gitignore:
required:
- ---.project

.gitlab-ci.yml:
unmanaged: true

.travis.yml:
docker_sets:
- set: docker/centos-7
- set: docker/ubuntu-14.04
docker_defaults:
bundler_args: ""
script: bundle exec rake task_acceptance
script: bundle exec rake beaker
secure: ""
global_env:
- BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0"
- GEM_BOLT=true
branches:
- release
remove_includes:
Expand All @@ -31,8 +41,21 @@ Gemfile:
- mswin
- mingw
- x64_mingw
- gem: 'bolt'
version: '~> 1.4'
- gem: bolt
version: '~> 1.15'
condition: ENV['GEM_BOLT']

.gitlab-ci.yml:
unmanaged: true
Rakefile:
extras: |
# The beaker task requires the test fixtures created by the spec_prep task
beaker_task_exists = Rake::Task.task_defined?('beaker')
spec_prep_task_exists = Rake::Task.task_defined?('spec_prep')
if beaker_task_exists && spec_prep_task_exists
beaker_task = Rake::Task['beaker']
spec_prep = Rake::Task['spec_prep']
beaker_task.enhance(beaker_task.prerequisite_tasks << spec_prep)
end
spec/spec_helper.rb:
mock_with: ':rspec'
coverage_report: true
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ dist: trusty
language: ruby
cache: bundler
before_install:
- if [ $BUNDLER_VERSION ]; then
gem install -v $BUNDLER_VERSION bundler --no-rdoc --no-ri;
fi
- bundle -v
- rm -f Gemfile.lock
- gem update --system $RUBYGEMS_VERSION
Expand All @@ -18,7 +15,8 @@ rvm:
- 2.5.1
env:
global:
- BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" GEM_BOLT=true
- BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0"
- GEM_BOLT=true
matrix:
fast_finish: true
include:
Expand All @@ -27,15 +25,15 @@ matrix:
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/centos-7 BEAKER_TESTMODE=apply
rvm: 2.5.1
script: bundle exec rake task_acceptance
script: bundle exec rake beaker
services: docker
sudo: required
-
bundler_args:
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/ubuntu-14.04 BEAKER_TESTMODE=apply
rvm: 2.5.1
script: bundle exec rake task_acceptance
script: bundle exec rake beaker
services: docker
sudo: required
-
Expand Down
22 changes: 18 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@

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

## [0.5.0](https://github.com/puppetlabs/puppetlabs-service/tree/0.5.0) (2019-01-08)
## [v0.6.0](https://github.com/puppetlabs/puppetlabs-service/tree/v0.6.0) (2019-04-08)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-service/compare/0.4.0...0.5.0)
[Full Changelog](https://github.com/puppetlabs/puppetlabs-service/compare/0.5.0...v0.6.0)

### Added

- \(SEN-796\) Move extension metadata [\#86](https://github.com/puppetlabs/puppetlabs-service/pull/86) ([conormurraypuppet](https://github.com/conormurraypuppet))
- \(SEN-796\) Add discovery extension metadata [\#85](https://github.com/puppetlabs/puppetlabs-service/pull/85) ([conormurraypuppet](https://github.com/conormurraypuppet))
- \(BOLT-1103\) Unify output of task implementations [\#83](https://github.com/puppetlabs/puppetlabs-service/pull/83) ([donoghuc](https://github.com/donoghuc))

### Fixed

- pdksync - \(FM-7655\) Fix rubygems-update for ruby \< 2.3 [\#62](https://github.com/puppetlabs/puppetlabs-service/pull/62) ([tphoney](https://github.com/tphoney))
- \(MODULES-8717\) Fix dependency issue with BoltSpec [\#80](https://github.com/puppetlabs/puppetlabs-service/pull/80) ([eimlav](https://github.com/eimlav))

## [0.5.0](https://github.com/puppetlabs/puppetlabs-service/tree/0.5.0) (2019-01-09)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-service/compare/0.4.0...0.5.0)

### Added

- \(MODULES-8420\) Move to GEM\_BOLT pattern [\#65](https://github.com/puppetlabs/puppetlabs-service/pull/65) ([donoghuc](https://github.com/donoghuc))
- \(MODULES-8391\) Enable implementations on the init task and hide others [\#61](https://github.com/puppetlabs/puppetlabs-service/pull/61) ([MikaelSmith](https://github.com/MikaelSmith))

### Fixed

- \(MODULES-8420\) Move to GEM\_BOLT pattern [\#65](https://github.com/puppetlabs/puppetlabs-service/pull/65) ([donoghuc](https://github.com/donoghuc))
- pdksync - \(FM-7655\) Fix rubygems-update for ruby \< 2.3 [\#62](https://github.com/puppetlabs/puppetlabs-service/pull/62) ([tphoney](https://github.com/tphoney))

## [0.4.0](https://github.com/puppetlabs/puppetlabs-service/tree/0.4.0) (2018-09-28)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-service/compare/0.3.1...0.4.0)
Expand Down
7 changes: 3 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ group :development do
gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9')
gem "json", '<= 2.0.4', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4')
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 "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby]
gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby]
gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
Expand All @@ -31,9 +32,7 @@ end
group :system_tests do
gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby]
gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
if ENV['GEM_BOLT']
gem 'bolt', '~> 1.4', require: false
end
gem "bolt", "~> 1.15", require: false if ENV['GEM_BOLT']
end

puppet_version = ENV['PUPPET_GEM_VERSION']
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ This module provides services tasks, There are two kinds of tasks. The default t
## Requirements
This module is compatible with Puppet Enterprise and Puppet Bolt.

* To run tasks with Puppet Enterprise, PE 2017.3 or later must be installed on the machine from which you are running task commands. Machines receiving task requests must be Puppet agents.
* To run tasks with Puppet Enterprise, PE 2018.1 or later must be installed on the machine from which you are running task commands. Machines receiving task requests must be Puppet agents.

* To run tasks with Puppet Bolt, Bolt 0.5 or later must be installed on the machine from which you are running task commands. Machines receiving task requests must have SSH or WinRM services enabled.
* To run tasks with Puppet Bolt, Bolt 1.0 or later must be installed on the machine from which you are running task commands. Machines receiving task requests must have SSH or WinRM services enabled.

## Usage

Expand Down Expand Up @@ -68,6 +68,8 @@ For a complete list of services that are supported see the Puppet [services](htt

## Limitations

To run acceptance tests against Windows machines, ensure that the `BEAKER_password` environment variable has been set to the password of the Administrator user of the target machine.

For an extensive list of supported operating systems, see [metadata.json](https://github.com/puppetlabs/puppetlabs-service/blob/master/metadata.json)

## Getting Help
Expand Down
12 changes: 9 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

def changelog_future_release
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = JSON.load(File.read('metadata.json'))['version']
returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version']
raise "unable to find the future_release (version) in metadata.json" if returnVal.nil?
puts "GitHubChangelogGenerator future_release:#{returnVal}"
returnVal
Expand Down Expand Up @@ -74,6 +74,12 @@ EOM
end
end

task :task_acceptance => [:spec_prep, :beaker] do
# nothing to do
# The beaker task requires the test fixtures created by the spec_prep task
beaker_task_exists = Rake::Task.task_defined?('beaker')
spec_prep_task_exists = Rake::Task.task_defined?('spec_prep')
if beaker_task_exists && spec_prep_task_exists
beaker_task = Rake::Task['beaker']
spec_prep = Rake::Task['spec_prep']
beaker_task.enhance(beaker_task.prerequisite_tasks << spec_prep)
end

8 changes: 0 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ environment:
-
RUBY_VERSION: 24-x64
CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
-
PUPPET_GEM_VERSION: ~> 4.0
RUBY_VERSION: 21
CHECK: parallel_spec
-
PUPPET_GEM_VERSION: ~> 4.0
RUBY_VERSION: 21-x64
CHECK: parallel_spec
-
PUPPET_GEM_VERSION: ~> 5.0
RUBY_VERSION: 24
Expand Down
10 changes: 5 additions & 5 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-service",
"version": "0.5.0",
"version": "0.6.0",
"author": "puppetlabs",
"summary": "Tasks that manipulate a service",
"license": "Apache-2.0",
Expand Down Expand Up @@ -65,7 +65,7 @@
}
],
"description": "Tasks that manipulate a service",
"pdk-version": "1.7.1",
"template-url": "https://github.com/puppetlabs/pdk-templates/",
"template-ref": "heads/master-0-g9c815ea"
}
"pdk-version": "1.9.0",
"template-url": "https://github.com/puppetlabs/pdk-templates.git",
"template-ref": "heads/master-0-gfde5699"
}
103 changes: 46 additions & 57 deletions spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,110 +1,99 @@
# run a test task
require 'spec_helper_acceptance'
require 'beaker-task_helper/inventory'
require 'bolt_spec/run'

describe 'service task' do
include Beaker::TaskHelper::Inventory
include BoltSpec::Run

def module_path
RSpec.configuration.module_path
def bolt_config
{ 'modulepath' => RSpec.configuration.module_path }
end

def config
{ 'modulepath' => module_path }
end

def inventory
hosts_to_inventory.merge('features' => ['puppet-agent'])
end

def run(params)
run_task('service', 'default', params, config: config, inventory: inventory)
end

osfamily_fact = fact('osfamily')
let(:bolt_inventory) { hosts_to_inventory.merge('features' => ['puppet-agent']) }

package_to_use = ''
before(:all) do
if osfamily_fact != 'windows'
if osfamily_fact == 'RedHat' && fact('operatingsystemrelease') < '6'
run('action' => 'stop', 'name' => 'syslog')
options = { inventory: hosts_to_inventory.merge('features' => ['puppet-agent']) }
if os[:family] != 'windows'
if os[:family] == 'redhat' && os[:release].to_i < 6
params = { 'action' => 'stop', 'name' => 'syslog' }
run_task('service', 'default', params, options)
end
package_to_use = 'rsyslog'
apply_manifest_on(default, "package { \"#{package_to_use}\": ensure => present, }")
else
package_to_use = 'W32Time'
run('action' => 'start', 'name' => package_to_use)
params = { 'action' => 'start', 'name' => package_to_use }
run_task('service', 'default', params, options)
end
end

describe 'enable action' do
it 'enable/status a service' do
result = run('action' => 'enable', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['status']).to match(%r{in_sync|enabled})
result = run_task('service', 'default', 'action' => 'enable', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('status' => %r{in_sync|enabled})

result = run('action' => 'status', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['enabled']).to eq('true')
result = run_task('service', 'default', 'action' => 'status', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('enabled' => 'true')
end
end

describe 'restart action' do
it 'restart/status a service' do
result = run('action' => 'restart', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['status']).to eq('restarted')

result = run('action' => 'status', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['status']).to eq('running')
expect(result[0]['result']['enabled']).to eq('true')
result = run_task('service', 'default', 'action' => 'restart', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('status' => 'restarted')

result = run_task('service', 'default', 'action' => 'status', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('status' => 'running')
expect(result[0]['result']).to include('enabled' => 'true')
end
end

describe 'stop action' do
it 'stop/status a service' do
result = run('action' => 'stop', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['status']).to match(%r{in_sync|stopped})
result = run_task('service', 'default', 'action' => 'stop', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('status' => %r{in_sync|stopped})

# Debian can give incorrect status
if osfamily_fact != 'Debian'
result = run('action' => 'status', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['status']).to eq('stopped')
expect(result[0]['result']['enabled']).to eq('true')
unless ['debian', 'ubuntu'].include?(os[:family])
result = run_task('service', 'default', 'action' => 'status', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('status' => 'stopped')
expect(result[0]['result']).to include('enabled' => 'true')
end
end
end

describe 'start action' do
it 'start/status a service' do
result = run('action' => 'start', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['status']).to match(%r{in_sync|started})
result = run_task('service', 'default', 'action' => 'start', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('status' => %r{in_sync|started})

# Debian can give incorrect status
if osfamily_fact != 'Debian'
result = run('action' => 'status', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['status']).to eq('running')
expect(result[0]['result']['enabled']).to eq('true')
if os[:family] != 'debian'
result = run_task('service', 'default', 'action' => 'status', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('status' => 'running')
expect(result[0]['result']).to include('enabled' => 'true')
end
end
end

describe 'disable action' do
it 'disable/status a service' do
result = run('action' => 'disable', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['status']).to eq('disabled')
result = run_task('service', 'default', 'action' => 'disable', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('status' => 'disabled')

result = run('action' => 'status', 'name' => package_to_use)
expect(result[0]['status']).to eq('success')
expect(result[0]['result']['enabled']).to eq('false')
result = run_task('service', 'default', 'action' => 'status', 'name' => package_to_use)
expect(result[0]).to include('status' => 'success')
expect(result[0]['result']).to include('enabled' => 'false')
end
end
end
Loading