I can't think of a better solution, but I'm not real stoked about  
'node_exists?' returning something other than a boolean.

Do we have a general naming issue here?  Should 'node' return straight  
equality while 'match_node' (or some other new method) returns  
equality or regex comparison?

On Sep 15, 2009, at 12:03 PM, Brice Figureau wrote:

>
> When we are checking if a node exists before creating a new one
> we were also trying to match with regex node names, finding matches
> where in fact there is no equality.
>
> Signed-off-by: Brice Figureau <[email protected]>
> ---
> lib/puppet/parser/loaded_code.rb    |    4 ++++
> lib/puppet/parser/parser_support.rb |    2 +-
> spec/unit/parser/loaded_code.rb     |   19 ++++++++++++++++++-
> spec/unit/parser/parser.rb          |    2 +-
> 4 files changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/lib/puppet/parser/loaded_code.rb b/lib/puppet/parser/ 
> loaded_code.rb
> index 065fcb9..3efd115 100644
> --- a/lib/puppet/parser/loaded_code.rb
> +++ b/lib/puppet/parser/loaded_code.rb
> @@ -36,6 +36,10 @@ class Puppet::Parser::LoadedCode
>         nil
>     end
>
> +    def node_exists?(name)
> +        @nodes[check_name(name)]
> +    end
> +
>     def nodes?
>         @nodes.length > 0
>     end
> diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/ 
> parser_support.rb
> index dfc14e0..4fe2a5a 100644
> --- a/lib/puppet/parser/parser_support.rb
> +++ b/lib/puppet/parser/parser_support.rb
> @@ -376,7 +376,7 @@ class Puppet::Parser::Parser
>         doc = lexer.getcomment
>         names.collect do |name|
>             name = AST::HostName.new :value => name unless name.is_a? 
> (AST::HostName)
> -            if other = @loaded_code.node(name)
> +            if other = @loaded_code.node_exists?(name)
>                 error("Node %s is already defined at %s:%s; cannot  
> redefine" % [other.name, other.file, other.line])
>             end
>             name = name.to_s if name.is_a?(Symbol)
> diff --git a/spec/unit/parser/loaded_code.rb b/spec/unit/parser/ 
> loaded_code.rb
> index ca4b0aa..75f2bc7 100644
> --- a/spec/unit/parser/loaded_code.rb
> +++ b/spec/unit/parser/loaded_code.rb
> @@ -156,7 +156,24 @@ describe Puppet::Parser::LoadedCode do
>             nameout = Puppet::Parser::AST::HostName.new(:value =>  
> "foo")
>
>             @loader.add_node(namein, "bar")
> -            @loader.node(nameout) == "bar"
> +            @loader.node(nameout).should == "bar"
> +        end
> +
> +        it "should be able to find node by HostName strict  
> equality" do
> +            namein = Puppet::Parser::AST::HostName.new(:value =>  
> "foo")
> +            nameout = Puppet::Parser::AST::HostName.new(:value =>  
> "foo")
> +
> +            @loader.add_node(namein, "bar")
> +            @loader.node_exists?(nameout).should == "bar"
> +        end
> +
> +        it "should not use node name matching when finding with  
> strict node HostName" do
> +            name1 = Puppet::Parser::AST::HostName.new(:value =>  
> "foo")
> +            name2 = Puppet::Parser::AST::HostName.new(:value =>  
> Puppet::Parser::AST::Regex.new(:value => /foo/))
> +
> +            @loader.add_node(name1, "bar")
> +            @loader.add_node(name2, "baz")
> +            @loader.node_exists?(name1).should == "bar"
>         end
>
>         it "should return the first matching regex nodename" do
> diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
> index 9127599..842dc19 100755
> --- a/spec/unit/parser/parser.rb
> +++ b/spec/unit/parser/parser.rb
> @@ -253,7 +253,7 @@ describe Puppet::Parser do
>         end
>
>         it "should raise an error if the node already exists" do
> -            @loaded_code.stubs(:node).with(@nodename).returns(@node)
> +             
> @loaded_code.stubs(:node_exists?).with(@nodename).returns(@node)
>
>             lambda { @parser.newnode(@nodename) }.should raise_error
>         end
> -- 
> 1.6.4
>
>
> >


-- 
A diplomat is a man who can convince his wife she'd look stout in a fur
coat.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to