Skip to content

Commit

Permalink
(FACT-2689) Add docker fact
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Tanasoiu committed Jul 2, 2020
1 parent ee5f5d4 commit 25a34ab
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 33 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

### Added
- \(FACT-2218\) virtual fact for OSX [\#1945](https://github.com/puppetlabs/facter/pull/1945) ([IrimieBogdan](https://github.com/IrimieBogdan))
- \(FACT-2232\) Add Aix networking facts [\#1937](https://github.com/puppetlabs/facter-ng/pull/1937) ([oanatmaria](https://github.com/oanatmaria))
- \(FACT-2232\) Add Aix networking facts [\#1937](https://github.com/puppetlabs/facter/pull/1937) ([oanatmaria](https://github.com/oanatmaria))

### Fixed
- \(FACT-2676\) fix os identifier for opensuse-leap [\#1944](https://github.com/puppetlabs/facter-ng/pull/1944) ([Filipovici-Andrei](https://github.com/Filipovici-Andrei))
- FACT-2679 Get DHCP for all interfaces on OSX [\#1940](https://github.com/puppetlabs/facter-ng/pull/1940) ([Filipovici-Andrei](https://github.com/Filipovici-Andrei))
- \(FACT-2676\) fix os identifier for opensuse-leap [\#1944](https://github.com/puppetlabs/facter/pull/1944) ([Filipovici-Andrei](https://github.com/Filipovici-Andrei))
- FACT-2679 Get DHCP for all interfaces on OSX [\#1940](https://github.com/puppetlabs/facter/pull/1940) ([Filipovici-Andrei](https://github.com/Filipovici-Andrei))

## [4.0.28](https://github.com/puppetlabs/facter/tree/4.0.28) (2020-06-25)

Expand Down
18 changes: 0 additions & 18 deletions lib/facts/linux/hypervisors.rb

This file was deleted.

21 changes: 21 additions & 0 deletions lib/facts/linux/hypervisors/docker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Facts
module Linux
module Hypervisors
class Docker
FACT_NAME = 'hypervisors.docker'

def call_the_resolver
fact_value = check_docker
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end

def check_docker
info = Facter::Resolvers::DockerLxc.resolve(:hypervisor)
info.values.first if info && info.keys.first == :docker
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# frozen_string_literal: true

describe Facts::Linux::Hypervisors do
describe Facts::Linux::Hypervisors::Docker do
describe '#call_the_resolver' do
subject(:fact) { Facts::Linux::Hypervisors.new }
subject(:fact) { Facts::Linux::Hypervisors::Docker.new }

before do
allow(Facter::Resolvers::DockerLxc).to \
receive(:resolve).with(:hypervisor).and_return(hv)
end

context 'when resolver returns docker' do
let(:hv) { { 'docker' => { 'id' => 'testid' } } }
let(:hv) { { docker: { 'id' => 'testid' } } }
let(:value) { { 'id' => 'testid' } }

it 'calls Facter::Resolvers::DockerLxc' do
fact.call_the_resolver
Expand All @@ -19,21 +20,16 @@

it 'returns virtual fact' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'hypervisors', value: hv)
have_attributes(name: 'hypervisors.docker', value: value)
end
end

context 'when resolver returns lxc' do
let(:hv) { { 'lxc' => { 'name' => 'test_name' } } }

it 'calls Facter::Resolvers::DockerLxc' do
fact.call_the_resolver
expect(Facter::Resolvers::DockerLxc).to have_received(:resolve).with(:hypervisor)
end
let(:hv) { { lxc: { 'name' => 'test_name' } } }

it 'returns virtual fact' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'hypervisors', value: hv)
have_attributes(name: 'hypervisors.docker', value: nil)
end
end

Expand All @@ -42,7 +38,17 @@

it 'returns virtual fact as nil' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'hypervisors', value: hv)
have_attributes(name: 'hypervisors.docker', value: hv)
end
end

context 'when docker info is empty' do
let(:hv) { { docker: {} } }
let(:value) { {} }

it 'returns virtual fact as nil' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'hypervisors.docker', value: value)
end
end
end
Expand Down

0 comments on commit 25a34ab

Please sign in to comment.