Commit 0b8b6f5b authored by Tim Meusel's avatar Tim Meusel Committed by GitHub

Merge pull request #875 from bastelfreak/manual_fixes

partial modulsync 1.9.2
parents bcf8ea2e 38df8f2a
......@@ -2,41 +2,28 @@
#
# A helper script for creating resources via the Jenkins cli
#
# Parameters:
#
# ssh_keyfile = undef
# Defaults to the value of $::jenkins::cli_ssh_keyfile. This parameter is
# deprecated, please set $::jenkins::cli_ssh_keyfile instead of setting this
# directly
#
class jenkins::cli_helper (
Optional[Stdlib::Absolutepath] $ssh_keyfile = $::jenkins::cli_ssh_keyfile,
) {
include ::jenkins
include ::jenkins::cli
class jenkins::cli_helper {
include jenkins
include jenkins::cli
Class['jenkins::cli']
-> Class['jenkins::cli_helper']
-> Anchor['jenkins::end']
-> Class['jenkins::cli_helper']
-> Anchor['jenkins::end']
$libdir = $::jenkins::libdir
$cli_jar = $::jenkins::cli::jar
$libdir = $jenkins::libdir
$cli_jar = $jenkins::cli::jar
$port = jenkins_port()
$prefix = jenkins_prefix()
$helper_groovy = "${libdir}/puppet_helper.groovy"
file { $helper_groovy:
source => 'puppet:///modules/jenkins/puppet_helper.groovy',
owner => $::jenkins::user,
group => $::jenkins::group,
owner => $jenkins::user,
group => $jenkins::group,
mode => '0444',
require => Class['jenkins::cli'],
}
if $ssh_keyfile != $::jenkins::cli_ssh_keyfile {
info("Using jenkins::cli_helper(${ssh_keyfile}) is deprecated and will be removed in the next major version of this module")
}
$helper_cmd = join(
delete_undef_values([
'/bin/cat',
......
require 'spec_helper'
describe 'jenkins::cli::config', type: :class do
shared_examples 'validate_absolute_path' do |param|
context 'absolute path' do
let(:params) { { param => '/dne' } }
it { is_expected.not_to raise_error }
end
end # validate_absolute_path
on_supported_os.each do |os, facts|
context "on #{os} " do
systemd_fact = case facts[:os]['family']
when 'Archlinux', 'Fedora'
{ systemd: true }
when 'Debian'
case facts[:os]['release']['major']
when '16.04', '18.04'
{ systemd: true }
when '8', '9'
{ systemd: true }
else
{ systemd: false }
end
when 'RedHat'
case facts[:os]['release']['major']
when '7'
{ systemd: true }
else
{ systemd: false }
end
else
{ systemd: false }
end
let :facts do
facts.merge(systemd_fact)
end
shared_examples 'validate_integer' do |param|
context 'integer' do
let(:params) { { param => 42 } }
shared_examples 'validate_absolute_path' do |param|
context 'absolute path' do
let(:params) { { param => '/dne' } }
it { is_expected.not_to raise_error }
end
end # validate_integer
it { is_expected.not_to raise_error }
end
end # validate_absolute_path
shared_examples 'validate_numeric' do |param|
context 'integer' do
let(:params) { { param => 42 } }
shared_examples 'validate_integer' do |param|
context 'integer' do
let(:params) { { param => 42 } }
it { is_expected.not_to raise_error }
end
it { is_expected.not_to raise_error }
end
end # validate_integer
context 'float' do
let(:params) { { param => 42.12345 } }
shared_examples 'validate_numeric' do |param|
context 'integer' do
let(:params) { { param => 42 } }
it { is_expected.not_to raise_error }
end
end # validate_numeric
it { is_expected.not_to raise_error }
end
shared_examples 'validate_string' do |param|
context 'string' do
let(:params) { { param => 'foo' } }
context 'float' do
let(:params) { { param => 42.12345 } }
it { is_expected.not_to raise_error }
end
end # validate_string
it { is_expected.not_to raise_error }
end
end # validate_numeric
describe 'parameters' do
context 'accept all params undef' do
it { is_expected.not_to raise_error }
end
shared_examples 'validate_string' do |param|
context 'string' do
let(:params) { { param => 'foo' } }
describe 'cli_jar' do
it_behaves_like 'validate_absolute_path', :cli_jar
end
it { is_expected.not_to raise_error }
end
end # validate_string
# context 'port' do
# it_behaves_like 'validate_integer', :port
# end
context 'url' do
it_behaves_like 'validate_string', :url
end
describe 'parameters' do
context 'accept all params undef' do
it { is_expected.not_to raise_error }
end
context 'ssh_private_key' do
it_behaves_like 'validate_absolute_path', :ssh_private_key
end
describe 'cli_jar' do
it_behaves_like 'validate_absolute_path', :cli_jar
end
context 'puppet_helper' do
it_behaves_like 'validate_absolute_path', :puppet_helper
end
# context 'port' do
# it_behaves_like 'validate_integer', :port
# end
context 'url' do
it_behaves_like 'validate_string', :url
end
context 'cli_tries' do
it_behaves_like 'validate_integer', :cli_tries
end
context 'ssh_private_key' do
it_behaves_like 'validate_absolute_path', :ssh_private_key
end
context 'cli_try_sleep' do
it_behaves_like 'validate_numeric', :cli_try_sleep
end
context 'puppet_helper' do
it_behaves_like 'validate_absolute_path', :puppet_helper
end
context 'ssh_private_key_content' do
it_behaves_like 'validate_string', :ssh_private_key_content
context 'cli_tries' do
it_behaves_like 'validate_integer', :cli_tries
end
context 'when ssh_private_key is also set' do
let(:params) do
{
ssh_private_key: '/dne',
ssh_private_key_content: 'foo'
}
context 'cli_try_sleep' do
it_behaves_like 'validate_numeric', :cli_try_sleep
end
context 'as non-root user' do
let(:facts) { { id: 'user' } }
it do
is_expected.to contain_file('/dne').with(
ensure: 'file',
mode: '0400',
backup: false,
owner: nil,
group: nil
)
context 'ssh_private_key_content' do
it_behaves_like 'validate_string', :ssh_private_key_content
context 'when ssh_private_key is also set' do
let(:params) do
{
ssh_private_key: '/dne',
ssh_private_key_content: 'foo'
}
end
context 'as non-root user' do
let :facts do
super().merge(id: 'user')
end
it do
is_expected.to contain_file('/dne').with(
ensure: 'file',
mode: '0400',
backup: false,
owner: nil,
group: nil
)
end
it { is_expected.to contain_file('/dne').with_content('foo') }
end # as non-root user
context 'as root' do
let :facts do
super().merge(id: 'root')
end
it do
is_expected.to contain_file('/dne').with(
ensure: 'file',
mode: '0400',
backup: false,
owner: 'jenkins',
group: 'jenkins'
)
end
it { is_expected.to contain_file('/dne').with_content('foo') }
end # as root
end # when ssh_private_key is also set
end # ssh_private_key_content
end # parameters
describe 'package gem provider' do
context 'is_pe fact' do
context 'true' do
let :facts do
super().merge(is_pe: true)
end
it { is_expected.to contain_package('retries').with(provider: 'pe_gem') }
end
it { is_expected.to contain_file('/dne').with_content('foo') }
end # as non-root user
context 'as root' do
let(:facts) { { id: 'root' } }
it do
is_expected.to contain_file('/dne').with(
ensure: 'file',
mode: '0400',
backup: false,
owner: 'jenkins',
group: 'jenkins'
)
end
it { is_expected.to contain_file('/dne').with_content('foo') }
end # as root
end # when ssh_private_key is also set
end # ssh_private_key_content
end # parameters
describe 'package gem provider' do
context 'is_pe fact' do
context 'true' do
let(:facts) { { is_pe: true } }
it { is_expected.to contain_package('retries').with(provider: 'pe_gem') }
end
context 'false' do
let(:facts) { { is_pe: false } }
it { is_expected.to contain_package('retries').with(provider: 'gem') }
end
end # 'is_pe fact' do
context 'puppetversion facts' do
context '=> 3.8.4' do
let(:facts) { { puppetversion: '3.8.4' } }
context 'false' do
let :facts do
super().merge(is_pe: false)
end
it { is_expected.to contain_package('retries').with(provider: 'gem') }
end
context '=> 4.0.0' do
let(:facts) { { puppetversion: '4.0.0' } }
it { is_expected.to contain_package('retries').with(provider: 'gem') }
end
end # 'is_pe fact' do
it { is_expected.to contain_package('retries').with(provider: 'gem') }
context 'puppetversion facts' do
context '=> 3.8.4' do
let :facts do
super().merge(puppetversion: '3.8.4')
end
context 'rubysitedir fact' do
context '=> /foo/bar' do
before { facts[:rubysitedir] = '/foo/bar' }
it { is_expected.to contain_package('retries').with(provider: 'gem') }
end
context '=> /opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0' do
before { facts[:rubysitedir] = '/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0' }
it { is_expected.to contain_package('retries').with(provider: 'puppet_gem') }
context '=> 4.0.0' do
let :facts do
super().merge(puppetversion: '4.0.0')
end
it { is_expected.to contain_package('retries').with(provider: 'gem') }
end
end
end
end # 'puppetversion facts' do
end # 'package gem provider' do
end # 'puppetversion facts' do
end # 'package gem provider' do
end
end
end
......@@ -29,14 +29,4 @@ describe 'jenkins::cli_helper', type: :class do
mode: '0444'
)
end
context 'should accept the ssh_keyfile parameter' do
let(:params) do
{
ssh_keyfile: '/tmp/rspec'
}
end
it { is_expected.to contain_class 'jenkins::cli_helper' }
end
end
require 'spec_helper'
describe 'jenkins', type: :class do
# Switching OS Family to prevent duplicate declaration
let(:facts) do
{
osfamily: 'Redhat',
operatingsystem: 'CentOS',
operatingsystemrelease: '6.7',
operatingsystemmajrelease: '6'
}
end
context 'repo::el' do
describe 'default' do
it { is_expected.to contain_yumrepo('jenkins').with_baseurl('https://pkg.jenkins.io/redhat-stable/') }
it { is_expected.to contain_yumrepo('jenkins').with_proxy(nil) }
end
describe 'lts = true' do
let(:params) { { lts: true } }
it { is_expected.to contain_yumrepo('jenkins').with_baseurl('https://pkg.jenkins.io/redhat-stable/') }
it { is_expected.to contain_yumrepo('jenkins').with_proxy(nil) }
end
describe 'lts = false' do
let(:params) { { lts: false } }
it { is_expected.to contain_yumrepo('jenkins').with_proxy(nil) }
it { is_expected.to contain_yumrepo('jenkins').with_baseurl('https://pkg.jenkins.io/redhat/') }
end
describe 'repo_proxy is set' do
let(:params) { { repo_proxy: 'http://proxy:8080/' } }
it { is_expected.to contain_yumrepo('jenkins').with_proxy('http://proxy:8080/') }
on_supported_os.each do |os, facts|
next unless facts[:os]['family'] == 'RedHat'
context "on #{os} " do
systemd_fact = case facts[:operatingsystemmajrelease]
when '6'
{ systemd: false }
else
{ systemd: true }
end
let :facts do
facts.merge(systemd_fact)
end
context 'repo::el' do
describe 'default' do
it { is_expected.to contain_yumrepo('jenkins').with_baseurl('https://pkg.jenkins.io/redhat-stable/') }
it { is_expected.to contain_yumrepo('jenkins').with_proxy(nil) }
end
describe 'lts = true' do
let(:params) { { lts: true } }
it { is_expected.to contain_yumrepo('jenkins').with_baseurl('https://pkg.jenkins.io/redhat-stable/') }
it { is_expected.to contain_yumrepo('jenkins').with_proxy(nil) }
end
describe 'lts = false' do
let(:params) { { lts: false } }
it { is_expected.to contain_yumrepo('jenkins').with_proxy(nil) }
it { is_expected.to contain_yumrepo('jenkins').with_baseurl('https://pkg.jenkins.io/redhat/') }
end
describe 'repo_proxy is set' do
let(:params) { { repo_proxy: 'http://proxy:8080/' } }
it { is_expected.to contain_yumrepo('jenkins').with_proxy('http://proxy:8080/') }
end
end
end
end
end
require 'spec_helper'
describe 'jenkins', type: :class do
let(:facts) do
{
osfamily: 'RedHat',
operatingsystem: 'RedHat',
operatingsystemrelease: '6.7',
operatingsystemmajrelease: '6'
}
end
context 'service' do
context 'default' do
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true
)
end
end
on_supported_os.each do |os, facts|
next unless facts[:os]['family'] == 'RedHat'
context 'EL 7' do
let(:facts) do
super().merge(
operatingsystemrelease: '7.1.1503',
operatingsystemmajrelease: '7',
systemd: true
)
context "on #{os} " do
systemd_fact = case facts[:operatingsystemmajrelease]
when '6'
{ systemd: false }
else
{ systemd: true }
end
let :facts do
facts.merge(systemd_fact)
end
let(:service_file) { '/etc/systemd/system/jenkins.service' }
let(:startup_script) { '/usr/lib/jenkins/jenkins-run' }
let(:sysv_file) { '/etc/init.d/jenkins' }
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true,
provider: 'systemd'
)
end
it do
is_expected.to contain_file(startup_script).
that_notifies('Service[jenkins]')
end
# XXX the prior_to args check fails under puppet 3.8.7 for unknown
# reasons...
if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0
it do
is_expected.to contain_transition('stop jenkins service').with(
prior_to: ["File[#{sysv_file}]"]
)
context 'service' do
context 'default' do
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true
)
end
end
else
it { is_expected.to contain_transition('stop jenkins service') }
end
it do
is_expected.to contain_file(sysv_file).
with(
ensure: 'absent',
selinux_ignore_defaults: true
).
that_comes_before('Systemd::Unit_file[jenkins.service]')
end
it do
is_expected.to contain_systemd__unit_file('jenkins.service').
that_notifies('Service[jenkins]')
end
end
context 'EL 6' do
let(:facts) do
super().merge(
operatingsystemrelease: '6.6',
operatingsystemmajrelease: '6',
systemd: false
)
end
case facts[:os]['release']['major']
when '7'
context 'EL 7' do
let(:service_file) { '/etc/systemd/system/jenkins.service' }
let(:startup_script) { '/usr/lib/jenkins/jenkins-run' }
let(:sysv_file) { '/etc/init.d/jenkins' }
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true,
provider: nil
)
end
end
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true,
provider: 'systemd'
)
end
context 'managing service' do
let(:params) { { service_ensure: 'stopped', service_enable: false } }
it do
is_expected.to contain_file(startup_script).
that_notifies('Service[jenkins]')
end
# XXX the prior_to args check fails under puppet 3.8.7 for unknown
# reasons...
if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0
it do
is_expected.to contain_transition('stop jenkins service').with(
prior_to: ["File[#{sysv_file}]"]
)
end
else
it { is_expected.to contain_transition('stop jenkins service') }
end
it do
is_expected.to contain_file(sysv_file).
with(
ensure: 'absent',
selinux_ignore_defaults: true
).
that_comes_before('Systemd::Unit_file[jenkins.service]')
end
it do
is_expected.to contain_systemd__unit_file('jenkins.service').
that_notifies('Service[jenkins]')
end
end
when '6'
context 'EL 6' do
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true
)
end
end
it do
is_expected.to contain_service('jenkins').with(
ensure: 'stopped',
enable: false,
provider: nil
)
context 'managing service' do
let(:params) { { service_ensure: 'stopped', service_enable: false } }
it do
is_expected.to contain_service('jenkins').with(
ensure: 'stopped',
enable: false
)
end
end
end
end
end
end
......
This diff is collapsed.
This diff is collapsed.
......@@ -303,7 +303,7 @@ describe 'jenkins::plugin' do
EOS
end
it { is_expected.to contain_file("#{pdir}/#{title}").only_with(ensure: nil) }
it { is_expected.to contain_file("#{pdir}/#{title}") }
end
context 'false' do
......
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