Luke Kanies a écrit :
> On Nov 27, 2009, at 8:43 AM, Yannick Perret wrote:
>
>   
>> Hello,
>>
>> the incident #2527 is related to the lack of control of loglevel on
>> puppetd program.
>>
>> This lack is still present in 0.25.1.
>> I wrote a patch for puppetd.rb code (located at
>> /usr/lib/ruby/site_ruby/1.8/puppet/application/puppetd.rb on my  
>> client).
>>
>> This patch adds an option "--loglevel" which accept
>> debug/notice/warning/... parameters. This loglevel is applied,  
>> appart if
>> an other option set the loglevel (i.e. --test).
>> If the given loglevel is not valid the current default loglevel is  
>> used.
>>
>> As I'm not very familiar with ruby code neigther with puppet code
>> structure, please feel free to review it.
>>
>> Here is the patch:
>> (...)
> This is much easier with something like:
>
> (...)
>
> No need for a huge case statement.
> (...)
>   
> I think there's some duplication of logic here, in that you're setting  
> the level to info at least three different places.
>
>   
You are right. As I said I'm still not familiar with ruby syntax (but 
I'm learning...).
I did not know the .to_sym which makes it easier. I also now set the 
default loglevel at the :loglevel creation, so that it is :info unless 
the option is used to overwrite it, which prevent the duplicated 'info' 
treatment.

A new version of the patch is available at the end.

> And it shouldn't be too hard to have some tests for this.
>   
Well, I can try this. As far as I can see I should look to RSpec, right? 
At this time I do not have imported git or so, just patched my installed 
sources. But how can I test such feature? I mean, how to check that the 
client will only print at the given loglevel?

Thanks for the help.

Regards,
--
Yannick



--- puppetd.rb    2009-11-27 15:43:29.191196367 +0100
+++ puppetd.new.rb    2009-11-27 21:13:32.731051572 +0100
@@ -25,6 +25,7 @@
             :debug => false,
             :centrallogs => false,
             :setdest => false,
+        :loglevel => :info,
             :enable => false,
             :disable => false,
             :client => true,
@@ -86,6 +87,10 @@
         @args[:Port] = arg
     end
 
+    option("--loglevel LOGLEVEL") do |arg|
+    options[:loglevel] = arg
+    end
+
     dispatch do
         return :onetime if options[:onetime]
         return :main
@@ -135,7 +140,12 @@
             if options[:debug]
                 Puppet::Util::Log.level = :debug
             else
-                Puppet::Util::Log.level = :info
+                begin
+                    Puppet::Util::Log.level = options[:loglevel].to_sym
+                rescue => detail
+                    Puppet.warning "Invalid loglevel %s, using info" % 
options[:loglevel]
+                    Puppet::Util::Log.level = :info
+                end
             end
         end
 

--

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