[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:31:52 UTC 2010


The following commit has been merged in the upstream branch:
commit d8e1b272ec321d5f86558672252de60983751a15
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Thu Mar 18 18:48:46 2010 -0700

    Feature #3394 REST runner, execution
    
    puppetrun uses REST to trigger puppet runs.

diff --git a/lib/puppet/application/run.rb b/lib/puppet/application/run.rb
index f08fade..26ca362 100644
--- a/lib/puppet/application/run.rb
+++ b/lib/puppet/application/run.rb
@@ -112,14 +112,22 @@ Puppet::Application.new(:run) do
                 next
             end
         end
-        client = Puppet::Network::Client.runner.new(
-            :Server => host,
-            :Port => Puppet[:puppetport]
-        )
+
+        require 'puppet/run'
+        Puppet::Run.indirection.terminus_class = :rest
+        port = Puppet[:puppetport]
+        url = ["https://#{host}:#{port}", "production", "run", host].join('/')
 
         print "Triggering %s\n" % host
         begin
-            result = client.run(@tags, options[:ignoreschedules] || false, options[:foreground] || false)
+            request = Puppet::Indirector::Request.new(:run, :save, url) # Yuck.
+            run_options = {
+                :tags => @tags,
+                :background => ! options[:foreground],
+                :ignoreschedules => options[:ignoreschedules]
+            }
+            run = Puppet::Run.new( run_options ).save( request )
+            result = run.status
         rescue => detail
             puts detail.backtrace if Puppet[:trace]
             $stderr.puts "Host %s failed: %s\n" % [host, detail]
@@ -183,12 +191,6 @@ Puppet::Application.new(:run) do
             exit(24)
         end
 
-        if @tags.empty?
-            @tags = ""
-        else
-            @tags = @tags.join(",")
-        end
-
         @children = {}
 
         # If we get a signal, then kill all of our children and get out.
diff --git a/lib/puppet/indirector/run/local.rb b/lib/puppet/indirector/run/local.rb
new file mode 100644
index 0000000..5e8f349
--- /dev/null
+++ b/lib/puppet/indirector/run/local.rb
@@ -0,0 +1,8 @@
+require 'puppet/run'
+require 'puppet/indirector/code'
+
+class Puppet::Run::Local < Puppet::Indirector::Code
+    def save( request )
+        request.instance.run
+    end
+end
diff --git a/lib/puppet/run.rb b/lib/puppet/run.rb
index 1503f5d..20e21dc 100644
--- a/lib/puppet/run.rb
+++ b/lib/puppet/run.rb
@@ -6,7 +6,7 @@ require 'puppet/indirector'
 # puppetrun to kick off agents remotely.
 class Puppet::Run
     extend Puppet::Indirector
-    indirects :runner, :terminus_class => :rest
+    indirects :run, :terminus_class => :local
 
     attr_reader :status, :background, :options
 
@@ -26,7 +26,7 @@ class Puppet::Run
 
         valid_options = [:tags, :ignoreschedules]
         options.each do |key, value|
-            raise ArgumentError, "Runner does not accept %s" % key unless valid_options.include?(key)
+            raise ArgumentError, "Run does not accept %s" % key unless valid_options.include?(key)
         end
 
         @options = options
@@ -36,7 +36,7 @@ class Puppet::Run
         msg = ""
         msg += "triggered run" %
         if options[:tags]
-            msg += " with tags %s" % options[:tags]
+            msg += " with tags #{options[:tags].inspect}"
         end
 
         if options[:ignoreschedules]
@@ -49,7 +49,7 @@ class Puppet::Run
     def run
         if agent.running?
             @status = "running"
-            return
+            return self
         end
 
         log_run()
@@ -61,5 +61,20 @@ class Puppet::Run
         end
 
         @status = "success"
+
+        self
+    end
+
+    def self.from_pson( pson )
+        options = {}
+        pson.each do |key, value|
+            options[key.to_sym] = value
+        end
+
+        new(options)
+    end
+
+    def to_pson
+        @options.merge(:background => @background).to_pson
     end
 end
diff --git a/spec/unit/application/puppetrun.rb b/spec/unit/application/puppetrun.rb
index 271fd6c..ce3af5a 100755
--- a/spec/unit/application/puppetrun.rb
+++ b/spec/unit/application/puppetrun.rb
@@ -213,9 +213,6 @@ describe "run" do
 
         describe "the main command" do
             before :each do
-                @client = stub_everything 'client'
-                @client.stubs(:run).returns("success")
-                Puppet::Network::Client.runner.stubs(:new).returns(@client)
                 @run.options.stubs(:[]).with(:parallel).returns(1)
                 @run.options.stubs(:[]).with(:ping).returns(false)
                 @run.options.stubs(:[]).with(:ignoreschedules).returns(false)
@@ -248,20 +245,26 @@ describe "run" do
             end
 
             describe "during call of run_for_host" do
-                it "should create a Runner Client per given host" do
-                    Puppet::Network::Client.runner.expects(:new).returns(@client)
-
-                    @run.run_for_host('host')
+                before do
+                    require 'puppet/run'
+                    options = {
+                        :background => true, :ignoreschedules => false, :tags => []
+                    }
+                    @run = Puppet::Run.new( options.dup )
+                    @run.stubs(:status).returns("success")
+
+                    Puppet::Run.indirection.expects(:terminus_class=).with( :rest )
+                    Puppet::Run.expects(:new).with( options ).returns(@run)
                 end
 
-                it "should call Client.run for the given host" do
-                    @client.expects(:run)
+                it "should call run on a Puppet::Run for the given host" do
+                    @run.expects(:save).with{|req| req.uri == 'https://host:8139/production/run/host'}.returns(@run)
 
                     @run.run_for_host('host')
                 end
 
                 it "should exit the child with 0 on success" do
-                    @client.stubs(:run).returns("success")
+                    @run.stubs(:status).returns("success")
 
                     @run.expects(:exit).with(0)
 
@@ -269,7 +272,7 @@ describe "run" do
                 end
 
                 it "should exit the child with 3 on running" do
-                    @client.stubs(:run).returns("running")
+                    @run.stubs(:status).returns("running")
 
                     @run.expects(:exit).with(3)
 
@@ -277,7 +280,7 @@ describe "run" do
                 end
 
                 it "should exit the child with 12 on unknown answer" do
-                    @client.stubs(:run).returns("whatever")
+                    @run.stubs(:status).returns("whatever")
 
                     @run.expects(:exit).with(12)
 
diff --git a/spec/unit/indirector/run/local.rb b/spec/unit/indirector/run/local.rb
new file mode 100644
index 0000000..face61d
--- /dev/null
+++ b/spec/unit/indirector/run/local.rb
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/run/local'
+
+describe Puppet::Run::Local do
+    it "should be a sublcass of Puppet::Indirector::Code" do
+        Puppet::Run::Local.superclass.should equal(Puppet::Indirector::Code)
+    end
+
+    it "should call runner.run on save and return the runner" do
+        runner  = Puppet::Run.new
+        runner.stubs(:run).returns(runner)
+
+        request = Puppet::Indirector::Request.new(:indirection, :save, "anything")
+        request.instance = runner = Puppet::Run.new
+        Puppet::Run::Local.new.save(request).should == runner
+    end
+end
diff --git a/spec/unit/indirector/run/rest.rb b/spec/unit/indirector/run/rest.rb
index e07fe7f..ee976ed 100755
--- a/spec/unit/indirector/run/rest.rb
+++ b/spec/unit/indirector/run/rest.rb
@@ -2,7 +2,7 @@
 
 require File.dirname(__FILE__) + '/../../../spec_helper'
 
-require 'puppet/indirector/runner/rest'
+require 'puppet/indirector/run/rest'
 
 describe Puppet::Run::Rest do
     it "should be a sublcass of Puppet::Indirector::REST" do
diff --git a/spec/unit/run.rb b/spec/unit/run.rb
index 57eff0f..4c5f6b1 100755
--- a/spec/unit/run.rb
+++ b/spec/unit/run.rb
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../spec_helper'
 require 'puppet/agent'
 require 'puppet/run'
 
@@ -9,8 +9,8 @@ describe Puppet::Run do
         @runner = Puppet::Run.new
     end
 
-    it "should indirect :runner" do
-        Puppet::Run.indirection.name.should == :runner
+    it "should indirect :run" do
+        Puppet::Run.indirection.name.should == :run
     end
 
     it "should use a configurer agent as its agent" do
@@ -115,4 +115,20 @@ describe Puppet::Run do
             @runner.run
         end
     end
+
+    describe ".from_pson" do
+        it "should accept a hash of options, and pass them with symbolified keys to new" do
+            options = {
+                "tags" => "whatever",
+                "background" => true,
+            }
+
+            Puppet::Run.expects(:new).with({
+                :tags => "whatever",
+                :background => true,
+            })
+
+            Puppet::Run.from_pson(options)
+        end
+    end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list