Commit 38d6d590 authored by mh's avatar mh
Browse files

Merge remote-tracking branch 'shared/master'

parents b1db79ba f41eebf3
fixtures:
repositories:
"common":
"repo": "https://gitlab.com/shared-puppet-modules-group/common.git"
symlinks:
"apt": "#{source_dir}"
/pkg/
/Gemfile.lock
/vendor/
/spec/fixtures/manifests/*
/spec/fixtures/modules/*
!/spec/fixtures/modules/apt
!/spec/fixtures/modules/apt/*
/spec/fixtures
/log
/.vagrant/
/.bundle/
......
image: leapcode/ruby
before_script:
- ruby -v
- gem install bundler --no-ri --no-rdoc
- bundle install --jobs $(nproc) "${FLAGS[@]}"
- "[ -d /var/cache/gitlab-runner ] || sudo mkdir /var/cache/gitlab-runner"
- sudo chown cirunner:cirunner -R /var/cache/gitlab-runner
- bundle install --jobs $(nproc) --without system_tests --path=/var/cache/gitlab-runner/ "${FLAGS[@]}"
# don't fail on lint warnings
rspec:
.job_template: &job_definition
script:
# don't fail on lint warnings
- bundle exec rake lint || /bin/true
- bundle exec rake syntax
- bundle exec rake validate
- bundle exec rake spec
# Default debian jessie versions
test:puppet37:
variables:
PUPPET_VERSION: "~> 3.7.2"
FACTER_VERSION: '~> 2.2.0'
<<: *job_definition
test:puppet38_future_parser:
variables:
PUPPET_VERSION: '~> 3.8'
FACTER_VERSION: '~> 2.2.0'
FUTURE_PARSER: 'yes'
<<: *job_definition
# Default debia stretch versions
test:puppet45:
variables:
PUPPET_VERSION: "~> 4.5.2"
FACTER_VERSION: '~> 2.4.6'
<<: *job_definition
# Latest greatest
test:puppet4x:
variables:
PUPPET_VERSION: "> 4"
FACTER_VERSION: '> 2'
<<: *job_definition
source "https://rubygems.org"
group :test do
group :development, :unit_tests do
gem "rake"
gem "rspec", '< 3.2.0'
gem "puppet", ENV['PUPPET_VERSION'] || ENV['GEM_PUPPET_VERSION'] || ENV['PUPPET_GEM_VERSION'] || '~> 3.7.0'
gem "facter", ENV['FACTER_VERSION'] || ENV['GEM_FACTER_VERSION'] || ENV['FACTER_GEM_VERSION'] || '~> 2.2.0'
gem "rspec-puppet"
gem "rspec-puppet", "~> 2.1", :require => false
gem "rspec-core"
gem "puppetlabs_spec_helper"
gem "metadata-json-lint"
gem "rspec-puppet-facts"
......@@ -13,8 +11,12 @@ group :test do
end
group :system_tests do
gem 'beaker', :require => false
gem 'beaker-rspec', :require => false
gem 'beaker_spec_helper', :require => false
gem 'serverspec', :require => false
gem 'beaker'
gem 'beaker-rspec'
gem 'beaker_spec_helper'
gem 'serverspec'
end
gem "puppet", ENV['PUPPET_VERSION'] || ENV['GEM_PUPPET_VERSION'] || ENV['PUPPET_GEM_VERSION'] || '~> 3.7.0'
gem "facter", ENV['FACTER_VERSION'] || ENV['GEM_FACTER_VERSION'] || ENV['FACTER_GEM_VERSION'] || '~> 2.2.0'
......@@ -4,8 +4,10 @@ rescue LoadError
require "#{File.dirname(__FILE__)}/util/debian"
end
def debian_codename_to_next(codename)
if codename == "sid"
def debian_codename_to_next(codename, release)
if release == "testing"
return "sid"
elsif release == "unstable"
return "experimental"
else
codenames = Facter::Util::Debian::CODENAMES
......@@ -18,6 +20,6 @@ end
Facter.add(:debian_nextcodename) do
confine :operatingsystem => 'Debian'
setcode do
debian_codename_to_next(Facter.value('debian_codename'))
debian_codename_to_next(Facter.value('debian_codename'), Facter.value('debian_release'))
end
end
define apt::apt_conf(
$ensure = 'present',
$source = '',
$source = undef,
$content = undef,
$refresh_apt = true )
{
if $source == '' and $content == undef {
if $source == undef and $content == undef {
fail("One of \$source or \$content must be specified for apt_conf ${name}")
}
if $source != '' and $content != undef {
if $source != undef and $content != undef {
fail("Only one of \$source or \$content must specified for apt_conf ${name}")
}
......
......@@ -40,14 +40,14 @@ class apt(
mode => '0644';
}
apt_conf { '02show_upgraded':
::apt::apt_conf { '02show_upgraded':
source => [ "puppet:///modules/site_apt/${::fqdn}/02show_upgraded",
'puppet:///modules/site_apt/02show_upgraded',
'puppet:///modules/apt/02show_upgraded' ]
}
if ( $::virtual == 'vserver' ) {
apt_conf { '03clean_vserver':
::apt::apt_conf { '03clean_vserver':
source => [ "puppet:///modules/site_apt/${::fqdn}/03clean_vserver",
'puppet:///modules/site_apt/03clean_vserver',
'puppet:///modules/apt/03clean_vserver' ],
......@@ -55,7 +55,7 @@ class apt(
}
}
else {
apt_conf { '03clean':
::apt::apt_conf { '03clean':
source => [ "puppet:///modules/site_apt/${::fqdn}/03clean",
'puppet:///modules/site_apt/03clean',
'puppet:///modules/apt/03clean' ]
......
......@@ -2,9 +2,9 @@ define apt::preferences_snippet (
$priority = undef,
$package = false,
$ensure = 'present',
$source = '',
$release = '',
$pin = ''
$source = undef,
$release = undef,
$pin = undef
) {
$real_package = $package ? {
......@@ -36,9 +36,9 @@ define apt::preferences_snippet (
}
case $source {
'': {
undef: {
case $release {
'': {
undef: {
File["/etc/apt/preferences.d/${name}"]{
content => template('apt/preferences_snippet.erb')
}
......
......@@ -3,7 +3,7 @@ class apt::proxy_client(
$port = '3142',
){
apt_conf { '20proxy':
::apt::apt_conf { '20proxy':
content => template('apt/20proxy.erb'),
}
}
# Configure an apt source
define apt::sources_list (
$ensure = 'present',
$source = '',
$ensure = 'present',
$source = undef,
$content = undef
) {
if $ensure == 'present' {
if $source == '' and $content == undef {
if $source == undef and $content == undef {
fail("One of \$source or \$content must be specified for apt_sources_snippet ${name}")
}
if $source != '' and $content != undef {
if $source != undef and $content != undef {
fail("Only one of \$source or \$content must specified for apt_sources_snippet ${name}")
}
}
......
......@@ -26,7 +26,7 @@ class apt::unattended_upgrades (
default => $config_content
}
apt_conf { '50unattended-upgrades':
::apt::apt_conf { '50unattended-upgrades':
content => $file_content,
require => Package['unattended-upgrades'],
refresh_apt => false
......
require 'spec_helper'
describe 'apt', :type => :class do
let :pre_condition do
'class { "apt": }'
end
let(:facts) { {
:lsbdistid => 'Debian',
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:debian_release => 'jessie',
:debian_codename => 'jessie',
:lsbdistcodename => 'jessie',
:virtual => 'physical',
:puppetversion => Puppet.version, } }
#it { is_expected.to compile.with_all_deps }
it { is_expected.to compile }
end
require 'spec_helper'
describe 'apt::apt_conf', :type => :define do
let :pre_condition do
'class { "apt": }'
end
let(:facts) { {
:lsbdistid => 'Debian',
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:debian_release => 'jessie',
:debian_codename => 'jessie',
:lsbdistcodename => 'jessie',
:virtual => 'physical',
:puppetversion => Puppet.version, } }
let :title do
'norecommends'
end
describe "when creating an apt_conf snippet" do
let :default_params do
{
:ensure => 'present',
:content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
}
end
let :params do
default_params
end
let :filename do
"/etc/apt/apt.conf.d/norecommends"
end
it { is_expected.to contain_file(filename).with({
'ensure' => 'present',
'content' => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/,
'owner' => 'root',
# default to '0', not 'root'
#'group' => 'root',
'mode' => '0644',
})
}
end
describe "when creating a preference without content" do
let :params do
{
:ensure => 'absent',
}
end
it 'fails' do
expect { subject.call } .to raise_error(Puppet::Error, /One of \$source or \$content must be specified for apt_conf norecommends/)
end
end
describe "when removing an apt preference" do
let :params do
{
:ensure => 'absent',
:content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
}
end
let :filename do
"/etc/apt/apt.conf.d/norecommends"
end
it { is_expected.to contain_file(filename).with({
'ensure' => 'absent',
})
}
end
end
require 'spec_helper'
describe 'apt::preferences_snippet', :type => :define do
let :pre_condition do
'class { "apt": }'
end
let(:facts) { {
:lsbdistid => 'Debian',
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:debian_release => 'jessie',
:debian_codename => 'jessie',
:lsbdistcodename => 'jessie',
:virtual => 'physical',
:puppetversion => Puppet.version, } }
let :title do
'test'
end
describe "when creating a preferences_snippet" do
let :default_params do
{
:ensure => 'present',
:release => "jessie-backports",
:priority => '999'
}
end
let :params do
default_params
end
let :filename do
"/etc/apt/preferences.d/test"
end
it { is_expected.to contain_file(filename).with({
'ensure' => 'present',
'content' => /Package: test\nPin: release a=jessie-backports\nPin-Priority: 999/,
'owner' => 'root',
'group' => '0',
'mode' => '0644',
})
}
end
describe "when using both pin and release parameters" do
let :default_params do
{
:ensure => 'present',
:priority => '999',
:release => "jessie-backports",
:pin => '1.0'
}
end
let :params do
default_params
end
let :filename do
"/etc/apt/preferences.d/test"
end
it 'fails' do
expect { subject.call } .to raise_error(Puppet::Error, /apt::preferences_snippet requires either a 'pin' or 'release' argument, not both/)
end
end
end
# https://puppetlabs.com/blog/testing-modules-in-the-puppet-forge
require 'rspec-puppet'
require 'mocha/api'
require 'puppetlabs_spec_helper/module_spec_helper'
RSpec.configure do |c|
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
c.module_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
c.color = true
RSpec.configure do |c|
#Puppet.features.stubs(:root? => true)
c.manifest_dir = File.join(fixture_path, 'manifests')
c.module_path = File.join(fixture_path, 'modules')
c.color = true
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment