Skip to content

Commit 3a3adef

Browse files
committed
Face: do not rely on legacy facts
1 parent 382cf18 commit 3a3adef

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/puppetserver/ca/config/puppet.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ def load(cli_overrides: {}, logger:, ca_dir_warn: true)
7777
end
7878

7979
def default_certname
80-
hostname = Facter.value(:hostname)
81-
domain = Facter.value(:domain)
80+
networking = Facter.value(:networking)
81+
hostname = networking['hostname']
82+
domain = networking['domain']
8283
if domain and domain != ''
8384
fqdn = [hostname, domain].join('.')
8485
else

spec/puppetserver/ca/config/puppet_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,14 @@
338338

339339
context 'building the default certname' do
340340
it 'when there is a domain, concatenates the hostname and domain' do
341-
expect(Facter).to receive(:value).with(:hostname).and_return("foo")
342-
expect(Facter).to receive(:value).with(:domain).and_return("example.com")
341+
expect(Facter).to receive(:value).with(:networking).and_return({'domain' => 'example.com', 'hostname' => 'foo'})
343342

344343
conf = Puppetserver::Ca::Config::Puppet.new
345344
expect(conf.default_certname).to eq("foo.example.com")
346345
end
347346

348347
it 'when domain is nil, returns just the hostname' do
349-
expect(Facter).to receive(:value).with(:hostname).and_return("foo")
350-
expect(Facter).to receive(:value).with(:domain).and_return(nil)
348+
expect(Facter).to receive(:value).with(:networking).and_return({'domain' => nil, 'hostname' => 'foo'})
351349

352350
conf = Puppetserver::Ca::Config::Puppet.new
353351
expect(conf.default_certname).to eq("foo")

0 commit comments

Comments
 (0)