Re: [PATCH 1/1] Fixes BUG #2250 - Error message for a missing template could be clearer

3 views
Skip to first unread message

Stéphan Gorget

unread,
May 13, 2009, 6:18:22 PM5/13/09
to Stéphan Gorget, puppe...@googlegroups.com
The spec tests wasn't working before the patch and still can't work
because of the slef-generate methods (in this precise case
template(file)) that aren't exist in the mock object, is there a way
to by-pass it ?

btw, the repo is here :
http://github.com/phantez/puppet/tree/tickets/master/2250

--
Stéphan Gorget

On Thu, May 14, 2009 at 12:15 AM, Stéphan Gorget <pha...@gmail.com> wrote:
> From: Stéphan Gorget <pha...@gmail.com>
>
> Signed-off-by: Stéphan Gorget <pha...@gmail.com>
> Signed-off-by: Stéphan Gorget <pha...@gmail.com>
> ---
>  lib/puppet/module.rb |    5 ++++-
>  spec/unit/module.rb  |    6 +++---
>  2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
> index 45b4069..284aa37 100644
> --- a/lib/puppet/module.rb
> +++ b/lib/puppet/module.rb
> @@ -78,7 +78,10 @@ class Puppet::Module
>         # check in the default template dir, if there is one
>         unless td_file = find_template_for_module(template, environment)
>             raise Puppet::Error, "No valid template directory found, please check templatedir settings" if template_paths.nil?
> -            td_file = File::join(template_paths.first, template)
> +            unless templ = template_paths.first
> +                templ = ""
> +            end
> +            td_file = File::join(templ, template)
>         end
>         td_file
>     end
> diff --git a/spec/unit/module.rb b/spec/unit/module.rb
> index 313de67..323defa 100755
> --- a/spec/unit/module.rb
> +++ b/spec/unit/module.rb
> @@ -172,7 +172,7 @@ describe Puppet::Module, " when searching for templates" do
>
>     it "should return the template from the first found module" do
>         mod = mock 'module'
> -        Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
> +        Puppet::Node::Environment.new("myenv").expects(:module).with("mymod").returns mod
>
>         mod.expects(:template).returns("/one/mymod/templates/mytemplate")
>         Puppet::Module.find_template("mymod/mytemplate").should == "/one/mymod/templates/mytemplate"
> @@ -193,7 +193,7 @@ describe Puppet::Module, " when searching for templates" do
>
>     it "should not raise an error if no valid templatedir exists and the template exists in a module" do
>         mod = mock 'module'
> -        Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
> +        Puppet::Node::Environment.new("myenv").expects(:module).with("mymod").returns mod
>
>         mod.expects(:template).returns("/one/mymod/templates/mytemplate")
>         Puppet::Module.stubs(:templatepath).with(nil).returns(nil)
> @@ -306,7 +306,7 @@ describe Puppet::Module, " when searching for manifests in a found module" do
>
>     it "should return the manifests from the first found module" do
>         mod = mock 'module'
> -        Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
> +        Puppet::Node::Environment.new("myenv").expects(:module).with("mymod").returns mod
>         mod.expects(:match_manifests).with("init.pp").returns(%w{/one/mymod/manifests/init.pp})
>         Puppet::Module.find_manifests("mymod/init.pp").should == ["/one/mymod/manifests/init.pp"]
>     end
> --
> 1.6.2.4
>
>

phantez

unread,
May 13, 2009, 6:21:12 PM5/13/09
to Puppet Developers
Due to a server mail the first mail reach my gmail box but was not
accepted by google groups. I will repost everything.

On 14 mai, 00:18, Stéphan Gorget <phan...@gmail.com> wrote:
> The spec tests wasn't working before the patch and still can't work
> because of the slef-generate methods (in this precise case
> template(file)) that aren't exist in the mock object, is there a way
> to by-pass it ?
>
> btw, the repo is here :http://github.com/phantez/puppet/tree/tickets/master/2250
>
> --
> Stéphan Gorget
>
> On Thu, May 14, 2009 at 12:15 AM, Stéphan Gorget <phan...@gmail.com> wrote:
> > From: Stéphan Gorget <phan...@gmail.com>
>
> > Signed-off-by: Stéphan Gorget <phan...@gmail.com>
> > Signed-off-by: Stéphan Gorget <phan...@gmail.com>

Stéphan Gorget

unread,
May 13, 2009, 6:21:27 PM5/13/09
to puppe...@googlegroups.com
Signed-off-by: Stéphan Gorget <pha...@gmail.com>

Stéphan Gorget

unread,
May 14, 2009, 4:09:17 AM5/14/09
to puppe...@googlegroups.com
The tests passes well on my centos boxes, but aren't on my debian and
ubuntu ones.

Debian configuration :
$ ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
$ gem list --local

*** LOCAL GEMS ***

builder (2.1.2)
ci_reporter (1.5.3)
cucumber (0.3.1)
diff-lcs (1.1.2)
hoe (1.12.2)
mocha (0.9.5)
polyglot (0.2.5)
rake (0.8.4)
rspec (1.2.2)
rubyforge (1.0.3)
term-ansicolor (1.0.3)
treetop (1.2.5)

output without the patch : http://pastie.org/477740
output with the patch : http://pastie.org/477742

Stéphan

Luke Kanies

unread,
May 14, 2009, 11:08:14 AM5/14/09
to puppe...@googlegroups.com
I'm a bit confused on this - the tests didn't work before, and now
they still don't work but have a different error?
--
If a dog jumps onto your lap it is because he is fond of you; but if a
cat does the same thing it is because your lap is warmer.
-- Alfred North Whitehead
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

Stéphan Gorget

unread,
May 14, 2009, 5:14:34 PM5/14/09
to puppe...@googlegroups.com
I tried to fix the bug and to make the spec pass on my debian
computer. I realized that the tests did not pass even with the patch
because of the Environment::initialize() that requires an argument,
but If I specified an argument then it breaks a bit farther on debian
because of the template() function which is not created (it is an auto
generated method).

On my CentOS computer (CentOS 5.2) everything works fine without the
patch but with the argument specified in Environment::initialize() the
behaviour changes and it makes the tests break.

Stéphan

James Turnbull

unread,
May 14, 2009, 10:06:12 PM5/14/09
to puppe...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stéphan Gorget wrote:
> Signed-off-by: Stéphan Gorget <pha...@gmail.com>
> ---
> lib/puppet/module.rb | 5 ++++-
> spec/unit/module.rb | 6 +++---
> 2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
> index 45b4069..284aa37 100644
> --- a/lib/puppet/module.rb
> +++ b/lib/puppet/module.rb
> @@ -78,7 +78,10 @@ class Puppet::Module
> # check in the default template dir, if there is one
> unless td_file = find_template_for_module(template, environment)
> raise Puppet::Error, "No valid template directory found, please check templatedir settings" if template_paths.nil?
> - td_file = File::join(template_paths.first, template)
> + unless templ = template_paths.first
> + templ = ""
> + end
> + td_file = File::join(templ, template)
> end

Whilst kudos for fixing the bug as such shouldn't we also add something
in the way of an error message?

Or maybe I am missing something.

James

- --
Author of:
* Pro Linux Systems Administration
(http://www.amazon.com/gp/product/1430219122/)
* Pulling Strings with Puppet
(http://www.amazon.com/gp/product/1590599780/)
* Pro Nagios 2.0
(http://www.amazon.com/gp/product/1590596099/)
* Hardening Linux
(http://www.amazon.com/gp/product/1590594444/)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkoMzhQACgkQ9hTGvAxC30DpsgCgs2jm+BwcqEYmaIw8nVjyBsbI
0ogAoNLbVnRwqRue8OP7TB6zbNOetf30
=ihB+
-----END PGP SIGNATURE-----

Stéphan Gorget

unread,
May 15, 2009, 12:54:11 AM5/15/09
to puppe...@googlegroups.com
In fact the error is catch higher by a function that test if the file
exist. And it produces the output "Template does not exist....
file.pp". But this error message right know cannot be reached because
the File.join(nil,<string>) generate an error that is why I put ""
instead of nil in the join arguments.

Stéphan

Luke Kanies

unread,
May 15, 2009, 1:01:17 AM5/15/09
to puppe...@googlegroups.com

This is why I added the new ticket for the module API - we should fix
this issue, but we should fix it using this new API. And it should be
straightforward to do so.

--
I'm worried about Bart. Today, he's sucking people's blood,
tommorrow he might be smoking. -Marge Simpson

Luke Kanies

unread,
May 18, 2009, 10:47:51 AM5/18/09
to puppe...@googlegroups.com
I've refactored the code around this so it fails correctly, and you
shouldn't be getting any failures with modules at all now.

If you are, please file that as a new ticket.
--
My definition of an expert in any field is a person who knows enough
about what's really going on to be scared. -- P. J. Plauger
Reply all
Reply to author
Forward
0 new messages