From f02d6faadd181493ccc9236f43296f2ba56ed592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Can=C3=A9vet?= Date: Tue, 17 Mar 2015 15:58:12 +0100 Subject: Encourage file() usage --- README.md | 18 +++++++++------ manifests/lens.pp | 50 ++++++++++++++++++++++++++++++---------- spec/defines/augeas_lens_spec.rb | 2 +- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e2055b0..863f4d6 100644 --- a/README.md +++ b/README.md @@ -36,18 +36,22 @@ The `augeas::lens` definition allows you to deploy an Augeas lens and any associ Parameters: - *ensure*: present/absent -- *lens_source*: the source for the lens -- *test_source*: optionally, the source for the test file. +- *lens_content*: the content of the lens +- *lens_source*: deprecated, the source for the lens +- *test_content*: optionally, the content of the test file +- *test_source*: deprecated, the source for the test file. - *stock_since*: optionally, indicate in which version of Augeas the lens became stock, so it will not be deployed above that version. Example usage: - augeas::lens { 'networkmanager': - lens_source => 'puppet:///modules/networkmanager/lenses/networkmanager.aug', - test_source => 'puppet:///modules/networkmanager/lenses/test_networkmanager.aug', - stock_since => '1.0.0', - } +```puppet +augeas::lens { 'networkmanager': + lens_content => file('networkmanager/lenses/networkmanager.aug'), + test_content => file('networkmanager/lenses/test_networkmanager.aug'), + stock_since => '1.0.0', +} +``` ### Functions diff --git a/manifests/lens.pp b/manifests/lens.pp index b5b9acd..f30a089 100644 --- a/manifests/lens.pp +++ b/manifests/lens.pp @@ -6,7 +6,9 @@ # # Parameters: # ['ensure'] - present/absent +# ['lens_content'] - the content of the lens # ['lens_source'] - the source for the lens +# ['test_content'] - optionally, the content of the test # ['test_source'] - optionally, the source for the test file. # ['stock_since'] - optionally, indicate in which version of Augeas # the lens became stock, so it will not be deployed @@ -15,21 +17,43 @@ # Example usage: # # augeas::lens { 'networkmanager': -# lens_source => 'puppet:///modules/networkmanager/lenses/networkmanager.aug', -# test_source => 'puppet:///modules/networkmanager/lenses/test_networkmanager.aug', -# stock_since => '1.0.0', +# lens_content => file('networkmanager/lenses/networkmanager.aug'), +# test_content => file('networkmanager/lenses/test_networkmanager.aug'), +# stock_since => '1.0.0', # } # define augeas::lens ( - $lens_source, - $ensure=present, - $test_source=false, - $stock_since=false, + $ensure = present, + $lens_content = undef, + $lens_source = undef, + $test_content = undef, + $test_source = undef, + $stock_since = false, ) { if !defined(Class['augeas']) { fail('You must declare the augeas class before using augeas::lens') } + if $lens_source != undef { + if $lens_content != undef { + fail "You can't set both \$lens_source and \$lens_content" + } else { + warning 'Passing "lens_source" is deprecated; please use "lens_content"' + } + } else { + if $lens_content == undef { + fail "You must set either \$lens_source or \$lens_content" + } + } + + if $test_source != undef { + if $test_content != undef { + fail "You can't set both \$test_source and \$test_content" + } else { + warning 'Passing "test_source" is deprecated; please use "test_content"' + } + } + File { owner => 'root', group => 'root', @@ -52,8 +76,9 @@ define augeas::lens ( $test_dest = "${augeas::lens_dir}/tests/test_${name}.aug" file { $lens_dest: - ensure => $ensure, - source => $lens_source, + ensure => $ensure, + source => $lens_source, + content => $lens_content, } exec { "Typecheck lens ${name}": @@ -64,9 +89,10 @@ define augeas::lens ( if $test_source { file { $test_dest: - ensure => $ensure, - source => $test_source, - notify => Exec["Test lens ${name}"], + ensure => $ensure, + source => $test_source, + content => $test_content, + notify => Exec["Test lens ${name}"], } exec { "Test lens ${name}": diff --git a/spec/defines/augeas_lens_spec.rb b/spec/defines/augeas_lens_spec.rb index 7feeefb..21dfd55 100644 --- a/spec/defines/augeas_lens_spec.rb +++ b/spec/defines/augeas_lens_spec.rb @@ -37,7 +37,7 @@ describe 'augeas::lens' do it 'should error' do expect { is_expected.to contain_file('/usr/share/augeas/lenses/foo.aug') - }.to raise_error(Puppet::Error, /Must pass lens_source/) + }.to raise_error(Puppet::Error, /You must set either \$lens_source or \$lens_content/) end end -- cgit v1.2.3