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

Commit

Permalink
(FACT-2600) Run acceptance tests on Windows (#519)
Browse files Browse the repository at this point in the history
* (FACT-2569) implemented acceptance tests run in GitHub Actions
* (FACT-2569) deactivate check for files with world writable permissions
* (FACT-2569) changed ruby setup
* (FACT-2569) skipped failing tests on ubuntu
* (FACT-2569) changed how facter is replaced
* (FACT-2599) run on all platforms except windows
* (FACT-2599) removed extra parameter
* (FACT-2599) debug
* (FACT-2599) run open3
* (FACT-2599) run on mac
* (FACT-2600) run on windows
* (FACT-2600) uninstall beaker
* (FACT-2600) beaker debug
* (FACT-2600) add custom beaker with git
* (FACT-2600) benchmark bundle install
* (FACT-2600) debug
* (FACT-2600) run on windows 2019 only
* (FACT-2600) removed use of custom beaker-puppet
* Revert "(FACT-2600) removed use of custom beaker-puppet"
(FACT-2600) revert last commit
* (FACT-2600) changed beaker repo
* (FACT-2600) changed facter branch
* (maint) changelog for 4.0.24 release
* (FACT-2635) Add SearchFact and ResolvedFact with nil type.
* (FACT-2635) Move nil fact resolution to internal fact manager. Fix tests.
* (FACT-2634) Add test for nil fact.
* (FACT-2635) Rubocop fixes.
* (FACT-2635) Remove unused arguments from  error_check.
* (FACT-2600) removed custom beaker-puppet
* (FACT-2635) Fix formatter for keys that contain ":" in their name.
  • Loading branch information
Filipovici-Andrei authored Jun 9, 2020
1 parent 68685dd commit 13ad3e6
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 48 deletions.
107 changes: 74 additions & 33 deletions .github/actions/presuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,91 @@ def install_bundler
run('gem install bundler')
end

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

def install_custom_beaker
message('BUILD CUSTOM BEAKER GEM')
run('gem build beaker.gemspec')

message('INSTALL CUSTOM BEAKER GEM')
run('gem install beaker-*.gem')
def use_custom_beaker
message('USE CUSTOM BEAKER')
beaker_path, _ = run('bundle info beaker --path', FACTER_3_ACCEPTANCE_PATH)
Dir.chdir(beaker_path.split("\n").last) do
run('git init')
run("git remote add origin https://github.com/Filipovici-Andrei/beaker.git")
run('git fetch')
run("git reset --hard origin/github_actions")
end
end

def initialize_beaker
beaker_options = "#{get_beaker_platform(ENV['ImageOS'].to_sym)}{hypervisor=none\\,hostname=localhost}"
beaker_platform_with_options = platform_with_options(beaker_platform)

message('BEAKER INITIALIZE')
run("beaker init -h #{beaker_options} -o config/aio/options.rb")
run("beaker init -h #{beaker_platform_with_options} -o #{File.join('config', 'aio', 'options.rb')}")

message('BEAKER PROVISION')
run('beaker provision')
end

def get_beaker_platform(host_platform)
beaker_platforms = {
ubuntu18: 'ubuntu1804-64a',
ubuntu16: 'ubuntu1604-64a',
macos1015: 'osx1015-64a'
}
def beaker_platform
{
'ubuntu-18.04' => 'ubuntu1804-64a',
'ubuntu-16.04' => 'ubuntu1604-64a',
'macos-10.15' => 'osx1015-64a',
'windows-2016' => 'windows2016-64a',
'windows-2019' => 'windows2019-64a'
}[HOST_PLATFORM]
end

beaker_platforms[host_platform]
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')
install_puppet_file_path = File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')
presuite_file_path = File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')

message('INSTALL PUPPET AGENT')
run("beaker exec pre-suite --pre-suite #{install_puppet_file_path}")
run("beaker exec pre-suite --pre-suite #{presuite_file_path} --preserve-state", './', env_path_var)
end

def replace_facter_3_with_facter_4
def puppet_bin_dir
linux_puppet_bin_dir = '/opt/puppetlabs/puppet/bin'
gem_command = File.join(linux_puppet_bin_dir, 'gem')
puppet_command = File.join(linux_puppet_bin_dir, 'puppet')
windows_puppet_bin_dir = 'C:\\Program Files\\Puppet Labs\\Puppet\\bin'

(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\""
end

def gem_command
return '/opt/puppetlabs/puppet/bin/gem' unless HOST_PLATFORM.include? 'windows'
"\"C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem\""
end

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

def replace_facter_3_with_facter_4
message('SET FACTER 4 FLAG TO TRUE')
run("#{puppet_command} config set facterng true")

install_latest_facter_4(gem_command)

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'])

Expand All @@ -62,14 +98,12 @@ def replace_facter_3_with_facter_4

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

message('CHANGE FACTER 3 WITH FACTER 4')
run('mv facter-ng facter', linux_puppet_bin_dir)
end

def run_acceptance_tests
message('RUN ACCEPTANCE TESTS')
run('beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high')

run('beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high', './', env_path_var)
end

def message(message)
Expand All @@ -80,21 +114,28 @@ def message(message)
puts "\n\n#{result}\n\n"
end

def run(command, dir = './')
def run(command, dir = './', env = {})
puts command
output, status = Open3.capture2(command, chdir: dir)
puts output
output = ''
status = 0
Open3.popen2e(env, command, chdir: dir) do |_stdin, stdout_and_err, wait_thr|
stdout_and_err.each do |line|
puts line
output += line
end
status = wait_thr.value
end
[output, status]
end

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

install_bundler

Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependecies }

Dir.chdir(ENV['BEAKER_ROOT']) { install_custom_beaker }
Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies }
use_custom_beaker

Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do
initialize_beaker
Expand Down
28 changes: 13 additions & 15 deletions .github/workflows/acceptance_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ jobs:
name: Platform
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-16.04, macos-10.15]
os: [windows-2016, windows-2019, ubuntu-16.04, ubuntu-18.04, macos-10.15]
runs-on: ${{ matrix.os }}
env:
FACTER_3_ROOT: facter_3
FACTER_4_ROOT: facter_4
BEAKER_ROOT: beaker
SHA: latest
BEAKER_VERSION: 4.21.0

steps:
- name: Checkout current PR
Expand All @@ -33,22 +31,16 @@ jobs:
uses: actions/checkout@v2
with:
repository: puppetlabs/facter
ref: skip_failures_on_ng
ref: windows_github
path: facter_3

- name: Clone custom beaker fork
uses: actions/checkout@v2
with:
repository: mihaibuzgau/beaker
ref: master
path: beaker

- name: Install Ruby 2.6
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6'

- name: Fix common permissions
- name: Fix common Linux and MacOs permissions
if: runner.os != 'Windows'
run: sudo chmod a-w /opt

- name: Fix Linux permissions
Expand All @@ -57,11 +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: Instal dhclient
- name: Instal dhclient for Linux
if: runner.os == 'Linux'
run: |
sudo apt install dhcpcd5
sudo dhclient
- name: Run acceptance tests
run: sudo -E "PATH=$PATH" ruby facter_4/.github/actions/presuite.rb
- 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 }}

0 comments on commit 13ad3e6

Please sign in to comment.