-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
835641d
commit 03adf43
Showing
6 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Solaris | ||
module Hypervisors | ||
class Ldom | ||
FACT_NAME = 'hypervisors.ldom' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Solaris::Ldom.resolve(:a) | ||
fact_value = fact_value[:available_bytes] if fact_value | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), | ||
Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Solaris | ||
class Virtual | ||
FACT_NAME = 'virtual' | ||
|
||
def initialize | ||
@log = Facter::Log.new(self) | ||
end | ||
|
||
def call_the_resolver | ||
@log.debug('Solaris Virtual Resolver') | ||
|
||
fact_value = check_ldom || check_zone || 'physical' | ||
|
||
@log.debug("Fact value is: #{fact_value}") | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
|
||
def check_ldom | ||
@log.debug('Checking LDoms') | ||
Facter::Resolvers::Solaris::Ldom.resolve(:role_impl) | ||
end | ||
|
||
def check_zone | ||
@log.debug('Checking LDoms') | ||
zone_name = Facter::Resolvers::SolarisZoneName.resolve(:current_zone_name) | ||
|
||
return if zone_name == 'global' | ||
|
||
zone_name | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Resolvers | ||
module Solaris | ||
class Ldom < BaseResolver | ||
@semaphore = Mutex.new | ||
@fact_list ||= {} | ||
class << self | ||
private | ||
|
||
def post_resolve(fact_name) | ||
@fact_list.fetch(fact_name) { call_virtinfo(fact_name) } | ||
end | ||
|
||
def call_virtinfo(fact_name) | ||
# return unless File.executable?('/usr/sbin/virtinfo') | ||
|
||
virtinfo_output = Facter::Core::Execution.execute('/usr/sbin/virtinfo -a -p', logger: log) | ||
return if virtinfo_output.empty? | ||
|
||
output_hash = parse_output(virtinfo_output) | ||
return if output_hash.empty? | ||
|
||
@fact_list[:chassis_serial] = output_hash['DOMAINCHASSIS']&.[]('serialno').strip | ||
@fact_list[:control_domain] = output_hash['DOMAINCONTROL']&.[]('name').strip | ||
@fact_list[:domain_name] = output_hash['DOMAINNAME']&.[]('name').strip | ||
@fact_list[:domain_uuid] = output_hash['DOMAINUUID']&.[]('uuid').strip | ||
@fact_list[:role_control] = output_hash['DOMAINROLE']&.[]('control').strip | ||
@fact_list[:role_io] = output_hash['DOMAINROLE']&.[]('io').strip | ||
@fact_list[:role_root] = output_hash['DOMAINROLE']&.[]('root').strip | ||
@fact_list[:role_service] = output_hash['DOMAINROLE']&.[]('service').strip | ||
@fact_list[:role_impl] = output_hash['DOMAINROLE']&.[]('impl').strip | ||
|
||
@fact_list[fact_name] | ||
end | ||
|
||
def parse_output(output) | ||
result = {} | ||
output.each_line do |line| | ||
next unless line.include? 'DOMAIN' | ||
|
||
x = line.split('|') | ||
result[x.shift] = x.map { |f| f.split('=') }.to_h | ||
end | ||
|
||
result | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Solaris::Virtual do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Solaris::Virtual.new } | ||
|
||
context 'when no hypervisor is found' do | ||
let(:vm) { 'physical' } | ||
|
||
before do | ||
allow(Facter::Resolvers::SolarisZoneName).to receive(:resolve).with(:current_zone_name).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_impl).and_return(nil) | ||
end | ||
|
||
it 'returns virtual fact as physical' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'virtual', value: vm) | ||
end | ||
end | ||
|
||
context 'when ldom hypervisor is found' do | ||
let(:vm) { 'LDoms' } | ||
|
||
before do | ||
allow(Facter::Resolvers::SolarisZoneName).to receive(:resolve).with(:current_zone_name).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_impl).and_return(vm) | ||
end | ||
|
||
it 'returns virtual fact as physical' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'virtual', value: vm) | ||
end | ||
end | ||
|
||
context 'when zone hypervisor is found' do | ||
let(:vm) { 'my_zone' } | ||
|
||
before do | ||
allow(Facter::Resolvers::SolarisZoneName).to receive(:resolve).with(:current_zone_name).and_return(vm) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_impl).and_return(nil) | ||
end | ||
|
||
it 'returns virtual fact as physical' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'virtual', value: vm) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facter::Resolvers::Solaris::Ldom do | ||
subject(:resolver) { Facter::Resolvers::Solaris::Ldom } | ||
|
||
let(:log_spy) { instance_spy(Facter::Log) } | ||
|
||
before do | ||
resolver.instance_variable_set(:@log, log_spy) | ||
allow(Facter::Core::Execution) | ||
.to receive(:execute) | ||
.with('/usr/sbin/virtinfo -a -p', logger: log_spy) | ||
.and_return(output) | ||
end | ||
|
||
after do | ||
resolver.invalidate_cache | ||
end | ||
|
||
context 'when syscall returns valid output' do | ||
let(:output) { load_fixture('virtinfo').read } | ||
|
||
it 'parses chassis_serial' do | ||
expect(resolver.resolve(:chassis_serial)).to eq('AK00358110') | ||
end | ||
|
||
it 'parses control_domain' do | ||
expect(resolver.resolve(:control_domain)).to eq('opdx-a0-sun2') | ||
end | ||
|
||
it 'parses domain_name' do | ||
expect(resolver.resolve(:domain_name)).to eq('sol11-11') | ||
end | ||
|
||
it 'parses domain_uuid' do | ||
expect(resolver.resolve(:domain_uuid)).to eq('415dfab4-c373-4ac0-9414-8bf00801fb72') | ||
end | ||
|
||
it 'parses role_control' do | ||
expect(resolver.resolve(:role_control)).to eq('false') | ||
end | ||
|
||
it 'parses role_io' do | ||
expect(resolver.resolve(:role_io)).to eq('false') | ||
end | ||
|
||
it 'parses role_root' do | ||
expect(resolver.resolve(:role_root)).to eq('false') | ||
end | ||
|
||
it 'parses role_service' do | ||
expect(resolver.resolve(:role_service)).to eq('false') | ||
end | ||
end | ||
|
||
context 'when syscall returns invalid output' do | ||
let(:output) { 'iNvAlId OuTpUt' } | ||
|
||
it 'parses chassis_serial to nil' do | ||
expect(resolver.resolve(:chassis_serial)).to be_nil | ||
end | ||
|
||
it 'parses control_domain to nil' do | ||
expect(resolver.resolve(:control_domain)).to be_nil | ||
end | ||
|
||
it 'parses domain_name to nil' do | ||
expect(resolver.resolve(:domain_name)).to be_nil | ||
end | ||
|
||
it 'parses domain_uuid to nil' do | ||
expect(resolver.resolve(:domain_uuid)).to be_nil | ||
end | ||
|
||
it 'parses role_control to nil' do | ||
expect(resolver.resolve(:role_control)).to be_nil | ||
end | ||
|
||
it 'parses role_io to nil' do | ||
expect(resolver.resolve(:role_io)).to be_nil | ||
end | ||
|
||
it 'parses role_root to nil' do | ||
expect(resolver.resolve(:role_root)).to be_nil | ||
end | ||
|
||
it 'parses role_service to nil' do | ||
expect(resolver.resolve(:role_service)).to be_nil | ||
end | ||
end | ||
|
||
context 'when syscall has no output' do | ||
let(:output) { '' } | ||
|
||
it 'parses chassis_serial to nil' do | ||
expect(resolver.resolve(:chassis_serial)).to be_nil | ||
end | ||
|
||
it 'parses control_domain to nil' do | ||
expect(resolver.resolve(:control_domain)).to be_nil | ||
end | ||
|
||
it 'parses domain_name to nil' do | ||
expect(resolver.resolve(:domain_name)).to be_nil | ||
end | ||
|
||
it 'parses domain_uuid to nil' do | ||
expect(resolver.resolve(:domain_uuid)).to be_nil | ||
end | ||
|
||
it 'parses role_control to nil' do | ||
expect(resolver.resolve(:role_control)).to be_nil | ||
end | ||
|
||
it 'parses role_io to nil' do | ||
expect(resolver.resolve(:role_io)).to be_nil | ||
end | ||
|
||
it 'parses role_root to nil' do | ||
expect(resolver.resolve(:role_root)).to be_nil | ||
end | ||
|
||
it 'parses role_service to nil' do | ||
expect(resolver.resolve(:role_service)).to be_nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
VERSION 1.0 | ||
DOMAINROLE|impl=LDoms|control=false|io=false|service=false|root=false | ||
DOMAINNAME|name=sol11-11 | ||
DOMAINUUID|uuid=415dfab4-c373-4ac0-9414-8bf00801fb72 | ||
DOMAINCONTROL|name=opdx-a0-sun2 | ||
DOMAINCHASSIS|serialno=AK00358110 |