Skip to content

Commit c0d2560

Browse files
committed
(PUP-11752) Fix usage of legacy fact in fqdn_rand
The `fqdn_rand` function rely on the `fqdn` legacy fact to operate. When running Puppet with `--no-include_legacy_facts`, the behavior is changed: ```sh-session romain@zappy ~/Projects/puppetlabs/puppet % bundle exec puppet apply -e 'warning(fqdn_rand(100))' --include_legacy_facts Warning: Scope(Class[main]): 4 Notice: Compiled catalog for zappy.blogreen.org in environment production in 0.01 seconds Notice: Applied catalog in 0.01 seconds romain@zappy ~/Projects/puppetlabs/puppet % bundle exec puppet apply -e 'warning(fqdn_rand(100))' --no-include_legacy_facts Warning: Undefined variable '::fqdn'; (file & line not available) Warning: Scope(Class[main]): 79 Notice: Compiled catalog for zappy.blogreen.org in environment production in 0.01 seconds Notice: Applied catalog in 0.01 seconds ``` Adjust the `fqdn_rand` function to use the `networking.fqdn` fact instead of the old one to fix this issue.
1 parent a11fbba commit c0d2560

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/puppet/parser/functions/fqdn_rand.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
initial_seed = args.shift
2424
downcase = !!args.shift
2525

26-
fqdn = self['::fqdn']
26+
fqdn = self['facts'].dig('networking', 'fqdn')
2727
fqdn = fqdn.downcase if downcase
2828

2929
# Puppet 5.4's fqdn_rand function produces a different value than earlier versions

spec/unit/parser/functions/fqdn_rand_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def fqdn_rand(max, args = {})
8080
extra = args[:extra_identifier] || []
8181

8282
scope = create_test_scope_for_node('localhost')
83-
scope.compiler.topscope['fqdn'] = host.freeze
83+
scope.set_facts({ 'networking' => { 'fqdn' => host }})
8484

8585
scope.function_fqdn_rand([max] + extra)
8686
end

0 commit comments

Comments
 (0)