aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNan Liu <nan@puppetlabs.com>2012-06-25 12:12:06 -0700
committerNan Liu <nan@puppetlabs.com>2012-06-25 12:15:21 -0700
commita45261555e1b70fc041fc001b4d4c1d18693ccc1 (patch)
tree1313860947ea07c362c1514a95a42d73ae2e349c
parent6500ac722b939b86c32559508be3c7f224ba5cfe (diff)
downloadpuppet-tftp-a45261555e1b70fc041fc001b4d4c1d18693ccc1.tar.gz
puppet-tftp-a45261555e1b70fc041fc001b4d4c1d18693ccc1.tar.bz2
Add default module path for tftp::file
This change provides the convenience of using caller_module_name for tftp files, so the following manifests can be abbreviated from: tftp::file { 'foo': source => 'puppet:///modules/example/foo', } tftp::file { 'baz/bar': source => 'puppet:///modules/example/baz/bar', } to: tftp::file { [ 'foo', 'baz/bar' ]: } This simplifies declaring large number of tftp files.
-rw-r--r--manifests/file.pp17
-rw-r--r--spec/defines/tftp_file_spec.rb75
2 files changed, 75 insertions, 17 deletions
diff --git a/manifests/file.pp b/manifests/file.pp
index ec67f2c..b3985c7 100644
--- a/manifests/file.pp
+++ b/manifests/file.pp
@@ -10,10 +10,10 @@
#
define tftp::file (
$ensure = file,
- $recurse = false,
$owner = 'tftp',
$group = 'tftp',
$mode = '0644',
+ $recurse = false,
$purge = undef,
$replace = undef,
$recurselimit = undef,
@@ -22,17 +22,28 @@ define tftp::file (
) {
include 'tftp'
+ if $source {
+ $source_real = $source
+ } elsif $ensure != 'directory' and ! $content {
+ if $caller_module_name {
+ $mod = $caller_module_name
+ } else {
+ $mod = $module_name
+ }
+ $source_real = "puppet:///modules/${mod}/${name}"
+ }
+
file { "${tftp::directory}/${name}":
ensure => $ensure,
- recurse => $recurse,
owner => $owner,
group => $group,
mode => $mode,
+ recurse => $recurse,
purge => $purge,
replace => $replace,
recurselimit => $recurselimit,
content => $content,
- source => $source,
+ source => $source_real,
require => Class['tftp'],
}
}
diff --git a/spec/defines/tftp_file_spec.rb b/spec/defines/tftp_file_spec.rb
index 6a032c0..0de1b6f 100644
--- a/spec/defines/tftp_file_spec.rb
+++ b/spec/defines/tftp_file_spec.rb
@@ -11,10 +11,10 @@ describe 'tftp::file' do
it { should include_class('tftp') }
it { should contain_file('/srv/tftp/sample').with({
'ensure' => 'file',
- 'recurse' => false,
'owner' => 'tftp',
'group' => 'tftp',
- 'mode' => '0644'
+ 'mode' => '0644',
+ 'recurse' => false,
}) }
end
@@ -25,29 +25,29 @@ describe 'tftp::file' do
it { should include_class('tftp') }
it { should contain_file('/var/lib/tftpboot/sample').with({
'ensure' => 'file',
- 'recurse' => false,
'owner' => 'tftp',
'group' => 'tftp',
- 'mode' => '0644'
+ 'mode' => '0644',
+ 'recurse' => false,
}) }
end
describe 'when deploying with parameters' do
- let(:params) { {:ensure => 'directory',
- :recurse => true,
- :owner => 'root',
- :group => 'root',
- :mode => '0755' }}
+ let(:params) { {:ensure => 'directory',
+ :owner => 'root',
+ :group => 'root',
+ :mode => '0755',
+ :recurse => true }}
let(:facts) { { :operatingsystem => 'Debian',
:path => '/usr/local/bin:/usr/bin:/bin', } }
it { should include_class('tftp') }
it { should contain_file('/srv/tftp/sample').with({
'ensure' => 'directory',
- 'recurse' => true,
'owner' => 'root',
'group' => 'root',
- 'mode' => '0755'
+ 'mode' => '0755',
+ 'recurse' => true,
}) }
end
@@ -61,14 +61,14 @@ describe 'tftp::file' do
'recurse' => false,
'purge' => nil,
'replace' => nil,
- 'recurselimit' => nil
+ 'recurselimit' => nil,
}) }
end
describe 'when deploying with recurse parameters' do
let(:params) { {:ensure => 'directory',
- :recurse => true,
:mode => '0755',
+ :recurse => true,
:recurselimit => 42,
:purge => true,
:replace => false }}
@@ -78,13 +78,60 @@ describe 'tftp::file' do
it { should include_class('tftp') }
it { should contain_file('/srv/tftp/sample').with({
'ensure' => 'directory',
- 'recurse' => true,
'owner' => 'tftp',
'group' => 'tftp',
'mode' => '0755',
+ 'recurse' => true,
'recurselimit' => 42,
'purge' => true,
'replace' => false,
}) }
end
+
+ describe 'when deploying directory' do
+ let(:params) { {:ensure => 'directory',
+ :mode => '0755' }}
+ let(:facts) { { :operatingsystem => 'Debian',
+ :caller_module_name => 'acme',
+ :path => '/usr/local/bin:/usr/bin:/bin', } }
+
+ it { should include_class('tftp') }
+ it { should contain_file('/srv/tftp/sample').with({
+ 'ensure' => 'directory',
+ 'mode' => '0755',
+ 'source' => nil,
+ }) }
+ end
+
+ describe 'when deploying file from another module' do
+ let(:params) { {:ensure => 'file',
+ :mode => '0755' }}
+ let(:facts) { { :operatingsystem => 'Debian',
+ :caller_module_name => 'acme',
+ :path => '/usr/local/bin:/usr/bin:/bin', } }
+
+ it { should include_class('tftp') }
+ it { should contain_file('/srv/tftp/sample').with({
+ 'ensure' => 'file',
+ 'mode' => '0755',
+ 'source' => 'puppet:///modules/acme/sample'
+ }) }
+ end
+
+ describe 'when deploying file with content' do
+ let(:params) { {:ensure => 'file',
+ :content => 'hi',
+ :mode => '0755' }}
+ let(:facts) { { :operatingsystem => 'Debian',
+ :caller_module_name => 'acme',
+ :path => '/usr/local/bin:/usr/bin:/bin', } }
+
+ it { should include_class('tftp') }
+ it { should contain_file('/srv/tftp/sample').with({
+ 'ensure' => 'file',
+ 'mode' => '0755',
+ 'content' => 'hi',
+ 'source' => nil,
+ }) }
+ end
end