summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2011-06-28 17:40:53 -0700
committerJacob Helwig <jacob@puppetlabs.com>2011-06-28 17:40:53 -0700
commit8432684e25cc82beb1f5d977dd509fd7bab3901b (patch)
tree02d1bd4a254b1adf04ea574759dfa498c38c7863 /lib
parent1feaf7cf163c060eb213ce5f7a37faa0b7a4716f (diff)
parent8bad457fb68f8550db4c1c4802cb024c4e719d33 (diff)
downloadpuppet-8432684e25cc82beb1f5d977dd509fd7bab3901b.tar.gz
puppet-8432684e25cc82beb1f5d977dd509fd7bab3901b.tar.xz
puppet-8432684e25cc82beb1f5d977dd509fd7bab3901b.zip
Merge branch '2.6.x' into 2.7.x
* 2.6.x: (#7956) Porting cron tests (#7956) Port resource acceptance tests Readying for release of 2.6.9 (#6854) Update Red Hat spec file Bumping release in lib/puppet.rb and updating CHANGELOG. Bumping RPM spec file to 2.6.9rc1. (#7506) Organize READMEs; specify supported Ruby versions in README.md (#6418) Make test 64118 more portable (#7127) Stop puppet if a prerun command fails Do not needlessly create multiple reports when creating a transaction (#4416) Ensure types are providified after reloading (#4416) Always remove old provider before recreating it Cleanup indentation, comment, and unused code Conflicts: CHANGELOG README.md conf/redhat/puppet.spec lib/puppet.rb lib/puppet/transaction.rb spec/unit/configurer_spec.rb spec/unit/transaction_spec.rb
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/application/apply.rb8
-rw-r--r--lib/puppet/configurer.rb107
-rw-r--r--lib/puppet/metatype/manager.rb27
-rw-r--r--lib/puppet/resource/catalog.rb12
-rw-r--r--lib/puppet/transaction.rb26
-rw-r--r--lib/puppet/transaction/report.rb4
-rw-r--r--lib/puppet/type.rb37
7 files changed, 103 insertions, 118 deletions
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 3ba06d34a..5562a9b09 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -213,7 +213,13 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
configurer = Puppet::Configurer.new
report = configurer.run(:skip_plugin_download => true, :catalog => catalog)
- exit( options[:detailed_exitcodes] ? report.exit_status : 0 )
+ if not report
+ exit(1)
+ elsif options[:detailed_exitcodes] then
+ exit(report.exit_status)
+ else
+ exit(0)
+ end
rescue => detail
puts detail.backtrace if Puppet[:trace]
$stderr.puts detail.message
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index 980da634e..3d6e8557c 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -5,8 +5,6 @@ require 'puppet/network/http_pool'
require 'puppet/util'
class Puppet::Configurer
- class CommandHookError < RuntimeError; end
-
require 'puppet/configurer/fact_handler'
require 'puppet/configurer/plugin_handler'
@@ -79,8 +77,6 @@ class Puppet::Configurer
download_plugins unless options[:skip_plugin_download]
download_fact_plugins unless options[:skip_plugin_download]
-
- execute_prerun_command
end
# Get the remote catalog, yo. Returns nil if no catalog can be found.
@@ -109,67 +105,73 @@ class Puppet::Configurer
catalog
end
- # The code that actually runs the catalog.
- # This just passes any options on to the catalog,
- # which accepts :tags and :ignoreschedules.
- def run(options = {})
- begin
- prepare(options)
- rescue SystemExit,NoMemoryError
- raise
- rescue Exception => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Failed to prepare catalog: #{detail}"
+ # Retrieve (optionally) and apply a catalog. If a catalog is passed in
+ # the options, then apply that one, otherwise retrieve it.
+ def retrieve_and_apply_catalog(options, fact_options)
+ unless catalog = (options.delete(:catalog) || retrieve_catalog(fact_options))
+ Puppet.err "Could not retrieve catalog; skipping run"
+ return
end
- if Puppet::Resource::Catalog.indirection.terminus_class == :rest
- # This is a bit complicated. We need the serialized and escaped facts,
- # and we need to know which format they're encoded in. Thus, we
- # get a hash with both of these pieces of information.
- fact_options = facts_for_uploading
+ report = options[:report]
+ report.configuration_version = catalog.version
+
+ benchmark(:notice, "Finished catalog run") do
+ catalog.apply(options)
end
+ report.finalize_report
+ report
+ end
+
+ # The code that actually runs the catalog.
+ # This just passes any options on to the catalog,
+ # which accepts :tags and :ignoreschedules.
+ def run(options = {})
options[:report] ||= Puppet::Transaction::Report.new("apply")
report = options[:report]
- Puppet::Util::Log.newdestination(report)
- if catalog = options[:catalog]
- options.delete(:catalog)
- elsif ! catalog = retrieve_catalog(fact_options)
- Puppet.err "Could not retrieve catalog; skipping run"
- return
- end
+ Puppet::Util::Log.newdestination(report)
+ begin
+ prepare(options)
- report.configuration_version = catalog.version
+ if Puppet::Resource::Catalog.indirection.terminus_class == :rest
+ # This is a bit complicated. We need the serialized and escaped facts,
+ # and we need to know which format they're encoded in. Thus, we
+ # get a hash with both of these pieces of information.
+ fact_options = facts_for_uploading
+ end
- transaction = nil
+ # set report host name now that we have the fact
+ report.host = Puppet[:node_name_value]
- begin
- benchmark(:notice, "Finished catalog run") do
- transaction = catalog.apply(options)
+ begin
+ execute_prerun_command or return nil
+ retrieve_and_apply_catalog(options, fact_options)
+ rescue SystemExit,NoMemoryError
+ raise
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Failed to apply catalog: #{detail}"
+ return nil
+ ensure
+ execute_postrun_command or return nil
end
- report
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Failed to apply catalog: #{detail}"
- return
+ ensure
+ # Make sure we forget the retained module_directories of any autoload
+ # we might have used.
+ Thread.current[:env_module_directories] = nil
+
+ # Now close all of our existing http connections, since there's no
+ # reason to leave them lying open.
+ Puppet::Network::HttpPool.clear_http_instances
end
ensure
- # Make sure we forget the retained module_directories of any autoload
- # we might have used.
- Thread.current[:env_module_directories] = nil
-
- # Now close all of our existing http connections, since there's no
- # reason to leave them lying open.
- Puppet::Network::HttpPool.clear_http_instances
- execute_postrun_command
-
Puppet::Util::Log.close(report)
- send_report(report, transaction)
+ send_report(report)
end
- def send_report(report, trans)
- report.finalize_report if trans
+ def send_report(report)
puts report.summary if Puppet[:summarize]
save_last_run_summary(report)
Puppet::Transaction::Report.indirection.save(report) if Puppet[:report]
@@ -207,12 +209,15 @@ class Puppet::Configurer
end
def execute_from_setting(setting)
- return if (command = Puppet[setting]) == ""
+ return true if (command = Puppet[setting]) == ""
begin
Puppet::Util.execute([command])
+ true
rescue => detail
- raise CommandHookError, "Could not run command from #{setting}: #{detail}"
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not run command from #{setting}: #{detail}"
+ false
end
end
diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb
index 12cbf645c..597a89f31 100644
--- a/lib/puppet/metatype/manager.rb
+++ b/lib/puppet/metatype/manager.rb
@@ -61,10 +61,9 @@ module Manager
# Then create the class.
- klass = genclass(
- name,
+ klass = genclass(
+ name,
:parent => (parent || Puppet::Type),
-
:overwrite => true,
:hash => @types,
:attributes => options,
@@ -87,14 +86,11 @@ module Manager
# Now set up autoload any providers that might exist for this type.
- klass.providerloader = Puppet::Util::Autoload.new(
- klass,
-
- "puppet/provider/#{klass.name.to_s}"
- )
+ klass.providerloader = Puppet::Util::Autoload.new(klass, "puppet/provider/#{klass.name.to_s}")
- # We have to load everything so that we can figure out the default type.
+ # We have to load everything so that we can figure out the default provider.
klass.providerloader.loadall
+ klass.providify unless klass.providers.empty?
klass
end
@@ -103,11 +99,7 @@ module Manager
def rmtype(name)
# Then create the class.
- klass = rmclass(
- name,
-
- :hash => @types
- )
+ klass = rmclass(name, :hash => @types)
singleton_class.send(:remove_method, "new#{name}") if respond_to?("new#{name}")
end
@@ -132,12 +124,7 @@ module Manager
# Create a loader for Puppet types.
def typeloader
unless defined?(@typeloader)
-
- @typeloader = Puppet::Util::Autoload.new(
- self,
-
- "puppet/type", :wrap => false
- )
+ @typeloader = Puppet::Util::Autoload.new(self, "puppet/type", :wrap => false)
end
@typeloader
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index b742d283f..8eb4266db 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -128,9 +128,10 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
expire
Puppet::Util::Storage.load if host_config?
- transaction = Puppet::Transaction.new(self)
- transaction.report = options[:report] if options[:report]
+ transaction = Puppet::Transaction.new(self, options[:report])
+ register_report = options[:report].nil?
+
transaction.tags = options[:tags] if options[:tags]
transaction.ignoreschedules = true if options[:ignoreschedules]
transaction.for_network_device = options[:network_device]
@@ -138,7 +139,12 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
transaction.add_times :config_retrieval => self.retrieval_duration || 0
begin
- transaction.evaluate
+ Puppet::Util::Log.newdestination(transaction.report) if register_report
+ begin
+ transaction.evaluate
+ ensure
+ Puppet::Util::Log.close(transaction.report) if register_report
+ end
rescue Puppet::Error => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not apply complete catalog: #{detail}"
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 089f4d945..3152d768d 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -16,7 +16,7 @@ class Puppet::Transaction
attr_accessor :configurator
# The report, once generated.
- attr_accessor :report
+ attr_reader :report
# Routes and stores any events and subscriptions.
attr_reader :event_manager
@@ -92,25 +92,17 @@ class Puppet::Transaction
# collects all of the changes, executes them, and responds to any
# necessary events.
def evaluate
- # Start logging.
- Puppet::Util::Log.newdestination(@report)
-
prepare
Puppet.info "Applying configuration version '#{catalog.version}'" if catalog.version
- begin
- relationship_graph.traverse do |resource|
- if resource.is_a?(Puppet::Type::Component)
- Puppet.warning "Somehow left a component in the relationship graph"
- else
- seconds = thinmark { eval_resource(resource) }
- resource.info "Evaluated in %0.2f seconds" % seconds if Puppet[:evaltrace] and @catalog.host_config?
- end
+ relationship_graph.traverse do |resource|
+ if resource.is_a?(Puppet::Type::Component)
+ Puppet.warning "Somehow left a component in the relationship graph"
+ else
+ seconds = thinmark { eval_resource(resource) }
+ resource.info "Evaluated in %0.2f seconds" % seconds if Puppet[:evaltrace] and @catalog.host_config?
end
- ensure
- # And then close the transaction log.
- Puppet::Util::Log.close(@report)
end
Puppet.debug "Finishing transaction #{object_id}"
@@ -221,10 +213,10 @@ class Puppet::Transaction
# this should only be called by a Puppet::Type::Component resource now
# and it should only receive an array
- def initialize(catalog)
+ def initialize(catalog, report = nil)
@catalog = catalog
- @report = Puppet::Transaction::Report.new("apply")
+ @report = report || Puppet::Transaction::Report.new("apply", catalog.version)
@event_manager = Puppet::Transaction::EventManager.new(self)
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index 020a5efce..807163961 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -10,8 +10,8 @@ class Puppet::Transaction::Report
indirects :report, :terminus_class => :processor
- attr_accessor :configuration_version
- attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind, :status
+ attr_accessor :configuration_version, :host
+ attr_reader :resource_statuses, :logs, :metrics, :time, :kind, :status
# This is necessary since Marshall doesn't know how to
# dump hash with default proc (see below @records)
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 558491a7f..15f340f55 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1442,9 +1442,8 @@ class Type
def self.provide(name, options = {}, &block)
name = Puppet::Util.symbolize(name)
- if obj = provider_hash[name]
+ if unprovide(name)
Puppet.debug "Reloading #{name} #{self.name} provider"
- unprovide(name)
end
parent = if pname = options[:parent]
@@ -1467,16 +1466,14 @@ class Type
self.providify
-
- provider = genclass(
- name,
- :parent => parent,
- :hash => provider_hash,
- :prefix => "Provider",
- :block => block,
- :include => feature_module,
- :extend => feature_module,
-
+ provider = genclass(
+ name,
+ :parent => parent,
+ :hash => provider_hash,
+ :prefix => "Provider",
+ :block => block,
+ :include => feature_module,
+ :extend => feature_module,
:attributes => options
)
@@ -1536,18 +1533,11 @@ class Type
end
def self.unprovide(name)
- if provider_hash.has_key? name
-
- rmclass(
- name,
- :hash => provider_hash,
-
- :prefix => "Provider"
- )
- if @defaultprovider and @defaultprovider.name == name
- @defaultprovider = nil
- end
+ if @defaultprovider and @defaultprovider.name == name
+ @defaultprovider = nil
end
+
+ rmclass(name, :hash => provider_hash, :prefix => "Provider")
end
# Return an array of all of the suitable providers.
@@ -1607,7 +1597,6 @@ class Type
# Collect the current prereqs
list.each { |dep|
- obj = nil
# Support them passing objects directly, to save some effort.
unless dep.is_a? Puppet::Type
# Skip autorequires that we aren't managing