This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FACT-2477) Collect facts from alternative sources
- Loading branch information
Oana Tanasoiu
committed
Apr 8, 2020
1 parent
673dff5
commit b38b56f
Showing
17 changed files
with
352 additions
and
56 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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Debian | ||
class Lsbdistcodename | ||
FACT_NAME = 'lsbdistcodename' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::LsbRelease.resolve(:codename) | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy) | ||
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Debian | ||
class Lsbdistdescription | ||
FACT_NAME = 'lsbdistdescription' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::LsbRelease.resolve(:description) | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy) | ||
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Debian | ||
class Lsbdistid | ||
FACT_NAME = 'lsbdistid' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::LsbRelease.resolve(:distributor_id) | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy) | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Debian | ||
class Lsbdistrelease | ||
FACT_NAME = 'lsbdistrelease' | ||
ALIASES = %w[lsbmajdistrelease lsbminordistrelease].freeze | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::LsbRelease.resolve(:release) | ||
|
||
return Facter::ResolvedFact.new(FACT_NAME, nil, :legacy) unless fact_value | ||
|
||
version = fact_value.split('.') | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy), | ||
Facter::ResolvedFact.new(ALIASES[0], version[0], :legacy), | ||
Facter::ResolvedFact.new(ALIASES[1], version[1], :legacy)] | ||
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
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Debian::Lsbdistcodename do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Debian::Lsbdistcodename.new } | ||
|
||
let(:value) { 'stretch' } | ||
|
||
before do | ||
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:codename).and_return(value) | ||
end | ||
|
||
it 'calls Facter::Resolvers::LsbRelease' do | ||
fact.call_the_resolver | ||
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:codename) | ||
end | ||
|
||
it 'returns lsbdistcodename fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'lsbdistcodename', value: value, type: :legacy) | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Debian::Lsbdistdescription do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Debian::Lsbdistdescription.new } | ||
|
||
let(:value) { 'stretch' } | ||
|
||
before do | ||
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:description).and_return(value) | ||
end | ||
|
||
it 'calls Facter::Resolvers::LsbRelease' do | ||
fact.call_the_resolver | ||
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:description) | ||
end | ||
|
||
it 'returns lsbdistdescription fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'lsbdistdescription', value: value, type: :legacy) | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Debian::Lsbdistid do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Debian::Lsbdistid.new } | ||
|
||
let(:value) { 'stretch' } | ||
|
||
before do | ||
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:distributor_id).and_return(value) | ||
end | ||
|
||
it 'calls Facter::Resolvers::LsbRelease' do | ||
fact.call_the_resolver | ||
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:distributor_id) | ||
end | ||
|
||
it 'returns lsbdistid fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'lsbdistid', value: value, type: :legacy) | ||
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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Debian::Lsbdistrelease do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Debian::Lsbdistrelease.new } | ||
|
||
context 'when lsb-release is installed' do | ||
before do | ||
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:release).and_return(value) | ||
end | ||
|
||
context 'when version_id is retrieved successful' do | ||
let(:value) { '18.04' } | ||
let(:value_final) { { 'full' => '18.04', 'major' => '18', 'minor' => '04' } } | ||
|
||
it 'calls Facter::Resolvers::LsbRelease with :name' do | ||
fact.call_the_resolver | ||
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:release) | ||
end | ||
|
||
it 'returns release fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ | ||
contain_exactly(an_object_having_attributes(name: 'lsbdistrelease', value: value, type: :legacy), | ||
an_object_having_attributes(name: 'lsbmajdistrelease', | ||
value: value_final['major'], type: :legacy), | ||
an_object_having_attributes(name: 'lsbminordistrelease', | ||
value: value_final['minor'], type: :legacy)) | ||
end | ||
end | ||
|
||
context 'when Debian 10' do | ||
let(:value) { '10' } | ||
let(:value_final) { { 'full' => '10', 'major' => '10', 'minor' => nil } } | ||
|
||
it 'calls Facter::Resolvers::LsbRelease with :name' do | ||
fact.call_the_resolver | ||
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:release) | ||
end | ||
|
||
it 'returns release fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ | ||
contain_exactly(an_object_having_attributes(name: 'lsbdistrelease', value: value, type: :legacy), | ||
an_object_having_attributes(name: 'lsbmajdistrelease', | ||
value: value_final['major'], type: :legacy), | ||
an_object_having_attributes(name: 'lsbminordistrelease', | ||
value: value_final['minor'], type: :legacy)) | ||
end | ||
end | ||
|
||
context 'when lsb-release is not installed' do | ||
let(:value) { nil } | ||
|
||
it 'returns release fact as nil' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'lsbdistrelease', value: value, type: :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
Oops, something went wrong.