Skip to content

Commit 538d25b

Browse files
authored
Merge pull request #2622 from mhashizume/FACT-3435/main/rescue-dmi-sparc
(FACT-3435) Guard against non-global zones in DMI
2 parents a866afe + b3a2ba3 commit 538d25b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/facter/resolvers/solaris/dmi_sparc.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ def read_facts(fact_name)
1919

2020
matches = output.match(/System Configuration:\s+(.+?)\s+sun\d+\S+\s+(.+)/)&.captures
2121

22+
# There are circumstances (e.g. in non-global zones) when prtdiag
23+
# will return text, but it's an error message or some other string
24+
# that isn't parsed by the above match/capture. In that case, we
25+
# simply return.
26+
return if matches.nil?
27+
2228
@fact_list[:manufacturer] = matches[0]&.strip
2329
@fact_list[:product_name] = matches[1]&.strip
2430

spec/facter/resolvers/solaris/dmi_sparc_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,34 @@
3333
expect(resolver.resolve(:serial_number)).to eq('random_string')
3434
end
3535
end
36+
37+
describe '#reolve under a non-global zone' do
38+
subject(:resolver) { Facter::Resolvers::Solaris::DmiSparc }
39+
40+
let(:log_spy) { instance_spy(Facter::Log) }
41+
42+
before do
43+
resolver.instance_variable_set(:@log, log_spy)
44+
allow(File).to receive(:executable?).with('/usr/sbin/prtdiag').and_return(true)
45+
allow(Facter::Core::Execution).to receive(:execute)
46+
.with('/usr/sbin/prtdiag', { logger: log_spy })
47+
.and_return('prtdiag can only be run in the global zone')
48+
end
49+
50+
after do
51+
Facter::Resolvers::Solaris::DmiSparc.invalidate_cache
52+
end
53+
54+
it 'does not return manufacturer' do
55+
expect(resolver.resolve(:manufacturer)).to eq(nil)
56+
end
57+
58+
it 'does not return product_name' do
59+
expect(resolver.resolve(:product_name)).to eq(nil)
60+
end
61+
62+
it 'does not return serial_number' do
63+
expect(resolver.resolve(:serial_number)).to eq(nil)
64+
end
65+
end
3666
end

0 commit comments

Comments
 (0)