Skip to content

Commit

Permalink
Detect augeas from gem if augparse is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanIrimie committed Jul 29, 2020
1 parent f8d665b commit 3be296e
Show file tree
Hide file tree
Showing 149 changed files with 648 additions and 1,720 deletions.
71 changes: 41 additions & 30 deletions .github/actions/presuite.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# frozen_string_literal: true

require 'open3'
require 'fileutils'

def install_bundler
message('INSTALL BUNDLER')
run('gem install bundler')
end

def install_facter_acceptance_dependencies
message('INSTALL FACTER ACCEPTANCE DEPENDENCIES')
def install_facter_3_dependencies
message('INSTALL FACTER 3 ACCEPTANCE DEPENDENCIES')
run('bundle install')
end

Expand All @@ -25,25 +22,24 @@ def initialize_beaker

def beaker_platform
{
'ubuntu-18.04' => 'ubuntu1804-64a',
'ubuntu-16.04' => 'ubuntu1604-64a',
'ubuntu-20.04' => 'ubuntu2004-64a',
'macos-10.15' => 'osx1015-64a',
'windows-2016' => 'windows2016-64a',
'windows-2019' => 'windows2019-64a'
'ubuntu-18.04' => 'ubuntu1804-64a',
'ubuntu-16.04' => 'ubuntu1604-64a',
'ubuntu-20.04' => 'ubuntu2004-64a',
'macos-10.15' => 'osx1015-64a',
'windows-2016' => 'windows2016-64a',
'windows-2019' => 'windows2019-64a'
}[HOST_PLATFORM]
end

def platform_with_options(platform)
return "\"#{platform}{hypervisor=none,hostname=localhost,is_cygwin=false}\"" if platform.include? 'windows'

"#{platform}{hypervisor=none\\,hostname=localhost}"
end

def install_puppet_agent
message('INSTALL PUPPET AGENT')

beaker_puppet_root, = run('bundle info beaker-puppet --path')
beaker_puppet_root, _ = run('bundle info beaker-puppet --path')
presuite_file_path = File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')

run("beaker exec pre-suite --pre-suite #{presuite_file_path} --preserve-state", './', env_path_var)
Expand All @@ -53,34 +49,45 @@ def puppet_bin_dir
linux_puppet_bin_dir = '/opt/puppetlabs/puppet/bin'
windows_puppet_bin_dir = 'C:\\Program Files\\Puppet Labs\\Puppet\\bin'

HOST_PLATFORM.include?('windows') ? windows_puppet_bin_dir : linux_puppet_bin_dir
(HOST_PLATFORM.include? 'windows') ? windows_puppet_bin_dir : linux_puppet_bin_dir
end

def puppet_command
return '/opt/puppetlabs/puppet/bin/puppet' unless HOST_PLATFORM.include? 'windows'

'"C:\\Program Files\\Puppet Labs\\Puppet\\bin\\puppet"'
"\"C:\\Program Files\\Puppet Labs\\Puppet\\bin\\puppet\""
end

def gem_command
return '/opt/puppetlabs/puppet/bin/gem' unless HOST_PLATFORM.include? 'windows'

'"C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem"'
"\"C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem\""
end

def env_path_var
HOST_PLATFORM.include?('windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {}
(HOST_PLATFORM.include? 'windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {}
end

def update_facter_lib
facter_lib_windows_path = 'C:/Program Files/Puppet Labs/Puppet/puppet/lib/ruby/vendor_ruby/facter'
facter_lib_linux_path = '/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/facter'
def replace_facter_3_with_facter_4
message('SET FACTER 4 FLAG TO TRUE')
run("#{puppet_command} config set facterng true")

facter_lib_path = HOST_PLATFORM.include?('windows') ? facter_lib_windows_path : facter_lib_linux_path
install_latest_facter_4(gem_command)

message('OVERWRITE FACTER FILES')
FileUtils.rm_r([facter_lib_path, facter_lib_path + '.rb'], force: true)
run("#{'powershell' if HOST_PLATFORM.include? 'windows'} mv ../lib/* \'#{facter_lib_path.sub('facter', '')}\'")
message('CHANGE FACTER 3 WITH FACTER 4')

extension = (HOST_PLATFORM.include? 'windows') ? '.bat' : ''
run("mv facter-ng#{extension} facter#{extension}", puppet_bin_dir)
end


def install_latest_facter_4(gem_command)
message('BUILD FACTER 4 LATEST AGENT GEM')
run("#{gem_command} build agent/facter-ng.gemspec", ENV['FACTER_4_ROOT'])

message('UNINSTALL DEFAULT FACTER 4 AGENT GEM')
run("#{gem_command} uninstall facter-ng")

message('INSTALL FACTER 4 GEM')
run("#{gem_command} install -f facter-ng-*.gem", ENV['FACTER_4_ROOT'])
end

def run_acceptance_tests
Expand Down Expand Up @@ -112,17 +119,21 @@ def run(command, dir = './', env = {})
end

ENV['DEBIAN_DISABLE_RUBYGEMS_INTEGRATION'] = 'no_warnings'
ACCEPTANCE_PATH = File.join(ENV['FACTER_4_ROOT'], 'acceptance')
FACTER_3_ACCEPTANCE_PATH = File.join(ENV['FACTER_3_ROOT'], 'acceptance')
HOST_PLATFORM = ARGV[0]

install_bundler

Dir.chdir(ACCEPTANCE_PATH) do
install_facter_acceptance_dependencies
Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies }

Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do
initialize_beaker
install_puppet_agent
update_facter_lib
end

replace_facter_3_with_facter_4

Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do
_, status = run_acceptance_tests
exit(status.exitstatus)
end
19 changes: 10 additions & 9 deletions .github/workflows/acceptance_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ jobs:
os: [windows-2016, windows-2019, ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-10.15]
runs-on: ${{ matrix.os }}
env:
FACTER_3_ROOT: facter_3
FACTER_4_ROOT: facter_4
SHA: latest
RELEASE_STREAM: puppet7

steps:
- name: Checkout current PR
uses: actions/checkout@v2
with:
path: facter_4

- name: Clone facter 3 repo
uses: actions/checkout@v2
with:
repository: puppetlabs/facter
ref: github_acceptance_tests
path: facter_3

- name: Install Ruby 2.6
uses: ruby/setup-ruby@v1
with:
Expand All @@ -42,23 +49,17 @@ jobs:
sudo chmod a-w /home/runner /usr/share &&
sudo chmod -R a-w /usr/share/rust /home/runner/.config /home/linuxbrew
- name: Install dhclient for Linux
- name: Instal dhclient for Linux
if: runner.os == 'Linux'
run: |
sudo apt install dhcpcd5
sudo dhclient
#Ipv6 is missing on the GitHub OSX machine and we need it for the networking facts tests
- name: Add ipv6 on OSX
if: runner.os == 'macOS'
run: |
primary_interface=`route -n get default | awk '/interface: */{print $NF}'`
sudo ifconfig $primary_interface inet6 add ::1/64
- name: Run acceptance tests on Linux like platform
if: runner.os != 'Windows'
run: sudo -E "PATH=$PATH" ruby $FACTER_4_ROOT/.github/actions/presuite.rb ${{ matrix.os }}

- name: Run acceptance tests on Windows like platform
if: runner.os == 'Windows'
run: ruby $Env:FACTER_4_ROOT/.github/actions/presuite.rb ${{ matrix.os }}

15 changes: 0 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
## [4.0.31](https://github.com/puppetlabs/facter/tree/4.0.31) (2020-07-29)

[Full Changelog](https://github.com/puppetlabs/facter/compare/4.0.30...4.0.31)

### Added
- \(FACT-2718\) Block custom facts [\#1996](https://github.com/puppetlabs/facter/pull/1996) ([IrimieBogdan](https://github.com/IrimieBogdan))
- \(FACT-2230\) Add Aix memory facts [\#1994](https://github.com/puppetlabs/facter/pull/1994) ([oanatmaria](https://github.com/oanatmaria))
- \(FACT-2220\) Add Aix disks fact [\#1987](https://github.com/puppetlabs/facter/pull/1987) ([oanatmaria](https://github.com/oanatmaria))
- \(FACT-2708\) Add man pages [\#1984 ](https://github.com/puppetlabs/facter/pull/1984) ([florindragos](https://github.com/florindragos))

### Fixed
- \(FACT-2710\) Correctly display vmware info [\#1988](https://github.com/puppetlabs/facter/pull/1987) ([oanatmaria](https://github.com/oanatmaria))
- \(FACT-2702\) Fix system_profiler legacy facts [\#1982](https://github.com/puppetlabs/facter/pull/1982) ([oanatmaria](https://github.com/oanatmaria))
- Handle Time and Symbol in executable facts [\#1977](https://github.com/puppetlabs/facter/pull/1977) ([gimmyxd](https://github.com/gimmyxd))

## [4.0.30](https://github.com/puppetlabs/facter/tree/4.0.30) (2020-07-15)

[Full Changelog](https://github.com/puppetlabs/facter/compare/4.0.29...4.0.30)
Expand Down
2 changes: 1 addition & 1 deletion acceptance/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def location_for(place, fake_version = nil)
end
end

gem "beaker", *location_for(ENV['BEAKER_VERSION'] || "~> 4.24")
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || "~> 4")
gem 'beaker-puppet', *location_for(ENV['BEAKER_PUPPET_VERSION'] || '~> 1')
gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'] || "~> 1.1")
gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || "~> 0.5")
Expand Down
3 changes: 3 additions & 0 deletions acceptance/config/aio/options.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
:type => 'aio',
:pre_suite => [
'setup/aio/pre-suite/001_run_with_facter_ng.rb',
],
}
2 changes: 1 addition & 1 deletion acceptance/lib/facter/acceptance/base_fact_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def windows_expected_facts(agent)
'os.name' => 'windows',
'os.release.full' => os_version,
'os.release.major' => os_version,
'os.windows.system32' => /C:\\(WINDOWS|[Ww]indows)\\(system32|sysnative)/,
'os.windows.system32' => /C:\\(WINDOWS|Windows)\\(system32|sysnative)/,
'processors.count' => /[1-9]/,
'processors.physicalcount' => /[1-9]/,
'processors.isa' => /x86|x64/,
Expand Down
8 changes: 0 additions & 8 deletions acceptance/lib/facter/acceptance/user_fact_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ def user_shell(agent)
'/bin/bash'
end
end

def escape_paths(host, str)
if host['platform'] =~ /windows/ && !host.is_cygwin?
str.gsub('\\') { '\\\\' }
else
str
end
end
end
end
end
6 changes: 1 addition & 5 deletions acceptance/lib/puppet/acceptance/common_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ module Puppet
module Acceptance
module CommandUtils
def ruby_command(host)
if host['platform'] =~ /windows/ && !host.is_cygwin?
"cmd /V /C \"set PATH=#{host['privatebindir']};!PATH! && ruby\""
else
"env PATH=\"#{host['privatebindir']}:${PATH}\" ruby"
end
"env PATH=\"#{host['privatebindir']}:${PATH}\" ruby"
end
module_function :ruby_command
end
Expand Down
75 changes: 75 additions & 0 deletions acceptance/setup/aio/pre-suite/001_run_with_facter_ng.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true
require 'open3'
require 'tmpdir'

def create_facter_gem
temp_dir = Dir.mktmpdir
Dir.chdir(temp_dir) do
download_and_build_facter_ng

facter_repo_dir = Pathname.new("#{temp_dir}/facter-ng")
facter_gem_path = Dir.entries(facter_repo_dir).select { |file| file =~ /facter-ng-[0-9]+.[0-9]+.[0-9]+(.pre)?.gem/ }
File.join(facter_repo_dir, facter_gem_path)
end
end

def download_and_build_facter_ng
branch_name = ENV['FACTER_4_BRANCH']
puts "Cloning branch #{branch_name}"
Open3.capture2('echo $PATH')

Open3.capture2("git clone https://github.com/puppetlabs/facter-ng.git &&" \
'cd facter-ng &&' \
'git fetch &&' \
"git reset --hard origin/#{branch_name}")

Dir.chdir('facter-ng') do
puts "Latest commit on branch #{branch_name}"
output, _stderr = Open3.capture2('git log -1')
puts output

Open3.capture2('gem build agent/facter-ng.gemspec')
end
end

def install_facter_gem(agent, facter_gem_path)
home_dir = on(agent, 'pwd').stdout.chop
gem_c = gem_command(agent)

scp_to(agent, facter_gem_path, home_dir)

on(agent, "#{gem_c} uninstall facter-ng")
on(agent, "#{gem_c} install -f facter-ng-*.gem")
end

test_name 'Setup for Facter NG' do
windows_puppet_bin_path = '/cygdrive/c/Program\ Files/Puppet\ Labs/Puppet/bin'
linux_puppet_bin_path = '/opt/puppetlabs/puppet/bin'
set_facter_ng_command = 'puppet config set facterng true'

puts 'Setting run with facter ng if environment variable FACTER_NG is true.'
puts "FACTER_NG is #{ENV["FACTER_NG"]}."
puts "FACTER_NG branch is #{ENV['FACTER_4_BRANCH']}"

if ENV["FACTER_NG"] == 'true'
puts 'Cloning facter ng repository and creating gem file.'
facter_gem_path = create_facter_gem

agents.each do |agent|
puts 'Installing Facter NG on agent.'
install_facter_gem(agent, facter_gem_path)

puts 'Renaming facter to facter-original and facter-ng to facter.'
if agent['platform'] =~ /windows/
on(agent, "cmd /c #{set_facter_ng_command}")
on(agent, "cd #{windows_puppet_bin_path} && mv facter-ng.bat facter.bat")
else
on(agent, "#{set_facter_ng_command} ")
on(agent, "cd #{linux_puppet_bin_path} && mv facter-ng facter")
end

puts 'FACTER VERSION'
on(agent, "facter -v")
end
end
end
47 changes: 0 additions & 47 deletions acceptance/tests/custom_facts/block_custom_fact.rb

This file was deleted.

Loading

0 comments on commit 3be296e

Please sign in to comment.