+1, nice fix to my error.

On Tue, Jul 13, 2010 at 11:54 AM, Matt Robinson <[email protected]> wrote:

> This came up because if you ran puppetd with a specific vardir, then
> when rundir got set to a hardcoded value its parent directory might not
> exist and the whole thing would fail.
>
> This change came about with the concept of run_mode, and this fix is
> restoring the behaviour that was in 0.25.x
>
> Reviewed-by: Jesse Wolfe
> Signed-off-by: Matt Robinson <[email protected]>
> ---
>  lib/puppet/util/run_mode.rb     |   18 +++++++-------
>  spec/unit/util/run_mode_spec.rb |   51
> +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 60 insertions(+), 9 deletions(-)
>  create mode 100644 spec/unit/util/run_mode_spec.rb
>
> diff --git a/lib/puppet/util/run_mode.rb b/lib/puppet/util/run_mode.rb
> index eb9c511..450cbf1 100644
> --- a/lib/puppet/util/run_mode.rb
> +++ b/lib/puppet/util/run_mode.rb
> @@ -40,17 +40,17 @@ module Puppet
>       end
>
>       def run_dir
> -        which_dir("/var/run/puppet", "~/.puppet/var")
> +        "$vardir/run"
>       end
>
>       def logopts
> -        if name == :master
> +        if master?
>           {
>             :default => "$vardir/log",
> -            :mode => 0750,
> -            :owner => "service",
> -            :group => "service",
> -            :desc => "The Puppet log directory."
> +            :mode    => 0750,
> +            :owner   => "service",
> +            :group   => "service",
> +            :desc    => "The Puppet log directory."
>           }
>         else
>           ["$vardir/log", "The Puppet log directory."]
> @@ -64,9 +64,9 @@ module Puppet
>         #       there's a comment that suggests that we do that
>         #       and we currently don't.
>         expand_path case
> -        when name == :master; global
> -        when Puppet.features.root?; global
> -        else user
> +          when name == :master; global
> +          when Puppet.features.root?; global
> +          else user
>         end
>       end
>
> diff --git a/spec/unit/util/run_mode_spec.rb
> b/spec/unit/util/run_mode_spec.rb
> new file mode 100644
> index 0000000..d6ab08a
> --- /dev/null
> +++ b/spec/unit/util/run_mode_spec.rb
> @@ -0,0 +1,51 @@
> +#!/usr/bin/env ruby
> +
> +require File.dirname(__FILE__) + '/../../spec_helper'
> +
> +describe Puppet::Util::RunMode do
> +  before do
> +    @run_mode = Puppet::Util::RunMode.new('fake')
> +  end
> +
> +  it "should have confdir /etc/puppet when run as root" do
> +    Puppet.features.stubs(:root?).returns(true)
> +    @run_mode.conf_dir.should == '/etc/puppet'
> +  end
> +
> +  it "should have confdir ~/.puppet when run as non-root" do
> +    Puppet.features.stubs(:root?).returns(false)
> +    @run_mode.expects(:expand_path).with("~/.puppet").returns("~/.puppet")
> +    @run_mode.conf_dir.should == "~/.puppet"
> +  end
> +
> +  it "should have vardir /var/lib/puppet when run as root" do
> +    Puppet.features.stubs(:root?).returns(true)
> +    @run_mode.var_dir.should == '/var/lib/puppet'
> +  end
> +
> +  it "should have vardir ~/.puppet/var when run as non-root" do
> +    Puppet.features.stubs(:root?).returns(false)
> +
>  
> @run_mode.expects(:expand_path).with("~/.puppet/var").returns("~/.puppet/var")
> +    @run_mode.var_dir.should == "~/.puppet/var"
> +  end
> +
> +  it "should have rundir depend on vardir" do
> +    @run_mode.run_dir.should == '$vardir/run'
> +  end
> +
> +  it "should have logopts return an array with $vardir/log if runmode is
> not master" do
> +    @run_mode.expects(:master?).returns false
> +    @run_mode.logopts.should == ["$vardir/log", "The Puppet log
> directory."]
> +  end
> +
> +  it "should have logopts return a hash with $vardir/log and other
> metadata if runmode is master" do
> +    @run_mode.expects(:master?).returns true
> +    @run_mode.logopts.should == {
> +      :default => "$vardir/log",
> +      :mode    => 0750,
> +      :owner   => "service",
> +      :group   => "service",
> +      :desc    => "The Puppet log directory.",
> +    }
> +  end
> +end
> --
> 1.7.1
>
> --
> 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]<puppet-dev%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en.
>
>

-- 
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