Skip to content

Commit 4bcbd4b

Browse files
authored
Merge pull request #8842 from BobosilaVictor/PUP-11330/environment-name
(PUP-11330) Puppet::Node#environment_name may return the wrong value
2 parents e70dbe1 + 905ec6a commit 4bcbd4b

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

lib/puppet/configurer.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,7 @@ def current_server_specified_environment(current_environment, configured_environ
513513
:transaction_uuid => @transaction_uuid,
514514
:fail_on_404 => true)
515515

516-
# The :rest node terminus returns a node with an environment_name, but not an
517-
# environment instance. Attempting to get the environment instance will load
518-
# it from disk, which will likely fail. So create a remote environment.
519-
#
520-
# The :plain node terminus returns a node with an environment, but not an
521-
# environment_name.
522-
if !node.has_environment_instance? && node.environment_name
523-
node.environment = Puppet::Node::Environment.remote(node.environment_name)
524-
end
525-
526-
@server_specified_environment = node.environment.to_s
516+
@server_specified_environment = node.environment_name.to_s
527517

528518
if @server_specified_environment != @environment
529519
Puppet.notice _("Local environment: '%{local_env}' doesn't match server specified node environment '%{node_env}', switching agent to '%{node_env}'.") % { local_env: @environment, node_env: @server_specified_environment }

lib/puppet/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def environment=(env)
8989
unless @environment.nil?
9090
# always set the environment parameter. It becomes top scope $environment for a manifest during catalog compilation.
9191
@parameters[ENVIRONMENT] = @environment.name.to_s
92-
self.environment_name = @environment.name if instance_variable_defined?(:@environment_name)
92+
self.environment_name = @environment.name
9393
end
9494
@environment
9595
end

spec/unit/node_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
expect(node.environment.name).to eq(:bar)
4141
end
4242

43+
it "sets environment_name with the correct environment name" do
44+
node = Puppet::Node.new("foo")
45+
node.environment = Puppet::Node::Environment.remote('www123')
46+
expect(node.environment_name).to eq(:www123)
47+
end
48+
4349
it "allows its environment to be set by parameters after initialization" do
4450
node = Puppet::Node.new("foo")
4551
node.parameters["environment"] = :bar

0 commit comments

Comments
 (0)