-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Microsoft Azure Linux to Facter 4.x
Add support for Microsoft Azure Linux, prevously known as CBL-Mariner, Microsoft's Linux distribution for cloud infrastructure and edge products and services.
- Loading branch information
1 parent
bb4a33c
commit faf7357
Showing
6 changed files
with
100 additions
and
3 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
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Azurelinux | ||
module Os | ||
class Release | ||
FACT_NAME = 'os.release' | ||
ALIASES = %w[operatingsystemmajrelease operatingsystemrelease].freeze | ||
|
||
def call_the_resolver | ||
version = from_specific_file || from_os_release | ||
|
||
return Facter::ResolvedFact.new(FACT_NAME, nil) unless version | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, version), | ||
Facter::ResolvedFact.new(ALIASES.first, version['major'], :legacy), | ||
Facter::ResolvedFact.new(ALIASES.last, version['full'], :legacy)] | ||
end | ||
|
||
def from_specific_file | ||
version = Facter::Resolvers::SpecificReleaseFile.resolve(:release, | ||
{ release_file: '/etc/azurelinux-release', | ||
regex: /AZURELINUX_BUILD_NUMBER=([0-9.]+)/ }) | ||
Facter::Util::Facts.release_hash_from_matchdata(version) | ||
end | ||
|
||
def from_os_release | ||
version = Facter::Resolvers::OsRelease.resolve(:version_id) | ||
|
||
Facter::Util::Facts.release_hash_from_string(version) | ||
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
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,56 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Azurelinux::Os::Release do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Azurelinux::Os::Release.new } | ||
|
||
before do | ||
allow(Facter::Resolvers::SpecificReleaseFile).to receive(:resolve) | ||
.with(:release, { release_file: '/etc/azurelinux-release', | ||
regex: /AZURELINUX_BUILD_NUMBER=([0-9.]+)/ }) | ||
.and_return(value) | ||
end | ||
|
||
context 'when version is retrieved from specific file' do | ||
let(:value) { /AZURELINUX_BUILD_NUMBER=([0-9.]+)/.match('AZURELINUX_BUILD_NUMBER=3.0.20240401') } | ||
let(:release) { { 'full' => '3.0.20240401', 'major' => '3', 'minor' => '0' } } | ||
|
||
it 'returns operating system name fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ | ||
contain_exactly(an_object_having_attributes(name: 'os.release', value: release), | ||
an_object_having_attributes(name: 'operatingsystemmajrelease', | ||
value: release['major'], type: :legacy), | ||
an_object_having_attributes(name: 'operatingsystemrelease', | ||
value: release['full'], type: :legacy)) | ||
end | ||
end | ||
|
||
context 'when version is retrieved from os-release file' do | ||
let(:value) { nil } | ||
let(:os_release) { '3.0.20240401' } | ||
let(:release) { { 'full' => '3.0.20240401', 'major' => '3', 'minor' => '0' } } | ||
|
||
before do | ||
allow(Facter::Resolvers::OsRelease).to receive(:resolve).with(:version_id).and_return(os_release) | ||
end | ||
|
||
it 'returns operating system name fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ | ||
contain_exactly(an_object_having_attributes(name: 'os.release', value: release), | ||
an_object_having_attributes(name: 'operatingsystemmajrelease', | ||
value: release['major'], type: :legacy), | ||
an_object_having_attributes(name: 'operatingsystemrelease', | ||
value: release['full'], type: :legacy)) | ||
end | ||
|
||
context 'when release can\'t be received' do | ||
let(:os_release) { nil } | ||
|
||
it 'returns operating system name fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'os.release', value: nil) | ||
end | ||
end | ||
end | ||
end | ||
end |