Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Merge d173d5e into 106aebd
Browse files Browse the repository at this point in the history
  • Loading branch information
oanatmaria authored Mar 25, 2020
2 parents 106aebd + d173d5e commit f6b8bea
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 102 deletions.
9 changes: 5 additions & 4 deletions lib/facts/debian/os/distro/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class Release
ALIASES = %w[lsbdistrelease lsbmajdistrelease lsbminordistrelease].freeze

def call_the_resolver
fact_value = Facter::Resolvers::LsbRelease.resolve(:release)
fact_value = Facter::Resolvers::OsRelease.resolve(:release)

return Facter::ResolvedFact.new(FACT_NAME, nil) unless fact_value

versions = fact_value.split('.')
release = {
'full' => fact_value,
'major' => versions[0],
'minor' => versions[1]
'full' => fact_value,
'major' => versions[0],
'minor' => versions[1].gsub(/^0([1-9])/, '\1')
}

[Facter::ResolvedFact.new(FACT_NAME, release),
Expand Down
2 changes: 1 addition & 1 deletion lib/facts/debian/os/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Name
ALIASES = 'operatingsystem'

def call_the_resolver
fact_value = Facter::Resolvers::LsbRelease.resolve(:distributor_id)
fact_value = Facter::Resolvers::OsRelease.resolve(:name)

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/facts/debian/os/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class Release
ALIASES = %w[operatingsystemmajrelease operatingsystemrelease].freeze

def call_the_resolver
fact_value = Facter::Resolvers::LsbRelease.resolve(:release)
fact_value = Facter::Resolvers::OsRelease.resolve(:release)

return Facter::ResolvedFact.new(FACT_NAME, nil) unless fact_value

versions = fact_value.split('.')
release = {
'full' => fact_value,
'major' => versions[0],
'minor' => versions[1]
'minor' => versions[1].gsub(/^0([1-9])/, '\1')
}

[Facter::ResolvedFact.new(FACT_NAME, release),
Expand Down
34 changes: 0 additions & 34 deletions lib/resolvers/debian_version_resolver.rb

This file was deleted.

9 changes: 9 additions & 0 deletions lib/resolvers/os_release_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def read_os_release_file(fact_name)

fill_fact_list(pairs)
process_name
find_debian_release if @fact_list[:name].match?(/Debian/)

@fact_list[fact_name]
end
Expand All @@ -48,6 +49,7 @@ def fill_fact_list(pairs)
result.each { |k, v| @fact_list[k.downcase.to_sym] = v }

@fact_list[:identifier] = @fact_list[:id]
@fact_list[:release] = @fact_list[:version_id]
end

def process_name
Expand All @@ -59,6 +61,13 @@ def process_name
@fact_list[:name].split(' ')[0].strip
end
end

def find_debian_release
return unless File.readable?('/etc/debian_version')

version = File.read('/etc/debian_version')
@fact_list[:release] = version.strip
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/facter/facts/debian/os/distro/release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
let(:release) { { 'full' => '9.0', 'major' => '9', 'minor' => '0' } }

before do
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:release).and_return(value)
allow(Facter::Resolvers::OsRelease).to receive(:resolve).with(:release).and_return(value)
end

it 'calls Facter::Resolvers::LsbRelease' do
fact.call_the_resolver
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:release)
expect(Facter::Resolvers::OsRelease).to have_received(:resolve).with(:release)
end

it 'returns release fact' do
Expand All @@ -30,7 +30,7 @@
let(:value) { nil }

before do
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:release).and_return(value)
allow(Facter::Resolvers::OsRelease).to receive(:resolve).with(:release).and_return(value)
end

it 'returns release fact' do
Expand Down
6 changes: 3 additions & 3 deletions spec/facter/facts/debian/os/name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
let(:value) { 'Debian' }

before do
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:distributor_id).and_return(value)
allow(Facter::Resolvers::OsRelease).to receive(:resolve).with(:name).and_return(value)
end

it 'calls Facter::Resolvers::LsbRelease' do
it 'calls Facter::Resolvers::OsRelease' do
fact.call_the_resolver
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:distributor_id)
expect(Facter::Resolvers::OsRelease).to have_received(:resolve).with(:name)
end

it 'returns operating system name fact' do
Expand Down
10 changes: 5 additions & 5 deletions spec/facter/facts/debian/os/release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
subject(:fact) { Facts::Debian::Os::Release.new }

before do
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:release).and_return(value)
allow(Facter::Resolvers::OsRelease).to receive(:resolve).with(:release).and_return(value)
end

context 'when lsb_release installed' do
let(:value) { '10.9' }
let(:value_final) { { 'full' => '10.9', 'major' => '10', 'minor' => '9' } }
let(:value) { '10.09' }
let(:value_final) { { 'full' => '10.09', 'major' => '10', 'minor' => '9' } }

it 'calls Facter::Resolvers::LsbRelease' do
it 'calls Facter::Resolvers::OsRelease' do
fact.call_the_resolver
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:release)
expect(Facter::Resolvers::OsRelease).to have_received(:resolve).with(:release)
end

it 'returns release fact' do
Expand Down
27 changes: 0 additions & 27 deletions spec/facter/resolvers/debian_version_resolver_spec.rb

This file was deleted.

103 changes: 80 additions & 23 deletions spec/facter/resolvers/os_release_resolver_spec.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,96 @@
# frozen_string_literal: true

describe Facter::Resolvers::OsRelease do
before do
allow(File).to receive(:readable?)
.with('/etc/os-release')
.and_return(true)
context 'when os is ubuntu' do
before do
allow(File).to receive(:readable?)
.with('/etc/os-release')
.and_return(true)

allow(File).to receive(:read)
.with('/etc/os-release')
.and_return(load_fixture('os_release').read)
allow(File).to receive(:read)
.with('/etc/os-release')
.and_return(load_fixture('os_release').read)
end

Facter::Resolvers::OsRelease.invalidate_cache
end
after do
Facter::Resolvers::OsRelease.invalidate_cache
end

it 'returns os NAME' do
result = Facter::Resolvers::OsRelease.resolve(:name)
it 'returns os NAME' do
result = Facter::Resolvers::OsRelease.resolve(:name)

expect(result).to eq('Ubuntu')
end
expect(result).to eq('Ubuntu')
end

it 'returns os PRETTY_NAME' do
result = Facter::Resolvers::OsRelease.resolve(:pretty_name)
it 'returns os PRETTY_NAME' do
result = Facter::Resolvers::OsRelease.resolve(:pretty_name)

expect(result).to eq('Ubuntu 18.04.1 LTS')
end
expect(result).to eq('Ubuntu 18.04.1 LTS')
end

it 'returns os VERSION_ID' do
result = Facter::Resolvers::OsRelease.resolve(:version_id)

expect(result).to eq('18.04')
end

it 'returns os VERSION_ID' do
result = Facter::Resolvers::OsRelease.resolve(:version_id)
it 'returns os release' do
result = Facter::Resolvers::OsRelease.resolve(:release)

expect(result).to eq('18.04')
expect(result).to eq('18.04')
end

it 'returns os VERSION_CODENAME' do
result = Facter::Resolvers::OsRelease.resolve(:version_codename)

expect(result).to eq('bionic')
end
end

it 'returns os VERSION_CODENAME' do
result = Facter::Resolvers::OsRelease.resolve(:version_codename)
context 'when os is Debian' do
before do
allow(File).to receive(:readable?).with('/etc/os-release').and_return(true)

allow(File).to receive(:read)
.with('/etc/os-release')
.and_return(load_fixture('os_release_debian').read)

allow(File).to receive(:readable?).with('/etc/debian_version').and_return(true)
allow(File).to receive(:read).with('/etc/debian_version').and_return("10.0\n")
end

after do
Facter::Resolvers::OsRelease.invalidate_cache
end

it 'returns os release' do
result = Facter::Resolvers::OsRelease.resolve(:release)

expect(result).to eq('10.0')
end

it 'returns os NAME' do
result = Facter::Resolvers::OsRelease.resolve(:name)

expect(result).to eq('Debian')
end

it 'returns os PRETTY_NAME' do
result = Facter::Resolvers::OsRelease.resolve(:pretty_name)

expect(result).to eq('Debian GNU/Linux 10 (buster)')
end

it 'returns os VERSION_ID' do
result = Facter::Resolvers::OsRelease.resolve(:version_id)

expect(result).to eq('10')
end

it 'returns os VERSION_CODENAME' do
result = Facter::Resolvers::OsRelease.resolve(:version_codename)

expect(result).to eq('bionic')
expect(result).to eq('buster')
end
end
end
9 changes: 9 additions & 0 deletions spec/fixtures/os_release_debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

0 comments on commit f6b8bea

Please sign in to comment.