From 7a74314a1e704f5bcb40d890d05dad88ce33e7c6 Mon Sep 17 00:00:00 2001 From: Nate Riffe Date: Thu, 8 Jan 2015 08:09:32 -0600 Subject: [PATCH] Make it all work again. Previous iterations and even a release were all broken. The module works again, sorry for the interlude. - Giving up on params and moving to module_data (WIP) - Change the Package and Service references to the static 'bind' name - Add a meager amount of test coverage --- .fixtures.yml | 2 +- Gemfile | 3 +- Gemfile.lock | 15 +++++---- Rakefile | 33 +++++++++++++++++--- data/common.yaml | 8 +++++ data/hiera.yaml | 6 ++++ data/osfamily/Debian.yaml | 13 ++++++++ manifests/acl.pp | 2 +- manifests/init.pp | 12 ++++---- manifests/key.pp | 4 +-- manifests/keydir.pp | 2 +- manifests/params.pp | 54 +++++++++++++++------------------ manifests/updater.pp | 15 ++++----- manifests/view.pp | 4 +-- manifests/zone.pp | 6 ++-- metadata.json | 1 + spec/classes/bind_spec.rb | 34 +++++++++------------ spec/classes/updater_spec.rb | 6 ++++ spec/fixtures/hiera/common.yaml | 2 ++ spec/fixtures/hiera/hiera.yaml | 9 ++++++ spec/spec_helper.rb | 13 ++++++++ 21 files changed, 156 insertions(+), 88 deletions(-) create mode 100644 data/common.yaml create mode 100644 data/hiera.yaml create mode 100644 data/osfamily/Debian.yaml create mode 100644 spec/classes/updater_spec.rb create mode 100644 spec/fixtures/hiera/common.yaml create mode 100644 spec/fixtures/hiera/hiera.yaml diff --git a/.fixtures.yml b/.fixtures.yml index edf911c..f42623f 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,9 +1,9 @@ ---- fixtures: forge_modules: concat: repo: "puppetlabs/concat" ref: "1.0.0" stdlib: "puppetlabs/stdlib" + module_data: "ripienaar/module_data" symlinks: bind: "#{source_dir}" diff --git a/Gemfile b/Gemfile index a30d1f9..ad7b61c 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' if ENV.include?('PUPPET_VERSION') puppetversion = "~>#{ENV['PUPPET_VERSION']}" else - puppetversion = '3.4.1' + puppetversion = '~>3.7.0' end gem 'rake' @@ -11,3 +11,4 @@ gem 'puppet', puppetversion gem 'puppet-lint' gem 'rspec-puppet' gem 'puppetlabs_spec_helper' +gem 'metadata-json-lint' diff --git a/Gemfile.lock b/Gemfile.lock index f574c88..ce957a8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,18 +1,21 @@ GEM remote: https://rubygems.org/ specs: + CFPropertyList (2.2.8) diff-lcs (1.2.5) - facter (1.7.6) + facter (2.3.0) + CFPropertyList (~> 2.2.6) hiera (1.3.4) json_pure json_pure (1.8.1) metaclass (0.0.4) + metadata-json-lint (0.0.2) mocha (1.1.0) metaclass (~> 0.0.1) - puppet (3.4.1) - facter (~> 1.6) + puppet (3.7.3) + facter (> 1.6, < 3) hiera (~> 1.0) - rgen (~> 0.6.5) + json_pure puppet-lint (1.1.0) puppet-syntax (1.3.0) rake @@ -24,7 +27,6 @@ GEM rspec rspec-puppet rake (10.4.2) - rgen (0.6.6) rspec (3.1.0) rspec-core (~> 3.1.0) rspec-expectations (~> 3.1.0) @@ -44,7 +46,8 @@ PLATFORMS ruby DEPENDENCIES - puppet (= 3.4.1) + metadata-json-lint + puppet (~> 3.7.0) puppet-lint puppetlabs_spec_helper rake diff --git a/Rakefile b/Rakefile index 147ef05..bf74c98 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,18 @@ -# ex: syntax=ruby ts=2 ts=2 si et -require 'puppet-lint/tasks/puppet-lint' require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'puppet-syntax/tasks/puppet-syntax' + +exclude_paths = [ + 'bundle/**/*', + 'pkg/**/*', + 'vendor/**/*', + 'spec/**/*' +] Rake::Task[:lint].clear PuppetLint::RakeTask.new :lint do |config| - config.fail_on_warnings - config.ignore_paths = [ 'pkg/**/*', 'spec/**/*', 'gemfiles/vendor/**/*' ] + config.fail_on_warnings = true + config.ignore_paths = exclude_paths config.disable_checks = [ '80chars', 'class_parameter_defaults', @@ -14,4 +21,20 @@ PuppetLint::RakeTask.new :lint do |config| ] end -task :default => [ :spec, :lint ] +PuppetSyntax.exclude_paths = exclude_paths + +RSpec::Core::RakeTask.new(:acceptance) do |t| + t.pattern = 'spec/acceptance' +end + +task :metadata do + sh 'metadata-json-lint metadata.json' +end + +desc 'Run syntax, lint, and spec tests.' +task :test => [ + :syntax, + :lint, + :spec, + :metadata +] diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..e64d433 --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,8 @@ +--- +bind::params::supported: false + +bind::forwarders: '' +bind::dnssec: true +bind::version: '' + +bind::updater::keydir: '/etc/nsupdate-keys' diff --git a/data/hiera.yaml b/data/hiera.yaml new file mode 100644 index 0000000..c59473f --- /dev/null +++ b/data/hiera.yaml @@ -0,0 +1,6 @@ +# ex: si ts=2 sw=2 et +:hierarchy: + - osfamily/%{::osfamily}/%{::operatingsystem}/%{lsbdistrelease} + - osfamily/%{::osfamily}/%{::operatingsystem} + - osfamily/%{::osfamily} + - common diff --git a/data/osfamily/Debian.yaml b/data/osfamily/Debian.yaml new file mode 100644 index 0000000..ca071ab --- /dev/null +++ b/data/osfamily/Debian.yaml @@ -0,0 +1,13 @@ +--- +bind::params::supported: true +bind::params::bind_user: 'bind' +bind::params::bind_group: 'bind' +bind::params::bind_package: 'bind9' +bind::params::bind_service: 'bind9' +bind::params::nsupdate_package: 'dnsutils' + +bind::confdir: '/etc/bind' +bind::cachedir: '/var/cache/bind' +bind::rndc: true + +bind::updater::keydir: '/etc/bind/keys' diff --git a/manifests/acl.pp b/manifests/acl.pp index f493e14..3737d94 100644 --- a/manifests/acl.pp +++ b/manifests/acl.pp @@ -6,7 +6,7 @@ define bind::acl ( concat::fragment { "bind-acl-${name}": order => '10', - target => "${bind::params::confdir}/acls.conf", + target => "${bind::confdir}/acls.conf", content => template('bind/acl.erb'), } diff --git a/manifests/init.pp b/manifests/init.pp index db20cd9..16b1f9c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,12 +1,12 @@ # ex: syntax=puppet si ts=4 sw=4 et class bind ( - $confdir = $::bind::params::confdir, - $cachedir = $::bind::params::cachedir, - $forwarders = '', - $dnssec = true, - $version = '', - $rndc = $::bind::params::bind_rndc, + $confdir = undef, + $cachedir = undef, + $forwarders = undef, + $dnssec = undef, + $version = undef, + $rndc = undef, ) { include params diff --git a/manifests/key.pp b/manifests/key.pp index 1a03982..a1c99f2 100644 --- a/manifests/key.pp +++ b/manifests/key.pp @@ -17,9 +17,7 @@ define bind::key ( } if (defined(Class['bind'])) { - Package[$bind::params::bind_package] -> - File["${keydir}/${name}"] ~> - Service[$bind::params::bind_service] + Package['bind'] -> File["${keydir}/${name}"] ~> Service['bind'] concat::fragment { "bind-key-${name}": order => '10', diff --git a/manifests/keydir.pp b/manifests/keydir.pp index b2a2192..6bf8952 100644 --- a/manifests/keydir.pp +++ b/manifests/keydir.pp @@ -1,7 +1,7 @@ # ex: syntax=puppet si ts=4 sw=4 et class bind::keydir ( - $keydir = "${::bind::params::confdir}/keys", + $keydir, ) { file { $keydir: ensure => directory, diff --git a/manifests/params.pp b/manifests/params.pp index 131eb7b..0abc023 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,35 +1,29 @@ # ex: syntax=puppet si ts=4 sw=4 et -class bind::params { - - case $::osfamily { - 'Debian': { - $bind_package = 'bind9' - $bind_service = 'bind9' - $confdir = '/etc/bind' - $cachedir = '/var/cache/bind' - $bind_user = 'bind' - $bind_group = 'bind' - $bind_rndc = true - - $nsupdate_package = 'dnsutils' - - $bind_files = [ - "${confdir}/bind.keys", - "${confdir}/db.empty", - "${confdir}/db.local", - "${confdir}/db.root", - "${confdir}/db.0", - "${confdir}/db.127", - "${confdir}/db.255", - "${confdir}/named.conf.default-zones", - "${confdir}/rndc.key", - "${confdir}/zones.rfc1918", - ] - } - default: { - fail("Operating system is not supported ${::osfamily}") - } +class bind::params ( + $supported, + $bind_user, + $bind_group, + $bind_package, + $bind_service, + $nsupdate_package, +) { + unless $supported { + fail('Platform is not supported') } + if $::osfamily == 'Debian' { + $bind_files = [ + "${::bind::confdir}/bind.keys", + "${::bind::confdir}/db.empty", + "${::bind::confdir}/db.local", + "${::bind::confdir}/db.root", + "${::bind::confdir}/db.0", + "${::bind::confdir}/db.127", + "${::bind::confdir}/db.255", + "${::bind::confdir}/named.conf.default-zones", + "${::bind::confdir}/rndc.key", + "${::bind::confdir}/zones.rfc1918", + ] + } } diff --git a/manifests/updater.pp b/manifests/updater.pp index 246e47f..daa1239 100644 --- a/manifests/updater.pp +++ b/manifests/updater.pp @@ -1,18 +1,15 @@ # ex: syntax=puppet si ts=4 sw=4 et class bind::updater ( - $nsupdate_package = $::bind::params::nsupdate_package, - $keydir = "${::bind::params::confdir}/keys", + $keydir = undef, ) { include params - package {'nsupdate': - ensure => present, - name => $nsupdate_package, - } - - file { $::bind::params::confdir: - ensure => directory, + if $::bind::params::nsupdate_package { + package { 'nsupdate': + ensure => present, + name => $::bind::params::nsupdate_package, + } } class { 'bind::keydir': diff --git a/manifests/view.pp b/manifests/view.pp index 5e2e942..3413e1e 100644 --- a/manifests/view.pp +++ b/manifests/view.pp @@ -8,11 +8,11 @@ define bind::view ( $recursion_match_clients = 'any', $recursion_match_destinations = '', ) { - $confdir = $bind::params::confdir + $confdir = $::bind::confdir concat::fragment { "bind-view-${name}": order => '10', - target => "${bind::params::confdir}/views.conf", + target => "${::bind::confdir}/views.conf", content => template('bind/view.erb'), } } diff --git a/manifests/zone.pp b/manifests/zone.pp index 46aa9a8..335006a 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -43,7 +43,7 @@ define bind::zone ( owner => $bind::params::bind_user, group => $bind::params::bind_group, mode => '0755', - require => Package[$bind::params::bind_package], + require => Package['bind'], } file { "${cachedir}/${name}/${_domain}": @@ -85,8 +85,8 @@ define bind::zone ( group => $bind::params::bind_group, mode => '0644', content => template('bind/zone.conf.erb'), - notify => Service[$bind::params::bind_service], - require => Package[$bind::params::bind_package], + notify => Service['bind'], + require => Package['bind'], } } diff --git a/metadata.json b/metadata.json index 6f891fd..cb6f066 100644 --- a/metadata.json +++ b/metadata.json @@ -20,5 +20,6 @@ ], "dependencies": [ { "name": "puppetlabs/concat", "version_requirement": ">=1.0.0 <2.0.0" } + { "name": "ripienaar/module_data", "version_requirement": ">=0.0.4" } ] } diff --git a/spec/classes/bind_spec.rb b/spec/classes/bind_spec.rb index 8d504ef..9fada43 100644 --- a/spec/classes/bind_spec.rb +++ b/spec/classes/bind_spec.rb @@ -3,28 +3,22 @@ require 'spec_helper' describe 'bind' do let(:facts) { { :concat_basedir => '/wtf' } } - let(:params) { { :confdir => '_CONFDIR_' } } + it { + should contain_package('bind').with({ + 'ensure' => 'latest', + 'name' => 'bind9' + }) + } - context 'on Debian-derived systems' do - let(:facts) { super().merge({ :osfamily => 'Debian' }) } - - it { - should contain_package('bind').with({ - 'ensure' => 'latest', - 'name' => 'bind9' - }) - } + it { should contain_file('_CONFDIR_/named.conf').that_requires('Package[bind]') } + it { should contain_file('_CONFDIR_/named.conf').that_notifies('Service[bind]') } - it { should contain_file('_CONFDIR_/named.conf').that_requires('Package[bind]') } - it { should contain_file('_CONFDIR_/named.conf').that_notifies('Service[bind]') } - - it { - should contain_service('bind').with({ - 'ensure' => 'running', - 'name' => 'bind9' - }) - } - end + it { + should contain_service('bind').with({ + 'ensure' => 'running', + 'name' => 'bind9' + }) + } end diff --git a/spec/classes/updater_spec.rb b/spec/classes/updater_spec.rb new file mode 100644 index 0000000..aab38c2 --- /dev/null +++ b/spec/classes/updater_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' + +describe 'bind::updater' do + it { should compile } + it { should compile.with_all_deps } +end diff --git a/spec/fixtures/hiera/common.yaml b/spec/fixtures/hiera/common.yaml new file mode 100644 index 0000000..631d77d --- /dev/null +++ b/spec/fixtures/hiera/common.yaml @@ -0,0 +1,2 @@ +--- +bind::confdir: '_CONFDIR_' diff --git a/spec/fixtures/hiera/hiera.yaml b/spec/fixtures/hiera/hiera.yaml new file mode 100644 index 0000000..f3e0521 --- /dev/null +++ b/spec/fixtures/hiera/hiera.yaml @@ -0,0 +1,9 @@ +--- +:hierarchy: + - "tests/%{::test_config}" + - common +:backends: + - yaml + - module_data +:yaml: + :datadir: 'spec/fixtures/hiera' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..f7b76c3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,14 @@ require 'puppetlabs_spec_helper/module_spec_helper' +require 'fixtures/modules/module_data/lib/hiera/backend/module_data_backend.rb' + +RSpec.configure do |c| + c.default_facts = { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :lsbdistcodename => 'wheezy', + :architecture => 'amd64', + :kernel => 'Linux', + :test_config => 'default' + } + c.hiera_config = File.join('spec', 'fixtures', 'hiera', 'hiera.yaml') +end