Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FACT-2676) fix os identifier for opensuse-leap #1944

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/resolvers/os_release_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def read_os_release_file(fact_name)
fill_fact_list(pairs)
process_name
pad_version_id
normalize_opensuse_identifier

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

def normalize_opensuse_identifier
@fact_list[:identifier] = 'opensuse' if @fact_list[:identifier] =~ /opensuse/i
end
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/facter/resolvers/os_release_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@

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

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

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

context 'when /etc/os-release file is not readable' do
Expand Down Expand Up @@ -75,5 +81,31 @@

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

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

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

context 'when on opensuse-leap' do
let(:os_release_content) { load_fixture('os_release_opensuse-leap').readlines }

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

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

context 'when opensuse identifier is capitalized' do
it 'returns os identifier' do
os_release_content[2] = 'ID="Opensuse-Leap"'

result = Facter::Resolvers::OsRelease.resolve(:identifier)

expect(result).to eq('opensuse')
end
end
end
end
10 changes: 10 additions & 0 deletions spec/fixtures/os_release_opensuse-leap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
NAME="openSUSE Leap"
VERSION="15.1"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.1"
PRETTY_NAME="openSUSE Leap 15.1"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.1"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"