Skip to content

Commit

Permalink
install.pp: Make class private
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jul 29, 2023
1 parent 74b59d7 commit 2862070
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 130 deletions.
80 changes: 1 addition & 79 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#### Public Classes

* [`r10k`](#r10k): This class configures r10k
* [`r10k::install`](#r10k--install): This class is used by the ruby or pe_ruby class
* [`r10k::install::bundle`](#r10k--install--bundle): This class installs the r10k bundle
* [`r10k::install::gem`](#r10k--install--gem): Install the r10k gem using system ruby
* [`r10k::install::puppet_gem`](#r10k--install--puppet_gem): This class links the r10k binary for Puppet FOSS 4.2 and up
Expand All @@ -26,6 +25,7 @@
#### Private Classes

* `r10k::config`: Set up the root r10k config file (/etc/r10k.yaml).
* `r10k::install`: This class is used by the ruby or pe_ruby class

### Data types

Expand Down Expand Up @@ -311,84 +311,6 @@ Data type: `Stdlib::Absolutepath`

Default value: `$r10k::params::puppetconf_path`

### <a name="r10k--install"></a>`r10k::install`

This class is used by the ruby or pe_ruby class

#### Parameters

The following parameters are available in the `r10k::install` class:

* [`package_name`](#-r10k--install--package_name)
* [`version`](#-r10k--install--version)
* [`provider`](#-r10k--install--provider)
* [`keywords`](#-r10k--install--keywords)
* [`install_options`](#-r10k--install--install_options)
* [`manage_ruby_dependency`](#-r10k--install--manage_ruby_dependency)
* [`puppet_master`](#-r10k--install--puppet_master)
* [`is_pe_server`](#-r10k--install--is_pe_server)
* [`gem_source`](#-r10k--install--gem_source)

##### <a name="-r10k--install--package_name"></a>`package_name`

Data type: `Any`



##### <a name="-r10k--install--version"></a>`version`

Data type: `Any`



##### <a name="-r10k--install--provider"></a>`provider`

Data type: `Any`



##### <a name="-r10k--install--keywords"></a>`keywords`

Data type: `Any`



##### <a name="-r10k--install--install_options"></a>`install_options`

Data type: `Any`



##### <a name="-r10k--install--manage_ruby_dependency"></a>`manage_ruby_dependency`

Data type: `Any`



##### <a name="-r10k--install--puppet_master"></a>`puppet_master`

Data type: `Any`



Default value: `true`

##### <a name="-r10k--install--is_pe_server"></a>`is_pe_server`

Data type: `Any`



Default value: `$r10k::params::is_pe_server`

##### <a name="-r10k--install--gem_source"></a>`gem_source`

Data type: `Optional[String[1]]`



Default value: `undef`

### <a name="r10k--install--bundle"></a>`r10k::install::bundle`

This class installs the r10k bundle
Expand Down
12 changes: 1 addition & 11 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,7 @@
include r10k::postrun_command
}

class { 'r10k::install':
install_options => $install_options,
keywords => $gentoo_keywords,
manage_ruby_dependency => $manage_ruby_dependency,
package_name => $package_name,
provider => $provider,
gem_source => $gem_source,
version => $version,
puppet_master => $puppet_master,
}

contain r10k::install
contain r10k::config

if $mcollective {
Expand Down
57 changes: 19 additions & 38 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
# This class is used by the ruby or pe_ruby class
class r10k::install (
$package_name,
$version,
$provider,
$keywords,
$install_options,
$manage_ruby_dependency,
$puppet_master = true,
$is_pe_server = $r10k::params::is_pe_server,
Optional[String[1]] $gem_source = undef,
) inherits r10k::params {
if $package_name == '' {
case $provider {
'openbsd': {
if (versioncmp("${facts['kernelversion']}", '5.8') < 0) { #lint:ignore:only_variable_string
$real_package_name = 'ruby21-r10k'
} else {
$real_package_name = 'ruby22-r10k'
}
}
default: { $real_package_name = 'r10k' }
}
} else {
$real_package_name = $package_name
}
#
# @summary This class is used by the ruby or pe_ruby class
#
# @api private
#
class r10k::install {
assert_private()

case $provider {
case $r10k::provider {
'bundle': {
include r10k::install::bundle
}
'puppet_gem', 'gem', 'openbsd', 'pkgng', 'pacman', 'portage': {
if $provider == 'gem' {
if $r10k::provider == 'gem' {
class { 'r10k::install::gem':
manage_ruby_dependency => $manage_ruby_dependency,
version => $version;
manage_ruby_dependency => $r10k::manage_ruby_dependency,
version => $r10k::version;
}
}
elsif $provider == 'puppet_gem' {
elsif $r10k::provider == 'puppet_gem' {
# Puppet FOSS 4.2 and up ships a vendor provided ruby.
# Using puppet_gem uses that instead of the system ruby.
include r10k::install::puppet_gem
Expand All @@ -47,21 +28,21 @@
# empty to value to the gem providers This code
# converts an empty array to semi-standard gem options
# This was previously undef but that caused strict var issues
if $provider in ['puppet_gem', 'gem'] and $install_options == [] {
if $r10k::provider in ['puppet_gem', 'gem'] and $r10k::install_options == [] {
$provider_install_options = ['--no-document']
} else {
$provider_install_options = $install_options
$provider_install_options = $r10k::install_options
}

# Puppet Enterprise 3.8 and ships an embedded r10k so thats all thats supported
# This conditional should not effect FOSS customers based on the fact
package { $real_package_name:
ensure => $version,
provider => $provider,
source => $gem_source,
package { $r10k::package_name:
ensure => $r10k::version,
provider => $r10k::provider,
source => $r10k::gem_source,
install_options => $provider_install_options,
}
}
default: { fail("${module_name}: ${provider} is not supported. Valid values are: 'gem', 'puppet_gem', 'bundle', 'openbsd'") }
default: { fail("${module_name}: ${r10k::provider} is not supported. Valid values are: 'gem', 'puppet_gem', 'bundle', 'openbsd'") }
}
}
6 changes: 4 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Reasonable defaults for all classes
class r10k::params {
$postrun = undef
$package_name = ''
$package_name = $facts['os']['name'] ? {
'OpenBSD' => 'ruby31-r10k',
default => 'r10k'
}
$version = 'installed'
$manage_modulepath = false
$manage_ruby_dependency = 'ignore'
Expand Down
150 changes: 150 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require 'spec_helper'

version = '2.0.0'

describe 'r10k' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
Expand Down Expand Up @@ -156,6 +159,153 @@

it { is_expected.to contain_file('r10k.yaml').with_content(%r{^pool_size: 5$}) }
end
# This install method uses the archived puppetlabs/ruby module
# It doesn't support Gentoo

context 'with gem provider', if: os_facts[:os]['name'] != 'Gentoo' do
let :params do
{
install_options: '',
manage_ruby_dependency: 'declare',
provider: 'gem',
version: version,
puppet_master: true
}
end

it { is_expected.to contain_class('r10k::install::gem').with(version: version) }

it do
expect(subject).to contain_package('r10k').with(
ensure: version,
provider: 'gem'
)
end
end

context 'with gem with empty install_options', if: os_facts[:os]['name'] != 'Gentoo' do
let :params do
{
manage_ruby_dependency: 'include',
provider: 'gem',
version: version,
install_options: [],
puppet_master: true
}
end

it do
expect(subject).to contain_package('r10k').with(
ensure: version,
provider: 'gem',
install_options: ['--no-document']
)
end
end

context 'with gem with populated install_options', if: os_facts[:os]['name'] != 'Gentoo' do
let :params do
{
manage_ruby_dependency: 'include',
provider: 'gem',
version: version,
install_options: ['BOGON'],
puppet_master: true
}
end

it do
expect(subject).to contain_package('r10k').with(
ensure: version,
provider: 'gem',
install_options: ['BOGON']
)
end
end

context 'with puppet_gem provider' do
let :params do
{
version: version,
provider: 'puppet_gem',
manage_ruby_dependency: 'declare',
install_options: ''
}
end

it { is_expected.to contain_class('r10k::install::puppet_gem') }

it do
expect(subject).to contain_package('r10k').with(
ensure: version,
provider: 'puppet_gem'
)
end
end

context 'with puppet_gem on Puppet FOSS' do
let :params do
{
manage_ruby_dependency: 'declare',
install_options: '',
provider: 'puppet_gem',
version: version,
}
end

it {
is_expected.to contain_package('r10k').with(
ensure: version,
provider: 'puppet_gem'
)
}

it do
expect(subject).to contain_file('/usr/bin/r10k').with(
ensure: 'link',
target: '/opt/puppetlabs/puppet/bin/r10k',
require: 'Package[r10k]'
)
end
end

context 'with defaults and source specified', if: os_facts[:os]['name'] != 'Gentoo' do
let :params do
{
manage_ruby_dependency: 'include',
provider: 'gem',
version: version,
gem_source: 'https://some.alternate.source.com/',
install_options: [],
puppet_master: true
}
end

it { is_expected.to contain_class('r10k::install::gem') }

it do
expect(subject).to contain_package('r10k').with(
ensure: version,
provider: 'gem',
source: 'https://some.alternate.source.com/'
)
end
end

context 'with bundle provider' do
let :params do
{
version: version,
provider: 'bundle',
manage_ruby_dependency: 'declare',
install_options: '',
puppet_master: true
}
end

it { is_expected.to contain_class('r10k::install::bundle') }
it { is_expected.not_to contain_package('r10k') }
end
end
end
end

0 comments on commit 2862070

Please sign in to comment.