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

Commit

Permalink
Merge branch 'master' into FACT-2582
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanIrimie committed May 11, 2020
2 parents 77ad8fd + 950dff8 commit 010ad22
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 106 deletions.
109 changes: 109 additions & 0 deletions .github/actions/presuite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
require 'open3'

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

def install_facter_3_dependecies
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')
end

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

message('BEAKER INITIALIZE')
run("beaker init -h #{beaker_options} -o 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'
}

beaker_platforms[host_platform]
end

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

message('INSTALL PUPPET AGENT')
run("beaker exec pre-suite --pre-suite #{install_puppet_file_path}")
end

def replace_facter_3_with_facter_4
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')

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

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

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

def message(message)
message_length = message.length
total_length = 130
lines_length = (total_length - message_length) / 2
result = ('-' * lines_length + ' ' + message + ' ' + '-' * lines_length)[0, total_length]
puts "\n\n#{result}\n\n"
end

def run(command, dir = './')
puts command
output, status = Open3.capture2(command, chdir: dir)
puts output
[output, status]
end

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

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) do
initialize_beaker
install_puppet_agent
end

replace_facter_3_with_facter_4

Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do
_, status = run_acceptance_tests
exit(status.exitstatus)
end
48 changes: 0 additions & 48 deletions .github/actions/presuite.sh

This file was deleted.

24 changes: 18 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ on: [pull_request]
jobs:
ci:
name: Run acceptance tests
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-16.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 @@ -26,22 +30,30 @@ jobs:
ref: skip_failures_on_ng
path: facter_3

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

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

- name: Fix permissions
- name: Fix common permissions
run: sudo chmod a-w /opt

- name: Fix Linux permissions
if: runner.os == 'Linux'
run: |
sudo chmod a-w /opt /home/runner /usr/share
sudo chmod a-w /home/runner /usr/share &&
sudo chmod -R a-w /usr/share/rust /home/runner/.config
- name: Fix ubuntu-16.04 permissions
if: matrix.os == 'ubuntu-16.04'
run: sudo chmod -R a-w /home/linuxbrew

- name: Run acceptance tests
run: sudo -E bash -c facter_4/.github/actions/presuite.sh
run: sudo -E "PATH=$PATH" ruby facter_4/.github/actions/presuite.rb
6 changes: 2 additions & 4 deletions spec/facter/resolvers/aix/ffi_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

describe Facter::Aix::FfiHelper do
let(:averages) { double('FFI::MemoryPointer') }
let(:averages_size) { double('FFI::MemoryPointer') }
let(:averages) { double('FFI::MemoryPointer', size: 24) }
let(:averages_size) { double('FFI::MemoryPointer', write_int: 24) }

before do
allow(FFI::MemoryPointer).to receive(:new).with(:long_long, 3).and_return(averages)
allow(FFI::MemoryPointer).to receive(:new).with(:int, 1).and_return(averages_size)
allow(averages).to receive(:size).and_return(24)
allow(averages_size).to receive(:write_int).with(24)
end

after do
Expand Down
3 changes: 1 addition & 2 deletions spec/facter/resolvers/bsd/ffi_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# frozen_string_literal: true

describe Facter::Bsd::FfiHelper do
let(:averages) { double('FFI::MemoryPointer') }
let(:averages) { double('FFI::MemoryPointer', size: 24) }

before do
allow(FFI::MemoryPointer).to receive(:new).with(:double, 3).and_return(averages)
allow(averages).to receive(:size).and_return(24)
end

after do
Expand Down
6 changes: 4 additions & 2 deletions spec/facter/resolvers/windows/fips_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

describe Facter::Resolvers::Windows::Fips do
describe '#resolve' do
let(:reg) { { 'Enabled' => is_fips } }
let(:reg) { instance_double('Win32::Registry::HKEY_LOCAL_MACHINE') }

before do
allow(reg).to receive(:close)
allow(reg).to receive(:[]).with('Enabled').and_return(is_fips)
allow(reg).to receive(:any?).and_yield('Enabled', '1')
allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
.with('System\\CurrentControlSet\\Control\\Lsa\\FipsAlgorithmPolicy').and_return(reg)
allow(reg).to receive(:close)
end

after do
Expand Down
10 changes: 6 additions & 4 deletions spec/facter/resolvers/windows/netkvm_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@

describe Facter::Resolvers::NetKVM do
describe '#resolve' do
let(:reg) { instance_double('Win32::Registry::HKEY_LOCAL_MACHINE') }

before do
allow(reg).to receive(:keys).and_return(reg_value)
allow(reg).to receive(:close)
allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
.with('SYSTEM\\CurrentControlSet\\Services')
.and_return(reg)
allow(reg).to receive(:keys?)
allow(reg).to receive(:close)
end

after do
Facter::Resolvers::NetKVM.invalidate_cache
end

context 'when is not kvm' do
let(:reg) { { 'puppet' => 'labs' } }
let(:reg_value) { { 'puppet' => 'labs' } }

it 'returns false' do
expect(Facter::Resolvers::NetKVM.resolve(:kvm)).to be(false)
end
end

context 'when is kvm' do
let(:reg) { { 'puppet' => 'labs', 'netkvm' => 'info' } }
let(:reg_value) { { 'puppet' => 'labs', 'netkvm' => 'info' } }

it 'returns true' do
expect(Facter::Resolvers::NetKVM.resolve(:kvm)).to be(true)
Expand Down
4 changes: 3 additions & 1 deletion spec/facter/resolvers/windows/networking_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@

context 'when it succeeded to retrieve networking information but all interface are down' do
let(:error_code) { NetworkingFFI::ERROR_SUCCES }
let(:adapter) { OpenStruct.new(OperStatus: NetworkingFFI::IF_OPER_STATUS_DOWN, Next: next_adapter) }
let(:adapter) { instance_double('FFI::MemoryPointer') }
let(:next_adapter) { instance_spy(FFI::Pointer) }

before do
allow(IpAdapterAddressesLh).to receive(:read_list).with(adapter_address).and_yield(adapter)
allow(IpAdapterAddressesLh).to receive(:new).with(next_adapter).and_return(adapter)
allow(adapter).to receive(:[]).with(:OperStatus).and_return(NetworkingFFI::IF_OPER_STATUS_DOWN)
allow(adapter).to receive(:[]).with(:Next).and_return(next_adapter)
allow(adapter).to receive(:to_ptr).and_return(FFI::Pointer::NULL)
end

Expand Down
64 changes: 27 additions & 37 deletions spec/facter/resolvers/windows/product_release_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@

describe Facter::Resolvers::ProductRelease do
describe '#resolve' do
context 'when all fields exist in registry' do
let(:reg) { { 'EditionID' => ed, 'InstallationType' => install, 'ProductName' => prod, 'ReleaseId' => release } }
let(:ed) { 'ServerStandard' }
let(:install) { 'Server' }
let(:prod) { 'Windows Server 2019 Standard' }
let(:release) { '1809' }
let(:reg) { instance_double('Win32::Registry::HKEY_LOCAL_MACHINE') }
let(:ed) { 'ServerStandard' }
let(:install) { 'Server' }
let(:prod) { 'Windows Server 2019 Standard' }
let(:release) { '1809' }

before do
allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
.with('SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
.and_return(reg)
allow(reg).to receive(:[]).with('EditionID').and_return(ed)
allow(reg).to receive(:[]).with('InstallationType').and_return(install)
allow(reg).to receive(:[]).with('ProductName').and_return(prod)
allow(reg).to receive(:[]).with('ReleaseId').and_return(release)
allow(reg).to receive(:close)
end
before do
allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
.with('SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
.and_return(reg)
allow(reg).to receive(:each)
.and_yield('EditionID', ed)
.and_yield('InstallationType', install)
.and_yield('ProductName', prod)
.and_yield('ReleaseId', release)

after do
Facter::Resolvers::ProductRelease.invalidate_cache
end
allow(reg).to receive(:[]).with('EditionID').and_return(ed)
allow(reg).to receive(:[]).with('InstallationType').and_return(install)
allow(reg).to receive(:[]).with('ProductName').and_return(prod)
allow(reg).to receive(:[]).with('ReleaseId').and_return(release)

allow(reg).to receive(:close)
end

after do
Facter::Resolvers::ProductRelease.invalidate_cache
end

context 'when all fields exist in registry' do
it 'detects edition id' do
expect(Facter::Resolvers::ProductRelease.resolve(:edition_id)).to eql(ed)
end
Expand All @@ -42,24 +49,7 @@
end

context "when InstallationType doen't exist in registry" do
let(:reg) { { 'EditionID' => ed, 'ProductName' => prod, 'ReleaseId' => release } }
let(:ed) { 'ServerStandard' }
let(:prod) { 'Windows Server 2019 Standard' }
let(:release) { '1809' }

before do
allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
.with('SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
.and_return(reg)
allow(reg).to receive(:[]).with('EditionID').and_return(ed)
allow(reg).to receive(:[]).with('ProductName').and_return(prod)
allow(reg).to receive(:[]).with('ReleaseId').and_return(release)
allow(reg).to receive(:close)
end

after do
Facter::Resolvers::ProductRelease.invalidate_cache
end
let(:install) { nil }

it 'detects edition id' do
expect(Facter::Resolvers::ProductRelease.resolve(:edition_id)).to eql(ed)
Expand Down
Loading

0 comments on commit 010ad22

Please sign in to comment.