From e7af2e0404764c285604e7ce774c96fc792ae9f7 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 28 Apr 2020 17:43:08 +0300 Subject: [PATCH 01/44] (FACT-2569) implemented acceptance tests run in GitHub Actions --- .github/actions/presuite.sh | 40 ++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100755 .github/actions/presuite.sh create mode 100644 .github/workflows/ci.yml diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh new file mode 100755 index 000000000..6c009354c --- /dev/null +++ b/.github/actions/presuite.sh @@ -0,0 +1,40 @@ +#!/bin/sh -x + +export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings +export PATH=/opt/puppetlabs/puppet/bin/:/opt/puppetlabs/bin:$PATH +cwd=$(pwd) + +printf '\nInstall bundler\n\n' +gem install bundler + +printf '\nInstall facter 3 dependencies\n\n' +cd $cwd/$FACTER_3_ROOT/acceptance && bundle install + +printf '\nInstall custom beaker\n\n' +cd $cwd/$BEAKER_ROOT +gem build beaker.gemspec +gem install beaker-*.gem --bindir /bin +bundle info beaker --path + +printf '\nBeaker provision\n\n' +cd $cwd/$FACTER_3_ROOT/acceptance +beaker init -h ubuntu1804-64a{hypervisor=none\,hostname=localhost} -o config/aio/options.rb +beaker provision + +printf '\nBeaker pre-suite\n\n' +BP_ROOT=`bundle info beaker-puppet --path` +beaker exec pre-suite --pre-suite $BP_ROOT/setup/aio/010_Install_Puppet_Agent.rb + +printf '\nConfigure facter 4 as facter 3\n\n' +puppet config set facterng true + +printf '\nInstall facter 4 dependencies\n\n' +cd $cwd/$FACTER_4_ROOT && bundle install + +printf '\nInstall facter 4\n\n' +gem build facter.gemspec +gem install -f facter-*.gem + +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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..cf8101374 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +--- +name: GitHub hosted facter CI + +on: [pull_request] + +jobs: + ci: + name: Run acceptance tests + runs-on: ubuntu-latest + env: + FACTER_3_ROOT: facter_3 + FACTER_4_ROOT: facter_4 + BEAKER_ROOT: beaker + SHA: latest + + 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: master + path: facter_3 + + - name: Clone Mihai's beaker fork + uses: actions/checkout@v2 + with: + repository: mihaibuzgau/beaker + ref: master + path: beaker + + - name: Install Ruby 2.6 + uses: actions/setup-ruby@v1 + with: + ruby-version: '2.6' + + - name: Run acceptance tests + run: sudo -E bash -c facter_4/.github/actions/presuite.sh + From a2bab86b0652a78830b6b8175c2193c49c7e5864 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 28 Apr 2020 19:35:06 +0300 Subject: [PATCH 02/44] (FACT-2569) deactivate check for files with world writable permissions --- .github/actions/presuite.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh index 6c009354c..d4b724633 100755 --- a/.github/actions/presuite.sh +++ b/.github/actions/presuite.sh @@ -1,6 +1,7 @@ #!/bin/sh -x export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings +export DENABLE_PATH_CHECK=0 export PATH=/opt/puppetlabs/puppet/bin/:/opt/puppetlabs/bin:$PATH cwd=$(pwd) From 8c81c5628de0d2490a8eeb57228480e34c808abc Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 28 Apr 2020 19:47:58 +0300 Subject: [PATCH 03/44] (FACT-2569) changed ruby setup --- .github/actions/presuite.sh | 23 ++++++++++++----------- .github/workflows/ci.yml | 10 +++++++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh index 17c70c7eb..492755008 100755 --- a/.github/actions/presuite.sh +++ b/.github/actions/presuite.sh @@ -1,21 +1,22 @@ #!/bin/sh -x export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings -export DENABLE_PATH_CHECK=0 export PATH=/opt/puppetlabs/puppet/bin/:/opt/puppetlabs/bin:$PATH cwd=$(pwd) printf '\nInstall bundler\n\n' gem install bundler -printf '\nInstall facter 3 dependencies\n\n' +printf '\nInstall facter 4 dependencies\n\n' +cd $cwd/$FACTER_4_ROOT && bundle install + +printf '\nInstall facter 3 acceptance dependencies\n\n' cd $cwd/$FACTER_3_ROOT/acceptance && bundle install printf '\nInstall custom beaker\n\n' cd $cwd/$BEAKER_ROOT gem build beaker.gemspec gem install beaker-*.gem --bindir /bin -bundle info beaker --path printf '\nBeaker provision\n\n' cd $cwd/$FACTER_3_ROOT/acceptance @@ -29,15 +30,15 @@ beaker exec pre-suite --pre-suite $BP_ROOT/setup/aio/010_Install_Puppet_Agent.rb printf '\nConfigure facter 4 as facter 3\n\n' puppet config set facterng true -printf '\nInstall facter 4 dependencies\n\n' -cd $cwd/$FACTER_4_ROOT && bundle install +agent_facter_ng_version=`facter-ng --version | tr -d '\r'` + +cp -r $cwd/$FACTER_4_ROOT/* /opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/facter-ng-$agent_facter_ng_version/ +mv /opt/puppetlabs/puppet/bin/facter-ng /opt/puppetlabs/bin/facter -printf '\nInstall facter 4\n\n' -gem build facter.gemspec -gem install -f facter-*.gem +puts facter -version +puts puppet facts | grep facterversion printf '\nBeaker tests\n\n' cd $cwd/$FACTER_3_ROOT/acceptance - -beaker exec tests/external_facts/external_fact_stderr_messages_output_to_stderr.rb --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high -echo $PATH +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'} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf8101374..16fce31a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v2 with: repository: puppetlabs/facter - ref: master + ref: run_tests_on_ng path: facter_3 - name: Clone Mihai's beaker fork @@ -34,10 +34,14 @@ jobs: path: beaker - name: Install Ruby 2.6 - uses: actions/setup-ruby@v1 + uses: ruby/setup-ruby@v1 with: ruby-version: '2.6' + - 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 - From ccc20f830cb8a930bc874b837ba6fc92bc70ccce Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 5 May 2020 15:00:17 +0300 Subject: [PATCH 04/44] (FACT-2569) skipped failing tests on ubuntu --- .github/actions/presuite.sh | 6 +++--- .github/workflows/ci.yml | 6 +++--- VERSION | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh index 492755008..6db0fd833 100755 --- a/.github/actions/presuite.sh +++ b/.github/actions/presuite.sh @@ -1,7 +1,7 @@ #!/bin/sh -x export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings -export PATH=/opt/puppetlabs/puppet/bin/:/opt/puppetlabs/bin:$PATH +export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:$PATH cwd=$(pwd) printf '\nInstall bundler\n\n' @@ -35,8 +35,8 @@ agent_facter_ng_version=`facter-ng --version | tr -d '\r'` cp -r $cwd/$FACTER_4_ROOT/* /opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/facter-ng-$agent_facter_ng_version/ mv /opt/puppetlabs/puppet/bin/facter-ng /opt/puppetlabs/bin/facter -puts facter -version -puts puppet facts | grep facterversion +facter -v +puppet facts | grep facterversion printf '\nBeaker tests\n\n' cd $cwd/$FACTER_3_ROOT/acceptance diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16fce31a1..07b91b744 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ --- name: GitHub hosted facter CI -on: [pull_request] +on: [pull_request, push] jobs: ci: @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v2 with: repository: puppetlabs/facter - ref: run_tests_on_ng + ref: skip_failures_on_ng path: facter_3 - name: Clone Mihai's beaker fork @@ -33,7 +33,7 @@ jobs: ref: master path: beaker - - name: Install Ruby 2.6 + - name: Install Ruby 2.6.x uses: ruby/setup-ruby@v1 with: ruby-version: '2.6' diff --git a/VERSION b/VERSION index 9d58a584e..ae4044558 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.17 +4.0.666 From b59a0d21dcecfdda048230f4c2c715f3edb72ac5 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 5 May 2020 17:24:54 +0300 Subject: [PATCH 05/44] (FACT-2569) skipped failing tests on ubuntu --- .github/actions/presuite.sh | 32 +++++++++++++++++++++----------- .github/workflows/ci.yml | 4 ++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh index 6db0fd833..35e6b292c 100755 --- a/.github/actions/presuite.sh +++ b/.github/actions/presuite.sh @@ -1,17 +1,17 @@ #!/bin/sh -x export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings -export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:$PATH cwd=$(pwd) -printf '\nInstall bundler\n\n' -gem install bundler +#printf '\nInstall bundler\n\n' +#gem install bundler -printf '\nInstall facter 4 dependencies\n\n' -cd $cwd/$FACTER_4_ROOT && bundle install +#printf '\nInstall facter 4 dependencies\n\n' +#cd $cwd/$FACTER_4_ROOT && bundle install 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 @@ -32,13 +32,23 @@ puppet config set facterng true agent_facter_ng_version=`facter-ng --version | tr -d '\r'` -cp -r $cwd/$FACTER_4_ROOT/* /opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/facter-ng-$agent_facter_ng_version/ -mv /opt/puppetlabs/puppet/bin/facter-ng /opt/puppetlabs/bin/facter +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 + +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'} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07b91b744..2c36b598f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,9 @@ 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 @@ -45,3 +48,4 @@ jobs: - name: Run acceptance tests run: sudo -E bash -c facter_4/.github/actions/presuite.sh + From 1cf9bf50a995e2aeba8aecc97e69d5cc6f1432c7 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 5 May 2020 20:06:28 +0300 Subject: [PATCH 06/44] (FACT-2569) changed how facter is replaced --- .github/actions/presuite.sh | 28 +++++++++++++++++++--------- .github/workflows/ci.yml | 3 +++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh index 6db0fd833..83349dd1d 100755 --- a/.github/actions/presuite.sh +++ b/.github/actions/presuite.sh @@ -1,17 +1,17 @@ #!/bin/sh -x export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings -export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:$PATH cwd=$(pwd) printf '\nInstall bundler\n\n' gem install bundler -printf '\nInstall facter 4 dependencies\n\n' -cd $cwd/$FACTER_4_ROOT && bundle install +#printf '\nInstall facter 4 dependencies\n\n' +#cd $cwd/$FACTER_4_ROOT && bundle install 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 @@ -32,13 +32,23 @@ puppet config set facterng true agent_facter_ng_version=`facter-ng --version | tr -d '\r'` -cp -r $cwd/$FACTER_4_ROOT/* /opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/facter-ng-$agent_facter_ng_version/ -mv /opt/puppetlabs/puppet/bin/facter-ng /opt/puppetlabs/bin/facter +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 + +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'} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07b91b744..552cfcc88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,9 @@ 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 From 3fc7a95b605fe65fa14167ab3294dc46ac50b014 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 6 May 2020 15:14:37 +0300 Subject: [PATCH 07/44] (FACT-2599) run on all platforms except windows --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38b1568c2..3e8b63ff2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,16 @@ --- name: GitHub hosted facter CI -on: [pull_request] +on: [push] jobs: ci: name: Run acceptance tests - runs-on: ubuntu-latest + build: + 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 From 709b42c629e7707159df001c6725459ca7e05329 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 6 May 2020 15:14:37 +0300 Subject: [PATCH 08/44] (FACT-2599) removed extra parameter --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38b1568c2..063670339 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,15 @@ --- name: GitHub hosted facter CI -on: [pull_request] +on: [push] 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 From fed1848fb677c3832911a7ed22b1eb1cc3e36f0c Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 6 May 2020 17:53:42 +0300 Subject: [PATCH 09/44] (FACT-2599) debug --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 063670339..9bb24faf9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: name: Run acceptance tests strategy: matrix: - os: [ubuntu-18.04, ubuntu-16.04, macos-10.15] + os: [ubuntu-18.04, ubuntu-16.04] runs-on: ${{ matrix.os }} env: FACTER_3_ROOT: facter_3 @@ -41,6 +41,9 @@ 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 From c475eabf1126ca288ba505e00d342c965b116b2f Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 6 May 2020 18:03:10 +0300 Subject: [PATCH 10/44] (FACT-2599) debug --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 063670339..fb9b755c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,4 +47,4 @@ jobs: 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 + run: echo $ImageOS From 6de6f0288f848d929e33dd616163caf9de2b85f8 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 6 May 2020 18:06:24 +0300 Subject: [PATCH 11/44] (FACT-2599) debug --- .github/actions/presuite.rb | 5 +++++ .github/actions/presuite.sh | 4 +++- .github/workflows/ci.yml | 15 ++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 .github/actions/presuite.rb diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb new file mode 100644 index 000000000..7f66b65a2 --- /dev/null +++ b/.github/actions/presuite.rb @@ -0,0 +1,5 @@ +ENV['DEBIAN_DISABLE_RUBYGEMS_INTEGRATION']='no_wornings' +ENV['PATH']='/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:' + ENV['PATH'] + +Open3.capture2('gem install bundle') + diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh index 73b6a63da..189732add 100755 --- a/.github/actions/presuite.sh +++ b/.github/actions/presuite.sh @@ -1,5 +1,7 @@ #!/bin/sh -x +declare -A PLATFORMS=( [ubuntu18]=ubuntu1804-64a [ubuntu16]=ubuntu1604-64a [macos1015]=osx1015-64a ) + export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:$PATH @@ -18,7 +20,7 @@ gem install beaker-*.gem --bindir /bin printf '\nBeaker provision\n\n' cd $cwd/$FACTER_3_ROOT/acceptance -beaker init -h ubuntu1804-64a{hypervisor=none\,hostname=localhost} -o config/aio/options.rb +beaker init -h ${PLATFORMS[$ImageOS]}{hypervisor=none\,hostname=localhost} -o config/aio/options.rb beaker provision printf '\nBeaker pre-suite\n\n' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3512787d..bbf4abcea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: name: Run acceptance tests strategy: matrix: - os: [ubuntu-18.04, ubuntu-16.04] + os: [ubuntu-18.04, ubuntu-16.04, macos-10.15] runs-on: ${{ matrix.os }} env: FACTER_3_ROOT: facter_3 @@ -41,13 +41,14 @@ 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 + if [ $ImageOS == ubuntu18 ] + then + sudo chmod a-w /opt /home/runner /usr/share && + sudo chmod -R a-w /usr/share/rust /home/runner/.config + fi - name: Run acceptance tests - run: echo $ImageOS + run: | + sudo -E ruby facter_4/.github/actions/presuite.rb \ No newline at end of file From 54e8374fa58a9ccbecd2c60807a0596d2f89c329 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 7 May 2020 12:05:20 +0300 Subject: [PATCH 12/44] (FACT-2599) run open3 --- .github/actions/presuite.rb | 100 ++++++++++++++++++++++++++++++++++-- .github/actions/presuite.sh | 9 ++-- .github/workflows/ci.yml | 10 ++-- 3 files changed, 108 insertions(+), 11 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 7f66b65a2..89f5836ff 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -1,5 +1,99 @@ -ENV['DEBIAN_DISABLE_RUBYGEMS_INTEGRATION']='no_wornings' -ENV['PATH']='/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:' + ENV['PATH'] +require 'open3' -Open3.capture2('gem install bundle') +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 --bindir /bin') +end + +def initialize_beaker + beaker_platforms = { + ubuntu18: 'ubuntu1804-64a', + ubuntu16: 'ubuntu1604-64a', + macos1015: 'osx1015-64a' + } + platform = beaker_platforms[ENV['ImageOS'].to_sym] + + message('BEAKER INITIALIZE') + run("beaker init -h #{platform}{hypervisor=none,hostname=localhost} -o config/aio/options.rb") + + message('BEAKER PROVISION') + run('beaker provision') +end + +def install_puppet_agent + beaker_puppet_root = run('bundle info beaker-puppet --path').chomp + install_puppet_file_path = File.join(beaker_puppet_root, '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' + linux_puppet_gem_command = File.join(linux_puppet_bin_dir, 'gem') + + message('SET FACTER 4 FLAG TO TRUE') + run('puppet config set facterng true', FACTER_3_ACCEPTANCE_PATH) + + message('BUILD FACTER 4 LATEST AGENT GEM') + run("#{linux_puppet_gem_command} build agent/facter-ng.gemspec") + + message('UNINSTALL DEFAULT FACTER 4 AGENT GEM') + run("#{linux_puppet_gem_command} uninstall facter-ng") + + message('INSTALL FACTER 4 GEM') + run("#{linux_puppet_gem_command} install -f facter-ng-*.gem") + + 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 2>&1') +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 = './') + output, _status = Open3.capture2(command, chdir: dir) + puts output + output +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 + +Dir.chdir(ENV['FACTER_4_ROOT']) { replace_facter_3_with_facter_4 } + +Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { run_acceptance_tests } diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh index 189732add..b23f2d194 100755 --- a/.github/actions/presuite.sh +++ b/.github/actions/presuite.sh @@ -1,9 +1,9 @@ #!/bin/sh -x -declare -A PLATFORMS=( [ubuntu18]=ubuntu1804-64a [ubuntu16]=ubuntu1604-64a [macos1015]=osx1015-64a ) +#declare -A PLATFORMS=( [ubuntu18]=ubuntu1804-64a [ubuntu16]=ubuntu1604-64a [macos1015]=osx1015-64a ) export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings -export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:$PATH +export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:/home/runner/.rubies/ruby-2.6.6/bin:$PATH cwd=$(pwd) @@ -18,9 +18,12 @@ cd $cwd/$BEAKER_ROOT gem build beaker.gemspec gem install beaker-*.gem --bindir /bin +printf '\nRuby version\n\n' +ruby --version + printf '\nBeaker provision\n\n' cd $cwd/$FACTER_3_ROOT/acceptance -beaker init -h ${PLATFORMS[$ImageOS]}{hypervisor=none\,hostname=localhost} -o config/aio/options.rb +beaker init -h ubuntu1604-64a{hypervisor=none\,hostname=localhost} -o config/aio/options.rb beaker provision printf '\nBeaker pre-suite\n\n' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbf4abcea..cd06abce3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: name: Run acceptance tests strategy: matrix: - os: [ubuntu-18.04, ubuntu-16.04, macos-10.15] + os: [ubuntu-18.04] runs-on: ${{ matrix.os }} env: FACTER_3_ROOT: facter_3 @@ -29,21 +29,21 @@ 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 run: | - if [ $ImageOS == ubuntu18 ] + if [ $ImageOS != macos1015 ] then sudo chmod a-w /opt /home/runner /usr/share && sudo chmod -R a-w /usr/share/rust /home/runner/.config @@ -51,4 +51,4 @@ jobs: - name: Run acceptance tests run: | - sudo -E ruby facter_4/.github/actions/presuite.rb \ No newline at end of file + sudo -E "PATH=$PATH" ruby facter_4/.github/actions/presuite.rb \ No newline at end of file From 6f00e7e362320e610328a0356776ddc7fecab752 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 7 May 2020 16:44:19 +0300 Subject: [PATCH 13/44] (FACT-2599) run open3 --- .github/actions/presuite.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 89f5836ff..83a575f22 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -49,13 +49,13 @@ def replace_facter_3_with_facter_4 run('puppet config set facterng true', FACTER_3_ACCEPTANCE_PATH) message('BUILD FACTER 4 LATEST AGENT GEM') - run("#{linux_puppet_gem_command} build agent/facter-ng.gemspec") + run("#{linux_puppet_gem_command} build agent/facter-ng.gemspec", ENV['FACTER_4_ROOT']) message('UNINSTALL DEFAULT FACTER 4 AGENT GEM') run("#{linux_puppet_gem_command} uninstall facter-ng") message('INSTALL FACTER 4 GEM') - run("#{linux_puppet_gem_command} install -f facter-ng-*.gem") + run("#{linux_puppet_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) @@ -94,6 +94,6 @@ def run(command, dir = './') install_puppet_agent end -Dir.chdir(ENV['FACTER_4_ROOT']) { replace_facter_3_with_facter_4 } +replace_facter_3_with_facter_4 Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { run_acceptance_tests } From 9410c9484027edf4bdd4c687a40f788210b6ab40 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 7 May 2020 16:52:23 +0300 Subject: [PATCH 14/44] (FACT-2599) run open3 --- .github/actions/presuite.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 83a575f22..b56a5503f 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -46,7 +46,7 @@ def replace_facter_3_with_facter_4 linux_puppet_gem_command = File.join(linux_puppet_bin_dir, 'gem') message('SET FACTER 4 FLAG TO TRUE') - run('puppet config set facterng true', FACTER_3_ACCEPTANCE_PATH) + run('puppet config set facterng true', '/opt/puppetlabs/bin') message('BUILD FACTER 4 LATEST AGENT GEM') run("#{linux_puppet_gem_command} build agent/facter-ng.gemspec", ENV['FACTER_4_ROOT']) From 272ed6ce44997ee04c94390071789bfa26e3d289 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 7 May 2020 16:56:51 +0300 Subject: [PATCH 15/44] (FACT-2599) run open3 --- .github/actions/presuite.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index b56a5503f..86886910b 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -46,7 +46,7 @@ def replace_facter_3_with_facter_4 linux_puppet_gem_command = File.join(linux_puppet_bin_dir, 'gem') message('SET FACTER 4 FLAG TO TRUE') - run('puppet config set facterng true', '/opt/puppetlabs/bin') + run('/opt/puppetlabs/puppet/bin/puppet config set facterng true') message('BUILD FACTER 4 LATEST AGENT GEM') run("#{linux_puppet_gem_command} build agent/facter-ng.gemspec", ENV['FACTER_4_ROOT']) @@ -75,8 +75,9 @@ def message(message) end def run(command, dir = './') - output, _status = Open3.capture2(command, chdir: dir) + output, std_err, _status = Open3.capture3(command, chdir: dir) puts output + puts std_err output end From e399197f4568eb199911c57de03e9911ee356175 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 7 May 2020 17:00:29 +0300 Subject: [PATCH 16/44] (FACT-2599) run open3 --- .github/actions/presuite.rb | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 86886910b..431892658 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -46,7 +46,7 @@ def replace_facter_3_with_facter_4 linux_puppet_gem_command = File.join(linux_puppet_bin_dir, 'gem') message('SET FACTER 4 FLAG TO TRUE') - run('/opt/puppetlabs/puppet/bin/puppet config set facterng true') + run("#{File.join(linux_puppet_bin_dir,'puppet')} config set facterng true") message('BUILD FACTER 4 LATEST AGENT GEM') run("#{linux_puppet_gem_command} build agent/facter-ng.gemspec", ENV['FACTER_4_ROOT']) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd06abce3..c43d3792c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: name: Run acceptance tests strategy: matrix: - os: [ubuntu-18.04] + os: [ubuntu-16.04, ubuntu-18.04] runs-on: ${{ matrix.os }} env: FACTER_3_ROOT: facter_3 From ed5e4a0abd64f87de8e212f8f79769f18fb74f5e Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 7 May 2020 17:04:30 +0300 Subject: [PATCH 17/44] (FACT-2599) run open3 --- .github/actions/presuite.rb | 11 ++++++----- .github/workflows/ci.yml | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 431892658..2792bd2db 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -43,19 +43,20 @@ def install_puppet_agent def replace_facter_3_with_facter_4 linux_puppet_bin_dir = '/opt/puppetlabs/puppet/bin' - linux_puppet_gem_command = File.join(linux_puppet_bin_dir, 'gem') + 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("#{File.join(linux_puppet_bin_dir,'puppet')} config set facterng true") + run("#{puppet_command} config set facterng true") message('BUILD FACTER 4 LATEST AGENT GEM') - run("#{linux_puppet_gem_command} build agent/facter-ng.gemspec", ENV['FACTER_4_ROOT']) + run("#{gem_command} build agent/facter-ng.gemspec", ENV['FACTER_4_ROOT']) message('UNINSTALL DEFAULT FACTER 4 AGENT GEM') - run("#{linux_puppet_gem_command} uninstall facter-ng") + run("#{gem_command} uninstall facter-ng") message('INSTALL FACTER 4 GEM') - run("#{linux_puppet_gem_command} install -f facter-ng-*.gem", ENV['FACTER_4_ROOT']) + 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) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c43d3792c..56b940b94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: name: Run acceptance tests strategy: matrix: - os: [ubuntu-16.04, ubuntu-18.04] + os: [ubuntu-18.04, ubuntu-16.04, macos-10.15] runs-on: ${{ matrix.os }} env: FACTER_3_ROOT: facter_3 @@ -47,6 +47,9 @@ jobs: then sudo chmod a-w /opt /home/runner /usr/share && sudo chmod -R a-w /usr/share/rust /home/runner/.config + elif [ $ImageOS == macos1015 ] + then + sudo chmod a+w /bin fi - name: Run acceptance tests From eb2a85cb3b426274beb666ed7704701e79907805 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 7 May 2020 17:19:49 +0300 Subject: [PATCH 18/44] (FACT-2599) run open3 --- .github/actions/presuite.rb | 4 +++- .github/actions/presuite.sh | 47 ------------------------------------- 2 files changed, 3 insertions(+), 48 deletions(-) delete mode 100755 .github/actions/presuite.sh diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 2792bd2db..bcfde9af3 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -11,11 +11,13 @@ def install_facter_3_dependecies end def install_custom_beaker + bin_path = {macos1015: 'usr/local/bin'} + message('BUILD CUSTOM BEAKER GEM') run('gem build beaker.gemspec') message('INSTALL CUSTOM BEAKER GEM') - run('gem install beaker-*.gem --bindir /bin') + run("gem install beaker-*.gem --bindir #{bin_path.fetch(ENV['ImageOS'].to_sym, '/bin')}") end def initialize_beaker diff --git a/.github/actions/presuite.sh b/.github/actions/presuite.sh deleted file mode 100755 index b23f2d194..000000000 --- a/.github/actions/presuite.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh -x - -#declare -A PLATFORMS=( [ubuntu18]=ubuntu1804-64a [ubuntu16]=ubuntu1604-64a [macos1015]=osx1015-64a ) - -export DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=no_wornings -export PATH=/opt/puppetlabs/bin/:/opt/puppetlabs/puppet/bin:/home/runner/.rubies/ruby-2.6.6/bin:$PATH - -cwd=$(pwd) - -printf '\nInstall bundler\n\n' -gem install bundler - -printf '\nInstall facter 3 acceptance dependencies\n\n' -cd $cwd/$FACTER_3_ROOT/acceptance && bundle install - -printf '\nInstall custom beaker\n\n' -cd $cwd/$BEAKER_ROOT -gem build beaker.gemspec -gem install beaker-*.gem --bindir /bin - -printf '\nRuby version\n\n' -ruby --version - -printf '\nBeaker provision\n\n' -cd $cwd/$FACTER_3_ROOT/acceptance -beaker init -h ubuntu1604-64a{hypervisor=none\,hostname=localhost} -o config/aio/options.rb -beaker provision - -printf '\nBeaker pre-suite\n\n' -BP_ROOT=`bundle info beaker-puppet --path` -beaker exec pre-suite --pre-suite $BP_ROOT/setup/aio/010_Install_Puppet_Agent.rb - -printf '\nConfigure facter 4 as facter 3\n\n' -puppet config set facterng true - -cd $cwd/$FACTER_4_ROOT -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 - -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 From b764d19831cb8088978360f73d2f10ee5925bbe4 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 7 May 2020 17:21:16 +0300 Subject: [PATCH 19/44] (FACT-2599) run on mac --- .github/actions/presuite.rb | 44 +++++++++++++++++++++++-------------- .github/workflows/ci.yml | 13 +++++------ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index bcfde9af3..070357442 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -11,33 +11,42 @@ def install_facter_3_dependecies end def install_custom_beaker - bin_path = {macos1015: 'usr/local/bin'} - message('BUILD CUSTOM BEAKER GEM') run('gem build beaker.gemspec') message('INSTALL CUSTOM BEAKER GEM') - run("gem install beaker-*.gem --bindir #{bin_path.fetch(ENV['ImageOS'].to_sym, '/bin')}") + run('gem install beaker-*.gem') end def initialize_beaker + beaker_platform = get_beaker_platform(ENV['ImageOS'].to_sym) + beaker_platform_with_options = get_platform_with_options(beaker_platform) + + message('BEAKER INITIALIZE') + run("beaker init -h #{beaker_platform_with_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' } - platform = beaker_platforms[ENV['ImageOS'].to_sym] - message('BEAKER INITIALIZE') - run("beaker init -h #{platform}{hypervisor=none,hostname=localhost} -o config/aio/options.rb") + beaker_platforms[host_platform] +end - message('BEAKER PROVISION') - run('beaker provision') +def get_platform_with_options(platform) + return "#{platform}{hypervisor=none,hostname=localhost}" if platform.include? 'ubuntu' + "\"#{platform}{hypervisor=none,hostname=localhost}\"" if platform.include? 'osx' end def install_puppet_agent - beaker_puppet_root = run('bundle info beaker-puppet --path').chomp - install_puppet_file_path = File.join(beaker_puppet_root, 'setup', 'aio', '010_Install_Puppet_Agent.rb') + 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}") @@ -46,7 +55,7 @@ def install_puppet_agent 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') + puppet_command = File.join(linux_puppet_bin_dir, 'puppet') message('SET FACTER 4 FLAG TO TRUE') run("#{puppet_command} config set facterng true") @@ -66,7 +75,7 @@ def replace_facter_3_with_facter_4 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 2>&1') + run('beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high') end def message(message) @@ -78,10 +87,10 @@ def message(message) end def run(command, dir = './') - output, std_err, _status = Open3.capture3(command, chdir: dir) + puts command + output, status = Open3.capture2(command, chdir: dir) puts output - puts std_err - output + [output, status] end ENV['DEBIAN_DISABLE_RUBYGEMS_INTEGRATION'] = 'no_wornings' @@ -100,4 +109,7 @@ def run(command, dir = './') replace_facter_3_with_facter_4 -Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { run_acceptance_tests } +Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do + _, status = run_acceptance_tests + exit(status.exitstatus) +end diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56b940b94..a423ea0e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ --- name: GitHub hosted facter CI -on: [push] +on: [pull_request] jobs: ci: @@ -43,15 +43,12 @@ jobs: - name: Fix permissions run: | - if [ $ImageOS != macos1015 ] + if [[ $ImageOS == *ubuntu* ]] then - 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 - elif [ $ImageOS == macos1015 ] - then - sudo chmod a+w /bin fi + sudo chmod a-w /opt - name: Run acceptance tests - run: | - sudo -E "PATH=$PATH" ruby facter_4/.github/actions/presuite.rb \ No newline at end of file + run: sudo -E "PATH=$PATH" ruby facter_4/.github/actions/presuite.rb \ No newline at end of file From 1587143a62523af92d9c86c85b63ac4687d788ad Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Fri, 8 May 2020 10:43:34 +0300 Subject: [PATCH 20/44] (FACT-2600) run on windows --- .github/actions/presuite.rb | 50 +++++++++++++++++++++++-------------- .github/workflows/ci.yml | 35 ++++++++++++++++---------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 070357442..a25903222 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -19,8 +19,7 @@ def install_custom_beaker end def initialize_beaker - beaker_platform = get_beaker_platform(ENV['ImageOS'].to_sym) - beaker_platform_with_options = get_platform_with_options(beaker_platform) + beaker_platform_with_options = platform_with_options(beaker_platform) message('BEAKER INITIALIZE') run("beaker init -h #{beaker_platform_with_options} -o config/aio/options.rb") @@ -29,19 +28,20 @@ def initialize_beaker 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] +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 -def get_platform_with_options(platform) +def platform_with_options(platform) return "#{platform}{hypervisor=none,hostname=localhost}" if platform.include? 'ubuntu' - "\"#{platform}{hypervisor=none,hostname=localhost}\"" if platform.include? 'osx' + return "\"#{platform}{hypervisor=none,hostname=localhost}\"" if platform.include? 'osx' + "\"#{platform}{hypervisor=none,hostname=localhost,is_cygwin=false}\"" if platform.include? 'windows' end def install_puppet_agent @@ -53,13 +53,27 @@ def install_puppet_agent 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') + gem_command = File.join(puppet_bin_dir, 'gem') + puppet_command = File.join(puppet_bin_dir, 'puppet') + run('') 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') + run('mv facter-ng facter', puppet_bin_dir) +end + +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.to_s.include? 'windows' ? windows_puppet_bin_dir : linux_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']) @@ -68,9 +82,6 @@ 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 @@ -93,8 +104,9 @@ def run(command, dir = './') [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].to_sym install_bundler diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a423ea0e9..602a13c89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,14 +1,17 @@ --- name: GitHub hosted facter CI -on: [pull_request] +on: [push] jobs: - ci: + linux: name: Run acceptance tests strategy: matrix: - os: [ubuntu-18.04, ubuntu-16.04, macos-10.15] + os: [macos-10.15] +# os: [ubuntu-18.04, ubuntu-16.04, macos-10.15] +# os: [windows-2016] +# os: [windows-2016, windows-2019] runs-on: ${{ matrix.os }} env: FACTER_3_ROOT: facter_3 @@ -41,14 +44,20 @@ jobs: with: ruby-version: '2.6' - - name: Fix permissions + - name: Fix Linux specific permissions + if: runner.os == 'Linux' run: | - if [[ $ImageOS == *ubuntu* ]] - then - sudo chmod a-w /home/runner /usr/share && - sudo chmod -R a-w /usr/share/rust /home/runner/.config - fi - sudo chmod a-w /opt - - - name: Run acceptance tests - run: sudo -E "PATH=$PATH" ruby facter_4/.github/actions/presuite.rb \ No newline at end of file + sudo chmod a-w /home/runner /usr/share && + sudo chmod -R a-w /usr/share/rust /home/runner/.config + + - name: Fix /opt permissions for Linux and MacOs + if: runner.os != 'Windows' + run: sudo chmod a-w /opt + + - name: Run acceptance tests on Linux like platform + if: runner.os != 'Windows' + run: sudo -E "PATH=$PATH" ruby facter_4/.github/actions/presuite.rb ${{ matrix.os }} + + - name: Run acceptance tests on Windows like platform + if: runner.os == 'Windows' + run: ruby facter_4/.github/actions/presuite.rb ${{ matrix.os }} From 308c584d104104f57291358b708507e63c489cba Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Fri, 8 May 2020 13:39:02 +0300 Subject: [PATCH 21/44] (FACT-2600) run on windows --- .github/actions/presuite.rb | 5 ++--- .github/workflows/ci.yml | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index a25903222..a1c0f949f 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -56,7 +56,6 @@ def replace_facter_3_with_facter_4 gem_command = File.join(puppet_bin_dir, 'gem') puppet_command = File.join(puppet_bin_dir, 'puppet') - run('') message('SET FACTER 4 FLAG TO TRUE') run("#{puppet_command} config set facterng true") @@ -68,9 +67,9 @@ def replace_facter_3_with_facter_4 def puppet_bin_dir linux_puppet_bin_dir = '/opt/puppetlabs/puppet/bin' - windows_puppet_bin_dir = 'c:\Program\ Files\Puppet\ Labs\Puppet\bin' + windows_puppet_bin_dir = 'C:\Program\ Files\Puppet\ Labs\Puppet\bin' - HOST_PLATFORM.to_s.include? 'windows' ? windows_puppet_bin_dir : linux_puppet_bin_dir + (HOST_PLATFORM.to_s.include? 'windows') ? windows_puppet_bin_dir : linux_puppet_bin_dir end def install_latest_facter_4(gem_command) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 602a13c89..6ee28c387 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,7 @@ jobs: name: Run acceptance tests strategy: matrix: - os: [macos-10.15] -# os: [ubuntu-18.04, ubuntu-16.04, macos-10.15] + os: [ubuntu-18.04, ubuntu-16.04, macos-10.15, windows-2016] # os: [windows-2016] # os: [windows-2016, windows-2019] runs-on: ${{ matrix.os }} @@ -44,20 +43,24 @@ jobs: with: ruby-version: '2.6' - - name: Fix Linux specific permissions + - name: Fix common Linux and MacOs permissions + if: runner.os != 'Windows' + run: sudo chmod a-w /opt + + - name: Fix Linux permissions if: runner.os == 'Linux' run: | sudo chmod a-w /home/runner /usr/share && sudo chmod -R a-w /usr/share/rust /home/runner/.config - - name: Fix /opt permissions for Linux and MacOs - if: runner.os != 'Windows' - run: sudo chmod a-w /opt + - name: Fix ubuntu-16.04 permissions + if: matrix.os == 'ubuntu-16.04' + run: sudo chmod -R a-w /home/linuxbrew - name: Run acceptance tests on Linux like platform if: runner.os != 'Windows' - run: sudo -E "PATH=$PATH" ruby facter_4/.github/actions/presuite.rb ${{ matrix.os }} + 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 facter_4/.github/actions/presuite.rb ${{ matrix.os }} + run: ruby $Env:FACTER_4_ROOT/.github/actions/presuite.rb ${{ matrix.os }} From 3a6cb0b1a084386bcd5778b4a63f7e3d95485b51 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Mon, 11 May 2020 12:53:34 +0300 Subject: [PATCH 22/44] (FACT-2600) uninstall beaker --- .github/actions/presuite.rb | 5 +++-- .github/workflows/ci.yml | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index a1c0f949f..a01dcc0f5 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -5,8 +5,9 @@ def install_bundler run('gem install bundler') end -def install_facter_3_dependecies +def install_facter_3_dependencies_without_beaker message('INSTALL FACTER 3 ACCEPTANCE DEPENDENCIES') + run('export BEAKER_VERSION=4.21.0') run('bundle install') end @@ -109,7 +110,7 @@ def run(command, dir = './') install_bundler -Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependecies } +Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies_without_beaker } Dir.chdir(ENV['BEAKER_ROOT']) { install_custom_beaker } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee28c387..04f24fb8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,8 @@ jobs: name: Run acceptance tests strategy: matrix: - os: [ubuntu-18.04, ubuntu-16.04, macos-10.15, windows-2016] -# os: [windows-2016] +# os: [ubuntu-18.04, ubuntu-16.04, macos-10.15, windows-2016] + os: [ubuntu-18.04] # os: [windows-2016, windows-2019] runs-on: ${{ matrix.os }} env: From 90f6e3dcde2f95d07153bb0911039fee52bf88e1 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Mon, 11 May 2020 12:53:34 +0300 Subject: [PATCH 23/44] (FACT-2600) uninstall beaker --- .github/actions/presuite.rb | 6 ++++-- .github/workflows/ci.yml | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index a1c0f949f..b9e6d3984 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -5,9 +5,11 @@ def install_bundler run('gem install bundler') end -def install_facter_3_dependecies +def install_facter_3_dependencies_without_beaker message('INSTALL FACTER 3 ACCEPTANCE DEPENDENCIES') run('bundle install') + run('export BEAKER_VERSION=4.21.0') + run('bundle update') end def install_custom_beaker @@ -109,7 +111,7 @@ def run(command, dir = './') install_bundler -Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependecies } +Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies_without_beaker } Dir.chdir(ENV['BEAKER_ROOT']) { install_custom_beaker } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee28c387..04f24fb8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,8 @@ jobs: name: Run acceptance tests strategy: matrix: - os: [ubuntu-18.04, ubuntu-16.04, macos-10.15, windows-2016] -# os: [windows-2016] +# os: [ubuntu-18.04, ubuntu-16.04, macos-10.15, windows-2016] + os: [ubuntu-18.04] # os: [windows-2016, windows-2019] runs-on: ${{ matrix.os }} env: From 194cb0b0f995f76e0b5f369dea51ff795a697cfe Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 12 May 2020 11:24:58 +0300 Subject: [PATCH 24/44] (FACT-2600) beaker debug --- .github/actions/presuite.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index fac0df584..a54496fca 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -22,10 +22,10 @@ def initialize_beaker beaker_platform_with_options = platform_with_options(beaker_platform) message('BEAKER INITIALIZE') - run("beaker init -h #{beaker_platform_with_options} -o config/aio/options.rb") + run("beaker init -h #{beaker_platform_with_options} -o config/aio/options.rb --debug") message('BEAKER PROVISION') - run('beaker provision') + run('beaker provision --debug') end def beaker_platform From eec16811289e78dccf0a4dc2b24b35b28bb045cb Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 12 May 2020 18:07:15 +0300 Subject: [PATCH 25/44] (FACT-2600) add custom beaker with git --- .github/actions/presuite.rb | 26 ++++++++++++++------------ .github/workflows/ci.yml | 14 +++++++------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index a54496fca..821193bba 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -11,21 +11,24 @@ def install_facter_3_dependencies 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') + message('INSTALL CUSTOM BEAKE GEM') + 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/mihaibuzgau/beaker.git') + run('git fetch') + run('git reset --hard origin/master') + end end def initialize_beaker beaker_platform_with_options = platform_with_options(beaker_platform) message('BEAKER INITIALIZE') - run("beaker init -h #{beaker_platform_with_options} -o config/aio/options.rb --debug") + run("beaker init -h #{beaker_platform_with_options} -o config/aio/options.rb") message('BEAKER PROVISION') - run('beaker provision --debug') + run('beaker provision') end def beaker_platform @@ -51,9 +54,9 @@ def install_puppet_agent presuite_files = ['012_Finalize_Installs.rb', '025_StopFirewall.rb', '030_StopSssd.rb'] abs_presuite_file_paths = [File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')] - presuite_files.each do |file| - abs_presuite_file_paths << File.join(beaker_puppet_root.chomp, path_tokens, file) - end + # presuite_files.each do |file| + # abs_presuite_file_paths << File.join(beaker_puppet_root.chomp, path_tokens, file) + # end run("beaker exec pre-suite --pre-suite #{abs_presuite_file_paths.join(',')}, --preserve-state") end @@ -116,8 +119,7 @@ def run(command, dir = './') install_bundler Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies } - -Dir.chdir(ENV['BEAKER_ROOT']) { install_custom_beaker } +install_custom_beaker Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do initialize_beaker diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4429252b3..0cb9c4ddd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: FACTER_4_ROOT: facter_4 BEAKER_ROOT: beaker SHA: latest - BEAKER_VERSION: 4.21.0 +# BEAKER_VERSION: 4.21.0 steps: - name: Checkout current PR @@ -32,12 +32,12 @@ jobs: ref: skip_failures_on_ng path: facter_3 - - name: Clone custom beaker fork - uses: actions/checkout@v2 - with: - repository: mihaibuzgau/beaker - ref: master - path: beaker +# - 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 From e7841d91330cbe1b0c416b51a71a7d97866df6bd Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 13 May 2020 11:40:07 +0300 Subject: [PATCH 26/44] (FACT-2600) benchmark bundle install --- .github/actions/presuite.rb | 20 ++++++++++++-------- .github/workflows/acceptance_tests.yml | 17 +++++------------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 821193bba..ff0c6964f 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -11,7 +11,7 @@ def install_facter_3_dependencies end def install_custom_beaker - message('INSTALL CUSTOM BEAKE GEM') + message('INSTALL CUSTOM BEAKER GEM') beaker_path, _ = run('bundle info beaker --path', FACTER_3_ACCEPTANCE_PATH) Dir.chdir(beaker_path.split("\n").last) do run('git init') @@ -29,6 +29,7 @@ def initialize_beaker message('BEAKER PROVISION') run('beaker provision') + message('done') end def beaker_platform @@ -50,15 +51,18 @@ def install_puppet_agent message('INSTALL PUPPET AGENT') beaker_puppet_root, _ = run('bundle info beaker-puppet --path') - path_tokens = ['setup', 'common'] - presuite_files = ['012_Finalize_Installs.rb', '025_StopFirewall.rb', '030_StopSssd.rb'] + presuite_file_paths = [File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')] - abs_presuite_file_paths = [File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')] - # presuite_files.each do |file| - # abs_presuite_file_paths << File.join(beaker_puppet_root.chomp, path_tokens, file) - # end + unless HOST_PLATFORM.to_s.include? 'windows' + path_tokens = ['setup', 'common'] + presuite_files = ['012_Finalize_Installs.rb', '025_StopFirewall.rb', '030_StopSssd.rb'] - run("beaker exec pre-suite --pre-suite #{abs_presuite_file_paths.join(',')}, --preserve-state") + presuite_files.each do |file| + presuite_file_paths << File.join(beaker_puppet_root.chomp, path_tokens, file) + end + end + + run("beaker exec pre-suite --pre-suite #{presuite_file_paths.join(',')}, --preserve-state") end def replace_facter_3_with_facter_4 diff --git a/.github/workflows/acceptance_tests.yml b/.github/workflows/acceptance_tests.yml index cb618f400..6d0b7e8a6 100644 --- a/.github/workflows/acceptance_tests.yml +++ b/.github/workflows/acceptance_tests.yml @@ -4,7 +4,8 @@ name: Acceptance tests on: push: branches: - - master +# - master + - FACT-2600 pull_request: branches: - master @@ -15,7 +16,7 @@ jobs: strategy: matrix: # os: [ubuntu-18.04, ubuntu-16.04, macos-10.15, windows-2016] - os: [windows-2016] + os: [windows-2016] # os: [windows-2016, windows-2019] runs-on: ${{ matrix.os }} env: @@ -23,7 +24,6 @@ jobs: FACTER_4_ROOT: facter_4 BEAKER_ROOT: beaker SHA: latest -# BEAKER_VERSION: 4.21.0 steps: - name: Checkout current PR @@ -38,13 +38,6 @@ jobs: ref: skip_failures_on_ng 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: @@ -61,8 +54,8 @@ jobs: sudo chmod -R a-w /usr/share/rust /home/runner/.config /home/linuxbrew - 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 }} + 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' From 6164a7c6db88584613a5210b0ae0860efcfd3677 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 13 May 2020 17:10:23 +0300 Subject: [PATCH 27/44] (FACT-2600) debug --- .github/actions/presuite.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index ff0c6964f..337f66c2c 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -29,7 +29,6 @@ def initialize_beaker message('BEAKER PROVISION') run('beaker provision') - message('done') end def beaker_platform @@ -62,7 +61,7 @@ def install_puppet_agent end end - run("beaker exec pre-suite --pre-suite #{presuite_file_paths.join(',')}, --preserve-state") + run("beaker exec pre-suite --pre-suite #{presuite_file_paths.join(',')} --preserve-state") end def replace_facter_3_with_facter_4 @@ -111,9 +110,9 @@ def message(message) def run(command, dir = './') puts command - output, status = Open3.capture2(command, chdir: dir) - puts output - [output, status] + # output, status = Open3.capture2(command, chdir: dir) + # puts output + # [output, status] end ENV['DEBIAN_DISABLE_RUBYGEMS_INTEGRATION'] = 'no_warnings' @@ -123,7 +122,7 @@ def run(command, dir = './') install_bundler Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies } -install_custom_beaker +# install_custom_beaker Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do initialize_beaker From 404b550f41567db6fff39c6660a28ed5761cde86 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 13 May 2020 17:35:51 +0300 Subject: [PATCH 28/44] (FACT-2600) debug --- .github/actions/presuite.rb | 50 +++++--- .github/actions/presuite_windows.rb | 156 +++++++++++++++++++++++++ .github/workflows/acceptance_tests.yml | 2 +- 3 files changed, 188 insertions(+), 20 deletions(-) create mode 100644 .github/actions/presuite_windows.rb diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 337f66c2c..08fc0f817 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -19,6 +19,15 @@ def install_custom_beaker run('git fetch') run('git reset --hard origin/master') end + + message('INSTALL CUSTOM BEAKER-PUPPET') + beaker_puppet_path, _ = run('bundle info beaker-puppet --path', FACTER_3_ACCEPTANCE_PATH) + Dir.chdir(beaker_puppet_path.split("\n").last) do + run('git init') + run('git remote add origin https://github.com/Filipovici-Andrei/beaker-puppet.git') + run('git fetch') + run('git reset --hard origin/BKR-1654') + end end def initialize_beaker @@ -50,22 +59,13 @@ def install_puppet_agent message('INSTALL PUPPET AGENT') beaker_puppet_root, _ = run('bundle info beaker-puppet --path') - presuite_file_paths = [File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')] - - unless HOST_PLATFORM.to_s.include? 'windows' - path_tokens = ['setup', 'common'] - presuite_files = ['012_Finalize_Installs.rb', '025_StopFirewall.rb', '030_StopSssd.rb'] - - presuite_files.each do |file| - presuite_file_paths << File.join(beaker_puppet_root.chomp, path_tokens, file) - end - end + 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_paths.join(',')} --preserve-state") + env = { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } + run("beaker exec pre-suite --pre-suite #{presuite_file_path.join(',')} --preserve-state", './', env) end def replace_facter_3_with_facter_4 - gem_command = File.join(puppet_bin_dir, 'gem') puppet_command = File.join(puppet_bin_dir, 'puppet') message('SET FACTER 4 FLAG TO TRUE') @@ -74,16 +74,21 @@ def replace_facter_3_with_facter_4 install_latest_facter_4(gem_command) message('CHANGE FACTER 3 WITH FACTER 4') - run('mv facter-ng facter', puppet_bin_dir) + run('mv "facter-ng" "facter"', puppet_bin_dir) end def puppet_bin_dir linux_puppet_bin_dir = '/opt/puppetlabs/puppet/bin' - windows_puppet_bin_dir = 'C:\Program\ Files\Puppet\ Labs\Puppet\bin' + windows_puppet_bin_dir = 'C:\\Program Files\\Puppet Labs\\Puppet\\bin' (HOST_PLATFORM.to_s.include? 'windows') ? windows_puppet_bin_dir : linux_puppet_bin_dir end +def gem_command + return File.join(puppet_bin_dir, 'gem') unless HOST_PLATFORM.to_s.include? 'windows' + "C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem" +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']) @@ -108,11 +113,18 @@ 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] + 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_warnings' @@ -122,7 +134,7 @@ def run(command, dir = './') install_bundler Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies } -# install_custom_beaker +install_custom_beaker Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do initialize_beaker diff --git a/.github/actions/presuite_windows.rb b/.github/actions/presuite_windows.rb new file mode 100644 index 000000000..b73640ee0 --- /dev/null +++ b/.github/actions/presuite_windows.rb @@ -0,0 +1,156 @@ +require 'open3' + +def install_bundler + message('INSTALL BUNDLER') + run('gem install bundler') +end + +def install_facter_3_dependencies + message('INSTALL FACTER 3 ACCEPTANCE DEPENDENCIES') + run('bundle install') +end + +def install_custom_beaker + message('INSTALL CUSTOM BEAKER GEM') + 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/mihaibuzgau/beaker.git') + run('git fetch') + run('git reset --hard origin/master') + end + + message('INSTALL CUSTOM BEAKER-PUPPET') + beaker_puppet_path, _ = run('bundle info beaker-puppet --path', FACTER_3_ACCEPTANCE_PATH) + Dir.chdir(beaker_puppet_path.split("\n").last) do + run('git init') + run('git remote add origin https://github.com/Filipovici-Andrei/beaker-puppet.git') + run('git fetch') + run('git reset --hard origin/BKR-1654') + end +end + +def initialize_beaker + beaker_platform_with_options = platform_with_options(beaker_platform) + + message('BEAKER INITIALIZE') + run("beaker init -h #{beaker_platform_with_options} -o config/aio/options.rb") + + message('BEAKER PROVISION') + run('beaker provision') +end + +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 + +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') + presuite_file_paths = [File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')] + + unless HOST_PLATFORM.to_s.include? 'windows' + path_tokens = ['setup', 'common'] + presuite_files = ['012_Finalize_Installs.rb', '025_StopFirewall.rb', '030_StopSssd.rb'] + + presuite_files.each do |file| + presuite_file_paths << File.join(beaker_puppet_root.chomp, path_tokens, file) + end + end + + run("beaker exec pre-suite --pre-suite #{presuite_file_paths.join(',')} --preserve-state") +end + +def replace_facter_3_with_facter_4 + gem_command = File.join(puppet_bin_dir, 'gem') + puppet_command = File.join(puppet_bin_dir, 'puppet') + + message('SET FACTER 4 FLAG TO TRUE') + run("'#{puppet_bin_dir}\\puppet' config set facterng true") + + install_latest_facter_4("'C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem'") + + message('CHANGE FACTER 3 WITH FACTER 4') + puts puppet_bin_dir + run('mv "facter-ng.bat" "facter.bat"', puppet_bin_dir) +end + +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.to_s.include? 'windows') ? windows_puppet_bin_dir : linux_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 + 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 = 0 + env = {} + env = { 'PATH' => "C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin;#{ENV['PATH']}" } if HOST_PLATFORM.to_s.include? 'windows' + 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_warnings' +FACTER_3_ACCEPTANCE_PATH = File.join(ENV['FACTER_3_ROOT'], 'acceptance') +HOST_PLATFORM = ARGV[0].to_sym + +install_bundler + +Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies } +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 diff --git a/.github/workflows/acceptance_tests.yml b/.github/workflows/acceptance_tests.yml index 6d0b7e8a6..8ab25fa27 100644 --- a/.github/workflows/acceptance_tests.yml +++ b/.github/workflows/acceptance_tests.yml @@ -15,7 +15,7 @@ jobs: name: Platform strategy: matrix: -# os: [ubuntu-18.04, ubuntu-16.04, macos-10.15, windows-2016] +# os: [ubuntu-18.04, macos-10.15, windows-2016] os: [windows-2016] # os: [windows-2016, windows-2019] runs-on: ${{ matrix.os }} From 37d6413943dfe066646aded259a29e5ab93af142 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Fri, 15 May 2020 12:55:05 +0300 Subject: [PATCH 29/44] (FACT-2600) debug --- .github/actions/presuite.rb | 34 +++--- .github/actions/presuite_windows.rb | 156 ------------------------- .github/workflows/acceptance_tests.yml | 7 +- 3 files changed, 24 insertions(+), 173 deletions(-) delete mode 100644 .github/actions/presuite_windows.rb diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 08fc0f817..e556ba1d9 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -11,7 +11,7 @@ def install_facter_3_dependencies end def install_custom_beaker - message('INSTALL CUSTOM BEAKER GEM') + 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') @@ -20,7 +20,7 @@ def install_custom_beaker run('git reset --hard origin/master') end - message('INSTALL CUSTOM BEAKER-PUPPET') + message('USE CUSTOM BEAKER-PUPPET') beaker_puppet_path, _ = run('bundle info beaker-puppet --path', FACTER_3_ACCEPTANCE_PATH) Dir.chdir(beaker_puppet_path.split("\n").last) do run('git init') @@ -59,15 +59,20 @@ def install_puppet_agent message('INSTALL PUPPET AGENT') 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')] + presuite_file_path = "#{beaker_puppet_root.chomp}/setup/aio/010_Install_Puppet_Agent.rb" - env = { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } - run("beaker exec pre-suite --pre-suite #{presuite_file_path.join(',')} --preserve-state", './', env) + env = { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } if HOST_PLATFORM.to_s.include? 'windows' + run("beaker exec pre-suite --pre-suite #{presuite_file_path} --preserve-state", './', env) end -def replace_facter_3_with_facter_4 - puppet_command = File.join(puppet_bin_dir, 'puppet') +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.to_s.include? 'windows') ? windows_puppet_bin_dir : linux_puppet_bin_dir +end +def replace_facter_3_with_facter_4 message('SET FACTER 4 FLAG TO TRUE') run("#{puppet_command} config set facterng true") @@ -77,16 +82,14 @@ def replace_facter_3_with_facter_4 run('mv "facter-ng" "facter"', puppet_bin_dir) end -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.to_s.include? 'windows') ? windows_puppet_bin_dir : linux_puppet_bin_dir +def puppet_command + return '/opt/puppetlabs/puppet/bin/puppet' unless HOST_PLATFORM.to_s.include? 'windows' + "\"C:\\Program Files\\Puppet Labs\\Puppet\\bin\\puppet\"" end def gem_command - return File.join(puppet_bin_dir, 'gem') unless HOST_PLATFORM.to_s.include? 'windows' - "C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem" + return '/opt/puppetlabs/puppet/bin/gem' unless HOST_PLATFORM.to_s.include? 'windows' + "\"C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem\"" end def install_latest_facter_4(gem_command) @@ -102,7 +105,8 @@ def install_latest_facter_4(gem_command) 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') + env = { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } + run('beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high', './', env) end def message(message) diff --git a/.github/actions/presuite_windows.rb b/.github/actions/presuite_windows.rb deleted file mode 100644 index b73640ee0..000000000 --- a/.github/actions/presuite_windows.rb +++ /dev/null @@ -1,156 +0,0 @@ -require 'open3' - -def install_bundler - message('INSTALL BUNDLER') - run('gem install bundler') -end - -def install_facter_3_dependencies - message('INSTALL FACTER 3 ACCEPTANCE DEPENDENCIES') - run('bundle install') -end - -def install_custom_beaker - message('INSTALL CUSTOM BEAKER GEM') - 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/mihaibuzgau/beaker.git') - run('git fetch') - run('git reset --hard origin/master') - end - - message('INSTALL CUSTOM BEAKER-PUPPET') - beaker_puppet_path, _ = run('bundle info beaker-puppet --path', FACTER_3_ACCEPTANCE_PATH) - Dir.chdir(beaker_puppet_path.split("\n").last) do - run('git init') - run('git remote add origin https://github.com/Filipovici-Andrei/beaker-puppet.git') - run('git fetch') - run('git reset --hard origin/BKR-1654') - end -end - -def initialize_beaker - beaker_platform_with_options = platform_with_options(beaker_platform) - - message('BEAKER INITIALIZE') - run("beaker init -h #{beaker_platform_with_options} -o config/aio/options.rb") - - message('BEAKER PROVISION') - run('beaker provision') -end - -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 - -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') - presuite_file_paths = [File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')] - - unless HOST_PLATFORM.to_s.include? 'windows' - path_tokens = ['setup', 'common'] - presuite_files = ['012_Finalize_Installs.rb', '025_StopFirewall.rb', '030_StopSssd.rb'] - - presuite_files.each do |file| - presuite_file_paths << File.join(beaker_puppet_root.chomp, path_tokens, file) - end - end - - run("beaker exec pre-suite --pre-suite #{presuite_file_paths.join(',')} --preserve-state") -end - -def replace_facter_3_with_facter_4 - gem_command = File.join(puppet_bin_dir, 'gem') - puppet_command = File.join(puppet_bin_dir, 'puppet') - - message('SET FACTER 4 FLAG TO TRUE') - run("'#{puppet_bin_dir}\\puppet' config set facterng true") - - install_latest_facter_4("'C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem'") - - message('CHANGE FACTER 3 WITH FACTER 4') - puts puppet_bin_dir - run('mv "facter-ng.bat" "facter.bat"', puppet_bin_dir) -end - -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.to_s.include? 'windows') ? windows_puppet_bin_dir : linux_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 - 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 = 0 - env = {} - env = { 'PATH' => "C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin;#{ENV['PATH']}" } if HOST_PLATFORM.to_s.include? 'windows' - 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_warnings' -FACTER_3_ACCEPTANCE_PATH = File.join(ENV['FACTER_3_ROOT'], 'acceptance') -HOST_PLATFORM = ARGV[0].to_sym - -install_bundler - -Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies } -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 diff --git a/.github/workflows/acceptance_tests.yml b/.github/workflows/acceptance_tests.yml index 16d4c8987..c508f05da 100644 --- a/.github/workflows/acceptance_tests.yml +++ b/.github/workflows/acceptance_tests.yml @@ -15,8 +15,8 @@ jobs: name: Platform strategy: matrix: -# os: [ubuntu-18.04, macos-10.15, windows-2016] - os: [windows-2016] + os: [macos-10.15] +# os: [windows-2016] # os: [windows-2016, windows-2019] runs-on: ${{ matrix.os }} env: @@ -44,6 +44,9 @@ jobs: with: ruby-version: '2.6' + - name: Setup tmate session + uses: mxschmitt/action-tmate@v2 + - name: Fix common Linux and MacOs permissions if: runner.os != 'Windows' run: sudo chmod a-w /opt From 995e7d3964c7fb1152ffd79fe24a8aab590d72fb Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Fri, 15 May 2020 14:37:56 +0300 Subject: [PATCH 30/44] (FACT-2600) debug --- .github/actions/presuite.rb | 5 +++-- .github/workflows/acceptance_tests.yml | 8 +------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index e556ba1d9..23dc0e2d2 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -61,7 +61,7 @@ def install_puppet_agent beaker_puppet_root, _ = run('bundle info beaker-puppet --path') presuite_file_path = "#{beaker_puppet_root.chomp}/setup/aio/010_Install_Puppet_Agent.rb" - env = { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } if HOST_PLATFORM.to_s.include? 'windows' + env = (HOST_PLATFORM.to_s.include? 'windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {} run("beaker exec pre-suite --pre-suite #{presuite_file_path} --preserve-state", './', env) end @@ -105,7 +105,8 @@ def install_latest_facter_4(gem_command) def run_acceptance_tests message('RUN ACCEPTANCE TESTS') - env = { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } + + env = (HOST_PLATFORM.to_s.include? 'windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {} run('beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high', './', env) end diff --git a/.github/workflows/acceptance_tests.yml b/.github/workflows/acceptance_tests.yml index c508f05da..5aa4d3201 100644 --- a/.github/workflows/acceptance_tests.yml +++ b/.github/workflows/acceptance_tests.yml @@ -15,16 +15,13 @@ jobs: name: Platform strategy: matrix: - os: [macos-10.15] -# os: [windows-2016] -# os: [windows-2016, windows-2019] + os: [ubuntu-16.04, ubuntu-18.04, macos-10.15, windows-2016, windows-2019] 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 @@ -44,9 +41,6 @@ jobs: with: ruby-version: '2.6' - - name: Setup tmate session - uses: mxschmitt/action-tmate@v2 - - name: Fix common Linux and MacOs permissions if: runner.os != 'Windows' run: sudo chmod a-w /opt From 5c6189cc8af7a1d547201b7fd89adc64ed14994c Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Fri, 15 May 2020 15:29:25 +0300 Subject: [PATCH 31/44] (FACT-2600) run on windows 2019 only --- .github/workflows/acceptance_tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/acceptance_tests.yml b/.github/workflows/acceptance_tests.yml index 118a5a5c6..f1f6b41dc 100644 --- a/.github/workflows/acceptance_tests.yml +++ b/.github/workflows/acceptance_tests.yml @@ -14,12 +14,11 @@ jobs: name: Platform strategy: matrix: - os: [ubuntu-16.04, ubuntu-18.04, macos-10.15, windows-2016, windows-2019] + os: [windows-2019] runs-on: ${{ matrix.os }} env: FACTER_3_ROOT: facter_3 FACTER_4_ROOT: facter_4 - BEAKER_ROOT: beaker SHA: latest steps: From 06d02aac20b21951f734fdc1420e3a1b4928fd60 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Mon, 18 May 2020 10:25:26 +0300 Subject: [PATCH 32/44] (FACT-2600) removed use of custom beaker-puppet --- .github/actions/presuite.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 23dc0e2d2..9a6a6c3fc 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -19,15 +19,6 @@ def install_custom_beaker run('git fetch') run('git reset --hard origin/master') end - - message('USE CUSTOM BEAKER-PUPPET') - beaker_puppet_path, _ = run('bundle info beaker-puppet --path', FACTER_3_ACCEPTANCE_PATH) - Dir.chdir(beaker_puppet_path.split("\n").last) do - run('git init') - run('git remote add origin https://github.com/Filipovici-Andrei/beaker-puppet.git') - run('git fetch') - run('git reset --hard origin/BKR-1654') - end end def initialize_beaker From dd333545fa2f8e93fd14c6f06ab18d8d13e989df Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Mon, 18 May 2020 11:04:45 +0300 Subject: [PATCH 33/44] Revert "(FACT-2600) removed use of custom beaker-puppet" This reverts commit 06d02aac20b21951f734fdc1420e3a1b4928fd60. (FACT-2600) revert last commit --- .github/actions/presuite.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 9a6a6c3fc..23dc0e2d2 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -19,6 +19,15 @@ def install_custom_beaker run('git fetch') run('git reset --hard origin/master') end + + message('USE CUSTOM BEAKER-PUPPET') + beaker_puppet_path, _ = run('bundle info beaker-puppet --path', FACTER_3_ACCEPTANCE_PATH) + Dir.chdir(beaker_puppet_path.split("\n").last) do + run('git init') + run('git remote add origin https://github.com/Filipovici-Andrei/beaker-puppet.git') + run('git fetch') + run('git reset --hard origin/BKR-1654') + end end def initialize_beaker From a5db86d8381bf3f9ce96ba2f35f6d65d91343efd Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 20 May 2020 15:53:35 +0300 Subject: [PATCH 34/44] (FACT-2600) changed beaker repo --- .github/actions/presuite.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 23dc0e2d2..c0e2b3a9b 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -15,9 +15,9 @@ def install_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/mihaibuzgau/beaker.git') + run('git remote add origin https://github.com/Filipovici-Andrei/beaker.git') run('git fetch') - run('git reset --hard origin/master') + run('git reset --hard origin/github_actions') end message('USE CUSTOM BEAKER-PUPPET') From feac35fe811310253327f46898fe3228a96db7fa Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Wed, 20 May 2020 18:26:15 +0300 Subject: [PATCH 35/44] (FACT-2600) changed facter branch --- .github/workflows/acceptance_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/acceptance_tests.yml b/.github/workflows/acceptance_tests.yml index f1f6b41dc..e7268d75e 100644 --- a/.github/workflows/acceptance_tests.yml +++ b/.github/workflows/acceptance_tests.yml @@ -31,7 +31,7 @@ jobs: uses: actions/checkout@v2 with: repository: puppetlabs/facter - ref: skip_failures_on_ng + ref: windows_github path: facter_3 - name: Install Ruby 2.6 From c8a81fa85ce29220541f89c0a83fc40d69015b8c Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Tue, 26 May 2020 10:13:32 +0300 Subject: [PATCH 36/44] (maint) changelog for 4.0.24 release --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57546c46e..4d4d9c85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ +## [4.0.24](https://github.com/puppetlabs/facter-ng/tree/4.0.24) (2020-05-26) + +[Full Changelog](https://github.com/puppetlabs/facter-ng/compare/4.0.23...4.0.24) + +### Added + +- \(FACT-2605\) Add vmware resolver [\#525](https://github.com/puppetlabs/facter-ng/pull/525) ([oanatmaria](https://github.com/oanatmaria)) +- \(FACT-2604\) Add virt-what resolver [\#523](https://github.com/puppetlabs/facter-ng/pull/523) ([oanatmaria](https://github.com/oanatmaria)) + + + ## [4.0.23](https://github.com/puppetlabs/facter-ng/tree/4.0.23) (2020-05-22) [Full Changelog](https://github.com/puppetlabs/facter-ng/compare/4.0.22...4.0.23) @@ -172,4 +183,7 @@ +\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* + + \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* From 6b0baf0efb94f3d9b6331f1c5ecf199286b95133 Mon Sep 17 00:00:00 2001 From: BogdanIrimie Date: Tue, 26 May 2020 16:08:31 +0300 Subject: [PATCH 37/44] (FACT-2635) Add SearchFact and ResolvedFact with nil type. --- lib/facter.rb | 4 +++- lib/framework/core/fact_manager.rb | 4 ++++ lib/framework/parsers/query_parser.rb | 2 ++ spec/facter/facter_spec.rb | 6 ++++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/facter.rb b/lib/facter.rb index b92503022..188ffb966 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -312,7 +312,9 @@ def resolve_fact(user_query) # @api private def error_check(args, resolved_facts) if Options[:strict] - missing_names = args - resolved_facts.map(&:user_query).uniq + # missing_names = args - resolved_facts.map(&:user_query).uniq + missing_names = resolved_facts.select { |fact| fact.type == :nil}.map(&:user_query) + if missing_names.count.positive? status = 1 log_errors(missing_names) diff --git a/lib/framework/core/fact_manager.rb b/lib/framework/core/fact_manager.rb index dfa005a50..b6e2eab1c 100644 --- a/lib/framework/core/fact_manager.rb +++ b/lib/framework/core/fact_manager.rb @@ -32,6 +32,10 @@ def resolve_facts(user_query = []) FactFilter.new.filter_facts!(resolved_facts) + searched_facts.select { |fact| fact.type == :nil }.each do |fact| + resolved_facts << ResolvedFact.new(fact.name, nil, :nil, fact.name) + end + resolved_facts end diff --git a/lib/framework/parsers/query_parser.rb b/lib/framework/parsers/query_parser.rb index c4c53de79..c1db7b09e 100644 --- a/lib/framework/parsers/query_parser.rb +++ b/lib/framework/parsers/query_parser.rb @@ -50,6 +50,8 @@ def search_for_facts(query, loaded_fact_hash) return resolvable_fact_list if resolvable_fact_list.any? end + resolvable_fact_list << SearchedFact.new(query, nil, [], query, :nil) if resolvable_fact_list.empty? + resolvable_fact_list end diff --git a/spec/facter/facter_spec.rb b/spec/facter/facter_spec.rb index 0151fbd2f..5cf418c61 100644 --- a/spec/facter/facter_spec.rb +++ b/spec/facter/facter_spec.rb @@ -3,8 +3,10 @@ describe Facter do let(:fact_name) { 'os.name' } let(:fact_value) { 'ubuntu' } + let(:type) { :core } let(:os_fact) do - double(Facter::ResolvedFact, name: fact_name, value: fact_value, user_query: fact_name, filter_tokens: []) + double(Facter::ResolvedFact, name: fact_name, value: fact_value, + user_query: fact_name, filter_tokens: [], type: type) end let(:empty_fact_collection) { Facter::FactCollection.new } let(:logger) { instance_spy(Facter::Log) } @@ -96,7 +98,7 @@ def mock_collection(method, os_name = nil, error = nil) end context 'when provided with --strict option' do - it 'returns no fact and status 1', resolved_fact: false do + it 'returns no fact and status 1', resolved_fact: true do user_query = ['os.name', 'missing_fact'] expected_json_output = '{}' allow(Facter::Options).to receive(:[]).with(:strict).and_return(true) From b0ef7d404bf03acea3e5ff80f157645678b97475 Mon Sep 17 00:00:00 2001 From: BogdanIrimie Date: Tue, 26 May 2020 17:18:43 +0300 Subject: [PATCH 38/44] (FACT-2635) Move nil fact resolution to internal fact manager. Fix tests. --- lib/facter.rb | 4 +- .../fact/internal/internal_fact_manager.rb | 22 ++++++++-- lib/framework/core/fact_manager.rb | 4 -- spec/facter/facter_spec.rb | 42 +++++++++++-------- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/lib/facter.rb b/lib/facter.rb index 188ffb966..bb1f852a4 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -310,10 +310,10 @@ def resolve_fact(user_query) # facts that are not found or resolved, otherwise it will return nil # # @api private - def error_check(args, resolved_facts) + def error_check(_args, resolved_facts) if Options[:strict] # missing_names = args - resolved_facts.map(&:user_query).uniq - missing_names = resolved_facts.select { |fact| fact.type == :nil}.map(&:user_query) + missing_names = resolved_facts.select { |fact| fact.type == :nil }.map(&:user_query) if missing_names.count.positive? status = 1 diff --git a/lib/framework/core/fact/internal/internal_fact_manager.rb b/lib/framework/core/fact/internal/internal_fact_manager.rb index 55d70ce47..4ff82bfa8 100644 --- a/lib/framework/core/fact/internal/internal_fact_manager.rb +++ b/lib/framework/core/fact/internal/internal_fact_manager.rb @@ -5,11 +5,14 @@ class InternalFactManager @@log = Facter::Log.new(self) def resolve_facts(searched_facts) - searched_facts = filter_internal_facts(searched_facts) + internal_searched_facts = filter_internal_facts(searched_facts) + threads = start_threads(internal_searched_facts) + resolved_facts = join_threads(threads, internal_searched_facts) - threads = start_threads(searched_facts) + nil_searched_facts = filter_nil_facts(searched_facts) + nil_resolved_facts = resolve_nil_facts(nil_searched_facts) - join_threads(threads, searched_facts) + resolved_facts.concat(nil_resolved_facts) end private @@ -18,6 +21,19 @@ def filter_internal_facts(searched_facts) searched_facts.select { |searched_fact| %i[core legacy].include? searched_fact.type } end + def filter_nil_facts(searched_facts) + searched_facts.select { |searched_fact| %i[nil].include? searched_fact.type } + end + + def resolve_nil_facts(searched_facts) + resolved_facts = [] + searched_facts.select { |fact| fact.type == :nil }.each do |fact| + resolved_facts << ResolvedFact.new(fact.name, nil, :nil, fact.name) + end + + resolved_facts + end + def start_threads(searched_facts) threads = [] # only resolve a fact once, even if multiple search facts depend on that fact diff --git a/lib/framework/core/fact_manager.rb b/lib/framework/core/fact_manager.rb index b6e2eab1c..dfa005a50 100644 --- a/lib/framework/core/fact_manager.rb +++ b/lib/framework/core/fact_manager.rb @@ -32,10 +32,6 @@ def resolve_facts(user_query = []) FactFilter.new.filter_facts!(resolved_facts) - searched_facts.select { |fact| fact.type == :nil }.each do |fact| - resolved_facts << ResolvedFact.new(fact.name, nil, :nil, fact.name) - end - resolved_facts end diff --git a/spec/facter/facter_spec.rb b/spec/facter/facter_spec.rb index 5cf418c61..2fc76f73d 100644 --- a/spec/facter/facter_spec.rb +++ b/spec/facter/facter_spec.rb @@ -6,7 +6,11 @@ let(:type) { :core } let(:os_fact) do double(Facter::ResolvedFact, name: fact_name, value: fact_value, - user_query: fact_name, filter_tokens: [], type: type) + user_query: fact_name, filter_tokens: [], type: type) + end + let(:missing_fact) do + double(Facter::ResolvedFact, name: 'missing_fact', value: nil, + user_query: 'missing_fact', filter_tokens: [], type: :nil) end let(:empty_fact_collection) { Facter::FactCollection.new } let(:logger) { instance_spy(Facter::Log) } @@ -70,8 +74,12 @@ def mock_collection(method, os_name = nil, error = nil) describe '#to_user_output' do before do |example| - resolved_fact = example.metadata[:resolved_fact] ? [os_fact] : [] - expected_json_output = example.metadata[:resolved_fact] ? '{"os" : {"name": "ubuntu"}' : '{}' + resolved_fact = example.metadata[:multiple_facts] ? [os_fact, missing_fact] : [os_fact] + expected_json_output = if example.metadata[:multiple_facts] + '{"os" : {"name": "ubuntu"}, "missing_fact": null}' + else + '{"os" : {"name": "ubuntu"}}' + end allow(fact_manager_spy).to receive(:resolve_facts).and_return(resolved_fact) json_fact_formatter = double(Facter::JsonFactFormatter) @@ -79,28 +87,28 @@ def mock_collection(method, os_name = nil, error = nil) allow(Facter::FormatterFactory).to receive(:build).and_return(json_fact_formatter) end - it 'returns one fact and status 0', resolved_fact: true do - user_query = 'os.name' - expected_json_output = '{"os" : {"name": "ubuntu"}' + it 'returns one fact with value and status 0', multiple_facts: false do + user_query = ['os.name'] + expected_json_output = '{"os" : {"name": "ubuntu"}}' - formated_facts = Facter.to_user_output({}, [user_query]) + formatted_facts = Facter.to_user_output({}, [user_query]) - expect(formated_facts).to eq([expected_json_output, 0]) + expect(formatted_facts).to eq([expected_json_output, 0]) end - it 'returns no facts and status 0', resolved_fact: false do - user_query = 'os.name' - expected_json_output = '{}' + it 'returns one fact with value, one without and status 0', multiple_facts: true do + user_query = ['os.name', 'missing_fact'] + expected_json_output = '{"os" : {"name": "ubuntu"}, "missing_fact": null}' - formatted_facts = Facter.to_user_output({}, [user_query]) + formated_facts = Facter.to_user_output({}, [user_query]) - expect(formatted_facts).to eq([expected_json_output, 0]) + expect(formated_facts).to eq([expected_json_output, 0]) end context 'when provided with --strict option' do - it 'returns no fact and status 1', resolved_fact: true do + it 'returns one fact with value, one without and status 1', multiple_facts: true do user_query = ['os.name', 'missing_fact'] - expected_json_output = '{}' + expected_json_output = '{"os" : {"name": "ubuntu"}, "missing_fact": null}' allow(Facter::Options).to receive(:[]).with(:strict).and_return(true) formatted_facts = Facter.to_user_output({}, *user_query) @@ -108,9 +116,9 @@ def mock_collection(method, os_name = nil, error = nil) expect(formatted_facts).to eq([expected_json_output, 1]) end - it 'returns one fact and status 0', resolved_fact: true do + it 'returns one fact and status 0', multiple_facts: false do user_query = 'os.name' - expected_json_output = '{"os" : {"name": "ubuntu"}' + expected_json_output = '{"os" : {"name": "ubuntu"}}' allow(Facter::Options).to receive(:[]).with(anything) allow(Facter::Options).to receive(:[]).with(:block_list).and_return([]) allow(Facter::Options).to receive(:[]).with(:strict).and_return(true) From 36c43ccb8a3eb008e51ea5ae89e40e3496887214 Mon Sep 17 00:00:00 2001 From: BogdanIrimie Date: Tue, 26 May 2020 17:56:43 +0300 Subject: [PATCH 39/44] (FACT-2634) Add test for nil fact. --- .../internal/internal_fact_manager_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/framework/core/fact/internal/internal_fact_manager_spec.rb b/spec/framework/core/fact/internal/internal_fact_manager_spec.rb index d3d16295e..e2528f001 100644 --- a/spec/framework/core/fact/internal/internal_fact_manager_spec.rb +++ b/spec/framework/core/fact/internal/internal_fact_manager_spec.rb @@ -32,6 +32,24 @@ expect(resolved_facts).to eq([resolved_fact]) end + context 'when resolved fac is of type nil' do + let(:searched_fact) do + instance_spy(Facter::SearchedFact, name: 'missing_fact', fact_class: nil, + filter_tokens: [], user_query: '', type: :nil) + end + let(:resolved_fact) { instance_spy(Facter::ResolvedFact) } + + before do + allow(Facter::ResolvedFact).to receive(:new).and_return(resolved_fact) + end + + it 'resolved one nil fact' do + resolved_facts = internal_fact_manager.resolve_facts([searched_fact]) + + expect(resolved_facts).to eq([resolved_fact]) + end + end + context 'when there are multiple search facts pointing to the same fact' do before do resolved_fact = mock_resolved_fact('os', 'Debian', nil, []) From f644cf5dc6ce3a9ac688450a928a617620d8c4b0 Mon Sep 17 00:00:00 2001 From: BogdanIrimie Date: Tue, 26 May 2020 18:21:53 +0300 Subject: [PATCH 40/44] (FACT-2635) Rubocop fixes. --- .rubocop_todo.yml | 2 -- spec/facter/facter_spec.rb | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index efbc96bdb..d0f27d646 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -129,7 +129,6 @@ RSpec/MessageSpies: - 'spec/custom_facts/util/loader_spec.rb' - 'spec/custom_facts/util/parser_spec.rb' - 'spec/custom_facts/util/resolution_spec.rb' - - 'spec/facter/facter_spec.rb' - 'spec/facter/facts/aix/os/name_spec.rb' - 'spec/facter/facts/aix/os/release_spec.rb' - 'spec/facter/facts/macosx/is_virtual_spec.rb' @@ -188,7 +187,6 @@ RSpec/VerifiedDoubles: - 'spec/custom_facts/util/directory_loader_spec.rb' - 'spec/custom_facts/util/fact_spec.rb' - 'spec/custom_facts/util/resolution_spec.rb' - - 'spec/facter/facter_spec.rb' - 'spec/facter/facts/aix/ssh_spec.rb' - 'spec/facter/facts/macosx/memory/swap/capacity_spec.rb' - 'spec/facter/facts/macosx/memory/swap/used_bytes_spec.rb' diff --git a/spec/facter/facter_spec.rb b/spec/facter/facter_spec.rb index 2fc76f73d..717a6b19f 100644 --- a/spec/facter/facter_spec.rb +++ b/spec/facter/facter_spec.rb @@ -5,19 +5,19 @@ let(:fact_value) { 'ubuntu' } let(:type) { :core } let(:os_fact) do - double(Facter::ResolvedFact, name: fact_name, value: fact_value, - user_query: fact_name, filter_tokens: [], type: type) + instance_spy(Facter::ResolvedFact, name: fact_name, value: fact_value, + user_query: fact_name, filter_tokens: [], type: type) end let(:missing_fact) do - double(Facter::ResolvedFact, name: 'missing_fact', value: nil, - user_query: 'missing_fact', filter_tokens: [], type: :nil) + instance_spy(Facter::ResolvedFact, name: 'missing_fact', value: nil, + user_query: 'missing_fact', filter_tokens: [], type: :nil) end let(:empty_fact_collection) { Facter::FactCollection.new } let(:logger) { instance_spy(Facter::Log) } let(:fact_manager_spy) { instance_spy(Facter::FactManager) } let(:fact_collection_spy) { instance_spy(Facter::FactCollection) } let(:key_error) { KeyError.new('key error') } - let(:config_reader_double) { double(Facter::ConfigReader) } + let(:config_reader_double) { class_spy(Facter::ConfigReader) } before do allow(Facter::ConfigReader).to receive(:init).and_return(config_reader_double) @@ -82,7 +82,7 @@ def mock_collection(method, os_name = nil, error = nil) end allow(fact_manager_spy).to receive(:resolve_facts).and_return(resolved_fact) - json_fact_formatter = double(Facter::JsonFactFormatter) + json_fact_formatter = instance_spy(Facter::JsonFactFormatter) allow(json_fact_formatter).to receive(:format).with(resolved_fact).and_return(expected_json_output) allow(Facter::FormatterFactory).to receive(:build).and_return(json_fact_formatter) end @@ -224,8 +224,10 @@ def mock_collection(method, os_name = nil, error = nil) describe '#search_path' do it 'sends call to Facter::Options' do - expect(Facter::Options).to receive(:custom_dir).once + allow(Facter::Options).to receive(:custom_dir) Facter.search_path + + expect(Facter::Options).to have_received(:custom_dir).once end end @@ -331,8 +333,9 @@ def mock_collection(method, os_name = nil, error = nil) describe '#debugging?' do it 'returns that log_level is not debug' do - expect(Facter::Options).to receive(:[]).with(:debug).and_return(false) Facter.debugging? + + expect(Facter::Options).to have_received(:[]).with(:debug) end end From b669e261d3d4da36aec7569d0c58d8204a233490 Mon Sep 17 00:00:00 2001 From: BogdanIrimie Date: Tue, 26 May 2020 18:35:10 +0300 Subject: [PATCH 41/44] (FACT-2635) Remove unused arguments from error_check. --- lib/facter.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/facter.rb b/lib/facter.rb index bb1f852a4..f189e7ba9 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -245,7 +245,7 @@ def to_user_output(cli_options, *args) SessionCache.invalidate_all_caches fact_formatter = Facter::FormatterFactory.build(Facter::Options.get) - status = error_check(args, resolved_facts) + status = error_check(resolved_facts) [fact_formatter.format(resolved_facts), status || 0] end @@ -310,9 +310,8 @@ def resolve_fact(user_query) # facts that are not found or resolved, otherwise it will return nil # # @api private - def error_check(_args, resolved_facts) + def error_check(resolved_facts) if Options[:strict] - # missing_names = args - resolved_facts.map(&:user_query).uniq missing_names = resolved_facts.select { |fact| fact.type == :nil }.map(&:user_query) if missing_names.count.positive? From a2e3fac44e01a195e9123cd6c7d36bea729acfe5 Mon Sep 17 00:00:00 2001 From: Andrei Filipovici Date: Thu, 21 May 2020 17:37:06 +0300 Subject: [PATCH 42/44] (FACT-2600) removed custom beaker-puppet --- .github/actions/presuite.rb | 58 +++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index c0e2b3a9b..6b3feadbf 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -15,18 +15,9 @@ def install_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 remote add origin https://github.com/Filipovici-Andrei/beaker.git") run('git fetch') - run('git reset --hard origin/github_actions') - end - - message('USE CUSTOM BEAKER-PUPPET') - beaker_puppet_path, _ = run('bundle info beaker-puppet --path', FACTER_3_ACCEPTANCE_PATH) - Dir.chdir(beaker_puppet_path.split("\n").last) do - run('git init') - run('git remote add origin https://github.com/Filipovici-Andrei/beaker-puppet.git') - run('git fetch') - run('git reset --hard origin/BKR-1654') + run("git reset --hard origin/github_actions") end end @@ -42,11 +33,11 @@ def initialize_beaker 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' + '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 @@ -61,7 +52,7 @@ def install_puppet_agent beaker_puppet_root, _ = run('bundle info beaker-puppet --path') presuite_file_path = "#{beaker_puppet_root.chomp}/setup/aio/010_Install_Puppet_Agent.rb" - env = (HOST_PLATFORM.to_s.include? 'windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {} + env = (HOST_PLATFORM.include? 'windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {} run("beaker exec pre-suite --pre-suite #{presuite_file_path} --preserve-state", './', env) end @@ -69,7 +60,17 @@ 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.to_s.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\"" +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 replace_facter_3_with_facter_4 @@ -79,18 +80,13 @@ def replace_facter_3_with_facter_4 install_latest_facter_4(gem_command) message('CHANGE FACTER 3 WITH FACTER 4') - run('mv "facter-ng" "facter"', puppet_bin_dir) -end - -def puppet_command - return '/opt/puppetlabs/puppet/bin/puppet' unless HOST_PLATFORM.to_s.include? 'windows' - "\"C:\\Program Files\\Puppet Labs\\Puppet\\bin\\puppet\"" + if HOST_PLATFORM.include? 'windows' + run('mv facter-ng.bat facter.bat', puppet_bin_dir) + else + run('mv facter-ng facter', puppet_bin_dir) + end end -def gem_command - return '/opt/puppetlabs/puppet/bin/gem' unless HOST_PLATFORM.to_s.include? 'windows' - "\"C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem\"" -end def install_latest_facter_4(gem_command) message('BUILD FACTER 4 LATEST AGENT GEM') @@ -106,7 +102,7 @@ def install_latest_facter_4(gem_command) def run_acceptance_tests message('RUN ACCEPTANCE TESTS') - env = (HOST_PLATFORM.to_s.include? 'windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {} + env = (HOST_PLATFORM.include? 'windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {} run('beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high', './', env) end @@ -134,7 +130,7 @@ def run(command, dir = './', env = {}) ENV['DEBIAN_DISABLE_RUBYGEMS_INTEGRATION'] = 'no_warnings' FACTER_3_ACCEPTANCE_PATH = File.join(ENV['FACTER_3_ROOT'], 'acceptance') -HOST_PLATFORM = ARGV[0].to_sym +HOST_PLATFORM = ARGV[0] install_bundler @@ -146,7 +142,7 @@ def run(command, dir = './', env = {}) install_puppet_agent end -replace_facter_3_with_facter_4 +# replace_facter_3_with_facter_4 Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do _, status = run_acceptance_tests From 920ceb7a45a3384306cd0859427d2a89d2536450 Mon Sep 17 00:00:00 2001 From: BogdanIrimie Date: Fri, 29 May 2020 17:35:51 +0300 Subject: [PATCH 43/44] (FACT-2635) Fix formatter for keys that contain ":" in their name. --- lib/framework/formatters/legacy_fact_formatter.rb | 6 ++++-- lib/framework/parsers/query_parser.rb | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/framework/formatters/legacy_fact_formatter.rb b/lib/framework/formatters/legacy_fact_formatter.rb index d61f6a62a..1541c3de2 100644 --- a/lib/framework/formatters/legacy_fact_formatter.rb +++ b/lib/framework/formatters/legacy_fact_formatter.rb @@ -60,7 +60,8 @@ def hash_to_facter_format(facts_hash) pretty_json = JSON.pretty_generate(facts_hash) @log.debug('Change key value delimiter from : to =>') - pretty_json.gsub!(/^(.*?)(:)/, '\1 =>') + # pretty_json.gsub!(/^(.*?)(:)/, '\1 =>') + pretty_json.gsub!(/":/, '" =>') @log.debug('Remove quotes from parent nodes') pretty_json.gsub!(/\"(.*)\"\ =>/, '\1 =>') @@ -85,7 +86,8 @@ def remove_enclosing_accolades(pretty_fact_json) def remove_comma_and_quation(output) @log.debug('Remove unnecessary comma and quotation marks on root facts') - output.split("\n").map! { |line| line =~ /^[\s]+/ ? line : line.gsub(/,$|\"/, '') }.join("\n") + output.split("\n") + .map! { |line| line =~ /^[\s]+/ ? line : line.gsub(/,$|(? Date: Tue, 2 Jun 2020 19:38:45 +0300 Subject: [PATCH 44/44] replace any combination of slashes in custom facts paths with File::SEPARATOR --- lib/custom_facts/util/loader.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/custom_facts/util/loader.rb b/lib/custom_facts/util/loader.rb index d8a909e91..d3796fb7f 100644 --- a/lib/custom_facts/util/loader.rb +++ b/lib/custom_facts/util/loader.rb @@ -40,6 +40,7 @@ def load_all paths = search_path paths&.each do |dir| # dir is already an absolute path + dir = dir.gsub(/[\/\\]+/, File::SEPARATOR) Dir.glob(File.join(dir, '*.rb')).each do |path| # exclude dirs that end with .rb load_file(path) if FileTest.file?(path)