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] beaker usually runs all tests on each provided os node #129

Merged
merged 14 commits into from
Jul 21, 2017
Merged
4 changes: 4 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fixtures:
symlinks:
site: "#{source_dir}/site"
r10k: "#{source_dir}/modules"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -213,3 +214,6 @@ ENV/
control-repo.iml
/site/profile/.vendor/
/site/profile/coverage/

# Beaker spec testing
environment.conf.rpmnew
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format documentation
--color
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
11 changes: 10 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,31 @@ 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'])

# Only explicitly specify Facter/Hiera if a version has been specified.
# 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
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)
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.puppetlint
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 63 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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:<role> 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
6 changes: 5 additions & 1 deletion bin/config_script.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion bin/papply.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions bin/travis_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions manifests/site.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# Exec {
# path => '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\',
# }
}
}
default: {
File {
owner => 'root',
Expand Down Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -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."
}
14 changes: 7 additions & 7 deletions site/profile/manifests/aws/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions site/profile/manifests/time/windows.pp
Original file line number Diff line number Diff line change
@@ -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 = [],
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion site/profile/templates/gitlab/gitlab.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
17 changes: 17 additions & 0 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions spec/acceptance/profile_base_linux_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading