Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request voxpupuli#875 from bastelfreak/manual_fixes
Browse files Browse the repository at this point in the history
partial modulsync 1.9.2
  • Loading branch information
bastelfreak authored Jun 22, 2018
2 parents bcf8ea2 + 38df8f2 commit 0b8b6f5
Show file tree
Hide file tree
Showing 8 changed files with 796 additions and 792 deletions.
31 changes: 9 additions & 22 deletions manifests/cli_helper.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
284 changes: 157 additions & 127 deletions spec/classes/cli/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,159 +1,189 @@
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
10 changes: 0 additions & 10 deletions spec/classes/jenkins_cli_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,4 @@
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
Loading

0 comments on commit 0b8b6f5

Please sign in to comment.