Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FACT-3121) Detect Illumos (SmartOS/OmniOS) LX virtualization #2492

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/facter/util/facts/posix/virtual_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module VirtualDetector
class << self
def platform
@fact_value ||= # rubocop:disable Naming/MemoizedInstanceVariableName
check_docker_lxc || check_freebsd || check_gce || retrieve_from_virt_what || \
check_vmware || check_open_vz || check_vserver || check_xen || check_other_facts || \
check_lspci || 'physical'
check_docker_lxc || check_freebsd || check_gce || check_illumos_lx || \
retrieve_from_virt_what || check_vmware || check_open_vz || check_vserver || \
check_xen || check_other_facts || check_lspci || 'physical'
end

private
Expand All @@ -24,6 +24,10 @@ def check_gce
'gce' if bios_vendor&.include?('Google')
end

def check_illumos_lx
'illumos-lx' if Facter::Resolvers::Uname.resolve(:kernelversion) == 'BrandZ virtual linux'
end

def check_vmware
Facter::Resolvers::Vmware.resolve(:vm)
end
Expand Down
26 changes: 26 additions & 0 deletions spec/facter/util/facts/posix/virtual_detector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(value)
end

Expand All @@ -96,6 +97,7 @@
allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil)
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(value)
end

Expand All @@ -119,6 +121,7 @@
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil)
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(value)
end

Expand All @@ -143,6 +146,7 @@
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(value)
end

Expand All @@ -168,6 +172,7 @@
allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(value)
end

Expand All @@ -193,6 +198,7 @@
allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(nil)
allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return('Bochs Machine')
end
Expand Down Expand Up @@ -227,6 +233,7 @@
allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return(value)
end

Expand All @@ -241,6 +248,23 @@
end
end

context 'when illumos-lx' do
let(:value) { 'illumos-lx' }

before do
allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return(nil)
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return('lxc')
smokris marked this conversation as resolved.
Show resolved Hide resolved
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return('BrandZ virtual linux')
end

it 'returns illumos-lx' do
expect(detector.platform).to eq(value)
end
end

context 'when all resolvers return nil ' do
let(:vm) { 'physical' }

Expand All @@ -255,6 +279,7 @@
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return(nil)
allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
end

it 'returns physical' do
Expand All @@ -274,6 +299,7 @@
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(nil)
allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return(nil)
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil)
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return('unknown')
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return('unknown')
end
Expand Down