[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:30:55 UTC 2010


The following commit has been merged in the upstream branch:
commit 6651aa4fc84506b9d20076be28741516214c5d5d
Author: Luke Kanies <luke at reductivelabs.com>
Date:   Tue Jan 19 15:42:59 2010 -0800

    Adding first version of Resource::Status class
    
    This is the class that will be returned in reports,
    and they'll contain the events being created.
    
    Signed-off-by: Luke Kanies <luke at reductivelabs.com>

diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb
new file mode 100644
index 0000000..0ca295d
--- /dev/null
+++ b/lib/puppet/resource/status.rb
@@ -0,0 +1,51 @@
+class Puppet::Resource::Status
+    include Puppet::Util::Tagging
+    include Puppet::Util::Logging
+
+    ATTRIBUTES = [:resource, :node, :version, :file, :line, :current_values, :skipped_reason, :status, :evaluation_time]
+    attr_accessor *ATTRIBUTES
+
+    STATES = [:skipped, :failed, :changed, :out_of_sync, :scheduled]
+    attr_accessor *STATES
+
+    attr_reader :source_description, :default_log_level, :time, :resource
+
+    # Provide a boolean method for each of the states.
+    STATES.each do |attr|
+        define_method("#{attr}?") do
+            !! send(attr)
+        end
+    end
+
+    def <<(event)
+        add_event(event)
+        self
+    end
+
+    def add_event(event)
+        @events << event
+    end
+
+    def events
+        @events
+    end
+
+    def initialize(resource)
+        @source_description = resource.path
+        @resource = resource.to_s
+
+        [:file, :line, :version].each do |attr|
+            send(attr.to_s + "=", resource.send(attr))
+        end
+
+        tag(*resource.tags)
+        @time = Time.now
+        @events = []
+    end
+
+    private
+
+    def log_source
+        source_description
+    end
+end
diff --git a/spec/unit/resource/status.rb b/spec/unit/resource/status.rb
new file mode 100755
index 0000000..47f2959
--- /dev/null
+++ b/spec/unit/resource/status.rb
@@ -0,0 +1,103 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/resource/status'
+
+describe Puppet::Resource::Status do
+    before do
+        @resource = Puppet::Type.type(:file).new :path => "/my/file"
+        @status = Puppet::Resource::Status.new(@resource)
+    end
+
+    [:node, :version, :file, :line, :current_values, :skipped_reason, :status, :evaluation_time].each do |attr|
+        it "should support #{attr}" do
+            @status.send(attr.to_s + "=", "foo")
+            @status.send(attr).should == "foo"
+        end
+    end
+
+    [:skipped, :failed, :changed, :out_of_sync, :scheduled].each do |attr|
+        it "should support #{attr}" do
+            @status.send(attr.to_s + "=", "foo")
+            @status.send(attr).should == "foo"
+        end
+
+        it "should have a boolean method for determining whehter it was #{attr}" do
+            @status.send(attr.to_s + "=", "foo")
+            @status.should send("be_#{attr}")
+        end
+    end
+
+    it "should accept a resource at initialization" do
+        Puppet::Resource::Status.new(@resource).resource.should_not be_nil
+    end
+
+    it "should set its source description to the resource's path" do
+        @resource.expects(:path).returns "/my/path"
+        Puppet::Resource::Status.new(@resource).source_description.should == "/my/path"
+    end
+
+    [:file, :line, :version].each do |attr|
+        it "should copy the resource's #{attr}" do
+            @resource.expects(attr).returns "foo"
+            Puppet::Resource::Status.new(@resource).send(attr).should == "foo"
+        end
+    end
+
+    it "should copy the resource's tags" do
+        @resource.expects(:tags).returns %w{foo bar}
+        Puppet::Resource::Status.new(@resource).tags.should == %w{foo bar}
+    end
+
+    it "should always convert the resource to a string" do
+        @resource.expects(:to_s).returns "foo"
+        Puppet::Resource::Status.new(@resource).resource.should == "foo"
+    end
+
+    it "should support tags" do
+        Puppet::Resource::Status.ancestors.should include(Puppet::Util::Tagging)
+    end
+
+    it "should create a timestamp at its creation time" do
+        @status.time.should be_instance_of(Time)
+    end
+
+    describe "when sending logs" do
+        before do
+            Puppet::Util::Log.stubs(:new)
+        end
+
+        it "should set the tags to the event tags" do
+            Puppet::Util::Log.expects(:new).with { |args| args[:tags] == %w{one two} }
+            @status.stubs(:tags).returns %w{one two}
+            @status.send_log :notice, "my message"
+        end
+
+        [:file, :line, :version].each do |attr|
+            it "should pass the #{attr}" do
+                Puppet::Util::Log.expects(:new).with { |args| args[attr] == "my val" }
+                @status.send(attr.to_s + "=", "my val")
+                @status.send_log :notice, "my message"
+            end
+        end
+
+        it "should use the source description as the source" do
+            Puppet::Util::Log.expects(:new).with { |args| args[:source] == "my source" }
+            @status.stubs(:source_description).returns "my source"
+            @status.send_log :notice, "my message"
+        end
+    end
+
+    it "should support adding events" do
+        event = Puppet::Transaction::Event.new(:name => :foobar)
+        @status.add_event(event)
+        @status.events.should == [event]
+    end
+
+    it "should use '<<' to add events" do
+        event = Puppet::Transaction::Event.new(:name => :foobar)
+        (@status << event).should equal(@status)
+        @status.events.should == [event]
+    end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list