Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP/RFC: Add run_agent task #709

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fixtures:
inifile: 'https://github.com/puppetlabs/puppetlabs-inifile.git'
puppetdb: 'https://github.com/puppetlabs/puppetlabs-puppetdb.git'
redis: 'https://github.com/voxpupuli/puppet-redis.git'
ruby_task_helper: 'https://github.com/puppetlabs/puppetlabs-ruby_task_helper.git'
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
systemd: 'https://github.com/camptocamp/puppet-systemd.git'
yumrepo_core:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ vendor/
.ruby-*

## rspec
spec/fixtures/
spec/fixtures/modules
spec/fixtures/manifests
junit/

## Puppet module
Expand Down
13 changes: 13 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@
Rakefile:
param_docs_pattern:
- manifests/init.pp
Gemfile:
extra:
- gem: bolt
version: '~> 1.15'
# TODO: Add something to foreman-installer-modulesync to support `unless ENV['PUPPET_VERSION'] =~ /^5/`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekohl a raw_append option??

options:
groups:
- 'system_tests'
- gem: beaker-task_helper
version: '~> 1.7'
options:
groups:
- 'system_tests'
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ matrix:
env:
- BEAKER_PUPPET_COLLECTION=puppet5
- BEAKER_setfile=centos6-64{hostname=centos6-64.example.com}
script: bundle exec rake beaker
script: bundle exec rake spec_prep beaker
services: docker
bundler_args: --without development
before_install:
Expand All @@ -27,7 +27,7 @@ matrix:
env:
- BEAKER_PUPPET_COLLECTION=puppet6
- BEAKER_setfile=centos6-64{hostname=centos6-64.example.com}
script: bundle exec rake beaker
script: bundle exec rake spec_prep beaker
services: docker
bundler_args: --without development
before_install:
Expand All @@ -38,7 +38,7 @@ matrix:
env:
- BEAKER_PUPPET_COLLECTION=puppet5
- BEAKER_setfile=debian9-64{hostname=debian9-64.example.com}
script: bundle exec rake beaker
script: bundle exec rake spec_prep beaker
services: docker
bundler_args: --without development
before_install:
Expand All @@ -49,7 +49,7 @@ matrix:
env:
- BEAKER_PUPPET_COLLECTION=puppet6
- BEAKER_setfile=debian9-64{hostname=debian9-64.example.com}
script: bundle exec rake beaker
script: bundle exec rake spec_prep beaker
services: docker
bundler_args: --without development
before_install:
Expand All @@ -60,7 +60,7 @@ matrix:
env:
- BEAKER_PUPPET_COLLECTION=puppet6
- BEAKER_setfile=debian10-64{hostname=debian10-64.example.com}
script: bundle exec rake beaker
script: bundle exec rake spec_prep beaker
services: docker
bundler_args: --without development
before_install:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ gem 'beaker-puppet_install_helper', {"groups"=>["system_tests"]}
gem 'metadata-json-lint'
gem 'kafo_module_lint'
gem 'parallel_tests'
gem 'bolt', '~> 1.15', {"groups"=>["system_tests"]} unless ENV['PUPPET_VERSION'] =~ /^5/
gem 'beaker-task_helper', '~> 1.7', {"groups"=>["system_tests"]}

# vim:ft=ruby
94 changes: 92 additions & 2 deletions spec/acceptance/puppetserver_latest_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'spec_helper_acceptance'
require 'beaker-task_helper/inventory'
require 'bolt_spec/run'

describe 'Scenario: install puppetserver (latest):' do
before(:context) do
Expand All @@ -22,11 +24,99 @@ class { '::puppet':
server_external_nodes => '',
# only for install test - don't think to use this in production!
# https://docs.puppet.com/puppetserver/latest/tuning_guide.html
server_jvm_max_heap_size => '256m',
server_jvm_min_heap_size => '256m',
server_jvm_max_heap_size => '256m',
server_jvm_min_heap_size => '256m',
server_max_active_instances => 1,
}
EOS
end

it_behaves_like 'a idempotent resource'

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

def bolt_config
{ 'modulepath' => File.join(File.dirname(File.expand_path(__FILE__)), '../', 'fixtures', 'modules') }
end

def bolt_inventory
hosts_to_inventory
end

context 'with empty catalog' do
before do
sleep 10
end
it 'applies and changes nothing' do
results = run_task('puppet::run_agent', 'agent', {})
expect(results.first).to include('status' => 'success')
expect(results.first['result']['detailed_exitcode']).to eq 0
expect(results.first['result']['last_run_summary']['changes']['total']).to eq 0
end
end

context 'with basic site.pp' do
before do
on default, 'mkdir -p /etc/puppetlabs/code/environments/production/manifests'
on default, 'echo "node default { notify {\'test\':}}" > /etc/puppetlabs/code/environments/production/manifests/site.pp'
end
describe 'running task with --noop' do
it 'changes nothing and reports noop events' do
results = run_task('puppet::run_agent', 'agent', '_noop' => true)
expect(results.first).to include('status' => 'success')
expect(results.first['result']['detailed_exitcode']).to eq 0
expect(results.first['result']['last_run_summary']['changes']['total']).to eq 0
expect(results.first['result']['last_run_summary']['events']['noop']).to eq 1
end
end
describe 'running task without --noop' do
it 'applies changes' do
results = run_task('puppet::run_agent', 'agent', {})
expect(results.first).to include('status' => 'success')
expect(results.first['result']['detailed_exitcode']).to eq 2
expect(results.first['result']['last_run_summary']['changes']['total']).to eq 1
expect(results.first['result']['last_run_summary']['events']['success']).to eq 1
end
end
end
context 'with invalid puppet_settings' do
it 'returns failure' do
results = run_task('puppet::run_agent', 'agent', 'puppet_settings' => { 'foo' => 'bar' })
expect(results.first).to include('status' => 'failure')
end
end
context 'with invalid manifest' do
before do
on default, 'echo "NOT A MANIFEST" > /etc/puppetlabs/code/environments/production/manifests/site.pp'
end
it 'returns failure' do
results = run_task('puppet::run_agent', 'agent', {})
expect(results.first).to include('status' => 'failure')
expect(results.first['result']['_error']['details']['detailed_exitcode']).to eq 1
end
end
context 'overriding environment' do
before do
on default, 'mkdir -p /etc/puppetlabs/code/environments/test/manifests'
on default, 'echo "node default { file {\'/tmp/overriding_environment_test\': ensure => \'file\'}}" > /etc/puppetlabs/code/environments/test/manifests/site.pp'
end
it 'applies changes' do
results = run_task('puppet::run_agent', 'agent', 'puppet_settings' => { 'environment' => 'test' })
expect(results.first).to include('status' => 'success')
expect(results.first['result']['detailed_exitcode']).to eq 2
expect(results.first['result']['last_run_summary']['changes']['total']).to eq 1
expect(results.first['result']['last_run_summary']['events']['success']).to eq 1
end
it 'is idempotent' do
results = run_task('puppet::run_agent', 'agent', 'puppet_settings' => { 'environment' => 'test' })
expect(results.first).to include('status' => 'success')
expect(results.first['result']['detailed_exitcode']).to eq 0
end
describe file('/tmp/overriding_environment_test') do
it { should exist }
end
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/agent_disabled.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"disabled_message":"example disable reason"}
63 changes: 63 additions & 0 deletions spec/fixtures/last_run_summary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
version:
config: puppet6server1-production-f2b1bf4a994
puppet: 6.9.0
resources:
changed: 0
corrective_change: 0
failed: 0
failed_to_restart: 0
out_of_sync: 0
restarted: 0
scheduled: 0
skipped: 0
total: 3902
time:
alternatives: 0.148090409
anchor: 0.007545186
archive: 0.002333299
augeas: 0.5816905290000001
catalog_application: 61.01259471802041
concat_file: 0.00382828
concat_fragment: 0.015766492
config_retrieval: 14.155975302215666
convert_catalog: 2.1152733135968447
cron: 0.02888307
exec: 1.223957106
fact_generation: 4.117020649369806
file: 8.819708986000013
file_line: 0.027194031
filebucket: 0.000287035
firewalld_direct_purge: 0.000981873
firewalld_direct_rule: 0.57764554
firewalld_service: 1.9242555670000001
firewalld_zone: 1.274301765
group: 0.004098342
host: 0.001780653
mailalias: 0.000318397
node_retrieval: 0.8955133240669966
package: 9.660382613000001
plugin_sync: 4.877481509000063
proxy_mysql_galera_hostgroup: 0.001988538
proxy_mysql_query_rule: 0.003255971
proxy_mysql_server: 0.005674009999999999
proxy_mysql_user: 0.010748484
proxy_scheduler: 0.002541261
pulp_register: 0.254169852
pulp_rpmbind: 0.011293752
selboolean: 0.045746527
service: 1.4152696620000003
ssh_authorized_key: 0.001582177
sysctl: 1.360353065
total: 87.194980791
transaction_evaluation: 59.95798896579072
user: 0.069402451
xml_fragment: 0.31662629200000003
yumrepo: 0.0013444239999999999
last_run: 1571832278
changes:
total: 0
events:
failure: 0
success: 0
total: 0
3 changes: 3 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
ENV['BEAKER_setfile'] ||= 'centos7-64{hostname=centos7-64.example.com}'
ENV['BEAKER_HYPERVISOR'] ||= 'docker'

require 'bolt/pal'
Bolt::PAL.load_puppet

require 'beaker-puppet'
require 'beaker-rspec'
require 'beaker/puppet_install_helper'
Expand Down
Loading