diff --git a/lib/facter/resolvers/uname.rb b/lib/facter/resolvers/uname.rb index 49dd3809c5..8213dcb9fc 100644 --- a/lib/facter/resolvers/uname.rb +++ b/lib/facter/resolvers/uname.rb @@ -3,6 +3,8 @@ module Facter module Resolvers class Uname < BaseResolver + @log = Facter::Log.new(self) + init_resolver class << self diff --git a/lib/facter/resolvers/xen.rb b/lib/facter/resolvers/xen.rb index 2f02bfa01a..cb2125322f 100644 --- a/lib/facter/resolvers/xen.rb +++ b/lib/facter/resolvers/xen.rb @@ -66,6 +66,8 @@ def find_command return XEN_TOOLSTACK if num_stacks > 1 && File.exist?(XEN_TOOLSTACK) XEN_COMMANDS.each { |command| return command if File.exist?(command) } + + nil end end end diff --git a/spec/facter/resolvers/amzn/os_release_rpm_spec.rb b/spec/facter/resolvers/amzn/os_release_rpm_spec.rb index b2ca9073ad..be2e24d672 100644 --- a/spec/facter/resolvers/amzn/os_release_rpm_spec.rb +++ b/spec/facter/resolvers/amzn/os_release_rpm_spec.rb @@ -3,7 +3,7 @@ describe Facter::Resolvers::Amzn::OsReleaseRpm do subject(:os_release_resolver) { Facter::Resolvers::Amzn::OsReleaseRpm } - let(:log_spy) { Facter::Log } + let(:log_spy) { instance_spy(Facter::Log) } before do os_release_resolver.instance_variable_set(:@log, log_spy) diff --git a/spec/facter/resolvers/ec2_spec.rb b/spec/facter/resolvers/ec2_spec.rb index 31305b1276..85d27a6106 100644 --- a/spec/facter/resolvers/ec2_spec.rb +++ b/spec/facter/resolvers/ec2_spec.rb @@ -11,6 +11,7 @@ before do Facter::Util::Resolvers::Http.instance_variable_set(:@log, log_spy) + allow(Socket).to receive(:tcp) if Gem.win_platform? end after do diff --git a/spec/facter/resolvers/processors_spec.rb b/spec/facter/resolvers/processors_spec.rb index 246f3699c9..972d25e369 100644 --- a/spec/facter/resolvers/processors_spec.rb +++ b/spec/facter/resolvers/processors_spec.rb @@ -52,8 +52,10 @@ allow(Facter::Util::FileHelper).to receive(:safe_readlines) .with('/proc/cpuinfo') .and_return(load_fixture('cpuinfo_wo_physical_id').readlines) + allow(Dir).to receive(:entries).and_call_original allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex]) + allow(File).to receive(:exist?).and_call_original allow(File).to receive(:exist?) .with('/sys/devices/system/cpu/cpu0/topology/physical_package_id') .and_return(true) @@ -117,9 +119,13 @@ .with('/proc/cpuinfo') .and_return(load_fixture('cpuinfo_powerpc').readlines) + allow(Dir).to receive(:entries).and_call_original allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex]) + + allow(File).to receive(:exist?).and_call_original allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu0/topology/physical_package_id').and_return(true) allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu1/topology/physical_package_id').and_return(true) + allow(Facter::Util::FileHelper).to receive(:safe_read) .with('/sys/devices/system/cpu/cpu0/topology/physical_package_id') .and_return('0') @@ -164,9 +170,13 @@ .with('/proc/cpuinfo') .and_return(load_fixture('cpuinfo_arm64').readlines) + allow(Dir).to receive(:entries).and_call_original allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex]) + + allow(File).to receive(:exist?).and_call_original allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu0/topology/physical_package_id').and_return(true) allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu1/topology/physical_package_id').and_return(true) + allow(Facter::Util::FileHelper).to receive(:safe_read) .with('/sys/devices/system/cpu/cpu0/topology/physical_package_id') .and_return('0') diff --git a/spec/facter/resolvers/uname_spec.rb b/spec/facter/resolvers/uname_spec.rb index 59e2af6769..e035d58237 100644 --- a/spec/facter/resolvers/uname_spec.rb +++ b/spec/facter/resolvers/uname_spec.rb @@ -3,7 +3,7 @@ describe Facter::Resolvers::Uname do subject(:uname_resolver) { Facter::Resolvers::Uname } - let(:log_spy) { Facter::Log } + let(:log_spy) { instance_spy(Facter::Log) } before do uname_resolver.instance_variable_set(:@log, log_spy) @@ -22,6 +22,11 @@ Darwin Kernel Version 18.2.0: Fri Oct 5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64') end + after do + uname_resolver.instance_variable_set(:@log, nil) + Facter::Resolvers::Uname.invalidate_cache + end + it 'returns machine' do expect(uname_resolver.resolve(:machine)).to eq('x86_64') end diff --git a/spec/facter/resolvers/xen_spec.rb b/spec/facter/resolvers/xen_spec.rb index 222b6de1ab..3b3db6b9f7 100644 --- a/spec/facter/resolvers/xen_spec.rb +++ b/spec/facter/resolvers/xen_spec.rb @@ -10,6 +10,7 @@ before do xen_resolver.instance_variable_set(:@log, log_spy) + allow(File).to receive(:exist?).and_call_original allow(File).to receive(:exist?).with('/dev/xen/evtchn').and_return(evtchn_file) allow(File).to receive(:exist?).with('/proc/xen').and_return(proc_xen_file) allow(File).to receive(:exist?).with('/dev/xvda1').and_return(xvda1_file) @@ -26,6 +27,18 @@ xen_resolver.invalidate_cache end + context 'when not xen' do + let(:evtchn_file) { false } + let(:proc_xen_file) { false } + let(:xvda1_file) { false } + + it 'returns' do + allow(File).to receive(:exist?).with('/usr/sbin/xm').and_return(false) + + expect(xen_resolver.resolve(:vm)).to be_nil + end + end + context 'when xen is privileged' do context 'when /dev/xen/evtchn exists' do let(:domains) { load_fixture('xen_domains').read } diff --git a/spec/facter/util/linux/if_inet6_spec.rb b/spec/facter/util/linux/if_inet6_spec.rb index 5adcd3fcd2..61f60c10e7 100644 --- a/spec/facter/util/linux/if_inet6_spec.rb +++ b/spec/facter/util/linux/if_inet6_spec.rb @@ -28,6 +28,7 @@ describe '#read_flags' do context 'when only ipv6 link-local and lo ipv6 present' do before do + allow(File).to receive(:exist?).and_call_original allow(File).to receive(:exist?).with('/proc/net/if_inet6').and_return(true) allow(Facter::Util::FileHelper).to receive(:safe_read) .with('/proc/net/if_inet6', nil).and_return(load_fixture('proc_net_if_inet6').read) @@ -38,6 +39,7 @@ context 'when multiple IPv6 addresses present with different flags' do before do + allow(File).to receive(:exist?).and_call_original allow(File).to receive(:exist?).with('/proc/net/if_inet6').and_return(true) allow(Facter::Util::FileHelper).to receive(:safe_read) .with('/proc/net/if_inet6', nil).and_return(load_fixture('proc_net_if_inet6_complex').read)