Unverified Commit e1dec8c7 authored by Jonathan's avatar Jonathan Committed by GitHub
Browse files

Merge pull request #141 from SearchLightNZ/pdk_1.18.1

Update PDK to 1.18.1 and re-work tests
parents b40d0884 d2d902dc
fixtures:
symlinks:
freeradius: "#{source_dir}"
repositories:
stdlib:
repo: https://github.com/puppetlabs/puppetlabs-stdlib.git
ref: 4.3.2
forge_modules:
forge_modules:
concat: "puppetlabs/concat"
firewall: "puppetlabs/firewall"
logrotate: "puppet/logrotate"
rsyslog: "saz/rsyslog"
stdlib: "puppetlabs/stdlib"
......@@ -10,22 +10,25 @@ cache:
before_script:
- bundle -v
- rm Gemfile.lock || true
- gem update --system $RUBYGEMS_VERSION
- "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner"
- "# Set `rubygems_version` in the .sync.yml to set a value"
- "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set"
- '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION'
- gem --version
- bundle -v
- bundle install --without system_tests --path vendor/bundle --jobs $(nproc)
syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.3-Puppet ~> 6:
syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.7-Puppet ~> 6:
stage: syntax
image: ruby:2.5.3
image: ruby:2.5.7
script:
- bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
variables:
PUPPET_GEM_VERSION: '~> 6'
parallel_spec-Ruby 2.5.3-Puppet ~> 6:
parallel_spec-Ruby 2.5.7-Puppet ~> 6:
stage: unit
image: ruby:2.5.3
image: ruby:2.5.7
script:
- bundle exec rake parallel_spec
variables:
......
......@@ -27,6 +27,7 @@ GetText/DecorateString:
Description: We don't want to decorate test output.
Exclude:
- spec/**/*
Enabled: false
RSpec/BeforeAfterAll:
Description: Beware of using after(:all) as it may cause state to leak between tests.
A necessary evil in acceptance testing.
......@@ -39,6 +40,10 @@ Style/BlockDelimiters:
Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to
be consistent then.
EnforcedStyle: braces_for_chaining
Style/BracesAroundHashParameters:
Description: Braces are required by Ruby 2.7. Cop removed from RuboCop v0.80.0.
See https://github.com/rubocop-hq/rubocop/pull/7643
Enabled: true
Style/ClassAndModuleChildren:
Description: Compact style reduces the required amount of indentation.
EnforcedStyle: compact
......@@ -88,6 +93,12 @@ Style/MethodCalledOnDoEndBlock:
Enabled: true
Style/StringMethods:
Enabled: true
GetText/DecorateFunctionMessage:
Enabled: false
GetText/DecorateStringFormattingUsingInterpolation:
Enabled: false
GetText/DecorateStringFormattingUsingPercent:
Enabled: false
Layout/EndOfLine:
Enabled: false
Layout/IndentHeredoc:
......
---
spec/spec_helper.rb:
mock_with: ":rspec"
---
os: linux
dist: xenial
language: ruby
cache: bundler
before_install:
- bundle -v
- rm -f Gemfile.lock
- gem update --system $RUBYGEMS_VERSION
- "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner"
- "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used"
- "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set"
- '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION'
- gem --version
- bundle -v
script:
- 'bundle exec rake $CHECK'
bundler_args: --without system_tests
rvm:
- 2.5.3
- 2.5.7
stages:
- static
- spec
......@@ -20,7 +24,7 @@ stages:
-
if: tag =~ ^v\d
name: deploy
matrix:
jobs:
fast_finish: true
include:
-
......@@ -32,7 +36,7 @@ matrix:
stage: spec
-
env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
rvm: 2.5.3
rvm: 2.5.7
stage: spec
-
env: DEPLOY_TO_FORGE=yes
......
{
"recommendations": [
"jpogran.puppet-vscode",
"puppet.puppet-vscode",
"rebornix.Ruby"
]
}
......@@ -24,10 +24,10 @@ group :development do
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 "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-posix-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby]
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-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby]
gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby]
gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
end
puppet_version = ENV['PUPPET_GEM_VERSION']
......
# frozen_string_literal: true
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'
......@@ -15,8 +17,17 @@ end
def changelog_project
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = nil || JSON.load(File.read('metadata.json'))['source'].match(%r{.*/([^/]*)})[1]
raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil?
returnVal = nil
returnVal ||= begin
metadata_source = JSON.load(File.read('metadata.json'))['source']
metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z})
metadata_source_match && metadata_source_match[1]
end
raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil?
puts "GitHubChangelogGenerator project:#{returnVal}"
returnVal
end
......@@ -41,7 +52,7 @@ if Bundler.rubygems.find_name('github_changelog_generator').any?
config.header = "# Change log\n\nAll 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)."
config.add_pr_wo_labels = true
config.issues = false
config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM"
config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB"
config.configure_sections = {
"Changed" => {
"prefix" => "### Changed",
......@@ -49,11 +60,11 @@ if Bundler.rubygems.find_name('github_changelog_generator').any?
},
"Added" => {
"prefix" => "### Added",
"labels" => ["feature", "enhancement"],
"labels" => ["enhancement", "feature"],
},
"Fixed" => {
"prefix" => "### Fixed",
"labels" => ["bugfix"],
"labels" => ["bug", "documentation", "bugfix"],
},
}
end
......@@ -61,16 +72,15 @@ else
desc 'Generate a Changelog from GitHub'
task :changelog do
raise <<EOM
The changelog tasks depends on unreleased features of the github_changelog_generator gem.
The changelog tasks depends on recent features of the github_changelog_generator gem.
Please manually add it to your .sync.yml for now, and run `pdk update`:
---
Gemfile:
optional:
':development':
- gem: 'github_changelog_generator'
git: 'https://github.com/skywinder/github-changelog-generator'
ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018'
condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')"
version: '~> 1.15'
condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')"
EOM
end
end
......
# Grab the FreeRADIUS version from the output of radiusd -v
# Set path to binary for our platform
dist = Facter.value(:osfamily)
case dist
when /RedHat/
binary = 'radiusd'
when /Debian/
binary = 'freeradius'
else
binary = 'radiusd'
end
module Facter::Util::FreeradiusVersion
class << self
def version_string
# Set path to binary for our platform
dist = Facter.value(:osfamily)
case dist
when /RedHat/
binary = 'radiusd'
when /Debian/
binary = 'freeradius'
else
binary = 'radiusd'
end
# Execute call to fetch version info
version = Facter::Core::Execution.exec("#{binary} -v")
Facter::Core::Execution.exec("#{binary} -v")
end
end
end
# Extract full version number
Facter.add(:freeradius_version) do
setcode do
if !version.nil?
minver = version.split(/\n/)[0].match(/FreeRADIUS Version (\d+\.\d+\.\d+)/)[1].to_s
version_string = Facter::Util::FreeradiusVersion.version_string
if !version_string.nil?
version = version_string.split(/\n/)[0].match(/FreeRADIUS Version (\d+\.\d+\.\d+)/)[1].to_s
end
minver
version
end
end
# Extract major version number
Facter.add(:freeradius_maj_version) do
setcode do
if !version.nil?
majver = version.split(/\n/)[0].match(/FreeRADIUS Version (\d+)\.\d+\.\d+/)[1].to_s
version_string = Facter::Util::FreeradiusVersion.version_string
if !version_string.nil?
majver = version_string.split(/\n/)[0].match(/FreeRADIUS Version (\d+)\.\d+\.\d+/)[1].to_s
end
majver
end
......
......@@ -63,6 +63,8 @@ class freeradius (
"${freeradius::fr_basepath}/mods-config/attr_filter",
"${freeradius::fr_basepath}/mods-config/preprocess",
"${freeradius::fr_basepath}/mods-config/sql",
"${freeradius::fr_basepath}/sites-available",
"${freeradius::fr_basepath}/mods-available",
]:
ensure => directory,
mode => '0755',
......@@ -138,12 +140,12 @@ class freeradius (
}
concat::fragment { 'policy_header':
target => "${freeradius::fr_basepath}/policy.conf",
content => "policy {\n",
content => 'policy {',
order => 10,
}
concat::fragment { 'policy_footer':
target => "${freeradius::fr_basepath}/policy.conf",
content => "}\n",
content => '}',
order => '99',
}
......@@ -162,7 +164,7 @@ class freeradius (
}
concat::fragment { 'template_footer':
target => "${freeradius::fr_basepath}/templates.conf",
content => "}\n",
content => '}',
order => '95',
}
......@@ -177,7 +179,7 @@ class freeradius (
}
concat::fragment { 'proxy_header':
target => "${freeradius::fr_basepath}/proxy.conf",
content => "# Proxy config\n\n",
content => '# Proxy config\n',
order => '05',
}
......@@ -341,7 +343,7 @@ class freeradius (
# Syslog rules
if $syslog == true {
rsyslog::snippet { '12-radiusd-log':
content => "if \$programname == \'radiusd\' then ${freeradius::fr_logpath}/radius.log\n&~",
content => "if \$programname == \'radiusd\' then ${freeradius::fr_logpath}/radius.log\n\&\~",
}
}
......@@ -434,7 +436,7 @@ class freeradius (
"${freeradius::fr_basepath}/clients.conf",
"${freeradius::fr_basepath}/sql.conf",
]:
content => "# FILE INTENTIONALLY BLANK\n",
content => '# FILE INTENTIONALLY BLANK\n',
mode => '0644',
owner => 'root',
group => $freeradius::fr_group,
......
......@@ -41,7 +41,7 @@
"operatingsystemrelease": [
"29",
"30",
"31"
"31"
]
},
{
......@@ -66,7 +66,7 @@
"version_requirement": ">=4.0.0 <7.0.0"
}
],
"pdk-version": "1.12.0",
"template-url": "pdk-default#1.12.0",
"template-ref": "1.12.0-0-g55d9ae2"
"pdk-version": "1.18.1",
"template-url": "pdk-default#1.18.1",
"template-ref": "tags/1.18.1-0-g3d2e75c"
}
require 'spec_helper'
require 'shared_contexts'
describe 'freeradius::control_socket' do
# by default the hiera integration uses hiera data from the shared_contexts.rb file
# but basically to mock hiera you first need to add a key/value pair
# to the specific context in the spec/shared_contexts.rb file
# Note: you can only use a single hiera context per describe/context block
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
on_supported_os.each do |os, os_facts|
context "on #{os}" do
include_context 'redhat_params'
include_context 'freeradius_default'
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
#:mode => "ro",
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_freeradius__site('control-socket')
.with(
'content' => 'template(freeradius/sites-enabled/control-socket.erb)'
)
let(:facts) { os_facts }
# Empty params hash by default so we can super().merge
let(:params) { {} }
describe 'freeradius::control_socket' do
it do
is_expected.to contain_freeradius__site('control-socket')
end
end
end
end
end
This diff is collapsed.
require 'spec_helper'
describe 'freeradius' do
context 'with defaults for all parameters' do
it { should contain_class('freeradius') }
end
end
require 'spec_helper'
require 'shared_contexts'
describe 'freeradius::params' do
# by default the hiera integration uses hiera data from the shared_contexts.rb file
# but basically to mock hiera you first need to add a key/value pair
# to the specific context in the spec/shared_contexts.rb file
# Note: you can only use a single hiera context per describe/context block
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
end
require 'spec_helper'
require 'shared_contexts'
describe 'freeradius::status_server' do
# by default the hiera integration uses hiera data from the shared_contexts.rb file
# but basically to mock hiera you first need to add a key/value pair
# to the specific context in the spec/shared_contexts.rb file
# Note: you can only use a single hiera context per describe/context block
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
on_supported_os.each do |os, os_facts|
context "on #{os}" do
include_context 'redhat_params'
include_context 'freeradius_default'
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
:secret => 'place_value_here',
#:port => "18121",
#:listen => "*",
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_freeradius__site('status')
.with(
'content' => 'template(freeradius/sites-enabled/status.erb)'
)
let(:facts) { os_facts }
# Empty params hash by default so we can super().merge
let(:params) { {} }
describe 'freeradius::status_server' do
it do
is_expected.to contain_freeradius__site('status')
end
end
end
end
end
......@@ -3,5 +3,6 @@
# Facts specified here will override the values provided by rspec-puppet-facts.
---
ipaddress: "172.16.254.254"
ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA"
is_pe: false
macaddress: "AA:AA:AA:AA:AA:AA"
require 'spec_helper'
require 'shared_contexts'
describe 'freeradius::attr' do
# by default the hiera integration uses hiera data from the shared_contexts.rb file
# but basically to mock hiera you first need to add a key/value pair
# to the specific context in the spec/shared_contexts.rb file
# Note: you can only use a single hiera context per describe/context block
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
include_context 'redhat_common_dependencies'
let(:title) { 'test' }
let(:title) { 'XXreplace_meXX' }
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
:source => 'place_value_here',
#:ensure => present,
#:key => "User-Name",
#:prefix => "filter",
:source => 'puppet:///modules/test/path/to/file',
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_file('$fr_version ? { 2 => $fr_basepath, 3 => $fr_moduleconfigpath/attr_filter, default => $fr_moduleconfigpath }/XXreplace_meXX')
.with(
'ensure' => 'present',
'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }',
'mode' => '0640',
'notify' => 'Service[$fr_service]',
'owner' => 'root',
'require' => '[Package[$fr_package], Group[$fr_group]]',
'source' => ''
)
is_expected.to contain_file('/etc/raddb/mods-config/attr_filter/test')
.that_notifies('Service[radiusd]')
.that_requires('Group[radiusd]')
.that_requires('Package[freeradius]')
.with_ensure('present')
.with_group('radiusd')
.with_mode('0640')
.with_owner('root')
.with_source('puppet:///modules/test/path/to/file')
end
it do
is_expected.to contain_concat__fragment('attr-XXreplace_meXX')
.with(
'content' => 'template(freeradius/attr.fr$fr_version.erb)',
'order' => '20',
'target' => '$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/$fr_version ? { 2 => modules, 3 => mods-enabled, default => modules }/attr_filter'
)
is_expected.to contain_concat__fragment('attr-test')
.with_content(%r{^attr_filter filter.test {\n\s+key = "\%{User-Name}"\n\s+filename = \${modconfdir}/\${\.:name}/test\n}})
.with_order('20')
.with_target('/etc/raddb/mods-available/attr_filter')
end
end
require 'spec_helper'
require 'shared_contexts'
describe 'freeradius::blank' do
# by default the hiera integration uses hiera data from the shared_contexts.rb file
# but basically to mock hiera you first need to add a key/value pair
# to the specific context in the spec/shared_contexts.rb file
# Note: you can only use a single hiera context per describe/context block
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
include_context 'redhat_common_dependencies'
let(:title) { 'test' }
let(:params) { {} }
let(:title) { 'XXreplace_meXX' }
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
}
end