puppetlabs/puppet — pull request #1339 by domcleal (2012-12-18 00:22:28+00:00)
Title: (#18187) Clear *root* environment when clearing caches

This is only applicable to 2.7.x, since it fixes a regression introduced in 2.7.20. Not applicable to Puppet 3.x either.

When changing settings or initializing Puppet via TestHelper, the
Puppet::Node::Environment.clear method is called to delete the cached
environment objects, as they may reference cached module paths based on old
values of settings.

The *root* environment is a special case, as it acts as the current environment
when no other environment has been created and set yet. It can still have a
module path based on current settings, so it too should be cleared along with
other cached environments.

Failure to reinitialize *root* causes failures when initializing Puppet via the
TestHelper. The Puppet::MetaType::Manager class uses the current environment
in calls to Puppet::Util::Autoload, which starts as the default *root*
enviroment. The type loader is called a few times during TestHelper
initialization and so if the module path is then changed (which triggers a
.clear call), the *root* environment will contain paths based on old settings,
so types won't load.

Loading types based on the environment is new in 8173a6e6 (2.7.19). 3.x is
unaffected as caching of module paths doesn't begin until
app_defaults_initialized? changes to true.