Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fact factory, OS and Puppet support and testing improved #3

Merged
merged 6 commits into from
Jan 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
mock_with: ':rspec'
.travis.yml:
docker_defaults:
bundler_args: --with system_tests
docker_sets:
- set: centos-7
- set: debian-8
- set: debian-9
includes:
- env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
rvm: 2.5.1
Gemfile:
required:
':system_tests':
- gem: 'puppet-module-posix-system-r#{minor_version}'
platforms: ruby
- gem: 'puppet-module-win-system-r#{minor_version}'
platforms:
- mswin
- mingw
- x64_mingw
- gem: beaker
version: '~> 3.13'
from_env: BEAKER_VERSION
- gem: beaker-abs
from_env: BEAKER_ABS_VERSION
version: '~> 0.1'
- gem: beaker-pe
- gem: beaker-hostgenerator
from_env: BEAKER_HOSTGENERATOR_VERSION
- gem: beaker-rspec
from_env: BEAKER_RSPEC_VERSION
- gem: 'rspec-json_expectations'
version: '~> 2.1'
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ env:
matrix:
fast_finish: true
include:
-
bundler_args: --with system_tests
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=centos-7 BEAKER_TESTMODE=apply
rvm: 2.5.0
script: bundle exec rake beaker
services: docker
sudo: required
-
bundler_args: --with system_tests
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=debian-8 BEAKER_TESTMODE=apply
rvm: 2.5.0
script: bundle exec rake beaker
services: docker
sudo: required
-
bundler_args: --with system_tests
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=debian-9 BEAKER_TESTMODE=apply
rvm: 2.5.0
script: bundle exec rake beaker
services: docker
sudo: required
-
env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop"
-
Expand All @@ -30,6 +54,9 @@ matrix:
-
env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec
rvm: 2.1.9
-
env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
rvm: 2.5.1
branches:
only:
- master
Expand Down
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ group :development do
gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
end
group :system_tests do
gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby]
gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 3.13')
gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1')
gem "beaker-pe", require: false
gem "beaker-hostgenerator"
gem "beaker-rspec"
gem "rspec-json_expectations", '~> 2.1', require: false
end

puppet_version = ENV['PUPPET_GEM_VERSION']
facter_version = ENV['FACTER_GEM_VERSION']
Expand Down
4 changes: 2 additions & 2 deletions manifests/fact.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# @param value The value of the fact (can include structured facts)
# @param ensure Set to absent to explicitly remove the custom fact - behaves like a normal ensure parameter
define static_custom_facts::fact (
Variant[String, Array, Hash, Numeric, Boolean] $value,
Enum['present', 'absent', 'file'] $ensure = present,
Data $value,
Enum['present', 'absent', 'file'] $ensure = present,
) {
$yaml_value = {
$name => $value,
Expand Down
33 changes: 26 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@
# @example Delcaring the class
# include ::static_custom_facts
#
# @example defining static facts via hiera
# static_custom_facts::custom_facts:
# static1: Hello world
# static2:
# - Hello
# - world
# static3:
# what: Hello
# whom: world
#
# @param parent_dirs Parent directories of facts_path to create
# @param facts_path The location where custom facts will be installed
# @param facts_path_owner The owner of the custom facts directory (not created by this module)
# @param facts_path_group The group that owns the custom facts directory (not created by this module)
# @param purge_unmanaged If facts in the facts_path not managed by puppet are deleted or not
# @param custom_facts A hash of facts that should be created (useful with hiera)
class static_custom_facts(
Array $parent_dirs = $static_custom_facts::params::parent_dirs,
String $facts_path = $static_custom_facts::params::facts_path,
String $facts_path_owner = $static_custom_facts::params::facts_path_owner,
String $facts_path_group = $static_custom_facts::params::facts_path_group,
Boolean $purge_unmanaged = $static_custom_facts::params::purge_unmanaged,
Hash $custom_facts = {},
Array $parent_dirs = $static_custom_facts::params::parent_dirs,
String $facts_path = $static_custom_facts::params::facts_path,
String $facts_path_owner = $static_custom_facts::params::facts_path_owner,
String $facts_path_group = $static_custom_facts::params::facts_path_group,
Boolean $purge_unmanaged = $static_custom_facts::params::purge_unmanaged,
Hash[String,Data] $custom_facts = {},
) inherits static_custom_facts::params {

case $::kernel {
Expand Down Expand Up @@ -53,5 +63,14 @@
}
}

create_resources('static_custom_facts::fact', $custom_facts)
$custom_facts.each |$name, $value| {
$ensure = defined('$value') ? {
true => 'present',
default => 'absent',
}
static_custom_facts::fact { $name:
ensure => $ensure,
value => $value,
}
}
rtib marked this conversation as resolved.
Show resolved Hide resolved
}
9 changes: 8 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
"18.04"
]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"8",
"9"
]
},
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
Expand Down Expand Up @@ -75,7 +82,7 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 4.0.0 < 5.0.0"
"version_requirement": ">= 4.0.0 < 7.0.0"
}
],
"tags": [
Expand Down
13 changes: 13 additions & 0 deletions spec/acceptance/001_basic_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper_acceptance'
require 'rspec/json_expectations'

describe 'static_custom_facts class' do
context 'default parameters' do
Expand All @@ -22,5 +23,17 @@
it { is_expected.to contain('user@example.com') }
it { is_expected.not_to contain('max_procs: !ruby') }
end

describe 'reported facts contain the correct custom values' do
subject(:puppet_facts) { command('puppet facts --render-as JSON') }

its(:stdout) do
is_expected.to include_json(
'values' => {
'responsible_people' => ['user@example.com'],
},
)
end
end
end
end
13 changes: 13 additions & 0 deletions spec/acceptance/nodesets/debian-8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
HOSTS:
debian-8-x64:
platform: debian-8-amd64
hypervisor: docker
image: debian:8
docker_preserve_image: true
docker_cmd: '["/sbin/init"]'
docker_image_commands:
- 'apt-get update && apt-get install -y net-tools wget locales strace lsof'
- 'locale-gen en_US en_US.UTF-8'
CONFIG:
trace_limit: 200
14 changes: 14 additions & 0 deletions spec/acceptance/nodesets/debian-9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
HOSTS:
debian-9-x64:
platform: debian-9-amd64
hypervisor: docker
image: debian:9
docker_preserve_image: true
docker_cmd: '["/sbin/init"]'
docker_image_commands:
- 'apt-get update && apt-get install -y cron locales-all net-tools wget systemd-sysv git'
- 'systemctl mask getty@tty1.service getty-static.service'
CONFIG:
trace_limit: 200
masterless: true
25 changes: 25 additions & 0 deletions spec/classes/static_custom_facts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
require 'spec_helper'

describe 'static_custom_facts', type: :class do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

context 'defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('static_custom_facts') }
it { is_expected.to contain_class('static_custom_facts::params') }
it do
is_expected.to contain_file('facts-directory').with(
ensure: 'directory',
)
end
end
end
end

context 'On a Linux system' do
let :facts do
{
Expand Down Expand Up @@ -34,6 +51,14 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('static_custom_facts') }
it { is_expected.to contain_class('static_custom_facts::params') }
it do
is_expected.to contain_file('/etc/puppetlabs/facter').with(
ensure: 'directory',
path: '/etc/puppetlabs/facter',
owner: 'root',
group: 'wheel',
)
end
it do
is_expected.to contain_file('facts-directory').with(
ensure: 'directory',
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
RSpec.configure do |c|
c.mock_with :rspec
end

require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'

Expand Down