puppetlabs/puppet — pull request #2031 by joshcooper (2013-11-04 23:52:02+00:00)
Title: (#22925) Fall back to cached catalog if we can't connect to the master

Prior to commit 093a0745b4, puppet would attempt to download a catalog, and if
that failed, it would apply a previously cached catalog. Note this
behavior is controlled by the [`usecacheonfailure`](http://docs.puppetlabs.com/references/latest/configuration.html#usecacheonfailure) setting, which is
disabled when using `--test`.

In commit 093a0745b4, the ENC was made authoritative for specifying node
environment. In doing so, the agent makes a REST call to the master for
its Node object, and then reads the environment from it.

However, the call is made in a begin/rescue block that only catches
Puppet::Error and Net::HTTPErrors, but not errors like
Errno::ECONNREFUSED, etc.

This commit ensures that any standard error will be caught when
retrieving the node's environment, as is done when retrieving the
catalog. If we fail to obtain the node's environment, we warn, and
continue trying to apply the catalog.

This commit does not try to fix consistency issues between the node and
catalog requests. For example, the node request could fail, resulting in
the agent requesting a catalog using its agent-configured environment.
The catalog request could succeed, resulting in the agent applying a
catalog from an environment that doesn't match what the ENC thinks it
should be.