[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5-303-gfcfa26a
Paul Berry
paul at puppetlabs.com
Thu Mar 17 10:47:48 UTC 2011
The following commit has been merged in the upstream branch:
commit 23b711954b1c1ba8deb4035503797c2f38a8ce12
Author: Paul Berry <paul at puppetlabs.com>
Date: Wed Feb 23 14:59:13 2011 -0800
Maint: Add an assertion mechanism to Puppet
This patch allows us to make C-style "assertions" in Puppet code,
e.g.:
assert_that { condition }
assert_that(message) { condition }
These methods will raise an exception if the environment variable
PUPPET_ENABLE_ASSERTIONS is set to a non-empty value, and the the
condition evaluates to false. If the environment variable
PUPPET_ENABLE_ASSERTIONS is not set, then the condition is not even
checked.
Switching the assertions on with PUPPET_ENABLE_ASSERTIONS carries
three advantages:
1. It makes it possible to put potentially expensive checks in
assertions without degrading the performance of the code in production
environments.
2. It allows strict assertions to catch Puppet bugs early in
development, without increasing the risk of a crash in production
environments.
3. It allows a simple command-line mechanism to run any Puppet command
with assertions enabled.
diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb
index 6b5af83..85854a0 100644
--- a/lib/puppet/util/monkey_patches.rb
+++ b/lib/puppet/util/monkey_patches.rb
@@ -48,3 +48,21 @@ if RUBY_VERSION == '1.8.7'
end
end
+class Object
+ # The following code allows callers to make assertions that are only
+ # checked when the environment variable PUPPET_ENABLE_ASSERTIONS is
+ # set to a non-empty string. For example:
+ #
+ # assert_that { condition }
+ # assert_that(message) { condition }
+ if ENV["PUPPET_ENABLE_ASSERTIONS"].to_s != ''
+ def assert_that(message = nil)
+ unless yield
+ raise Exception.new("Assertion failure: #{message}")
+ end
+ end
+ else
+ def assert_that(message = nil)
+ end
+ end
+end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list