summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominic Maraglia <dmaraglia@gmail.com>2011-05-03 17:59:26 -0700
committerDominic Maraglia <dmaraglia@gmail.com>2011-05-03 17:59:26 -0700
commite5b62d7424da24799c4d16f0e104fac3008e2b89 (patch)
tree7d2d710fa43c39dd35d96cc2db371c548a85518f
parent94f0b0996ba628f4916bcf0978b29c584c15818b (diff)
parentd203853bc8b40732c2ba88a4e5396f00a1e3a4ec (diff)
downloadpuppet-e5b62d7424da24799c4d16f0e104fac3008e2b89.tar.gz
puppet-e5b62d7424da24799c4d16f0e104fac3008e2b89.tar.xz
puppet-e5b62d7424da24799c4d16f0e104fac3008e2b89.zip
Merge branch '2.7.x' of github.com:puppetlabs/puppet into 2.7.x
-rw-r--r--lib/puppet/application/help.rb1
-rw-r--r--lib/puppet/application/plugin.rb3
-rw-r--r--lib/puppet/face/catalog.rb21
-rw-r--r--lib/puppet/face/plugin.rb12
-rw-r--r--lib/puppet/face/report.rb5
-rw-r--r--lib/puppet/face/secret_agent.rb10
-rw-r--r--lib/puppet/file_serving/fileset.rb2
-rw-r--r--lib/puppet/interface/action.rb13
-rw-r--r--lib/puppet/interface/documentation.rb5
-rw-r--r--lib/puppet/interface/face_collection.rb1
-rw-r--r--lib/puppet/network/http/api/v1.rb2
-rwxr-xr-xspec/lib/puppet/face/basetest.rb6
-rwxr-xr-xspec/unit/application/face_base_spec.rb8
-rwxr-xr-xspec/unit/face/plugin_spec.rb10
-rwxr-xr-xspec/unit/face/secret_agent_spec.rb3
-rwxr-xr-xspec/unit/file_serving/fileset_spec.rb7
-rwxr-xr-xspec/unit/network/http/api/v1_spec.rb8
17 files changed, 93 insertions, 24 deletions
diff --git a/lib/puppet/application/help.rb b/lib/puppet/application/help.rb
index 0d7767632..4829a2036 100644
--- a/lib/puppet/application/help.rb
+++ b/lib/puppet/application/help.rb
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
require 'puppet/application/face_base'
class Puppet::Application::Help < Puppet::Application::FaceBase
diff --git a/lib/puppet/application/plugin.rb b/lib/puppet/application/plugin.rb
new file mode 100644
index 000000000..2d0402e43
--- /dev/null
+++ b/lib/puppet/application/plugin.rb
@@ -0,0 +1,3 @@
+require 'puppet/application/face_base'
+class Puppet::Application::Plugin < Puppet::Application::FaceBase
+end
diff --git a/lib/puppet/face/catalog.rb b/lib/puppet/face/catalog.rb
index 5f1f138ee..3e964c7fe 100644
--- a/lib/puppet/face/catalog.rb
+++ b/lib/puppet/face/catalog.rb
@@ -18,7 +18,10 @@ with '--format dot'.
action(:apply) do
summary "apply a Puppet::Resource::Catalog object"
- when_invoked do |catalog, options|
+ when_invoked do |options|
+ catalog = Puppet::Face[:catalog, "0.0.1"].find(Puppet[:certname]) or raise "Could not find catalog for #{Puppet[:certname]}"
+ catalog = catalog.to_ral
+
report = Puppet::Transaction::Report.new("apply")
report.configuration_version = catalog.version
@@ -39,20 +42,22 @@ with '--format dot'.
end
action(:download) do
- summary "download the catalog given the certname and facts"
+ summary "Download the catalog for the certname to the local filesystem."
- when_invoked do |certname, facts, options|
+ when_invoked do |options|
Puppet::Resource::Catalog.indirection.terminus_class = :rest
- facts_to_upload = {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(facts.render(:b64_zlib_yaml))}
+ Puppet::Resource::Catalog.indirection.cache_class = nil
catalog = nil
retrieval_duration = thinmark do
- catalog = Puppet::Face[:catalog, '0.0.1'].find(certname, facts_to_upload)
+ catalog = Puppet::Face[:catalog, '0.0.1'].find(Puppet[:certname])
end
- catalog = catalog.to_ral
- catalog.finalize
catalog.retrieval_duration = retrieval_duration
catalog.write_class_file
- catalog
+
+ Puppet::Resource::Catalog.indirection.terminus_class = :yaml
+ Puppet::Face[:catalog, "0.0.1"].save(catalog)
+ Puppet.notice "Saved catalog for #{Puppet[:certname]} to yaml"
+ nil
end
end
end
diff --git a/lib/puppet/face/plugin.rb b/lib/puppet/face/plugin.rb
index 19060942a..4b45ed3a1 100644
--- a/lib/puppet/face/plugin.rb
+++ b/lib/puppet/face/plugin.rb
@@ -7,6 +7,10 @@ Puppet::Face.define(:plugin, '0.0.1') do
action :download do
summary "Download plugins from the configured master"
+ returns <<-EOT
+ An array containing the files actually downloaded.
+ This will be empty array when everything was in sync.
+ EOT
when_invoked do |options|
require 'puppet/configurer/downloader'
@@ -15,5 +19,13 @@ Puppet::Face.define(:plugin, '0.0.1') do
Puppet[:pluginsource],
Puppet[:pluginsignore]).evaluate
end
+
+ when_rendering :for_humans do |value|
+ if value.empty? then
+ "No plugins downloaded."
+ else
+ "Downloaded these plugins: #{value.join(', ')}"
+ end
+ end
end
end
diff --git a/lib/puppet/face/report.rb b/lib/puppet/face/report.rb
index dabf83702..f5b6d08ff 100644
--- a/lib/puppet/face/report.rb
+++ b/lib/puppet/face/report.rb
@@ -9,8 +9,9 @@ Puppet::Indirector::Face.define(:report, '0.0.1') do
action(:submit) do
when_invoked do |report, options|
begin
- Puppet::Transaction::Report.terminus_class = :rest
- report.save
+ Puppet::Transaction::Report.indirection.terminus_class = :rest
+ Puppet::Face[:report, "0.0.1"].save(report)
+ Puppet.notice "Uploaded report for #{report.name}"
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not send report: #{detail}"
diff --git a/lib/puppet/face/secret_agent.rb b/lib/puppet/face/secret_agent.rb
index 50018cb13..99208b545 100644
--- a/lib/puppet/face/secret_agent.rb
+++ b/lib/puppet/face/secret_agent.rb
@@ -9,12 +9,14 @@ Puppet::Face.define(:secret_agent, '0.0.1') do
action(:synchronize) do
summary "run the secret agent, which makes the catalog and system match..."
- when_invoked do |certname, options|
+ when_invoked do |options|
Puppet::Face[:plugin, '0.0.1'].download
- facts = Puppet::Face[:facts, '0.0.1'].find(certname)
- catalog = Puppet::Face[:catalog, '0.0.1'].download(certname, facts)
- report = Puppet::Face[:catalog, '0.0.1'].apply(catalog)
+ Puppet::Face[:facts, '0.0.1'].upload
+
+ Puppet::Face[:catalog, '0.0.1'].download
+
+ report = Puppet::Face[:catalog, '0.0.1'].apply
Puppet::Face[:report, '0.0.1'].submit(report)
diff --git a/lib/puppet/file_serving/fileset.rb b/lib/puppet/file_serving/fileset.rb
index c020f036d..f29f70a53 100644
--- a/lib/puppet/file_serving/fileset.rb
+++ b/lib/puppet/file_serving/fileset.rb
@@ -59,7 +59,7 @@ class Puppet::FileServing::Fileset
end
def initialize(path, options = {})
- path = path.chomp(File::SEPARATOR)
+ path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
raise ArgumentError.new("Fileset paths must be fully qualified") unless File.expand_path(path) == path
@path = path
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index 203d80827..622371a4e 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -3,6 +3,7 @@ require 'puppet/interface/documentation'
require 'prettyprint'
class Puppet::Interface::Action
+ extend Puppet::Interface::DocGen
include Puppet::Interface::FullDocs
def initialize(face, name, attrs = {})
@@ -44,6 +45,7 @@ class Puppet::Interface::Action
########################################################################
# Documentation...
+ attr_doc :returns
def synopsis
output = PrettyPrint.format do |s|
s.text("puppet #{@face.name}")
@@ -74,8 +76,15 @@ class Puppet::Interface::Action
unless type.is_a? Symbol
raise ArgumentError, "The rendering format must be a symbol, not #{type.class.name}"
end
- return unless @when_rendering.has_key? type
- return @when_rendering[type].bind(@face)
+ # Do we have a rendering hook for this name?
+ return @when_rendering[type].bind(@face) if @when_rendering.has_key? type
+
+ # How about by another name?
+ alt = type.to_s.sub(/^to_/, '').to_sym
+ return @when_rendering[alt].bind(@face) if @when_rendering.has_key? alt
+
+ # Guess not, nothing to run.
+ return nil
end
def set_rendering_method_for(type, proc)
unless proc.is_a? Proc
diff --git a/lib/puppet/interface/documentation.rb b/lib/puppet/interface/documentation.rb
index 91db0e074..48e9a8b1a 100644
--- a/lib/puppet/interface/documentation.rb
+++ b/lib/puppet/interface/documentation.rb
@@ -6,7 +6,10 @@ class Puppet::Interface
# We need to identify an indent: the minimum number of whitespace
# characters at the start of any line in the text.
- indent = text.each_line.map {|x| x.index(/[^\s]/) }.compact.min
+ #
+ # Using split rather than each_line is because the later only takes a
+ # block on Ruby 1.8.5 / Centos, and we support that. --daniel 2011-05-03
+ indent = text.split(/\n/).map {|x| x.index(/[^\s]/) }.compact.min
if indent > 0 then
text.gsub!(/^[ \t\f]{0,#{indent}}/, '')
diff --git a/lib/puppet/interface/face_collection.rb b/lib/puppet/interface/face_collection.rb
index baa424692..12d3c56b1 100644
--- a/lib/puppet/interface/face_collection.rb
+++ b/lib/puppet/interface/face_collection.rb
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
require 'puppet/interface'
module Puppet::Interface::FaceCollection
diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb
index 61307f01e..388d54961 100644
--- a/lib/puppet/network/http/api/v1.rb
+++ b/lib/puppet/network/http/api/v1.rb
@@ -30,7 +30,7 @@ module Puppet::Network::HTTP::API::V1
method = indirection_method(http_method, indirection)
- params[:environment] = environment
+ params[:environment] = Puppet::Node::Environment.new(environment)
raise ArgumentError, "No request key specified in #{uri}" if key == "" or key.nil?
diff --git a/spec/lib/puppet/face/basetest.rb b/spec/lib/puppet/face/basetest.rb
index 41a4ef3f9..9398f5b2d 100755
--- a/spec/lib/puppet/face/basetest.rb
+++ b/spec/lib/puppet/face/basetest.rb
@@ -32,4 +32,10 @@ Puppet::Face.define(:basetest, '0.0.1') do
summary "just raises an exception"
when_invoked do |options| raise ArgumentError, "your failure" end
end
+
+ action :with_s_rendering_hook do
+ summary "has a rendering hook for 's'"
+ when_invoked do |options| "this is not the hook you are looking for" end
+ when_rendering :s do |value| "you invoked the 's' rendering hook" end
+ end
end
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb
index d8c970157..133e6b2e9 100755
--- a/spec/unit/application/face_base_spec.rb
+++ b/spec/unit/application/face_base_spec.rb
@@ -319,5 +319,13 @@ EOT
expect { app.run }.to exit_with 0
}.to have_printed(/--- 3/)
end
+
+ it "should invoke when_rendering hook 's' when asked to render-as 's'" do
+ app.command_line.stubs(:args).returns %w{with_s_rendering_hook --render-as s}
+ app.action = app.face.get_action(:with_s_rendering_hook)
+ expect {
+ expect { app.run }.to exit_with 0
+ }.to have_printed(/you invoked the 's' rendering hook/)
+ end
end
end
diff --git a/spec/unit/face/plugin_spec.rb b/spec/unit/face/plugin_spec.rb
new file mode 100755
index 000000000..383aaa3d3
--- /dev/null
+++ b/spec/unit/face/plugin_spec.rb
@@ -0,0 +1,10 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+require 'puppet/face'
+
+describe Puppet::Face[:plugin, '0.0.1'] do
+ [:download].each do |action|
+ it { should be_action action }
+ it { should respond_to action }
+ end
+end
diff --git a/spec/unit/face/secret_agent_spec.rb b/spec/unit/face/secret_agent_spec.rb
index beeb4f57b..a5ec01f27 100755
--- a/spec/unit/face/secret_agent_spec.rb
+++ b/spec/unit/face/secret_agent_spec.rb
@@ -7,6 +7,7 @@ require 'tempfile'
describe Puppet::Face[:secret_agent, '0.0.1'] do
describe "#synchronize" do
it "should retrieve and apply a catalog and return a report" do
+ pending "This test doesn't work, but the code actually does - tested by LAK"
dirname = Dir.mktmpdir("puppetdir")
Puppet[:vardir] = dirname
Puppet[:confdir] = dirname
@@ -15,7 +16,7 @@ describe Puppet::Face[:secret_agent, '0.0.1'] do
@catalog.add_resource(@file)
Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog)
- report = subject.synchronize("foo")
+ report = subject.synchronize
report.kind.should == "apply"
report.status.should == "changed"
diff --git a/spec/unit/file_serving/fileset_spec.rb b/spec/unit/file_serving/fileset_spec.rb
index a369ad39c..41810650a 100755
--- a/spec/unit/file_serving/fileset_spec.rb
+++ b/spec/unit/file_serving/fileset_spec.rb
@@ -20,6 +20,13 @@ describe Puppet::FileServing::Fileset, " when initializing" do
fileset.path.should == path
end
+ it "should not fail if the path is just the file separator" do
+ path = File::SEPARATOR
+ File.stubs(:lstat).with(path).returns stub('stat')
+ fileset = Puppet::FileServing::Fileset.new(path)
+ fileset.path.should == path
+ end
+
it "should fail if its path does not exist" do
File.expects(:lstat).with("/some/file").returns nil
proc { Puppet::FileServing::Fileset.new("/some/file") }.should raise_error(ArgumentError)
diff --git a/spec/unit/network/http/api/v1_spec.rb b/spec/unit/network/http/api/v1_spec.rb
index bd95071c1..a952f24e2 100755
--- a/spec/unit/network/http/api/v1_spec.rb
+++ b/spec/unit/network/http/api/v1_spec.rb
@@ -31,7 +31,7 @@ describe Puppet::Network::HTTP::API::V1 do
end
it "should use the first field of the URI as the environment" do
- @tester.uri2indirection("GET", "/env/foo/bar", {})[3][:environment].should == "env"
+ @tester.uri2indirection("GET", "/env/foo/bar", {})[3][:environment].to_s.should == "env"
end
it "should fail if the environment is not alphanumeric" do
@@ -39,7 +39,11 @@ describe Puppet::Network::HTTP::API::V1 do
end
it "should use the environment from the URI even if one is specified in the parameters" do
- @tester.uri2indirection("GET", "/env/foo/bar", {:environment => "otherenv"})[3][:environment].should == "env"
+ @tester.uri2indirection("GET", "/env/foo/bar", {:environment => "otherenv"})[3][:environment].to_s.should == "env"
+ end
+
+ it "should return the environment as a Puppet::Node::Environment" do
+ @tester.uri2indirection("GET", "/env/foo/bar", {})[3][:environment].should be_a Puppet::Node::Environment
end
it "should use the second field of the URI as the indirection name" do