-
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.
(FACT-2728) Added hypervisors fact for Solaris
- Loading branch information
1 parent
b7fa483
commit 9c36e5c
Showing
4 changed files
with
215 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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Solaris | ||
module Hypervisors | ||
class Ldom | ||
FACT_NAME = 'hypervisors.ldom' | ||
|
||
def initialize | ||
@log = Facter::Log.new(self) | ||
end | ||
|
||
def call_the_resolver | ||
fact_value = %i[ | ||
chassis_serial control_domain domain_name | ||
domain_uuid role_control role_io role_root role_service | ||
].map! { |key| [key, Facter::Resolvers::Solaris::Ldom.resolve(key)] }.to_h | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
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,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Solaris | ||
module Hypervisors | ||
class Zone | ||
FACT_NAME = 'hypervisors.zone' | ||
|
||
def initialize | ||
@log = Facter::Log.new(self) | ||
end | ||
|
||
def call_the_resolver | ||
fact_value = current_zone | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
|
||
def current_zone | ||
current_zone_name = Facter::Resolvers::Solaris::ZoneName.resolve(:current_zone_name) | ||
return unless current_zone_name | ||
|
||
zones = Facter::Resolvers::Solaris::Zone.resolve(:zone) | ||
return Facter::ResolvedFact.new(FACT_NAME, nil) unless zones | ||
|
||
current_zone = zones.find { |r| r[:name] == current_zone_name } | ||
|
||
{ | ||
brand: current_zone[:brand], | ||
id: current_zone[:id], | ||
ip_type: current_zone[:iptype], | ||
name: current_zone[:name], | ||
uuid: current_zone[:uuid] | ||
} | ||
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,79 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Solaris::Hypervisors::Ldom do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Solaris::Hypervisors::Ldom.new } | ||
|
||
before do | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve) | ||
end | ||
|
||
context 'when Ldom resolver returns values' do | ||
let(:value) do | ||
{ | ||
'chassis_serial' => 'AK00358110', | ||
'control_domain' => 'opdx-a0-sun2', | ||
'domain_name' => 'sol11-9', | ||
'domain_uuid' => 'd7a3a4df-ce8c-47a9-b396-cb5a5f30c0b2', | ||
'role_control' => 'false', | ||
'role_io' => 'false', | ||
'role_root' => 'false', | ||
'role_service' => 'false' | ||
} | ||
end | ||
|
||
before do | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:chassis_serial).and_return('AK00358110') | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:control_domain).and_return('opdx-a0-sun2') | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:domain_name).and_return('sol11-9') | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_control).and_return('false') | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_io).and_return('false') | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_root).and_return('false') | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_service).and_return('false') | ||
allow(Facter::Resolvers::Solaris::Ldom) | ||
.to receive(:resolve) | ||
.with(:domain_uuid) | ||
.and_return('d7a3a4df-ce8c-47a9-b396-cb5a5f30c0b2') | ||
end | ||
|
||
it 'returns virtual fact as physical' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'hypervisors.ldom', value: value) | ||
end | ||
end | ||
|
||
context 'when ldom resolver returns nil' do | ||
before do | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:chassis_serial).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:control_domain).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:domain_name).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_control).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_impl).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_io).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_root).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:role_service).and_return(nil) | ||
allow(Facter::Resolvers::Solaris::Ldom).to receive(:resolve).with(:domain_uuid).and_return(nil) | ||
end | ||
|
||
context 'when role_control is false' do | ||
let(:value) do | ||
{ | ||
'chassis_serial' => nil, | ||
'control_domain' => nil, | ||
'domain_name' => nil, | ||
'domain_uuid' => nil, | ||
'role_control' => nil, | ||
'role_io' => nil, | ||
'role_root' => nil, | ||
'role_service' => 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: 'hypervisors.ldom', value: value) | ||
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,73 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Solaris::Hypervisors::Zone do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Solaris::Hypervisors::Zone.new } | ||
|
||
before do | ||
allow(Facter::Resolvers::Solaris::ZoneName).to receive(:resolve) | ||
allow(Facter::Resolvers::Solaris::Zone).to receive(:resolve) | ||
end | ||
|
||
context 'when current zone name is nil' do | ||
let(:current_zone_name) { nil } | ||
|
||
before do | ||
allow(Facter::Resolvers::Solaris::ZoneName) | ||
.to receive(:resolve) | ||
.with(:current_zone_name) | ||
.and_return(current_zone_name) | ||
end | ||
|
||
it 'returns virtual fact as physical' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'hypervisors.zone', value: nil) | ||
end | ||
end | ||
|
||
context 'when current zone name is valid' do | ||
let(:current_zone_name) { 'global' } | ||
let(:zones) do | ||
[ | ||
{ | ||
brand: 'solaris', | ||
id: 0, | ||
iptype: 'shared', | ||
name: 'global', | ||
uuid: '1234', | ||
status: 'running', | ||
path: 'my/path' | ||
}, | ||
{ | ||
brand: 'solaris', | ||
id: 1, | ||
iptype: 'not_shared', | ||
name: 'global2', | ||
uuid: '4321', | ||
status: 'running', | ||
path: 'my/path' | ||
} | ||
] | ||
end | ||
|
||
before do | ||
allow(Facter::Resolvers::Solaris::ZoneName) | ||
.to receive(:resolve) | ||
.with(:current_zone_name) | ||
.and_return(current_zone_name) | ||
allow(Facter::Resolvers::Solaris::Zone).to receive(:resolve).with(:zone).and_return(zones) | ||
end | ||
|
||
it 'returns current zone details' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'hypervisors.zone', value: { | ||
'brand' => 'solaris', | ||
'id' => 0, | ||
'ip_type' => 'shared', | ||
'name' => 'global', | ||
'uuid' => '1234' | ||
}) | ||
end | ||
end | ||
end | ||
end |