diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2010-05-19 23:44:30 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 738802e1a56312c468e99a43c0ffd64dd47c4382 (patch) | |
| tree | 42c2ac28e9d7f3f7384504e41fedb466a27b0073 | |
| parent | 50a626daa1bef956ea63c405fddeaeab8a9a0756 (diff) | |
| download | puppet-738802e1a56312c468e99a43c0ffd64dd47c4382.tar.gz puppet-738802e1a56312c468e99a43c0ffd64dd47c4382.tar.xz puppet-738802e1a56312c468e99a43c0ffd64dd47c4382.zip | |
Fixing #2337 - Adding 'freeze_main' setting
This disables adding any code to 'main' except
in site.pp, so if you have code outside of a node,
class, or define it will throw an exception.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
| -rw-r--r-- | lib/puppet/defaults.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/resource/type.rb | 1 | ||||
| -rwxr-xr-x | spec/unit/resource/type.rb | 8 |
3 files changed, 13 insertions, 1 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 9de73f526..f2e498d5a 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -169,7 +169,10 @@ module Puppet return code, the entire Puppet run will fail."], :postrun_command => ["", "A command to run after every agent run. If this command returns a non-zero return code, the entire Puppet run will be considered to have failed, even though it might have - performed work during the normal run."] + performed work during the normal run."], + :freeze_main => [false, "Freezes the 'main' class, disallowing any code to be added to it. This + essentially means that you can't have any code outside of a node, class, or definition other + than in the site manifest."] ) hostname = Facter["hostname"].value diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index e13b1834e..e60f87953 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -106,6 +106,7 @@ class Puppet::Resource::Type def merge(other) fail "#{name} is not a class; cannot add code to it" unless type == :hostclass fail "#{other.name} is not a class; cannot add code from it" unless other.type == :hostclass + fail "Cannot have code outside of a class/node/define because 'freeze_main' is enabled" if name == "" and Puppet.settings[:freeze_main] if parent and other.parent and parent != other.parent fail "Cannot merge classes with different parent classes (#{name} => #{parent} vs. #{other.name} => #{other.parent})" diff --git a/spec/unit/resource/type.rb b/spec/unit/resource/type.rb index 3d0e82498..514e6943b 100755 --- a/spec/unit/resource/type.rb +++ b/spec/unit/resource/type.rb @@ -586,6 +586,14 @@ describe Puppet::Resource::Type do lambda { code.hostclass("b").merge(code.hostclass("d")) }.should raise_error(Puppet::Error) end + it "should fail if it's named 'main' and 'freeze_main' is enabled" do + Puppet.settings[:freeze_main] = true + code = Puppet::Resource::TypeCollection.new("env") + code.add Puppet::Resource::Type.new(:hostclass, "") + other = Puppet::Resource::Type.new(:hostclass, "") + lambda { code.hostclass("").merge(other) }.should raise_error(Puppet::Error) + end + it "should copy the other class's parent if it has not parent" do dest = Puppet::Resource::Type.new(:hostclass, "bar") |
