From 26e4c303fd7bd6c61db469cbc63616e82a6f425b Mon Sep 17 00:00:00 2001 From: Nick Miller Date: Thu, 27 Oct 2016 17:46:10 -0400 Subject: [PATCH] (SIMP-1839) Add journald module In order to get the systemd journal to pass to rsyslog, it needs to be configured to pass to syslog. Default is to not. - SIMPed module - Wrote more spec tests - Added a few config options to the defaults - Added details to metadata.json - Added CentOS as a supported OS - Fixed lint errors SIMP-1839 #comment added journald module Change-Id: I30ab02a6f6f7d9a359186bee74bb1dc17c082905 --- .fixtures.yml | 2 +- .gitignore | 23 +++-- .puppet-lint.rc | 4 + .rspec | 3 + .travis.yml | 43 +++++++-- CHANGELOG | 7 ++ CONTRIBUTING.md | 92 ++++++++++++++++++++ Gemfile | 59 ++++++++----- LICENSE | 16 +++- README.md | 6 +- Rakefile | 23 +---- manifests/config.pp | 7 +- manifests/init.pp | 15 ++-- manifests/params.pp | 7 +- manifests/service.pp | 3 +- metadata.json | 31 +++++-- spec/classes/config_spec.rb | 111 ++++++++++++++++++++++++ spec/classes/init_spec.rb | 18 +++- spec/classes/service_spec.rb | 22 +++++ spec/spec_helper.rb | 153 +++++++++++++++++++++++++++++++++ spec/spec_helper_acceptance.rb | 49 +++++++++++ templates/journald.conf.erb | 6 +- 22 files changed, 612 insertions(+), 88 deletions(-) create mode 100644 .puppet-lint.rc create mode 100644 .rspec create mode 100644 CHANGELOG create mode 100644 CONTRIBUTING.md create mode 100644 spec/classes/config_spec.rb create mode 100644 spec/classes/service_spec.rb create mode 100644 spec/spec_helper_acceptance.rb diff --git a/.fixtures.yml b/.fixtures.yml index d8db45e..fec3aa6 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,6 +1,6 @@ fixtures: repositories: - stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" + stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" symlinks: journald: "#{source_dir}" diff --git a/.gitignore b/.gitignore index f217231..5bf726d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,15 @@ -*.log -*~ -.DS_Store -spec/fixtures/* -*.tmp -.librarian -pkg/* - +.*.sw? +.yardoc +dist +/pkg +/spec/fixtures +/spec/rp_env +!/spec/hieradata/default.yaml +!/spec/fixtures/site.pp +/.rspec_system +/.vagrant +/.bundle +/Gemfile.lock +/vendor +/junit +/log diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..e2ea6e8 --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,4 @@ +--log-format="%{path}:%{line}:%{check}:%{KIND}:%{message}" +--relative +--no-class_inherits_from_params_class-check +--no-80chars-check diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4cd92bf --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--fail-fast diff --git a/.travis.yml b/.travis.yml index bd7bede..ecebd43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,40 @@ +# PE/SIMP versions +# app pup ruby +# 2015.2 4.3 2.1.7 +# 2015.3 4.3 2.1.8 +# 2016.1 4.4 2.1.9 +# 2016.2 4.5 2.1.9 +# S6.0.0 4.7 2.1.9 --- -script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" +language: ruby +sudo: true +cache: bundler +before_script: + - bundle +bundler_args: --without development system_tests +before_install: rm Gemfile.lock || true +script: + - bundle exec rake test +notifications: + email: false rvm: - - 1.8.7 - - 1.9.3 - - 2.0.0 + - 2.1.9 env: - - PUPPET_VERSION=3.8 -sudo: false + global: + - STRICT_VARIABLES=yes + - TRUSTED_NODE_DATA=yes + matrix: + - PUPPET_VERSION="~> 4.7.0" + - PUPPET_VERSION="~> 4.5.0" + - PUPPET_VERSION="~> 3.8.0" + - PUPPET_VERSION="~> 4.4.0" + - PUPPET_VERSION="~> 4.3.0" + - PUPPET_VERSION="~> 3.8.0" FUTURE_PARSER=yes +matrix: + fast_finish: true + allow_failures: + - env: PUPPET_VERSION="~> 4.5.0" + - env: PUPPET_VERSION="~> 3.8.0" + - env: PUPPET_VERSION="~> 4.4.0" + - env: PUPPET_VERSION="~> 4.3.0" +- env: PUPPET_VERSION="~> 3.8.0" FUTURE_PARSER=yes diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..5e228ed --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,7 @@ +* Thu Nov 03 2016 Nick Miller - 0.2.2-0 +- SIMPed module +- Wrote more spec tests +- Added a few config options to the defaults +- Added details to metadata.json +- Added CentOS as a supported OS +- Fixed lint errors diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..36d07a8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,92 @@ +This module has grown over time based on a range of contributions from +people using it. If you follow these contributing guidelines your patch +will likely make it into a release a little quicker. + + +## Contributing + +1. Fork the repo. + +2. Run the tests. We only take pull requests with passing tests, and + it's great to know that you have a clean slate. + +3. Add a test for your change. Only refactoring and documentation + changes require no new tests. If you are adding functionality + or fixing a bug, please add a test. + +4. Make the test pass. + +5. Push to your fork and submit a pull request. + + +## Dependencies + +The testing and development tools have a bunch of dependencies, +all managed by [Bundler](http://bundler.io/) according to the +[Puppet support matrix](http://docs.puppetlabs.com/guides/platforms.html#ruby-versions). + +By default the tests use a baseline version of Puppet. + +If you have Ruby 2.x or want a specific version of Puppet, +you must set an environment variable such as: + + export PUPPET_VERSION="~> 3.2.0" + +Install the dependencies like so... + + bundle install + +## Syntax and style + +The test suite will run [Puppet Lint](http://puppet-lint.com/) and +[Puppet Syntax](https://github.com/gds-operations/puppet-syntax) to +check various syntax and style things. You can run these locally with: + + bundle exec rake lint + bundle exec rake syntax + +## Running the unit tests + +The unit test suite covers most of the code, as mentioned above please +add tests if you're adding new functionality. If you've not used +[rspec-puppet](http://rspec-puppet.com/) before then feel free to ask +about how best to test your new feature. Running the test suite is done +with: + + bundle exec rake spec + +Note also you can run the syntax, style and unit tests in one go with: + + bundle exec rake test + +### Automatically run the tests + +During development of your puppet module you might want to run your unit +tests a couple of times. You can use the following command to automate +running the unit tests on every change made in the manifests folder. + + bundle exec guard + +## Integration tests + +The unit tests just check the code runs, not that it does exactly what +we want on a real machine. For that we're using +[Beaker](https://github.com/puppetlabs/beaker). + +Beaker fires up a new virtual machine (using Vagrant) and runs a series of +simple tests against it after applying the module. You can run our +Beaker tests with: + + bundle exec rake acceptance + +This will use the host described in `spec/acceptance/nodeset/default.yml` +by default. To run against another host, set the `BEAKER_set` environment +variable to the name of a host described by a `.yml` file in the +`nodeset` directory. For example, to run against CentOS 6.4: + + BEAKER_set=centos-64-x64 bundle exec rake acceptance + +If you don't want to have to recreate the virtual machine every time you +can use `BEAKER_destroy=no` and `BEAKER_provision=no`. On the first run you will +at least need `BEAKER_provision` set to yes (the default). The Vagrantfile +for the created virtual machines will be in `.vagrant/beaker_vagrant_files`. diff --git a/Gemfile b/Gemfile index 818dbcc..4a7a6a2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,22 +1,39 @@ -source ENV['GEM_SOURCE'] || "https://rubygems.org" +# ------------------------------------------------------------------------------ +# NOTE: SIMP Puppet rake tasks support ruby 2.0 and ruby 2.1 +# ------------------------------------------------------------------------------ +gem_sources = ENV.key?('SIMP_GEM_SERVERS') ? ENV['SIMP_GEM_SERVERS'].split(/[, ]+/) : ['https://rubygems.org'] -gem 'puppet', ENV.key?('PUPPET_VERSION') ? "~> #{ENV['PUPPET_VERSION']}" : "~> 3.0" -gem 'rake', '~> 10' -gem 'rspec-puppet', '~> 2.0' -gem 'puppetlabs_spec_helper', '>= 0.8.0' -gem 'puppet-lint', '>= 1' -gem 'puppet-lint-unquoted_string-check' -gem 'puppet-lint-empty_string-check' -gem 'puppet-lint-spaceship_operator_without_tag-check' -gem 'puppet-lint-absolute_classname-check' -gem 'puppet-lint-undef_in_function-check' -gem 'puppet-lint-leading_zero-check' -gem 'puppet-lint-trailing_comma-check' -gem 'puppet-lint-file_ensure-check' -gem 'puppet-lint-variable_contains_upcase' -gem 'simplecov' -gem 'rspec-puppet-facts' -gem 'metadata-json-lint' -gem 'rspec', '< 3.2.0', {"platforms"=>["ruby_18"]} -gem 'json', '< 2.0', {"platforms"=>["ruby_18"]} -gem 'json_pure', '< 2.0', {"platforms"=>["ruby_18"]} +gem_sources.each { |gem_source| source gem_source } + +group :test do + gem "rake" + gem 'puppet', ENV.fetch('PUPPET_VERSION', '~>4') + gem "rspec", '< 3.2.0' + gem "rspec-puppet" + gem "hiera-puppet-helper" + gem "puppetlabs_spec_helper" + gem "metadata-json-lint" + gem "simp-rspec-puppet-facts", ENV.fetch('SIMP_RSPEC_PUPPET_FACTS_VERSION', '~> 1.3') + gem 'simp-rake-helpers', ENV.fetch('SIMP_RAKE_HELPERS_VERSION', '~> 3') +end + +group :development do + gem "travis" + gem "travis-lint" + gem "travish" + gem "puppet-blacksmith" + gem "guard-rake" + gem 'pry' + gem 'pry-doc' + gem 'puppet-strings' + + # `listen` is a dependency of `guard` + # from `listen` 3.1+, `ruby_dep` requires Ruby version >= 2.2.3, ~> 2.2 + gem 'listen', '~> 3.0.6' +end + +group :system_tests do + gem 'beaker', :git => 'https://github.com/trevor-vaughan/beaker', :ref => 'BKR-931-2.51.0' + gem 'beaker-rspec' + gem 'simp-beaker-helpers', ENV.fetch('SIMP_BEAKER_HELPERS_VERSION', '~> 1.5') +end diff --git a/LICENSE b/LICENSE index 5690f37..fe520e4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,18 @@ -Copyright (C) 2014 R. Tyler Croy +pupmod-simp-nfs - A Puppet Module for managing NFS + +-- + +Per Section 105 of the Copyright Act of 1976, these works are not entitled to +domestic copyright protection under US Federal law. + +The US Government retains the right to pursue copyright protections outside of +the United States. + +The United States Government has unlimited rights in this software and all +derivatives thereof, pursuant to the contracts under which it was developed and +the License under which it falls. + +--- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 6318117..d30f03c 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ ## Overview -systemd-journald is a system service that collects and stores logging data. -It creates and maintains structured, indexed journals based on logging information +systemd-journald is a system service that collects and stores logging data. +It creates and maintains structured, indexed journals based on logging information that is received from a variety of sources: * Kernel log messages, via kmsg @@ -41,7 +41,7 @@ that is received from a variety of sources: ## Limitations -This module is only appicable on EL7 machines +This module is only applicable on EL7 machines ## Development diff --git a/Rakefile b/Rakefile index b0cb303..1b7080e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,22 +1,3 @@ -require 'bundler' -Bundler.require(:rake) -require 'rake/clean' - -CLEAN.include('spec/fixtures/', 'doc', 'pkg') -CLOBBER.include('.tmp', '.librarian') - -require 'puppetlabs_spec_helper/rake_tasks' - -task :default => [:clean, :spec] - -PuppetLint.configuration.fail_on_warnings = true -PuppetLint.configuration.send('relative') -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.send('disable_class_inherits_from_params_class') -PuppetLint.configuration.send('disable_class_parameter_defaults') -PuppetLint.configuration.send('disable_documentation') -PuppetLint.configuration.send('disable_single_quote_string_with_variables') -PuppetLint.configuration.send('disable_empty_string_assignment') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] - +require 'simp/rake/pupmod/helpers' +Simp::Rake::Pupmod::Helpers.new(File.dirname(__FILE__)) diff --git a/manifests/config.pp b/manifests/config.pp index c07fcdc..605e643 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,3 +1,4 @@ +# Configure journald.conf class journald::config { $merged_options = merge($::journald::params::default_options, $::journald::options) @@ -10,14 +11,14 @@ file { '/var/log/journal/': ensure => $journald_dir, force => true, - owner => 0, + owner => 'root', group => 'systemd-journal', } file { '/etc/systemd/journald.conf': ensure => 'file', - owner => 0, - group => 0, + owner => 'root', + group => 'root', content => template("${module_name}/journald.conf.erb"), } } diff --git a/manifests/init.pp b/manifests/init.pp index 6783873..2288c09 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,22 +4,21 @@ # # === Parameters: # -# $persist_log:: By default, the journal stores log data in /run/log/journal/. -# Since /run/ is volatile, log data is lost at reboot. To make the -# data persistent, it is sufficient to create /var/log/journal/ -# where systemd-journald will then store the data. +# $persist_log:: By default, the journal stores log data in /run/log/journal/. +# Since /run/ is volatile, log data is lost at reboot. To make the +# data persistent, it is sufficient to create /var/log/journal/ +# where systemd-journald will then store the data. # -# $options:: a hash with journald parameters +# $options:: a hash with journald parameters # class journald ( $persist_log = $journald::params::persist_log, $options = undef ) inherits journald::params { - if $::osfamily == 'RedHat' and versioncmp($::operatingsystemrelease, '7.0') >= 0 { + if $::osfamily in ['RedHat','CentOS'] and versioncmp($::operatingsystemrelease, '7.0') >= 0 { contain ::journald::config contain ::journald::service - Class['journald::config'] ~> - Class['journald::service'] + Class['journald::config'] ~> Class['journald::service'] } } diff --git a/manifests/params.pp b/manifests/params.pp index 4cf07e8..1fe41f0 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,3 +1,4 @@ +# Default parameters class journald::params { $persist_log = true $default_options = { @@ -10,12 +11,14 @@ 'RateLimitBurst' => '10000', 'MaxFileSec' => '1month', 'ForwardToSyslog' => 'yes', - 'ForwardToKMsg' => 'yes', + 'ForwardToKMsg' => 'no', 'ForwardToConsole' => 'no', + 'ForwardToWall' => 'yes', 'TTYPath' => '/dev/console', 'MaxLevelStore' => 'debug', 'MaxLevelSyslog' => 'debug', - 'MaxLevelKMsg' => 'notice', + 'MaxLevelKMsg' => 'err', 'MaxLevelConsole' => 'info', + 'MaxLevelWall' => 'emerg', } } diff --git a/manifests/service.pp b/manifests/service.pp index db89787..6db727b 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,5 +1,6 @@ +# manage the systemd-journald service class journald::service { - service { ['systemd-journald']: + service { 'systemd-journald': ensure => running, enable => true, } diff --git a/metadata.json b/metadata.json index 11239a1..8cff942 100644 --- a/metadata.json +++ b/metadata.json @@ -1,19 +1,34 @@ { - "name": "cristifalcas-journald", + "name": "cristifalcas-journald", "author": "Cristian Falcas", - "version": "0.2.1", - "dependencies": [{ - "name": "puppetlabs/stdlib", - "version_requirement": "4.x" - } + "version": "0.2.2", + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 4.9.0 < 5.0.0" + } ], "license": "Apache-2.0", - "operatingsystem_support": [], + "operatingsystem_support": [ + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "7" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "7" + ] + } + ], "source": "git@github.com:cristifalcas/puppet-journald.git", "project_page": "https://github.com/cristifalcas/puppet-journald", "issues_url": "https://github.com/cristifalcas/puppet-journald/issues", "requirements": [], "summary": "Configures journald on el7", - "tags": [ "journald" + "tags": [ + "journald" ] } diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb new file mode 100644 index 0000000..a6bf1d0 --- /dev/null +++ b/spec/classes/config_spec.rb @@ -0,0 +1,111 @@ +require 'spec_helper' + +describe 'journald' do + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context 'with defaults for all parameters' do + let(:content) { + <<-EOF +## file generated by puppet +# See journald.conf(5) for details + +[Journal] +Compress=yes +ForwardToConsole=no +ForwardToKMsg=no +ForwardToSyslog=yes +ForwardToWall=yes +MaxFileSec=1month +MaxLevelConsole=info +MaxLevelKMsg=err +MaxLevelStore=debug +MaxLevelSyslog=debug +MaxLevelWall=emerg +RateLimitBurst=10000 +RateLimitInterval=30s +Seal=yes +SplitMode=login +Storage=auto +SyncIntervalSec=5m +TTYPath=/dev/console +EOF + } + + it { should compile.with_all_deps() } + it { should contain_class('journald::config') } + it { should contain_file('/var/log/journal/').with({ + 'ensure' => 'directory', + 'force' => 'true', + 'owner' => 'root', + 'group' => 'systemd-journal', + }) } + it { should contain_file('/etc/systemd/journald.conf').with({ + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'content' => content + }) } + end + + context 'with persist_log => false' do + let(:params) {{ :persist_log => false }} + + it { should compile.with_all_deps() } + it { should contain_class('journald::config') } + it { should contain_file('/var/log/journal/').with({ + 'ensure' => 'absent', + 'force' => 'true', + 'owner' => 'root', + 'group' => 'systemd-journal', + }) } + end + + context 'with a hash that deviates from default' do + let(:params) {{ :options => {'SplitMode' => 'none'} }} + + let(:content) { + <<-EOF +## file generated by puppet +# See journald.conf(5) for details + +[Journal] +Compress=yes +ForwardToConsole=no +ForwardToKMsg=no +ForwardToSyslog=yes +ForwardToWall=yes +MaxFileSec=1month +MaxLevelConsole=info +MaxLevelKMsg=err +MaxLevelStore=debug +MaxLevelSyslog=debug +MaxLevelWall=emerg +RateLimitBurst=10000 +RateLimitInterval=30s +Seal=yes +SplitMode=none +Storage=auto +SyncIntervalSec=5m +TTYPath=/dev/console +EOF + } + + it { should compile.with_all_deps() } + it { should contain_class('journald::config') } + it { should contain_file('/etc/systemd/journald.conf').with({ + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'content' => content + }) } + end + + end + end + end +end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index ff421e7..1a73f50 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,7 +1,21 @@ require 'spec_helper' + describe 'journald' do + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end - context 'with defaults for all parameters' do - it { should contain_class('journald') } + context 'with defaults for all parameters' do + it { should compile.with_all_deps() } + it { should contain_class('journald') } + it { should contain_class('journald::config') } + # it { should contain_class('journald::config').that_notifies("Class['journald::service']") } + it { should contain_class('journald::service') } + end + end + end end end diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb new file mode 100644 index 0000000..1d0940e --- /dev/null +++ b/spec/classes/service_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe 'journald' do + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context 'with defaults for all parameters' do + it { should compile.with_all_deps() } + it { should contain_class('journald::service') } + it { should contain_service('systemd-journald').with({ + 'ensure' => 'running', + 'enable' => 'true', + }) } + end + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..f2014d0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,154 @@ require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet' +require 'simp/rspec-puppet-facts' +include Simp::RspecPuppetFacts + +require 'pathname' + +# RSpec Material +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) +module_name = File.basename(File.expand_path(File.join(__FILE__,'../..'))) + +# Add fixture lib dirs to LOAD_PATH. Work-around for PUP-3336 +if Puppet.version < "4.0.0" + Dir["#{fixture_path}/modules/*/lib"].entries.each do |lib_dir| + $LOAD_PATH << lib_dir + end +end + + +if !ENV.key?( 'TRUSTED_NODE_DATA' ) + warn '== WARNING: TRUSTED_NODE_DATA is unset, using TRUSTED_NODE_DATA=yes' + ENV['TRUSTED_NODE_DATA']='yes' +end + +default_hiera_config =<<-EOM +--- +:backends: + - "yaml" +:yaml: + :datadir: "stub" +:hierarchy: + - "%{custom_hiera}" + - "%{module_name}" + - "default" +EOM + +# This can be used from inside your spec tests to set the testable environment. +# You can use this to stub out an ENC. +# +# Example: +# +# context 'in the :foo environment' do +# let(:environment){:foo} +# ... +# end +# +def set_environment(environment = :production) + RSpec.configure { |c| c.default_facts['environment'] = environment.to_s } +end + +# This can be used from inside your spec tests to load custom hieradata within +# any context. +# +# Example: +# +# describe 'some::class' do +# context 'with version 10' do +# let(:hieradata){ "#{class_name}_v10" } +# ... +# end +# end +# +# Then, create a YAML file at spec/fixtures/hieradata/some__class_v10.yaml. +# +# Hiera will use this file as it's base of information stacked on top of +# 'default.yaml' and .yaml per the defaults above. +# +# Note: Any colons (:) are replaced with underscores (_) in the class name. +def set_hieradata(hieradata) + RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata } +end + +if not File.directory?(File.join(fixture_path,'hieradata')) then + FileUtils.mkdir_p(File.join(fixture_path,'hieradata')) +end + +if not File.directory?(File.join(fixture_path,'modules',module_name)) then + FileUtils.mkdir_p(File.join(fixture_path,'modules',module_name)) +end + +RSpec.configure do |c| + # If nothing else... + c.default_facts = { + :production => { + #:fqdn => 'production.rspec.test.localdomain', + :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + :concat_basedir => '/tmp' + } + } + + c.mock_framework = :rspec + c.mock_with :mocha + + c.module_path = File.join(fixture_path, 'modules') + c.manifest_dir = File.join(fixture_path, 'manifests') + + c.hiera_config = File.join(fixture_path,'hieradata','hiera.yaml') + + # Useless backtrace noise + backtrace_exclusion_patterns = [ + /spec_helper/, + /gems/ + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end + + c.before(:all) do + data = YAML.load(default_hiera_config) + data[:yaml][:datadir] = File.join(fixture_path, 'hieradata') + + File.open(c.hiera_config, 'w') do |f| + f.write data.to_yaml + end + end + + c.before(:each) do + @spec_global_env_temp = Dir.mktmpdir('simpspec') + + if defined?(environment) + set_environment(environment) + FileUtils.mkdir_p(File.join(@spec_global_env_temp,environment.to_s)) + end + + # ensure the user running these tests has an accessible environmentpath + Puppet[:environmentpath] = @spec_global_env_temp + Puppet[:user] = Etc.getpwuid(Process.uid).name + Puppet[:group] = Etc.getgrgid(Process.gid).name + + # sanitize hieradata + if defined?(hieradata) + set_hieradata(hieradata.gsub(':','_')) + elsif defined?(class_name) + set_hieradata(class_name.gsub(':','_')) + end + end + + c.after(:each) do + # clean up the mocked environmentpath + FileUtils.rm_rf(@spec_global_env_temp) + @spec_global_env_temp = nil + end +end + +Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir| + begin + Pathname.new(dir).realpath + rescue + fail "ERROR: The module '#{dir}' is not installed. Tests cannot continue." + end +end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..a89cb16 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,49 @@ +require 'beaker-rspec' +require 'tmpdir' +require 'yaml' +require 'simp/beaker_helpers' +include Simp::BeakerHelpers + +unless ENV['BEAKER_provision'] == 'no' + hosts.each do |host| + # Install Puppet + if host.is_pe? + install_pe + else + install_puppet + end + end +end + + +RSpec.configure do |c| + # ensure that environment OS is ready on each host + fix_errata_on hosts + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + begin + # Install modules and dependencies from spec/fixtures/modules + copy_fixture_modules_to( hosts ) + server = only_host_with_role(hosts, 'server') + + # Generate and install PKI certificates on each SUT + Dir.mktmpdir do |cert_dir| + run_fake_pki_ca_on(server, hosts, cert_dir ) + hosts.each{ |sut| copy_pki_to( sut, cert_dir, '/etc/pki/simp-testing' )} + end + + # add PKI keys + copy_keydist_to(server) + rescue StandardError, ScriptError => e + if ENV['PRY'] + require 'pry'; binding.pry + else + raise e + end + end + end +end diff --git a/templates/journald.conf.erb b/templates/journald.conf.erb index 250fc2b..6517ceb 100644 --- a/templates/journald.conf.erb +++ b/templates/journald.conf.erb @@ -3,7 +3,7 @@ [Journal] <%- scope.lookupvar('journald::config::merged_options').sort.each do |k, v| -%> -<%- if v != :undef -%> -<%= k %>=<%= v %> -<%- end -%> +<%- if v != :undef -%> +<%= k %>=<%= v %> +<%- end -%> <%- end -%>