Skip to content

Commit

Permalink
Merge pull request #517 from puppetlabs/FM-8188
Browse files Browse the repository at this point in the history
(FM-8188) convert ntp to use litmus
  • Loading branch information
pmcmaw authored Jun 10, 2019
2 parents b4b661a + f1e8d9d commit e358b3b
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 75 deletions.
5 changes: 4 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
fixtures:
repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib.git"
"augeas_core": "https://github.com/puppetlabs/puppetlabs-augeas_core.git"
facts: 'git://github.com/puppetlabs/puppetlabs-facts.git'
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib.git"
provision: "git://github.com/puppetlabs/provision.git"
puppet_agent: 'git://github.com/puppetlabs/puppetlabs-puppet_agent.git'
symlinks:
"ntp": "#{source_dir}"
"my_ntp": "#{source_dir}/spec/fixtures/my_ntp"
18 changes: 10 additions & 8 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
delete: true

.travis.yml:
docker_sets:
- set: docker/centos-7
- set: docker/ubuntu-14.04
docker_defaults:
bundler_args: ""
secure: ""
branches:
- release
unmanaged: true

appveyor.yml:
delete: true
Expand All @@ -29,6 +22,14 @@ Gemfile:
- mswin
- mingw
- x64_mingw
':development':
- gem: 'puppet_litmus'
platforms:
- ruby
- mswin
- mingw
- x64_mingw
condition: "ENV['PUPPET_GEM_VERSION'].nil? or ENV['PUPPET_GEM_VERSION'] !~ %r{ 5}"
optional:
':development':
- gem: 'github_changelog_generator'
Expand All @@ -38,6 +39,7 @@ Gemfile:

Rakefile:
changelog_user: puppetlabs
use_litmus_tasks: true

spec/spec_helper.rb:
mock_with: ':rspec'
Expand Down
77 changes: 69 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,84 @@ matrix:
fast_finish: true
include:
-
bundler_args:
bundler_args:
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/centos-7 BEAKER_TESTMODE=apply
env: PLATFORMS=deb_puppet5
rvm: 2.5.3
script: bundle exec rake beaker
before_script:
- bundle exec rake 'litmus:provision_list[waffle_deb]'
- bundle exec rake 'litmus:install_agent[puppet5]'
- bundle exec rake litmus:install_module
script:
- bundle exec rake litmus:acceptance:parallel
services: docker
stage: acceptance
sudo: required
-
bundler_args:
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
env: PLATFORMS=deb_puppet6
rvm: 2.5.3
script: bundle exec rake beaker
before_script:
- bundle exec rake 'litmus:provision_list[waffle_deb]'
- bundle exec rake 'litmus:install_agent[puppet6]'
- bundle exec rake litmus:install_module
script:
- bundle exec rake litmus:acceptance:parallel
services: docker
stage: acceptance
sudo: required
-
bundler_args:
dist: trusty
env: PLATFORMS=el6_puppet5
rvm: 2.5.3
before_script:
- bundle exec rake 'litmus:provision_list[waffle_el6]'
- bundle exec rake 'litmus:install_agent[puppet5]'
- bundle exec rake litmus:install_module
script:
- bundle exec rake litmus:acceptance:parallel
services: docker
sudo: required
-
bundler_args:
dist: trusty
env: PLATFORMS=el6_puppet6
rvm: 2.5.3
before_script:
- bundle exec rake 'litmus:provision_list[waffle_el6]'
- bundle exec rake 'litmus:install_agent[puppet6]'
- bundle exec rake litmus:install_module
script:
- bundle exec rake litmus:acceptance:parallel
services: docker
sudo: required
-
bundler_args:
dist: trusty
env: PLATFORMS=el7_puppet5
rvm: 2.5.3
before_script:
- bundle exec rake 'litmus:provision_list[waffle_el7]'
- bundle exec rake 'litmus:install_agent[puppet5]'
- bundle exec rake litmus:install_module
script:
- bundle exec rake litmus:acceptance:parallel
services: docker
sudo: required
-
bundler_args:
dist: trusty
env: PLATFORMS=el7_puppet6
rvm: 2.5.3
before_script:
- bundle exec rake 'litmus:provision_list[waffle_el7]'
- bundle exec rake 'litmus:install_agent[puppet6]'
- bundle exec rake litmus:install_module
script:
- bundle exec rake litmus:acceptance:parallel
services: docker
sudo: required

-
env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint"
stage: static
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ group :development do
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_litmus", require: false, platforms: [:ruby, :mswin, :mingw, :x64_mingw] if ENV['PUPPET_GEM_VERSION'].nil? or ENV['PUPPET_GEM_VERSION'] !~ %r{ 5}
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
group :system_tests do
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ For an extensive list of supported operating systems, see [metadata.json](https:
<a id="development"></a>
## Development

We are experimenting with a new tool for running acceptance tests. It's name is [puppet_litmus](https://github.com/puppetlabs/puppet_litmus) this replaces beaker as the test runner. To run the acceptance tests follow the instructions [here](https://github.com/puppetlabs/puppet_litmus/wiki/Tutorial:-use-Litmus-to-execute-acceptance-tests-with-a-sample-module-(MoTD)#install-the-necessary-gems-for-the-module).

Puppet modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. Please follow our guidelines when contributing changes.

For more information, see our [module contribution guide.](https://puppet.com/docs/puppet/latest/contributing.html)
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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'
require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any?
Expand Down
25 changes: 25 additions & 0 deletions distelli-manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
team-modules/puppetlabs-ntp:
PreBuild:
- source /opt/rh/rh-ruby25/enable
- echo "--- LETS update BUNDLER ---"
- bundle install --path vendor/bundle --jobs 3
Build:
- echo "--- PROVISIONING ---"
- source /opt/rh/rh-ruby25/enable
- bundle exec rake litmus:provision_list[release_checks]
- cat inventory.yaml
- echo "--- AGENT INSTALLATION ---"
- bundle exec rake litmus:install_agent
- echo "--- MODULE INSTALLATION ---"
- bundle exec rake litmus:install_module
- echo "--- TESTS RUNNING ---"
- bundle exec rake litmus:acceptance:parallel
AfterBuildSuccess:
- source /opt/rh/rh-ruby25/enable
- bundle exec rake litmus:tear_down
AfterBuildFailure:
- source /opt/rh/rh-ruby25/enable
- bundle exec rake litmus:tear_down
CommitData:
- RepoType: Git
- RepoPath: .
16 changes: 16 additions & 0 deletions provision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
default:
provisioner: docker_exp
images: ['waffleimage/centos7']
waffle_deb:
provisioner: docker_exp
images: ['waffleimage/debian8', 'waffleimage/debian9', 'waffleimage/ubuntu14.04', 'waffleimage/ubuntu16.04', 'waffleimage/ubuntu18.04']
waffle_el6:
provisioner: docker_exp
images: ['waffleimage/centos6', 'waffleimage/scientificlinux6']
waffle_el7:
provisioner: docker_exp
images: ['waffleimage/centos7', 'waffleimage/oraclelinux7', 'waffleimage/scientificlinux7']
release_checks:
provisioner: vmpooler
images: ['redhat-5-x86_64', 'redhat-6-x86_64', 'redhat-7-x86_64', 'centos-5-x86_64', 'centos-6-x86_64', 'centos-7-x86_64', 'oracle-5-x86_64', 'oracle-6-x86_64', 'oracle-7-x86_64', 'scientific-6-x86_64', 'scientific-7-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'sles-11-x86_64', 'sles-12-x86_64', 'sles-15-x86_64', 'ubuntu-1404-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64']
11 changes: 5 additions & 6 deletions spec/acceptance/ntp_parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'/etc/ntp.conf'
end

modulepath = run_shell('puppet config print modulepath').stdout.split(':')[0]
describe 'ntp class', unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do
it 'applies successfully' do
pp = "class { 'ntp': }"
Expand All @@ -45,10 +46,9 @@

describe 'config_template' do
before :all do
modulepath = default['distmoduledir']
shell("mkdir -p #{modulepath}/test/templates")
run_shell("mkdir -p #{modulepath}/test/templates")
# Add spurious template logic to verify the use of the correct template rendering engine
shell("echo '<% [1].each do |i| %>erbserver<%= i %><%end %>' >> #{modulepath}/test/templates/ntp.conf.erb")
run_shell("echo '<% [1].each do |i| %>erbserver<%= i %><%end %>' >> #{modulepath}/test/templates/ntp.conf.erb")
end

it 'sets the ntp.conf erb template location' do
Expand All @@ -66,10 +66,9 @@

describe 'config_epp' do
before :all do
modulepath = default['distmoduledir']
shell("mkdir -p #{modulepath}/test/templates")
run_shell("mkdir -p #{modulepath}/test/templates")
# Add spurious template logic to verify the use of the correct template rendering engine
shell("echo '<% [1].each |$i| { -%>eppserver<%= $i %><% } -%>' >> #{modulepath}/test/templates/ntp.conf.epp")
run_shell("echo '<% [1].each |$i| { -%>eppserver<%= $i %><% } -%>' >> #{modulepath}/test/templates/ntp.conf.epp")
end

it 'sets the ntp.conf epp template location' do
Expand Down
108 changes: 56 additions & 52 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
require 'beaker-pe'
require 'beaker-puppet'
require 'beaker-rspec'
require 'beaker/puppet_install_helper'
require 'beaker/module_install_helper'

UNSUPPORTED_PLATFORMS = ['windows', 'darwin'].freeze

run_puppet_install_helper
configure_type_defaults_on(hosts)
install_ca_certs unless ENV['PUPPET_INSTALL_TYPE'] =~ %r{pe}i
install_module_on(hosts)
install_module_dependencies_on(hosts)

unless ENV['RS_PROVISION'] == 'no' || ENV['BEAKER_provision'] == 'no'

hosts.each do |host|
# Need to disable update of ntp servers from DHCP, as subsequent restart of ntp causes test failures
if fact_on(host, 'osfamily') == 'Debian'
on host, 'dpkg-divert --divert /etc/dhcp-ntp.bak --local --rename --add /etc/dhcp/dhclient-exit-hooks.d/ntp'
on host, 'dpkg-divert --divert /etc/dhcp3-ntp.bak --local --rename --add /etc/dhcp3/dhclient-exit-hooks.d/ntp'
elsif fact_on(host, 'osfamily') == 'RedHat'
on host, 'echo "PEERNTP=no" >> /etc/sysconfig/network'
end
end
end

RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

# Readable test descriptions
c.formatter = :documentation

# Configure all nodes in nodeset
c.before :suite do
hosts.each do |host|
copy_module_to(host, source: proj_root, module_name: 'ntp')
end
# frozen_string_literal: true

require 'serverspec'
require 'puppet_litmus'
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
include PuppetLitmus

if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
puts 'Running tests against this machine !'
if Gem.win_platform?
set :backend, :cmd
else
set :backend, :exec
end
end

def idempotent_apply(hosts, manifest, opts = {}, &block)
block_on hosts, opts do |host|
file_path = host.tmpfile('apply_manifest.pp')
create_remote_file(host, file_path, manifest + "\n")

puppet_apply_opts = { :verbose => nil, 'detailed-exitcodes' => nil }
on_options = { acceptable_exit_codes: [0, 2] }
on host, puppet('apply', file_path, puppet_apply_opts), on_options, &block
puppet_apply_opts2 = { :verbose => nil, 'detailed-exitcodes' => nil }
on_options2 = { acceptable_exit_codes: [0] }
on host, puppet('apply', file_path, puppet_apply_opts2), on_options2, &block
else
# load inventory
inventory_hash = inventory_hash_from_inventory_file
node_config = config_from_node(inventory_hash, ENV['TARGET_HOST'])

if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes')
host = ENV['TARGET_HOST']
set :backend, :docker
set :docker_container, host
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes')
set :backend, :ssh
options = Net::SSH::Config.for(host)
options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil?
options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil?
options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil?
options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil?
options[:verify_host_key] = Net::SSH::Verifiers::Null.new unless node_config.dig('ssh', 'host-key-check').nil?
host = if ENV['TARGET_HOST'].include?(':')
ENV['TARGET_HOST'].split(':').first
else
ENV['TARGET_HOST']
end
set :host, options[:host_name] || host
set :ssh_options, options
set :request_pty, true
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
require 'winrm'

set :backend, :winrm
set :os, family: 'windows'
user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil?
pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil?
endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman"

opts = {
user: user,
password: pass,
endpoint: endpoint,
operation_timeout: 300,
}

winrm = WinRM::Connection.new opts
Specinfra.configuration.winrm = winrm
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper_acceptance_local.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

UNSUPPORTED_PLATFORMS = ['windows', 'darwin'].freeze

0 comments on commit e358b3b

Please sign in to comment.