-
Notifications
You must be signed in to change notification settings - Fork 493
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
Oana Tanasoiu
committed
Jul 13, 2020
1 parent
353bf71
commit 1b3b419
Showing
6 changed files
with
123 additions
and
4 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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
module Hypervisors | ||
class Openvz | ||
FACT_NAME = 'hypervisors.openvz' | ||
|
||
def call_the_resolver | ||
fact_value = check_openvz | ||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
|
||
def check_openvz | ||
openvz = Facter::Resolvers::OpenVz.resolve(:vm) | ||
return unless openvz | ||
|
||
id = Facter::Resolvers::OpenVz.resolve(:id) | ||
|
||
{ id: id.to_i, host: openvz == 'openvzhn' } | ||
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
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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Linux::Hypervisors::Openvz do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Linux::Hypervisors::Openvz.new } | ||
|
||
before do | ||
allow(Facter::Resolvers::OpenVz).to \ | ||
receive(:resolve).with(:vm).and_return(ovz) | ||
end | ||
|
||
context 'when resolver returns nil' do | ||
let(:ovz) { nil } | ||
|
||
it 'calls Facter::Resolvers::Containers' do | ||
fact.call_the_resolver | ||
expect(Facter::Resolvers::OpenVz).to have_received(:resolve).with(:vm) | ||
end | ||
|
||
it 'returns virtual fact as nil' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'hypervisors.openvz', value: nil) | ||
end | ||
end | ||
|
||
context 'when resolver returns openvz host' do | ||
before { allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:id).and_return('0') } | ||
|
||
let(:ovz) { 'openvzhn' } | ||
let(:value) { { 'id' => 0, 'host' => true } } | ||
|
||
it 'returns openvz info' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'hypervisors.openvz', value: value) | ||
end | ||
end | ||
|
||
context 'when resolver returns openvz' do | ||
before { allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:id).and_return('101') } | ||
|
||
let(:ovz) { 'openvze' } | ||
let(:value) { { 'id' => 101, 'host' => false } } | ||
|
||
it 'returns openvz info' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'hypervisors.openvz', value: value) | ||
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
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
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,18 @@ | ||
Name: cat | ||
Umask: 0002 | ||
State: R (running) | ||
Tgid: 14437 | ||
Ngid: 0 | ||
Pid: 14437 | ||
PPid: 14122 | ||
TracerPid: 0 | ||
Uid: 1000 1000 1000 1000 | ||
Gid: 1000 1000 1000 1000 | ||
FDSize: 256 | ||
Groups: 4 20 24 25 27 29 30 44 46 108 114 1000 | ||
NStgid: 14437 | ||
NSpid: 14437 | ||
NSpgid: 14437 | ||
envID: 0 | ||
NSsid: 14122 | ||
VxID: 0 |