diff --git a/lib/puppet/face/plugin.rb b/lib/puppet/face/plugin.rb index 73792ada6..7710b98f5 100644 --- a/lib/puppet/face/plugin.rb +++ b/lib/puppet/face/plugin.rb @@ -1,64 +1,65 @@ require 'puppet/face' Puppet::Face.define(:plugin, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Interact with the Puppet plugin system." description <<-'EOT' This subcommand provides network access to the puppet master's store of plugins. The puppet master serves Ruby code collected from the `lib` directories of its modules. These plugins can be used on agent nodes to extend Facter and implement custom types and providers. Plugins are normally downloaded by puppet agent during the course of a run. EOT action :download do summary "Download plugins from the puppet master." description <<-'EOT' Downloads plugins from the configured puppet master. Any plugins downloaded in this way will be used in all subsequent Puppet activity. This action modifies files on disk. EOT returns <<-'EOT' A list of the files downloaded, or a confirmation that no files were downloaded. When used from the Ruby API, this action returns an array of the files downloaded, which will be empty if none were retrieved. EOT examples <<-'EOT' Retrieve plugins from the puppet master: $ puppet plugin download Retrieve plugins from the puppet master (API example): $ Puppet::Face[:plugin, '0.0.1'].download EOT when_invoked do |options| require 'puppet/configurer/downloader' remote_environment_for_plugins = Puppet::Node::Environment.remote(Puppet[:environment]) - Puppet::Configurer::Downloader.new("plugin", + result = Puppet::Configurer::Downloader.new("plugin", Puppet[:plugindest], Puppet[:pluginsource], Puppet[:pluginsignore], remote_environment_for_plugins).evaluate if Puppet.features.external_facts? - Puppet::Configurer::Downloader.new("pluginfacts", + result += Puppet::Configurer::Downloader.new("pluginfacts", Puppet[:pluginfactdest], Puppet[:pluginfactsource], Puppet[:pluginsignore], remote_environment_for_plugins).evaluate end + result end when_rendering :console do |value| if value.empty? then "No plugins downloaded." else "Downloaded these plugins: #{value.join(', ')}" end end end end diff --git a/spec/integration/faces/plugin_spec.rb b/spec/integration/faces/plugin_spec.rb index 5621a3c0b..0ca7574a6 100644 --- a/spec/integration/faces/plugin_spec.rb +++ b/spec/integration/faces/plugin_spec.rb @@ -1,54 +1,62 @@ require 'spec_helper' require 'puppet/face' require 'puppet/file_serving/metadata' require 'puppet/file_serving/content' require 'puppet/indirector/memory' module PuppetFaceIntegrationSpecs -describe Puppet::Face[:plugin, '0.0.1'] do +describe "Puppet plugin face" do INDIRECTORS = [ Puppet::Indirector::FileMetadata, Puppet::Indirector::FileContent, ] INDIRECTED_CLASSES = [ Puppet::FileServing::Metadata, Puppet::FileServing::Content, Puppet::Node::Facts, ] INDIRECTORS.each do |indirector| class indirector::Memory < Puppet::Indirector::Memory def find(request) model.new('/dev/null', { 'type' => 'directory' }) end end end before do FileUtils.mkdir(Puppet[:vardir]) + FileUtils.mkdir(File.join(Puppet[:vardir], 'lib')) + FileUtils.mkdir(File.join(Puppet[:vardir], 'facts.d')) @termini_classes = {} INDIRECTED_CLASSES.each do |indirected| @termini_classes[indirected] = indirected.indirection.terminus_class indirected.indirection.terminus_class = :memory end end after do FileUtils.rmdir(File.join(Puppet[:vardir],'lib')) FileUtils.rmdir(File.join(Puppet[:vardir],'facts.d')) FileUtils.rmdir(Puppet[:vardir]) INDIRECTED_CLASSES.each do |indirected| indirected.indirection.terminus_class = @termini_classes[indirected] indirected.indirection.termini.clear end end - it "processes a download request without logging errors" do - Puppet[:trace] = true - result = subject.download - expect(result).to eq([File.join(Puppet[:vardir],'facts.d')]) - expect(@logs.select { |l| l.level == :err }).to eq([]) + def init_cli_args_and_apply_app(args = ["download"]) + Puppet::Application.find(:plugin).new(stub('command_line', :subcommand_name => :plugin, :args => args)) + end + + it "processes a download request" do + app = init_cli_args_and_apply_app + expect do + expect { + app.run + }.to exit_with(0) + end.to have_printed(/No plugins downloaded/) end end end