Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-11330

Puppet::Node#environment_name may return the wrong value

    XMLWordPrintable

Details

    • Night's Watch
    • 3
    • NW - 2021-12-17, NW - 2022-01-27
    • Needs Assessment
    • Bug Fix
    • Puppet::Node#environment_name now always returns the symbolic name of the environment (if one has been set on the node).
    • Needs Assessment

    Description

      If an environment instance is set on a node, then the Node#environment_name returns nil, but Node#environment returns the instance whose name is the expected symbolic value:

      irb(main):010:0> node = Puppet::Node.new('hostname')
      => #<Puppet::Node:0x00005582e746c3e0 @name="hostname", @classes=[], @parameters={}, @facts=nil, @server_facts={}, @time...
      irb(main):011:0> node.environment = Puppet::Node::Environment.remote('www123')
      => <Puppet::Node::Environment::Remote:7880 @name="www123" @manifest="no_manifest" @modulepath="" >
      irb(main):012:0> node.environment_name
      => nil
      irb(main):013:0> node.environment.name
      => :www123
      

      However, setting environment_name on the node DOES cause Node#environment to load that environment (which must exist on disk):

      irb(main):001:0> require 'puppet'
      => true
      irb(main):002:0> Puppet.initialize_settings
      => {}
      irb(main):003:0> FileUtils.mkdir(File.join(Puppet[:environmentpath], "www123"))
      => ["/home/josh/.puppetlabs/etc/code/environments/www123"]
      irb(main):004:0> run_mode = Puppet::Util::RunMode[:agent]
      => #<Puppet::Util::UnixRunMode:0x00005582e7075520 @name=:agent>
      irb(main):005:0> Puppet::ApplicationSupport.push_application_context(run_mode)
      => #<Puppet::Context::Stack:0x00005582e646cc88 ...
      irb(main):006:0> node = Puppet::Node.new('hostname')
      => #<Puppet::Node:0x00005582e7152c40 @name="hostname", @classes=[], @parameters={}, @facts=nil, @server_facts={}, @time...
      irb(main):007:0> node.environment_name = 'www123'
      => "www123"
      irb(main):008:0> node.environment_name
      => "www123"
      irb(main):009:0> node.environment.name
      => :www123
      

      This inconsistency leads to complicated logic where we can never be sure how to retrieve the node's environment, while trying to be careful to not load the environment from disk:

      https://github.com/puppetlabs/puppet/blob/e89bc9f1e0a9365cb7f0e8b105c04c50a7b43395/lib/puppet/configurer.rb#L313-L317

      Attachments

        Issue Links

          Activity

            People

              victor.bobosila Victor Bobosila
              josh Josh Cooper
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support