diff --git a/manifests/config.pp b/manifests/config.pp index 39c2553..6eecaf3 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,58 +1,58 @@ # == Class hitch::config # # This class is called from hitch for service config. # class hitch::config { validate_absolute_path($::hitch::config_root) validate_absolute_path($::hitch::config_file) validate_absolute_path($::hitch::dhparams_file) if $::hitch::dhparams_content { validate_re($::hitch::dhparams_content, 'BEGIN DH PARAMETERS') } file { $::hitch::config_root: ensure => directory, recurse => true, purge => $::hitch::purge_config_root, owner => $::hitch::file_owner, group => $::hitch::group, mode => '0750', } concat { $::hitch::config_file: ensure => present, } if $::hitch::dhparams_content { file { $::hitch::dhparams_file: ensure => present, owner => $::hitch::file_owner, group => $::hitch::group, mode => '0640', content => $::hitch::dhparams_content, } } else { exec { "${title} generate dhparams": path => '/usr/local/bin:/usr/bin:/bin', command => "openssl dhparam 2048 -out ${::hitch::dhparams_file}", creates => $::hitch::dhparams_file, } - -> - file { $::hitch::dhparams_file: + + -> file { $::hitch::dhparams_file: ensure => present, owner => $::hitch::file_owner, group => $::hitch::group, mode => '0640', } } concat::fragment { "${title} config": content => template('hitch/hitch.conf.erb'), target => $::hitch::config_file, } create_resources('hitch::domain', $::hitch::domains) } diff --git a/manifests/init.pp b/manifests/init.pp index bec37a2..a418d47 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,42 +1,42 @@ # Class: hitch # =========================== # # Full description of class hitch here. # # Parameters # ---------- # # * `package_name` # Package name for installing hitch # # * `service_name` # Service name for the hitch service # # * `config_file` # Configuration file. Default: /etc/hitch/hitch.conf # # * `config_root` # Configuration root directory. Default: /etc/hitch/ class hitch ( $package_name = $::hitch::params::package_name, $service_name = $::hitch::params::service_name, $file_owner = $::hitch::params::file_owner, $config_file = $::hitch::params::config_file, $dhparams_file = $::hitch::params::dhparams_file, $dhparams_content = $::hitch::params::dhparams, $config_root = $::hitch::params::config_root, $purge_config_root = $::hitch::params::purge_config_root, $frontend = $::hitch::params::frontend, $backend = $::hitch::params::backend, $write_proxy_v2 = $::hitch::params::write_proxy_v2, $ciphers = $::hitch::params::ciphers, $domains = $::hitch::params::domains, ) inherits ::hitch::params { # validate parameters here - class { '::hitch::install': } -> - class { '::hitch::config': } ~> - class { '::hitch::service': } -> - Class['::hitch'] + class { '::hitch::install': } + -> class { '::hitch::config': } + ~> class { '::hitch::service': } + -> Class['::hitch'] } diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index d827344..d2fe022 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,33 +1,33 @@ require 'spec_helper_acceptance' describe 'hitch class' do context 'default parameters' do # Using puppet_apply as a helper - it 'should work idempotently with no errors' do + it 'works idempotently with no errors' do pp = <<-EOS class { 'hitch': } hitch::domain { 'example.org': key_source => '/tmp/example.org_key.pem', cert_source => '/tmp/example.org_cert.pem', } hitch::domain { 'example.com': key_source => '/tmp/example.com_key.pem', cert_source => '/tmp/example.com_cert.pem', } EOS # Run it twice and test for idempotency - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end describe package('hitch') do it { is_expected.to be_installed } end describe service('hitch') do it { is_expected.to be_enabled } it { is_expected.to be_running } end end end diff --git a/spec/classes/hitch_spec.rb b/spec/classes/hitch_spec.rb index f44a949..4a7c2f7 100644 --- a/spec/classes/hitch_spec.rb +++ b/spec/classes/hitch_spec.rb @@ -1,72 +1,71 @@ require 'spec_helper' describe 'hitch' do context 'supported operating systems' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - context "hitch class without any parameters" do + context 'hitch class without any parameters' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('hitch') } it { is_expected.to contain_class('hitch::params') } it { is_expected.to contain_class('hitch::install').that_comes_before('hitch::config') } it { is_expected.to contain_class('hitch::config') } it { is_expected.to contain_class('hitch::service').that_subscribes_to('hitch::config') } it { is_expected.to contain_service('hitch') } it { is_expected.to contain_package('hitch').with_ensure('present') } it { is_expected.to contain_file('/etc/hitch') } it { is_expected.to contain_file('/etc/hitch/dhparams.pem') } it { is_expected.to contain_concat('/etc/hitch/hitch.conf') } it { is_expected.to contain_concat__fragment('hitch::config config') } it { is_expected.to contain_exec('hitch::config generate dhparams') } - context "osfamily specifics" do + context 'osfamily specifics' do if facts[:osfamily] == 'RedHat' it { is_expected.to contain_package('epel-release') } else it { is_expected.not_to contain_package('epel-release') } end end end - - context "hitch class with domains" do + context 'hitch class with domains' do let(:params) do - { :domains => { - 'example.com' => { - 'key_content' => '-----BEGIN PRIVATE KEY-----', - 'cert_content' => '-----BEGIN CERTIFICATE-----', - 'cacert_content' => '-----BEGIN CERTIFICATE-----', - 'dhparams_content' => '-----BEGIN DH PARAMETERS-----' - } - } - } + { domains: { + 'example.com' => { + 'key_content' => '-----BEGIN PRIVATE KEY-----', + 'cert_content' => '-----BEGIN CERTIFICATE-----', + 'cacert_content' => '-----BEGIN CERTIFICATE-----', + 'dhparams_content' => '-----BEGIN DH PARAMETERS-----', + }, + } } end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_hitch__domain('example.com') } it { is_expected.to contain_file('/etc/hitch/example.com.pem') } it { is_expected.to contain_concat__fragment('hitch::domain example.com') } end end end end context 'unsupported operating system' do describe 'hitch class without any parameters on Solaris/Nexenta' do let(:facts) do { - :osfamily => 'Solaris', - :operatingsystem => 'Nexenta', + osfamily: 'Solaris', + operatingsystem: 'Nexenta', } end - it { expect { is_expected.to contain_package('hitch') }.to raise_error(Puppet::Error, /Nexenta not supported/) } + it { expect { is_expected.to contain_package('hitch') }.to raise_error(Puppet::Error, %r{Nexenta not supported}) } end end end diff --git a/spec/defines/hitch__domain_spec.rb b/spec/defines/hitch__domain_spec.rb index fee257e..294c969 100644 --- a/spec/defines/hitch__domain_spec.rb +++ b/spec/defines/hitch__domain_spec.rb @@ -1,84 +1,87 @@ require 'spec_helper' describe 'hitch::domain' do context 'supported operating systems' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end let(:title) { 'example.com' } - context "with all content parameters" do + context 'with all content parameters' do let(:params) do { 'cacert_content' => '-----BEGIN CERTIFICATE-----', 'cert_content' => '-----BEGIN CERTIFICATE-----', 'dhparams_content' => '-----BEGIN DH PARAMETERS-----', 'key_content' => '-----BEGIN PRIVATE KEY-----', } end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_hitch__domain('example.com') } # for the pem file it { is_expected.to contain_concat('/etc/hitch/example.com.pem') } it { is_expected.to contain_concat__fragment('example.com cacert') } it { is_expected.to contain_concat__fragment('example.com cert') } it { is_expected.to contain_concat__fragment('example.com key') } it { is_expected.to contain_concat__fragment('example.com dhparams') } # for the config file it { is_expected.to contain_concat('/etc/hitch/hitch.conf') } it { is_expected.to contain_concat__fragment('hitch::domain example.com') } end - context "with all source parameters" do + context 'with all source parameters' do let(:params) do { 'cacert_source' => '/tmp/cacert.pem', 'cert_source' => '/tmp/cert.pem', 'dhparams_source' => '/tmp/dhparams.pem', 'key_source' => '/tmp/key.pem', } end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_hitch__domain('example.com') } # for the pem file it { is_expected.to contain_concat('/etc/hitch/example.com.pem') } it { is_expected.to contain_concat__fragment('example.com cacert') } it { is_expected.to contain_concat__fragment('example.com cert') } it { is_expected.to contain_concat__fragment('example.com key') } it { is_expected.to contain_concat__fragment('example.com dhparams') } # for the config file it { is_expected.to contain_concat('/etc/hitch/hitch.conf') } it { is_expected.to contain_concat__fragment('hitch::domain example.com') } end - context "mandatory parameters" do + context 'mandatory parameters' do let(:params) do { 'cert_source' => '/tmp/cert.pem', 'key_source' => '/tmp/key.pem', } end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_hitch__domain('example.com') } # for the pem file it { is_expected.to contain_concat('/etc/hitch/example.com.pem') } it { is_expected.not_to contain_concat__fragment('example.com cacert') } it { is_expected.to contain_concat__fragment('example.com cert') } it { is_expected.to contain_concat__fragment('example.com key') } it { is_expected.to contain_concat__fragment('example.com dhparams') } # for the config file it { is_expected.to contain_concat('/etc/hitch/hitch.conf') } it { is_expected.to contain_concat__fragment('hitch::domain example.com') } end end end end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index c5abb30..ad5da2e 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,27 +1,27 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' require 'beaker/puppet_install_helper' run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' RSpec.configure do |c| # Project root proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) # Readable test descriptions c.formatter = :documentation # Configure all nodes in nodeset c.before :suite do # Install module and dependencies - puppet_module_install(:source => proj_root, :module_name => 'hitch') + puppet_module_install(source: proj_root, module_name: 'hitch') hosts.each do |host| - on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } - on host, puppet('module', 'install', 'puppetlabs-concat'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1] + on host, puppet('module', 'install', 'puppetlabs-concat'), acceptable_exit_codes: [0, 1] ['example.com', 'example.org'].each do |domain| - on host, 'openssl req -newkey rsa:2048 -sha256 -keyout /tmp/%s_key.pem -nodes -x509 -days 365 -out /tmp/%s_cert.pem -subj "/CN=%s"' % [ domain, domain, domain ] + on host, 'openssl req -newkey rsa:2048 -sha256 -keyout /tmp/%s_key.pem -nodes -x509 -days 365 -out /tmp/%s_cert.pem -subj "/CN=%s"' % [domain, domain, domain] end on host, 'ls -l /tmp' end end end