diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 00000000..e3ea35d9 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,4 @@ +fixtures: + symlinks: + site: "#{source_dir}/site" + r10k: "#{source_dir}/modules" diff --git a/.gitignore b/.gitignore index 1d01ef16..8c56a781 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ modules/ /keys/private_key.pkcs7.pem *.pyc *Gemfile.lock +vendor # Vagrant artifacts vagrant/environments/*/ubuntu-xenial-16.04-cloudimg-console.log @@ -213,3 +214,6 @@ ENV/ control-repo.iml /site/profile/.vendor/ /site/profile/coverage/ + +# Beaker spec testing +environment.conf.rpmnew diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..8c18f1ab --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/.travis.yml b/.travis.yml index 803473bd..9a2104a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ cache: bundler script: "bin/travis_check.sh" before_install: - gem update bundler + - gem install r10k + - r10k puppetfile install -v matrix: fast_finish: true include: @@ -14,8 +16,8 @@ matrix: - rvm: 2.1.9 bundler_args: --without system_tests env: PUPPET_GEM_VERSION="~> 4.0" STDLIB_LOG_DEPRECATIONS="false" - - rvm: 2.1.5 + - rvm: 2.4.1 bundler_args: --without system_tests - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" + env: PUPPET_GEM_VERSION="~> 5.0" STDLIB_LOG_DEPRECATIONS="false" notifications: email: false diff --git a/Gemfile b/Gemfile index d1a26d6e..9a3370ed 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,7 @@ group :system_tests do gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1') end +gem 'puppetlabs_spec_helper' gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION']) gem 'r10k', *location_for(ENV['R10K_GEM_VERSION']) @@ -57,8 +58,10 @@ gem 'r10k', *location_for(ENV['R10K_GEM_VERSION']) # Otherwise it can lead to strange bundler behavior. If you are seeing weird # gem resolution behavior, try setting `DEBUG_RESOLVER` environment variable # to `1` and then run bundle install. -gem 'facter', *location_for(ENV['FACTER_GEM_VERSION']) if ENV['FACTER_GEM_VERSION'] +gem 'facter', *location_for(ENV['FACTER_GEM_VERSION'] || '= 2.4.0') gem 'hiera', *location_for(ENV['HIERA_GEM_VERSION']) if ENV['HIERA_GEM_VERSION'] +gem 'hiera-eyaml' +gem 'rspec-puppet-facts' # Evaluate Gemfile.local if it exists @@ -66,6 +69,12 @@ if File.exists? "#{__FILE__}.local" eval(File.read("#{__FILE__}.local"), binding) end +# Evaluate Gemfile.puppetlint if it exists +if File.exists? "#{__FILE__}.puppetlint" + eval(File.read("#{__FILE__}.puppetlint"), binding) +end + + # Evaluate ~/.gemfile if it exists if File.exists?(File.join(Dir.home, '.gemfile')) eval(File.read(File.join(Dir.home, '.gemfile')), binding) diff --git a/Gemfile.puppetlint b/Gemfile.puppetlint index 196780c9..d64072a7 100644 --- a/Gemfile.puppetlint +++ b/Gemfile.puppetlint @@ -19,9 +19,9 @@ gem 'puppet-lint-file_ensure-check', gem 'puppet-lint-leading_zero-check', :git => 'https://github.com/voxpupuli/puppet-lint-leading_zero-check.git', :require => false -gem 'puppet-lint-numericvariable', - :git => 'https://github.com/fiddyspence/puppetlint-numericvariable.git', - :require => false +#gem 'puppet-lint-numericvariable', +# :git => 'https://github.com/fiddyspence/puppetlint-numericvariable.git', +# :require => false gem 'puppet-lint-resource_reference_syntax', :git => 'https://github.com/voxpupuli/puppet-lint-resource_reference_syntax.git', :require => false diff --git a/Rakefile b/Rakefile index 74dbb11a..10007ff3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,66 @@ require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet-lint/tasks/puppet-lint' +require 'rspec/core/rake_task' +require 'puppet' -PuppetSyntax.exclude_paths = ['spec/fixtures/**/*', 'vendor/**/*'] -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.ignore_paths = ["pkg/**/*.pp", 'spec/**/*.pp', 'tests/**/*.pp', "vendor/**/*.pp"] +# abort if puppet version is to old +if Puppet::version < '4' + puts 'YOU MUST RUN THIS WITH PUPPET 4.x' + abort +end +exclude_paths = %w( + vendor/**/* + spec/**/* + modules/**/* + pkg/**/* + tests/**/* +) + +# the default lint task can not override the pattern configuration +Rake::Task[:lint].clear +PuppetLint::RakeTask.new(:lint) do |config| + # Pattern of files to ignore + config.ignore_paths = exclude_paths + # Pattern of files to check, defaults to `**/*.pp` + config.pattern = ['manifests/**/*.pp', 'site/**/*.pp'] + # List of checks to disable + config.disable_checks = ['140chars', 'relative', 'class_inherits_from_params_class'] + # Should the task fail if there were any warnings, defaults to false + config.fail_on_warnings = true + # Print out the context for the problem, defaults to false + #config.with_context = true + # Log Format + #config.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' +end + +# beaker is designed to run same tests on multiple nodes +# we have another usecase: multiple tests on multiple os +Rake::Task[:beaker].clear +RSpec::Core::RakeTask.new(:beaker) do |config| + puts 'dont use beaker, use beaker_roles: or all_roles instead' + abort +end + +# iterate over acceptance tests and create namespaced rake tasks +namespace :beaker_roles do + Dir.glob("spec/acceptance/*_spec.rb") do |acceptance_test| + test_name = acceptance_test.split('/').last.split('_spec').first + RSpec::Core::RakeTask.new(test_name) do |t| + t.rspec_opts = ['--color'] + t.pattern = acceptance_test + end + end +end + +# find all rake tasks in beaker_roles namespace and run them in parallel +all_roles = [] +Rake.application.in_namespace(:beaker_roles) do |beaker_roles_namespace| + beaker_roles_namespace.tasks.each do |beaker_roles_tasks| + all_roles << beaker_roles_tasks + end +end +multitask :all_roles => all_roles + +PuppetSyntax.exclude_paths = exclude_paths + +# vim: syntax=ruby diff --git a/bin/config_script.sh b/bin/config_script.sh index f762a1e6..5c50b230 100755 --- a/bin/config_script.sh +++ b/bin/config_script.sh @@ -1,2 +1,6 @@ #!/bin/bash -/usr/bin/git --git-dir /etc/puppetlabs/code/environments/$1/.git log --pretty=format:"%h - %an, %ad : %s" -1 +if [ -x /usr/bin/git ]; then + /usr/bin/git --git-dir /etc/puppetlabs/code/environments/$1/.git log --pretty=format:"%h - %an, %ad : %s" -1 +else + echo "no git - environment $1" +fi diff --git a/bin/papply.sh b/bin/papply.sh index 8b9458b4..f9bd4755 100755 --- a/bin/papply.sh +++ b/bin/papply.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +PATH=$PATH:/opt/puppetlabs/server/bin repo_dir="$(dirname $0)/.." # repo_dir=$(git rev-parse --show-toplevel) . "${repo_dir}/bin/functions" @@ -11,7 +12,7 @@ PATH=$PATH:/opt/puppetlabs/puppet/bin echo_title "Running Puppet version $(puppet --version) apply on ${manifest}" echo_subtitle "Role: ${FACTER_role} - $(facter -p role)" -puppet --version | grep "^4" > /dev/null +puppet --version | grep "^[4|5]" > /dev/null if [ "x$?" == "x0" ] ; then manifest_option='' else diff --git a/bin/travis_check.sh b/bin/travis_check.sh index 807354b0..dacd0bd2 100755 --- a/bin/travis_check.sh +++ b/bin/travis_check.sh @@ -15,8 +15,12 @@ run_script() { fi } -run_script bin/puppet_check_syntax_fast.sh -run_script bin/puppet_lint.sh optional -run_script "bin/puppet_check_rake.sh site bundle" +bundle exec rake validate +bundle exec rake lint +bundle exec rake spec -exit $global_exit +#run_script bin/puppet_check_syntax_fast.sh +#run_script bin/puppet_lint.sh optional +#run_script "bin/puppet_check_rake.sh site bundle" + +#exit $global_exit diff --git a/manifests/site.pp b/manifests/site.pp index 1852d7ea..0e68cd0f 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -50,7 +50,7 @@ # Exec { # path => '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\', # } - } + } default: { File { owner => 'root', @@ -120,9 +120,9 @@ contain "::profile::base::${kernel_down}" # Class ordering - Class['::tools'] -> - Class['::profile::settings'] -> - Class['::profile::pre'] -> + Class['::tools'] -> # lint:ignore:arrow_on_right_operand_line + Class['::profile::settings'] -> # lint:ignore:arrow_on_right_operand_line + Class['::profile::pre'] -> # lint:ignore:arrow_on_right_operand_line Class["::profile::base::${kernel_down}"] # Classification option 1 - Profiles defined in Hiera diff --git a/metadata.json b/metadata.json new file mode 100644 index 00000000..015858db --- /dev/null +++ b/metadata.json @@ -0,0 +1,61 @@ +{ + "name": "example42-psick", + "version": "0.0.2", + "author": "Example42", + "summary": "Control Repo.", + "license": "Apache-2.0", + "source": "https://github.com/example42/psick", + "project_page": "https://github.com/example42/psick", + "dependencies": [ + { "name":"puppetlabs/stdlib","version_requirement":">= 4.0.0 < 5.0.0" } + ], + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "OracleLinux", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "11 SP1", + "12" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "8" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "16.04" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.5.0 < 6.0.0" + } + ], + "description": "PSICK control repo." +} diff --git a/site/profile/manifests/aws/cli.pp b/site/profile/manifests/aws/cli.pp index 8343ba70..0cdb9f9b 100644 --- a/site/profile/manifests/aws/cli.pp +++ b/site/profile/manifests/aws/cli.pp @@ -21,17 +21,17 @@ $install_gems.each | $gem | { if $install_system_gems { package { $gem: - ensure => $ensure, - provider => 'gem', - require => Class['profile::ruby'], + ensure => $ensure, + provider => 'gem', + require => Class['profile::ruby'], } } if $install_puppet_gems { package { "puppet_${gem}": - ensure => $ensure, - name => $gem, - provider => 'puppet_gem', - require => Class['profile::ruby'], + ensure => $ensure, + name => $gem, + provider => 'puppet_gem', + require => Class['profile::ruby'], } } } diff --git a/site/profile/manifests/time/windows.pp b/site/profile/manifests/time/windows.pp index 6630b89b..53520ff7 100644 --- a/site/profile/manifests/time/windows.pp +++ b/site/profile/manifests/time/windows.pp @@ -1,5 +1,5 @@ # This profile manages ntp client on Windows -# Derived from https://github.com/ncorrare/windowstime +# Derived from https://github.com/ncorrare/windowstime class profile::time::windows ( Array $ntp_servers = $::profile::time::servers, Array $fallback_servers = [], @@ -36,10 +36,10 @@ if $timezone { if $timezone != $facts['timezone'] { exec { "tzutil.exe /s ${timezone}": - command => "tzutil.exe /s \"${timezone}\"", - unless => "tzutil.exe /g | findstr /R /C:\"${timezone}\"", + command => "tzutil.exe /s \"${timezone}\"", + unless => "tzutil.exe /g | findstr /R /C:\"${timezone}\"", + path => $::path, # refreshonly => true, - path => $::path, } } } diff --git a/site/profile/templates/gitlab/gitlab.rb.erb b/site/profile/templates/gitlab/gitlab.rb.erb index 884cd3fa..abfaea42 100644 --- a/site/profile/templates/gitlab/gitlab.rb.erb +++ b/site/profile/templates/gitlab/gitlab.rb.erb @@ -509,7 +509,7 @@ external_url '<%= @options['external_url'] %>' # Git trace log file. # If set, git commands receive GIT_TRACE* environment variables # See https://git-scm.com/book/es/v2/Git-Internals-Environment-Variables#Debugging for documentation -# An absolute path starting with / – the trace output will be appended to that file. +# An absolute path starting with / the trace output will be appended to that file. # It needs to exist so we can check permissions and avoid to throwing warnings to the users. # gitlab_shell['git_trace_log_file'] = "/var/log/gitlab/gitlab-shell/gitlab-shell-git-trace.log" diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 00000000..8fd1456d --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,17 @@ +HOSTS: + centos-7-x64: + platform: el-7-x86_64 + hypervisor : docker + image: centos:centos7 + docker_preserve_image: true + mount_folders: + controlrepo: + host_path: . + container_path: /etc/puppetlabs/code/environments/production + docker_cmd: '["/usr/sbin/init"]' + docker_image_commands: + - 'yum -y swap -- remove fakesystemd -- install systemd systemd-libs' + - 'yum -y install cronie initscripts which' + - 'yum -y update; yum clean all; yum makecache' +CONFIG: + type: foss diff --git a/spec/acceptance/profile_base_linux_spec.rb b/spec/acceptance/profile_base_linux_spec.rb new file mode 100644 index 00000000..4bad49ef --- /dev/null +++ b/spec/acceptance/profile_base_linux_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper_acceptance' + +describe 'profile::base::linux' do + let(:manifest) { + <<-EOS + Tp::Install { + test_enable => lookup('tp::test_enable', Boolean, 'first', false), + puppi_enable => lookup('tp::puppi_enable', Boolean, 'first', false), + debug => lookup('tp::debug', Boolean, 'first', false), + data_module => lookup('tp::data_module', String, 'first', 'tinydata'), + } + Tp::Conf { + config_file_notify => lookup('tp::config_file_notify', Boolean, 'first', true), + config_file_require => lookup('tp::config_file_require', Boolean, 'first', true), + debug => lookup('tp::debug', Boolean, 'first', false), + data_module => lookup('tp::data_module', String, 'first', 'tinydata'), + } + Tp::Dir { + config_dir_notify => lookup('tp::config_dir_notify', Boolean, 'first', true), + config_dir_require => lookup('tp::config_dir_require', Boolean, 'first', true), + debug => lookup('tp::debug', Boolean, 'first', false), + data_module => lookup('tp::data_module', String, 'first', 'tinydata'), + } + Exec { + path => '/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin', + } + include profile::base::linux + EOS + } + it 'should run without errors or wthout changes' do + result = apply_manifest(manifest, :catch_failures => true) + expect(@result.exit_code).to eq(2).or(eq(0)) + end + it 'should run a second time without changes' do + result = apply_manifest(manifest, :catch_changes => true) + expect(@result.exit_code).to eq 0 + end +end diff --git a/spec/spec.yaml b/spec/spec.yaml new file mode 100644 index 00000000..aacfd196 --- /dev/null +++ b/spec/spec.yaml @@ -0,0 +1,54 @@ +networking: + dhcp: 10.0.2.2 + domain: lan + fqdn: puppet.lan + hostname: puppet + interfaces: + docker0: + bindings: + - address: 172.17.0.1 + netmask: 255.255.0.0 + network: 172.17.0.0 + ip: 172.17.0.1 + mac: "02:42:8e:da:27:96" + mtu: 1500 + netmask: 255.255.0.0 + network: 172.17.0.0 + eth0: + bindings: + - address: 10.0.2.15 + netmask: 255.255.255.0 + network: 10.0.2.0 + dhcp: 10.0.2.2 + ip: 10.0.2.15 + mac: "52:54:00:22:5b:53" + mtu: 1500 + netmask: 255.255.255.0 + network: 10.0.2.0 + eth1: + bindings: + - address: 10.42.42.101 + netmask: 255.255.255.0 + network: 10.42.42.0 + ip: 10.42.42.101 + mac: "08:00:27:e4:c8:bd" + mtu: 1500 + netmask: 255.255.255.0 + network: 10.42.42.0 + lo: + bindings: + - address: 127.0.0.1 + netmask: 255.0.0.0 + network: 127.0.0.0 + ip: 127.0.0.1 + mtu: 65536 + netmask: 255.0.0.0 + network: 127.0.0.0 + ip: 10.0.2.15 + mac: "52:54:00:22:5b:53" + mtu: 1500 + netmask: 255.255.255.0 + network: 10.0.2.0 + primary: eth0 + + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..617e80aa --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,18 @@ +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts + +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) + +support_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec/support/*.rb')) +Dir[support_path].each {|f| require f} + +RSpec.configure do |c| + c.module_path = File.join(fixture_path, 'modules/site') + ':' + File.join(fixture_path, 'modules/r10k') + c.manifest_dir = File.join(fixture_path, '../../manifests') + c.manifest = File.join(fixture_path, '../../manifests/site.pp') + c.hiera_config = File.join(fixture_path, '../../hiera.yaml') + c.fail_fast = true +end + +at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 00000000..114913db --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,21 @@ +require 'beaker-rspec' +require 'beaker-hiera' + +hosts.each do |host| + # Install Puppet + install_puppet_agent_on(host) +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| + on(host, '/opt/puppetlabs/puppet/bin/gem install hiera-eyaml') + on(host, 'cd /etc/puppetlabs/puppet/ && /opt/puppetlabs/puppet/bin/eyaml createkeys') + end + end +end