summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/validate_augeas.rb
diff options
context:
space:
mode:
authorRaphaël Pinson <raphael.pinson@camptocamp.com>2013-01-18 21:42:54 +0100
committerRaphaël Pinson <raphael.pinson@camptocamp.com>2013-01-18 22:02:13 +0100
commit41bc722139028929b9ab1f9a14b318d1a23206f9 (patch)
tree389b784f59bef319ad7a9aa58f8956ba9fcfd2ca /lib/puppet/parser/functions/validate_augeas.rb
parent3a97c2314c67245be3190cc485cff63e40a833fd (diff)
downloadpuppet-stdlib-41bc722139028929b9ab1f9a14b318d1a23206f9.tar.gz
puppet-stdlib-41bc722139028929b9ab1f9a14b318d1a23206f9.tar.bz2
validate_augeas: Ensure augeas handler gets closed
Diffstat (limited to 'lib/puppet/parser/functions/validate_augeas.rb')
-rw-r--r--lib/puppet/parser/functions/validate_augeas.rb55
1 files changed, 29 insertions, 26 deletions
diff --git a/lib/puppet/parser/functions/validate_augeas.rb b/lib/puppet/parser/functions/validate_augeas.rb
index 01a2e91..273b954 100644
--- a/lib/puppet/parser/functions/validate_augeas.rb
+++ b/lib/puppet/parser/functions/validate_augeas.rb
@@ -17,7 +17,7 @@ module Puppet::Parser::Functions
Or if you wanted to ensure that no users used the '/bin/barsh' shell,
you could use:
-
+
validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
If a fourth argument is specified, this will be the error message raised and
@@ -36,35 +36,38 @@ module Puppet::Parser::Functions
require 'augeas'
aug = Augeas::open(nil, nil, Augeas::NO_MODL_AUTOLOAD)
+ begin
+ content = args[0]
- content = args[0]
-
- # Test content in a temporary file
- tmpfile = Tempfile.new("validate_augeas")
- tmpfile.write(content)
- tmpfile.close
+ # Test content in a temporary file
+ tmpfile = Tempfile.new("validate_augeas")
+ tmpfile.write(content)
+ tmpfile.close
- # Check for syntax
- lens = args[1]
- aug.transform(
- :lens => lens,
- :name => 'Validate_augeas',
- :incl => tmpfile.path
- )
- aug.load!
+ # Check for syntax
+ lens = args[1]
+ aug.transform(
+ :lens => lens,
+ :name => 'Validate_augeas',
+ :incl => tmpfile.path
+ )
+ aug.load!
- unless aug.match("/augeas/files#{tmpfile.path}//error").empty?
- error = aug.get("/augeas/files#{tmpfile.path}//error/message")
- msg += " with error: #{error}"
- raise Puppet::ParseError, (msg)
- end
+ unless aug.match("/augeas/files#{tmpfile.path}//error").empty?
+ error = aug.get("/augeas/files#{tmpfile.path}//error/message")
+ msg += " with error: #{error}"
+ raise Puppet::ParseError, (msg)
+ end
- # Launch unit tests
- tests = args[2] || []
- aug.defvar('file', "/files#{tmpfile.path}")
- tests.each do |t|
- msg += " testing path #{t}"
- raise Puppet::ParseError, (msg) unless aug.match(t).empty?
+ # Launch unit tests
+ tests = args[2] || []
+ aug.defvar('file', "/files#{tmpfile.path}")
+ tests.each do |t|
+ msg += " testing path #{t}"
+ raise Puppet::ParseError, (msg) unless aug.match(t).empty?
+ end
+ ensure
+ aug.close
end
end
end