Fixing #1242 -- lack of storeconfigs only produces warning, not exception.

Exporting or collecting resources no longer raises an exception
when no storeconfigs is enabled, it just produces a warning.
This commit is contained in:
Luke Kanies 2008-05-26 22:33:26 -05:00
Родитель 3d51a287e8
Коммит 65c1889f09
5 изменённых файлов: 24 добавлений и 6 удалений

Просмотреть файл

@ -1,3 +1,6 @@
Exporting or collecting resources no longer raises an exception
when no storeconfigs is enabled, it just produces a warning.
Always using the cert name to store yaml files, which fixes #1178. Always using the cert name to store yaml files, which fixes #1178.
The Master handler previously provided the support for the :node_name The Master handler previously provided the support for the :node_name
setting, and that functionality has now been moved into the Node setting, and that functionality has now been moved into the Node

Просмотреть файл

@ -6,6 +6,12 @@ class Puppet::Parser::Collector
# Call the collection method, mark all of the returned objects as non-virtual, # Call the collection method, mark all of the returned objects as non-virtual,
# and then delete this object from the list of collections to evaluate. # and then delete this object from the list of collections to evaluate.
def evaluate def evaluate
# Shortcut if we're not using storeconfigs and they're trying to collect
# exported resources.
if form == :exported and Puppet[:storeconfigs] != true
Puppet.warning "Not collecting exported resources without storeconfigs"
return false
end
if self.resources if self.resources
if objects = collect_resources and ! objects.empty? if objects = collect_resources and ! objects.empty?
return objects return objects

Просмотреть файл

@ -152,7 +152,7 @@ virtualresource: at resource {
type = val[0] type = val[0]
if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly]
error "You cannot collect without storeconfigs being set" Puppet.warning addcontext("You cannot collect without storeconfigs being set")
end end
if val[1].is_a? AST::ResourceDefaults if val[1].is_a? AST::ResourceDefaults
@ -193,7 +193,7 @@ collection: classref collectrhand {
args[:form] = val[1] args[:form] = val[1]
end end
if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly]
error "You cannot collect exported resources without storeconfigs being set" Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored")
end end
result = ast AST::Collection, args result = ast AST::Collection, args
} }

Просмотреть файл

@ -29,7 +29,7 @@ module Puppet
class Parser < Racc::Parser class Parser < Racc::Parser
module_eval <<'..end grammar.ra modeval..idfef5d70c9f', 'grammar.ra', 638 module_eval <<'..end grammar.ra modeval..id9145566289', 'grammar.ra', 638
# It got too annoying having code in a file that needs to be compiled. # It got too annoying having code in a file that needs to be compiled.
require 'puppet/parser/parser_support' require 'puppet/parser/parser_support'
@ -41,7 +41,7 @@ require 'puppet/parser/parser_support'
# $Id$ # $Id$
..end grammar.ra modeval..idfef5d70c9f ..end grammar.ra modeval..id9145566289
##### racc 1.4.5 generates ### ##### racc 1.4.5 generates ###
@ -958,7 +958,7 @@ module_eval <<'.,.,', 'grammar.ra', 174
type = val[0] type = val[0]
if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly]
error "You cannot collect without storeconfigs being set" Puppet.warning addcontext("You cannot collect without storeconfigs being set")
end end
if val[1].is_a? AST::ResourceDefaults if val[1].is_a? AST::ResourceDefaults
@ -1011,7 +1011,7 @@ module_eval <<'.,.,', 'grammar.ra', 199
args[:form] = val[1] args[:form] = val[1]
end end
if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly]
error "You cannot collect exported resources without storeconfigs being set" Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored")
end end
result = ast AST::Collection, args result = ast AST::Collection, args
result result

Просмотреть файл

@ -204,6 +204,8 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@equery = "test = true" @equery = "test = true"
@vquery = proc { |r| true } @vquery = proc { |r| true }
Puppet.settings.stubs(:value).with(:storeconfigs).returns true
@collector = Puppet::Parser::Collector.new(@scope, @resource_type, @equery, @vquery, :exported) @collector = Puppet::Parser::Collector.new(@scope, @resource_type, @equery, @vquery, :exported)
end end
@ -217,6 +219,11 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
end end
end end
it "should just return false if :storeconfigs is not enabled" do
Puppet.settings.expects(:value).with(:storeconfigs).returns false
@collector.evaluate.should be_false
end
it "should use initialize the Rails support if ActiveRecord is not connected" do it "should use initialize the Rails support if ActiveRecord is not connected" do
@compiler.stubs(:resources).returns([]) @compiler.stubs(:resources).returns([])
ActiveRecord::Base.expects(:connected?).returns(false) ActiveRecord::Base.expects(:connected?).returns(false)
@ -375,6 +382,8 @@ describe Puppet::Parser::Collector, "when building its ActiveRecord query for co
Puppet::Rails.stubs(:init) Puppet::Rails.stubs(:init)
Puppet::Rails::Host.stubs(:find_by_name).returns(nil) Puppet::Rails::Host.stubs(:find_by_name).returns(nil)
Puppet::Rails::Resource.stubs(:find).returns([]) Puppet::Rails::Resource.stubs(:find).returns([])
Puppet.settings.stubs(:value).with(:storeconfigs).returns true
end end
it "should exclude all resources from the host if ActiveRecord contains information for this host" do it "should exclude all resources from the host if ActiveRecord contains information for this host" do