Skip to content

Commit

Permalink
Merge pull request #2003 from IrimieBogdan/FACT-2734
Browse files Browse the repository at this point in the history
(FACT-2734) Return nil codename if we cannot determine it from /etc/redhat_release
  • Loading branch information
oanatmaria authored Jul 30, 2020
2 parents ab7fcc2 + 06e0e7c commit 1bf4470
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
7 changes: 4 additions & 3 deletions lib/facter/resolvers/redhat_release_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def build_fact_list(output)
version_codename = output_strings[1].split(' ')

@fact_list[:name] = name(output_strings[0])
@fact_list[:version] = version_codename[0].strip
codename = version_codename[1].strip
@fact_list[:codename] = codename.gsub(/[()]/, '')
@fact_list[:version] = version_codename[0]&.strip

codename = version_codename[1]&.strip
@fact_list[:codename] = codename ? codename.gsub(/[()]/, '') : nil

@fact_list[:identifier] = identifier(@fact_list[:name])
end
Expand Down
48 changes: 37 additions & 11 deletions spec/facter/resolvers/redhat_release_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,47 @@

let(:log_spy) { instance_spy(Facter::Log) }

before do
allow(Facter::Util::FileHelper).to receive(:safe_read)
.with('/etc/redhat-release', nil)
.and_return("Red Hat Enterprise Linux Server release 5.10 (Tikanga)\n")
after do
Facter::Resolvers::RedHatRelease.invalidate_cache
end

it 'returns os NAME' do
expect(redhat_release.resolve(:name)).to eq('RedHat')
end
context 'when redhat-realse has codename' do
before do
allow(Facter::Util::FileHelper).to receive(:safe_read)
.with('/etc/redhat-release', nil)
.and_return("Red Hat Enterprise Linux Server release 5.10 (Tikanga)\n")
end

it 'returns os NAME' do
expect(redhat_release.resolve(:name)).to eq('RedHat')
end

it 'returns os VERSION_ID' do
expect(redhat_release.resolve(:version)).to eq('5.10')
end

it 'returns os VERSION_ID' do
expect(redhat_release.resolve(:version)).to eq('5.10')
it 'returns os VERSION_CODENAME' do
expect(redhat_release.resolve(:codename)).to eq('Tikanga')
end
end

it 'returns os VERSION_CODENAME' do
expect(redhat_release.resolve(:codename)).to eq('Tikanga')
context 'when redhat-relase does not have codename' do
before do
allow(Facter::Util::FileHelper).to receive(:safe_read)
.with('/etc/redhat-release', nil)
.and_return("Oracle VM server release 3.4.4\n")
end

it 'returns os NAME' do
expect(redhat_release.resolve(:name)).to eq('OracleVM')
end

it 'returns os VERSION_ID' do
expect(redhat_release.resolve(:version)).to eq('3.4.4')
end

it 'returns os VERSION_CODENAME' do
expect(redhat_release.resolve(:codename)).to be_nil
end
end
end

0 comments on commit 1bf4470

Please sign in to comment.