Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #12 from tmcinerney/trav/hiera_support
Browse files Browse the repository at this point in the history
Add Hiera support
  • Loading branch information
dgoodlad committed Sep 13, 2014
2 parents 3a16761 + 6090965 commit ce8de85
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 137 deletions.
84 changes: 48 additions & 36 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.5)
CFPropertyList (2.2.8)
addressable (2.3.6)
ansi (1.4.3)
boxen (1.5.2)
ansi (~> 1.4)
Expand All @@ -16,26 +17,30 @@ GEM
puppet-lint (~> 0.3)
puppetlabs_spec_helper (~> 0.4)
rspec-puppet (~> 0.1)
diff-lcs (1.2.4)
facter (1.7.2)
faraday (0.8.7)
multipart-post (~> 1.1)
faraday_middleware (0.9.0)
faraday (>= 0.7.4, < 0.9)
hashie (2.0.5)
hiera (1.2.1)
diff-lcs (1.2.5)
facter (2.2.0)
CFPropertyList (~> 2.2.6)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.9.1)
faraday (>= 0.7.4, < 0.10)
hashie (2.1.2)
hiera (1.3.4)
json_pure
highline (1.6.19)
json (1.8.0)
json_pure (1.8.0)
librarian-puppet (0.9.9)
json
highline (1.6.21)
json (1.8.1)
json_pure (1.8.1)
librarian (0.1.2)
highline
thor (~> 0.15)
metaclass (0.0.1)
mocha (0.14.0)
librarian-puppet (0.9.17)
json
librarian (>= 0.1.2)
metaclass (0.0.4)
mocha (1.1.0)
metaclass (~> 0.0.1)
multi_json (1.7.7)
multipart-post (1.2.0)
multi_json (1.10.1)
multipart-post (2.0.0)
netrc (0.7.7)
octokit (1.25.0)
addressable (~> 2.2)
Expand All @@ -44,29 +49,36 @@ GEM
hashie (~> 2.0)
multi_json (~> 1.3)
netrc (~> 0.7.7)
puppet (3.2.3)
facter (~> 1.6)
puppet (3.7.0)
facter (> 1.6, < 3)
hiera (~> 1.0)
rgen (~> 0.6.5)
json_pure
puppet-lint (0.3.2)
puppetlabs_spec_helper (0.4.1)
mocha (>= 0.10.5)
puppet-syntax (1.3.0)
rake
rspec (>= 2.9.0)
rspec-puppet (>= 0.1.1)
rake (10.1.0)
rgen (0.6.5)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.4)
rspec-expectations (2.14.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.1)
puppetlabs_spec_helper (0.8.1)
mocha
puppet-lint
puppet-syntax
rake
rspec
rspec-puppet
rake (10.3.2)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.2)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.0)
rspec-support (~> 3.1.0)
rspec-puppet (0.1.6)
rspec
thor (0.18.1)
rspec-support (3.1.0)
thor (0.19.1)

PLATFORMS
ruby
Expand Down
7 changes: 7 additions & 0 deletions data/Darwin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
dnsmasq::configdir: "%{boxen::config::configdir}/dnsmasq"
dnsmasq::configfile: "%{boxen::config::configdir}/dnsmasq/dnsmasq.conf"
dnsmasq::datadir: "%{boxen::config::datadir}/dnsmasq"
dnsmasq::executable: "%{boxen::config::homebrewdir}/sbin/dnsmasq"
dnsmasq::logdir: "%{boxen::config::logdir}/dnsmasq"
dnsmasq::logfile: "%{boxen::config::logdir}/dnsmasq/console.log"
3 changes: 3 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dnsmasq::host: 127.0.0.1
dnsmasq::tld: dev
4 changes: 4 additions & 0 deletions data/hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
:hierarchy:
- "%{::osfamily}"
- common
24 changes: 0 additions & 24 deletions manifests/config.pp

This file was deleted.

50 changes: 30 additions & 20 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,49 @@
# Examples
#
# include dnsmasq
class dnsmasq {
class dnsmasq(
$host = undef,
$tld = undef,

$configdir = undef,
$configfile = undef,
$datadir = undef,
$executable = undef,
$logdir = undef,
$logfile = undef,
) {
require homebrew
require dnsmasq::config
$servicename = 'dev.dnsmasq'

file { [$dnsmasq::config::configdir, $dnsmasq::config::logdir, $dnsmasq::config::datadir]:
ensure => directory
file { [$configdir, $logdir, $datadir]:
ensure => directory,
}

file { "${dnsmasq::config::configdir}/dnsmasq.conf":
notify => Service['dev.dnsmasq'],
require => File[$dnsmasq::config::configdir],
source => 'puppet:///modules/dnsmasq/dnsmasq.conf'
file { "${configdir}/dnsmasq.conf":
content => template('dnsmasq/dnsmasq.conf.erb'),
notify => Service[$servicename],
require => File[$configdir],
}

file { '/Library/LaunchDaemons/dev.dnsmasq.plist':
content => template('dnsmasq/dev.dnsmasq.plist.erb'),
file { "/Library/LaunchDaemons/${tld}.dnsmasq.plist":
content => template("dnsmasq/${tld}.dnsmasq.plist.erb"),
group => 'wheel',
notify => Service['dev.dnsmasq'],
owner => 'root'
notify => Service[$servicename],
owner => 'root',
}

file { '/etc/resolver':
ensure => directory,
group => 'wheel',
owner => 'root'
owner => 'root',
}

file { '/etc/resolver/dev':
file { "/etc/resolver/${tld}":
content => 'nameserver 127.0.0.1',
group => 'wheel',
owner => 'root',
require => File['/etc/resolver'],
notify => Service['dev.dnsmasq'],
notify => Service[$servicename],
}

homebrew::formula { 'dnsmasq':
Expand All @@ -44,16 +54,16 @@

package { 'boxen/brews/dnsmasq':
ensure => '2.71-boxen1',
notify => Service['dev.dnsmasq']
notify => Service[$servicename],
}

service { 'dev.dnsmasq':
service { $servicename:
ensure => running,
require => Package['boxen/brews/dnsmasq']
require => Package['boxen/brews/dnsmasq'],
}

service { 'com.boxen.dnsmasq': # replaced by dev.dnsmasq
before => Service['dev.dnsmasq'],
enable => false
before => Service[$servicename],
enable => false,
}
}
24 changes: 0 additions & 24 deletions spec/classes/dnsmasq_config_spec.rb

This file was deleted.

53 changes: 31 additions & 22 deletions spec/classes/dnsmasq_spec.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
require 'spec_helper'

describe 'dnsmasq' do
let(:boxen_home) { '/opt/boxen' }
let(:logdir) { "#{boxen_home}/log" }
let(:confdir) { "#{boxen_home}/config" }

let(:facts) do
{
:boxen_home => '/opt/boxen',
:boxen_user => 'testuser',
:boxen_srcdir => '/tmp/src',
:github_login => 'testuser',
}
end

let(:facts) { default_test_facts }
let(:boxen_home) { "/test/boxen" }
let(:configdir) { "#{boxen_home}/config/dnsmasq" }
let(:configfile) { "#{configdir}/dnsmasq.conf" }
let(:datadir) { "#{boxen_home}/data/dnsmasq" }
let(:logdir) { "#{boxen_home}/log/dnsmasq" }
let(:logfile) { "#{logdir}/console.log" }
let(:executable) { "#{boxen_home}/homebrew/sbin/dnsmasq" }
let(:tld) { "dev" }
let(:servicename) { "#{tld}.dnsmasq" }
let(:params) {{
'host' => "127.0.0.1",
'tld' => tld,
'configdir' => configdir,
'datadir' => datadir,
'logdir' => logdir,
'configfile' => configfile,
'logfile' => logfile,
'executable' => executable,
}}

it do
should include_class('homebrew')
should include_class('dnsmasq::config')

should contain_file("#{confdir}/dnsmasq").with_ensure('directory')
should contain_file("#{logdir}/dnsmasq").with_ensure('directory')
should contain_file(configdir).with_ensure('directory')
should contain_file(datadir).with_ensure('directory')
should contain_file(logdir).with_ensure('directory')

should contain_file("#{confdir}/dnsmasq/dnsmasq.conf").with({
:notify => 'Service[dev.dnsmasq]',
:require => "File[#{confdir}/dnsmasq]",
:source => 'puppet:///modules/dnsmasq/dnsmasq.conf',
should contain_file(configfile).with({
:content => File.read('spec/fixtures/dnsmasq.conf'),
:notify => "Service[#{servicename}]",
:require => "File[#{configdir}]",
})

should contain_file('/Library/LaunchDaemons/dev.dnsmasq.plist').with({
:content => File.read('spec/fixtures/dev.dnsmasq.plist'),
:group => 'wheel',
:notify => 'Service[dev.dnsmasq]',
:notify => "Service[#{servicename}]",
:owner => 'root',
})

Expand All @@ -51,10 +60,10 @@

should contain_package('boxen/brews/dnsmasq').with({
:ensure => '2.71-boxen1',
:notify => 'Service[dev.dnsmasq]',
:notify => "Service[#{servicename}]",
})

should contain_service('dev.dnsmasq').with({
should contain_service(servicename).with({
:ensure => 'running',
:require => 'Package[boxen/brews/dnsmasq]',
})
Expand Down
10 changes: 5 additions & 5 deletions spec/fixtures/dev.dnsmasq.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

<key>ProgramArguments</key>
<array>
<string>/opt/boxen/homebrew/sbin/dnsmasq</string>
<string>--conf-file=/opt/boxen/config/dnsmasq/dnsmasq.conf</string>
<string>/test/boxen/homebrew/sbin/dnsmasq</string>
<string>--conf-file=/test/boxen/config/dnsmasq/dnsmasq.conf</string>
<string>--keep-in-foreground</string>
</array>

Expand All @@ -28,12 +28,12 @@
</dict>

<key>WorkingDirectory</key>
<string>/opt/boxen/data/dnsmasq</string>
<string>/test/boxen/data/dnsmasq</string>

<key>StandardErrorPath</key>
<string>/opt/boxen/log/dnsmasq/console.log</string>
<string>/test/boxen/log/dnsmasq/console.log</string>

<key>StandardOutPath</key>
<string>/opt/boxen/log/dnsmasq/console.log</string>
<string>/test/boxen/log/dnsmasq/console.log</string>
</dict>
</plist>
File renamed without changes.
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
end

def default_test_facts
@default_test_facts ||= {
:boxen_home => "/test/boxen",
:boxen_user => "testuser",
:operatingsystem => "Debian",
:osfamily => "Debian",
:ipaddress => "127.0.0.1",
}
end
Loading

0 comments on commit ce8de85

Please sign in to comment.