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

Commit

Permalink
(FACT-2569) changed how facter is replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Filipovici committed May 5, 2020
2 parents f24ec56 + 9933642 commit 4a6dbb3
Show file tree
Hide file tree
Showing 17 changed files with 309 additions and 255 deletions.
30 changes: 12 additions & 18 deletions .github/actions/presuite.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#!/bin/sh -x

export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings
cwd=$(pwd)
export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:$PATH

#printf '\nInstall bundler\n\n'
#gem install bundler
cwd=$(pwd)

#printf '\nInstall facter 4 dependencies\n\n'
#cd $cwd/$FACTER_4_ROOT && bundle install
printf '\nInstall bundler\n\n'
gem install bundler

printf '\nInstall facter 3 acceptance dependencies\n\n'
cd $cwd/$FACTER_3_ROOT/acceptance && bundle install
export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:$PATH

printf '\nInstall custom beaker\n\n'
cd $cwd/$BEAKER_ROOT
Expand All @@ -31,22 +29,18 @@ printf '\nConfigure facter 4 as facter 3\n\n'
puppet config set facterng true

cd $cwd/$FACTER_4_ROOT
/opt/puppetlabs/puppet/bin/gem build agent/facter-ng.gemspec
/opt/puppetlabs/puppet/bin/gem uninstall facter-ng
/opt/puppetlabs/puppet/bin/gem install -f facter-ng-*.gem
puppet_gem_command=/opt/puppetlabs/puppet/bin/gem
$puppet_gem_command build agent/facter-ng.gemspec
$puppet_gem_command uninstall facter-ng
$puppet_gem_command install -f facter-ng-*.gem

cd /opt/puppetlabs/puppet/bin
mv facter-ng facter

#rm -rf /opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/facter-ng-$agent_facter_ng_version/*
#cp -r $cwd/$FACTER_4_ROOT/* /opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/facter-ng-$agent_facter_ng_version/
#cp /opt/puppetlabs/puppet/bin/facter-ng /opt/puppetlabs/bin/
#mv /opt/puppetlabs/bin/facter-ng /opt/puppetlabs/bin/facter

facter -v
puppet facts | grep facterversion

#printf '\nBeaker tests\n\n'
#cd $cwd/$FACTER_3_ROOT/acceptance
#beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high 2>&1 | tee results.txt
#sed -n '/Failed Tests Cases:/,/Skipped Tests Cases:/p' results.txt | grep 'Test Case' | awk {'print $3'}
printf '\nBeaker tests\n\n'
cd $cwd/$FACTER_3_ROOT/acceptance
beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high 2>&1 | tee results.txt
sed -n '/Failed Tests Cases:/,/Skipped Tests Cases:/p' results.txt | grep 'Test Case' | awk {'print $3'}
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: GitHub hosted facter CI

on: [pull_request, push]
on: [pull_request]

jobs:
ci:
Expand Down Expand Up @@ -38,14 +38,10 @@ jobs:
with:
ruby-version: '2.6'

- name: Setup tmate session
uses: mxschmitt/action-tmate@v2

- name: Fix permissions
run: |
sudo chmod a-w /opt /home/runner /usr/share
sudo chmod -R a-w /usr/share/rust /home/runner/.config
- name: Run acceptance tests
run: sudo -E bash -c facter_4/.github/actions/presuite.sh

6 changes: 4 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 80
# Offense count: 81
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Exclude:
Expand Down Expand Up @@ -37,6 +37,7 @@ RSpec/FilePath:
- 'spec/facter/resolvers/aix/architecture_resolver_spec.rb'
- 'spec/facter/resolvers/aix/ffi_helper_spec.rb'
- 'spec/facter/resolvers/aix/hardware_resolver_spec.rb'
- 'spec/facter/resolvers/bsd/ffi_helper_spec.rb'
- 'spec/facter/resolvers/disk_resolver_spec.rb'
- 'spec/facter/resolvers/dmi_resolver_spec.rb'
- 'spec/facter/resolvers/filesystems_resolver_spec.rb'
Expand Down Expand Up @@ -191,7 +192,7 @@ RSpec/SubjectStub:
- 'spec/custom_facts/util/fact_spec.rb'
- 'spec/custom_facts/util/resolution_spec.rb'

# Offense count: 169
# Offense count: 180
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
Expand Down Expand Up @@ -227,6 +228,7 @@ RSpec/VerifiedDoubles:
- 'spec/facter/resolvers/aix/architecture_resolver_spec.rb'
- 'spec/facter/resolvers/aix/ffi_helper_spec.rb'
- 'spec/facter/resolvers/aix/hardware_resolver_spec.rb'
- 'spec/facter/resolvers/bsd/ffi_helper_spec.rb'
- 'spec/facter/resolvers/macosx/mountpoints_resolver_spec.rb'
- 'spec/facter/resolvers/mountpoints_resolver_spec.rb'
- 'spec/facter/resolvers/solaris/current_zone_resolver_spec.rb'
Expand Down
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@


## [4.0.19](https://github.com/puppetlabs/facter-ng/tree/4.0.19) (2020-04-29)

[Full Changelog](https://github.com/puppetlabs/facter-ng/compare/4.0.18...4.0.19)

### Added

- \(FACT-2555\)Create OS hierarchy and mechanism for loading it [\#470](https://github.com/puppetlabs/facter-ng/pull/470) ([IrimieBogdan](https://github.com/IrimieBogdan))
- \(FACT-2552\) Add Solaris processors facts [\#451](https://github.com/puppetlabs/facter-ng/pull/451) ([oanatmaria](https://github.com/oanatmaria))
- \(Fact 2486\) Add facts cache [\#430](https://github.com/puppetlabs/facter-ng/pull/430) ([florindragos](https://github.com/florindragos))

### Fixed

- \(FACT-2585\) Mountpoints fact returns ASCI-8BIT instead of UTF-8 in some cases [\#472](https://github.com/puppetlabs/facter-ng/pull/472) ([IrimieBogdan](https://github.com/IrimieBogdan))
- \(FACT-2570\) Use Facter options to store custom and external facts [\#467](https://github.com/puppetlabs/facter-ng/pull/467) ([IrimieBogdan](https://github.com/IrimieBogdan))
- \(FACT-2565\) Debian development versions causes fatal error when resolving os.release [\#466](https://github.com/puppetlabs/facter-ng/pull/466) ([Filipovici-Andrei](https://github.com/Filipovici-Andrei))



## [4.0.18](https://github.com/puppetlabs/facter-ng/tree/4.0.18) (2020-04-24)

[Full Changelog](https://github.com/puppetlabs/facter-ng/compare/4.0.17...4.0.18)

### Added

- \(FACT-2564\) Add support for zpool\_featureflags and fix zpool\_version [\#443](https://github.com/puppetlabs/facter-ng/pull/443) ([smortex](https://github.com/smortex))

### Fixed

- \(FACT-2553\) remove double backslashes from windows path [\#456](https://github.com/puppetlabs/facter-ng/pull/456) ([oanatmaria](https://github.com/oanatmaria))
- \(FACT-2559\) Fix Facter.debugging? call when Facter not fully loaded [\#455](https://github.com/puppetlabs/facter-ng/pull/455) ([Filipovici-Andrei](https://github.com/Filipovici-Andrei))



## [4.0.17](https://github.com/puppetlabs/facter-ng/tree/4.0.17) (2020-04-21)

[Full Changelog](https://github.com/puppetlabs/facter-ng/compare/4.0.16...4.0.17)
Expand Down
4 changes: 2 additions & 2 deletions lib/facts/debian/os/distro/codename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class Codename

def call_the_resolver
fact_value = Facter::Resolvers::OsRelease.resolve(:version_codename)
fact_value ||= retreieve_from_version
fact_value ||= retrieve_from_version

Facter::ResolvedFact.new(FACT_NAME, fact_value)
end

def retreieve_from_version
def retrieve_from_version
version = Facter::Resolvers::OsRelease.resolve(:version)
return unless version

Expand Down
27 changes: 17 additions & 10 deletions lib/facts/debian/os/distro/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ class Release
def call_the_resolver
fact_value = determine_release_for_os

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

versions = fact_value.split('.')
release = {}
release['full'] = fact_value
release['major'] = versions[0]
release['minor'] = versions[1].gsub(/^0([1-9])/, '\1') if versions[1]
Facter::ResolvedFact.new(FACT_NAME, release)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end

private
Expand All @@ -26,9 +19,23 @@ def determine_release_for_os
os_name = Facter::Resolvers::OsRelease.resolve(:name)

if os_name =~ /Debian|Raspbian/
Facter::Resolvers::DebianVersion.resolve(:version)
release = Facter::Resolvers::DebianVersion.resolve(:version)
return unless release

versions = release.split('.')
fact_value = {}
fact_value['full'] = release
fact_value['major'] = versions[0]
fact_value['minor'] = versions[1].gsub(/^0([1-9])/, '\1') if versions[1]
fact_value
else
Facter::Resolvers::OsRelease.resolve(:version_id)
release = Facter::Resolvers::OsRelease.resolve(:version_id)
return unless release

{
'full' => release,
'major' => release
}
end
end
end
Expand Down
32 changes: 20 additions & 12 deletions lib/facts/debian/os/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ class Release
def call_the_resolver
fact_value = determine_release_for_os

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

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

[Facter::ResolvedFact.new(FACT_NAME, release),
Facter::ResolvedFact.new(ALIASES.first, versions[0], :legacy),
Facter::ResolvedFact.new(ALIASES.last, fact_value, :legacy)]
[Facter::ResolvedFact.new(FACT_NAME, fact_value),
Facter::ResolvedFact.new(ALIASES.first, fact_value['major'], :legacy),
Facter::ResolvedFact.new(ALIASES.last, fact_value['full'], :legacy)]
end

private
Expand All @@ -29,9 +23,23 @@ def determine_release_for_os
os_name = Facter::Resolvers::OsRelease.resolve(:name)

if os_name =~ /Debian|Raspbian/
Facter::Resolvers::DebianVersion.resolve(:version)
release = Facter::Resolvers::DebianVersion.resolve(:version)
return unless release

versions = release.split('.')
fact_value = {}
fact_value['full'] = release
fact_value['major'] = versions[0]
fact_value['minor'] = versions[1].gsub(/^0([1-9])/, '\1') if versions[1]
fact_value
else
Facter::Resolvers::OsRelease.resolve(:version_id)
release = Facter::Resolvers::OsRelease.resolve(:version_id)
return unless release

{
'full' => release,
'major' => release
}
end
end
end
Expand Down
12 changes: 10 additions & 2 deletions lib/framework/detector/os_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class OsDetector
attr_reader :identifier, :version, :hierarchy

def initialize(*_args)
@log = Facter::Log.new(self)
@os_hierarchy = Facter::OsHierarchy.new
@identifier = detect
end
Expand Down Expand Up @@ -39,8 +40,15 @@ def detect

def detect_hierarchy(identifier)
hierarchy = @os_hierarchy.construct_hierarchy(identifier)
hierarchy = @os_hierarchy.construct_hierarchy(detect_family) if hierarchy.empty?
hierarchy = @os_hierarchy.construct_hierarchy(:linux) if hierarchy.empty?
if hierarchy.empty?
@log.debug("Could not detect hierarchy using os identifier: #{identifier} , trying with family")
hierarchy = @os_hierarchy.construct_hierarchy(detect_family)
end

if hierarchy.empty?
@log.debug("Could not detect hierarchy using family #{detect_family}, falling back to Linux")
hierarchy = @os_hierarchy.construct_hierarchy(:linux)
end

hierarchy
end
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/detector/os_hierarchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Facter
class OsHierarchy
def initialize
@log = Log.new(self)
json_file = Util::FileHelper.safe_read('os_hierarchy.json')
json_file = Util::FileHelper.safe_read(File.join(ROOT_DIR, 'os_hierarchy.json'))

begin
@json_os_hierarchy = JSON.parse(json_file)
Expand Down
5 changes: 5 additions & 0 deletions lib/resolvers/os_release_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def read_os_release_file(fact_name)

fill_fact_list(pairs)
process_name
pad_version_id

@fact_list[fact_name]
end
Expand All @@ -47,6 +48,10 @@ def fill_fact_list(pairs)
@fact_list[:identifier] = @fact_list[:id]
end

def pad_version_id
@fact_list[:version_id] = "#{@fact_list[:version_id]}.0" unless @fact_list[:version_id] =~ /\./
end

def process_name
return unless @fact_list[:name]

Expand Down
3 changes: 2 additions & 1 deletion os_hierarchy.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"El": [
"Fedora",
"Amzn",
"Centos"
"Centos",
"Rhel"
]
},
{
Expand Down

0 comments on commit 4a6dbb3

Please sign in to comment.