From b34bf64b8b3ff698ad77628e364f0640ab2983c0 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 16 Dec 2019 20:14:40 +0000 Subject: [PATCH 01/20] (maint) update travis to not use bundle update --system --- .travis.yml | 3 +-- metadata.json | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 071477d9..d6c7047c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,7 @@ before_install: - rm -f Gemfile.lock - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - '[ -z "$RUBYGEMS_VERSION" ] || gem update --system $RUBYGEMS_VERSION' - gem --version - bundle -v script: diff --git a/metadata.json b/metadata.json index 38568494..ca6ed507 100644 --- a/metadata.json +++ b/metadata.json @@ -79,5 +79,5 @@ ], "pdk-version": "1.15.0", "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "heads/master-0-g5676b3f" + "template-ref": "heads/master-0-gcaed9d7" } From c4eb72e96d354614501184c50db178dafb19435c Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 16 Dec 2019 20:57:22 +0000 Subject: [PATCH 02/20] (maint) update travis to notify puppet slack --- .sync.yml | 59 ++++++++++++++++++++++++++++------------------------- .travis.yml | 2 ++ 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/.sync.yml b/.sync.yml index 48218bb4..e87c6c9f 100644 --- a/.sync.yml +++ b/.sync.yml @@ -9,25 +9,28 @@ enabled: false simplecov: true before_install_pre: - - bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -skip-sudo-check - - 'pwsh -NoProfile -NoLogo -NonInteractive -Command \$PSVersionTable # Output the PowerShell Core version information' - - if [ $BUNDLER_VERSION ]; then - gem install -v $BUNDLER_VERSION bundler --no-rdoc --no-ri; - fi + - bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -skip-sudo-check + - 'pwsh -NoProfile -NoLogo -NonInteractive -Command \$PSVersionTable # Output the PowerShell Core version information' + - if [ $BUNDLER_VERSION ]; then gem install -v $BUNDLER_VERSION bundler --no-rdoc --no-ri; fi includes: - - os: osx - comment: test Mac OSX edition of PowerShell Core on a single job - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec - rvm: 2.5.3 - stage: acceptance + - os: osx + comment: test Mac OSX edition of PowerShell Core on a single job + env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + rvm: 2.5.3 + stage: acceptance + notifications: + slack: + secure: Yqv+S1Bwz19bor4xu3v7i5rLPzQuwTSZhO5wjsrX+jhKDN5/+e7e53x/v3Onjdrn9rjwFAxwzciAte0MO96xLFjyzWyUSziGur8/v3TcbRnnVQMOnIEj0HfmyLbx1cpxGK9V8MPsWQVAoHCklTtZIsRjMw0PcD8+aVKVF3NcBK4= appveyor.yml: simplecov: true install_post: - - 'ps: "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri https://github.com/PowerShell/PowerShell/raw/master/tools/install-powershell.ps1 -UseBasicParsing -OutFile install-pwsh.ps1"' - - 'ps: "& ./install-pwsh.ps1"' - - set PATH=%LOCALAPPDATA%\Microsoft\powershell;%PATH% - - pwsh -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable - - powershell -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable + - >- + ps: "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri https://github.com/PowerShell/PowerShell/raw/master/tools/install-powershell.ps1 -UseBasicParsing + -OutFile install-pwsh.ps1" + - 'ps: "& ./install-pwsh.ps1"' + - set PATH=%LOCALAPPDATA%\Microsoft\powershell;%PATH% + - pwsh -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable + - powershell -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable Gemfile: optional: ":development": @@ -37,18 +40,18 @@ Gemfile: ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') required: - ':system_tests': - - gem: 'puppet-module-posix-system-r#{minor_version}' - platforms: ruby - - gem: 'puppet-module-win-system-r#{minor_version}' - platforms: - - mswin - - mingw - - x64_mingw - - gem: beaker-testmode_switcher - version: '~> 0.4' - - gem: master_manipulator - - gem: puppet-blacksmith - version: '~> 3.4' + ":system_tests": + - gem: puppet-module-posix-system-r#{minor_version} + platforms: ruby + - gem: puppet-module-win-system-r#{minor_version} + platforms: + - mswin + - mingw + - x64_mingw + - gem: beaker-testmode_switcher + version: "~> 0.4" + - gem: master_manipulator + - gem: puppet-blacksmith + version: "~> 3.4" spec/spec_helper.rb: coverage_report: true diff --git a/.travis.yml b/.travis.yml index d6c7047c..08eee6f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,3 +48,5 @@ branches: - /^v\d/ notifications: email: false + slack: + secure: Yqv+S1Bwz19bor4xu3v7i5rLPzQuwTSZhO5wjsrX+jhKDN5/+e7e53x/v3Onjdrn9rjwFAxwzciAte0MO96xLFjyzWyUSziGur8/v3TcbRnnVQMOnIEj0HfmyLbx1cpxGK9V8MPsWQVAoHCklTtZIsRjMw0PcD8+aVKVF3NcBK4= From c21905d818e07054181bcc2f5289796ec6834c4c Mon Sep 17 00:00:00 2001 From: "Michael T Lombardi (He/Him)" Date: Tue, 21 Jan 2020 10:15:58 -0600 Subject: [PATCH 03/20] Correct supported Puppet lower bound to 5.5.0 Prior to this commit the metadata erroneously claimed support for 4x versions of Puppet, on which it has not been tested and would fail to run as the `ruby-pwsh` dependency requires Ruby 2.3 or higher which ships in Puppet 5x. Further, Puppeet 4x is no longer officially supported at all. --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index ca6ed507..e6c71b69 100644 --- a/metadata.json +++ b/metadata.json @@ -74,7 +74,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 4.7.0 < 7.0.0" + "version_requirement": ">= 5.5.0 < 7.0.0" } ], "pdk-version": "1.15.0", From 9df45f85998f18b904ad846115de223644b16da0 Mon Sep 17 00:00:00 2001 From: sheena Date: Wed, 5 Feb 2020 11:13:17 +0000 Subject: [PATCH 04/20] (IAC-365) updating tokens and dataset for honeycomb --- .sync.yml | 5 +++++ .travis.yml | 6 +++++- Rakefile | 2 ++ appveyor.yml | 2 ++ metadata.json | 4 ++-- spec/spec_helper.rb | 2 ++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.sync.yml b/.sync.yml index e87c6c9f..fdec1390 100644 --- a/.sync.yml +++ b/.sync.yml @@ -5,6 +5,8 @@ include_todos: true selected_profile: false ".travis.yml": + global_env: + - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" deploy_to_forge: enabled: false simplecov: true @@ -22,6 +24,9 @@ slack: secure: Yqv+S1Bwz19bor4xu3v7i5rLPzQuwTSZhO5wjsrX+jhKDN5/+e7e53x/v3Onjdrn9rjwFAxwzciAte0MO96xLFjyzWyUSziGur8/v3TcbRnnVQMOnIEj0HfmyLbx1cpxGK9V8MPsWQVAoHCklTtZIsRjMw0PcD8+aVKVF3NcBK4= appveyor.yml: + environment: + HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 + HONEYCOMB_DATASET: litmus tests simplecov: true install_post: - >- diff --git a/.travis.yml b/.travis.yml index 08eee6f0..048c06ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,8 @@ before_install: - rm -f Gemfile.lock - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - - '[ -z "$RUBYGEMS_VERSION" ] || gem update --system $RUBYGEMS_VERSION' + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - gem --version - bundle -v script: @@ -18,6 +19,9 @@ script: bundler_args: --without system_tests rvm: - 2.5.3 +env: + global: + - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" stages: - static - spec diff --git a/Rakefile b/Rakefile index 395df547..cb7ed0cc 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' diff --git a/appveyor.yml b/appveyor.yml index 19ce756b..f1349186 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,6 +14,8 @@ init: - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0' - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0' environment: + HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 + HONEYCOMB_DATASET: litmus tests SIMPLECOV: yes matrix: - diff --git a/metadata.json b/metadata.json index e6c71b69..a4533c4c 100644 --- a/metadata.json +++ b/metadata.json @@ -77,7 +77,7 @@ "version_requirement": ">= 5.5.0 < 7.0.0" } ], - "pdk-version": "1.15.0", + "pdk-version": "1.16.0", "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "heads/master-0-gcaed9d7" + "template-ref": "heads/master-0-g5d52853" } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index eab931d6..f028d577 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' From 3cb1fe2976b51147b07901aef2c2ee06308ae30b Mon Sep 17 00:00:00 2001 From: Michael T Lombardi Date: Thu, 23 Jan 2020 00:53:28 -0600 Subject: [PATCH 05/20] (FM-8856) Convert acceptance testing to litmus This commit changes the acceptance testing framework from beaker to litmus, enabling acceptance testing in CI. --- .fixtures.yml | 4 + .github/workflows/release.yml | 43 + .sync.yml | 38 +- .travis.yml | 86 +- appveyor.yml | 30 +- metadata.json | 2 +- provision.yaml | 19 + spec/acceptance/exec_powershell_spec.rb | 248 +++--- spec/acceptance/exec_pwsh_spec.rb | 774 +++++++++--------- spec/acceptance/files/services.ps1 | 2 +- spec/fixtures/scripts/install_pwsh/darwin.sh | 1 + .../fixtures/scripts/install_pwsh/debian_8.sh | 18 + .../fixtures/scripts/install_pwsh/debian_9.sh | 18 + spec/fixtures/scripts/install_pwsh/rhel.sh | 8 + .../scripts/install_pwsh/ubuntu_16.04.sh | 17 + .../scripts/install_pwsh/ubuntu_18.04.sh | 17 + .../fixtures/scripts/install_pwsh/windows.ps1 | 7 + spec/spec_helper_acceptance.rb | 90 +- spec/spec_helper_acceptance_local.rb | 67 ++ 19 files changed, 848 insertions(+), 641 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 provision.yaml create mode 100644 spec/fixtures/scripts/install_pwsh/darwin.sh create mode 100644 spec/fixtures/scripts/install_pwsh/debian_8.sh create mode 100644 spec/fixtures/scripts/install_pwsh/debian_9.sh create mode 100644 spec/fixtures/scripts/install_pwsh/rhel.sh create mode 100644 spec/fixtures/scripts/install_pwsh/ubuntu_16.04.sh create mode 100644 spec/fixtures/scripts/install_pwsh/ubuntu_18.04.sh create mode 100644 spec/fixtures/scripts/install_pwsh/windows.ps1 create mode 100644 spec/spec_helper_acceptance_local.rb diff --git a/.fixtures.yml b/.fixtures.yml index c23ac487..77b24226 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,4 +1,8 @@ fixtures: + repositories: + facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' + puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + provision: 'https://github.com/puppetlabs/provision.git' forge_modules: pwshlib: "puppetlabs/pwshlib" symlinks: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..dacc2ff7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,43 @@ +name: "release" + +on: + push: + branches: + - 'release' + +jobs: + LitmusAcceptance: + runs-on: self-hosted + strategy: + matrix: + ruby_version: [2.5.x] + puppet_gem_version: [~> 6.0] + platform: [release_checks] + agent_family: ['puppet5', 'puppet6'] + + steps: + - uses: actions/checkout@v1 + - name: Litmus Parallel + uses: puppetlabs/action-litmus_parallel@master + with: + platform: ${{ matrix.platform }} + agent_family: ${{ matrix.agent_family }} + Spec: + runs-on: self-hosted + strategy: + matrix: + check: [parallel_spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'] + ruby_version: [2.5.x] + puppet_gem_version: [~> 5.0, ~> 6.0] + exclude: + - puppet_gem_version: ~> 5.0 + check: 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop' + - ruby_version: 2.5.x + puppet_gem_version: ~> 5.0 + steps: + - uses: actions/checkout@v1 + - name: Spec Tests + uses: puppetlabs/action-litmus_spec@master + with: + puppet_gem_version: ${{ matrix.puppet_gem_version }} + check: ${{ matrix.check }} diff --git a/.sync.yml b/.sync.yml index fdec1390..b08c4ab4 100644 --- a/.sync.yml +++ b/.sync.yml @@ -10,32 +10,44 @@ deploy_to_forge: enabled: false simplecov: true - before_install_pre: - - bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -skip-sudo-check - - 'pwsh -NoProfile -NoLogo -NonInteractive -Command \$PSVersionTable # Output the PowerShell Core version information' - - if [ $BUNDLER_VERSION ]; then gem install -v $BUNDLER_VERSION bundler --no-rdoc --no-ri; fi + use_litmus: true + litmus: + provision_list: + - travis_deb + - travis_ub + - travis_el includes: - os: osx - comment: test Mac OSX edition of PowerShell Core on a single job env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec rvm: 2.5.3 + stage: spec + - bundler_args: + os: osx + rvm: 2.5.1 + before_script: + - brew update + - brew install openssl + - bundle exec rake spec_prep + script: + - bundle exec rake litmus:acceptance:localhost stage: acceptance notifications: slack: secure: Yqv+S1Bwz19bor4xu3v7i5rLPzQuwTSZhO5wjsrX+jhKDN5/+e7e53x/v3Onjdrn9rjwFAxwzciAte0MO96xLFjyzWyUSziGur8/v3TcbRnnVQMOnIEj0HfmyLbx1cpxGK9V8MPsWQVAoHCklTtZIsRjMw0PcD8+aVKVF3NcBK4= appveyor.yml: + use_litmus: true + matrix_extras: + - RUBY_VERSION: 25-x64 + ACCEPTANCE: 'yes' + TARGET_HOST: localhost + - RUBY_VERSION: 25-x64 + ACCEPTANCE: 'yes' + TARGET_HOST: localhost + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 environment: HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 HONEYCOMB_DATASET: litmus tests simplecov: true - install_post: - - >- - ps: "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri https://github.com/PowerShell/PowerShell/raw/master/tools/install-powershell.ps1 -UseBasicParsing - -OutFile install-pwsh.ps1" - - 'ps: "& ./install-pwsh.ps1"' - - set PATH=%LOCALAPPDATA%\Microsoft\powershell;%PATH% - - pwsh -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable - - powershell -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable Gemfile: optional: ":development": diff --git a/.travis.yml b/.travis.yml index 048c06ed..1df32765 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ --- +os: linux dist: xenial language: ruby cache: bundler before_install: - - bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -skip-sudo-check - - pwsh -NoProfile -NoLogo -NonInteractive -Command \$PSVersionTable # Output the PowerShell Core version information - - if [ $BUNDLER_VERSION ]; then gem install -v $BUNDLER_VERSION bundler --no-rdoc --no-ri; fi - bundle -v - rm -f Gemfile.lock - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" @@ -26,9 +24,81 @@ stages: - static - spec - acceptance -matrix: +jobs: fast_finish: true include: + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_deb]'" + - "bundle exec rake 'litmus:install_agent[puppet5]'" + - "bundle exec rake litmus:install_module" + bundler_args: + dist: trusty + env: PLATFORMS=travis_deb_puppet5 + rvm: 2.5.3 + script: ["bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_el]'" + - "bundle exec rake 'litmus:install_agent[puppet5]'" + - "bundle exec rake litmus:install_module" + bundler_args: + dist: trusty + env: PLATFORMS=travis_el_puppet5 + rvm: 2.5.3 + script: ["bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_ub]'" + - "bundle exec rake 'litmus:install_agent[puppet5]'" + - "bundle exec rake litmus:install_module" + bundler_args: + dist: trusty + env: PLATFORMS=travis_ub_puppet5 + rvm: 2.5.3 + script: ["bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_deb]'" + - "bundle exec rake 'litmus:install_agent[puppet6]'" + - "bundle exec rake litmus:install_module" + bundler_args: + dist: trusty + env: PLATFORMS=travis_deb_puppet6 + rvm: 2.5.3 + script: ["bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_el]'" + - "bundle exec rake 'litmus:install_agent[puppet6]'" + - "bundle exec rake litmus:install_module" + bundler_args: + dist: trusty + env: PLATFORMS=travis_el_puppet6 + rvm: 2.5.3 + script: ["bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_ub]'" + - "bundle exec rake 'litmus:install_agent[puppet6]'" + - "bundle exec rake litmus:install_module" + bundler_args: + dist: trusty + env: PLATFORMS=travis_ub_puppet6 + rvm: 2.5.3 + script: ["bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" stage: static @@ -41,10 +111,16 @@ matrix: rvm: 2.5.3 stage: spec - - comment: test Mac OSX edition of PowerShell Core on a single job env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec os: osx rvm: 2.5.3 + stage: spec + - + before_script: ["brew update", "brew install openssl", "bundle exec rake spec_prep"] + bundler_args: + os: osx + rvm: 2.5.1 + script: ["bundle exec rake litmus:acceptance:localhost"] stage: acceptance branches: only: diff --git a/appveyor.yml b/appveyor.yml index f1349186..e4f2e745 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -37,17 +37,37 @@ environment: PUPPET_GEM_VERSION: ~> 6.0 RUBY_VERSION: 25-x64 CHECK: parallel_spec + - + RUBY_VERSION: 25-x64 + ACCEPTANCE: yes + TARGET_HOST: localhost + - + RUBY_VERSION: 25-x64 + ACCEPTANCE: yes + TARGET_HOST: localhost + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 +for: +- + matrix: + only: + - ACCEPTANCE: yes + install: + - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% + - bundle install --jobs 4 --retry 2 + - type Gemfile.lock + test_script: + - bundle exec puppet -V + - ruby -v + - gem -v + - bundle -v + - bundle exec rake spec_prep + - bundle exec rake litmus:acceptance:localhost matrix: fast_finish: true install: - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% - bundle install --jobs 4 --retry 2 --without system_tests - type Gemfile.lock - - ps: "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri https://github.com/PowerShell/PowerShell/raw/master/tools/install-powershell.ps1 -UseBasicParsing -OutFile install-pwsh.ps1" - - ps: "& ./install-pwsh.ps1" - - set PATH=%LOCALAPPDATA%\Microsoft\powershell;%PATH% - - pwsh -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable - - powershell -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable build: off test_script: - bundle exec puppet -V diff --git a/metadata.json b/metadata.json index a4533c4c..5f748358 100644 --- a/metadata.json +++ b/metadata.json @@ -79,5 +79,5 @@ ], "pdk-version": "1.16.0", "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "heads/master-0-g5d52853" + "template-ref": "heads/master-0-g88c96ab" } diff --git a/provision.yaml b/provision.yaml new file mode 100644 index 00000000..3d0cbbc2 --- /dev/null +++ b/provision.yaml @@ -0,0 +1,19 @@ +--- +default: + provisioner: docker + images: ['waffleimage/ubuntu18.04', 'waffleimage/centos7'] +vagrant: + provisioner: vagrant + images: ['centos/7', 'generic/ubuntu1804', 'generic/debian8', 'gusztavvargadr/windows-server'] +travis_deb: + provisioner: docker + images: ['waffleimage/debian8', 'waffleimage/debian9'] +travis_ub: + provisioner: docker + images: ['waffleimage/ubuntu16.04', 'waffleimage/ubuntu18.04'] +travis_el: + provisioner: docker + images: ['waffleimage/centos7'] +release_checks: + provisioner: vmpooler + images: ['redhat-7-x86_64', 'redhat-8-x86_64', 'centos-7-x86_64', 'centos-8-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64', 'win-2012r2-x86_64', 'win-2016-core-x86_64', 'win-2019-core-x86_64'] diff --git a/spec/acceptance/exec_powershell_spec.rb b/spec/acceptance/exec_powershell_spec.rb index b1801e60..7253a451 100644 --- a/spec/acceptance/exec_powershell_spec.rb +++ b/spec/acceptance/exec_powershell_spec.rb @@ -1,9 +1,6 @@ require 'spec_helper_acceptance' -powershell_agents = agents.select { |a| not_controller(a) } -windows_agents = powershell_agents.select { |a| a.platform =~ /^windows.*$/ } - -describe 'powershell provider:', :if => windows_agents.count > 0 do +describe 'powershell provider:', if: (os[:family] == 'windows') do # Due to https://github.com/PowerShell/PowerShell/issues/1794 the HOME directory must be passed in the environment explicitly # In this case, it just needs a HOME that has a valid directory, no files get stored there # HOME is not used on Windows so it is safe to apply hosts, no matter its platform @@ -12,24 +9,19 @@ shared_examples 'should fail' do |manifest, error_check| it 'should throw an error' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each do |hut| - result = execute_manifest_on(hut, manifest, :expect_failures => true) - unless error_check.nil? - expect(result.stderr).to match(error_check) - end + apply_manifest(manifest, expect_failures: true) do |result| + expect(result.stderr).to match(error_check) unless error_check.nil? end end end shared_examples 'apply success' do |manifest| it 'should succeed' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, manifest, :catch_failures => true) } + apply_manifest(manifest, catch_failures: true) end end - shared_examples 'standard exec' do |powershell_cmd, host_list| + shared_examples 'standard exec' do |powershell_cmd| padmin = <<-MANIFEST exec{'no fail test': command => '#{powershell_cmd}', @@ -38,111 +30,100 @@ } MANIFEST it 'should not fail' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - host_list.each { |hut| execute_manifest_on(hut, padmin, :catch_failures => true) } + apply_manifest(padmin, catch_failures: true) end end describe "should run successfully" do - windows_agents.each do |host| - context "on host with platform #{host.platform}" do - let(:manifest) { - <<-MANIFEST - exec{'TestPowershell': - command => 'Get-Process > c:/process.txt', - unless => 'if(!(test-path "c:/process.txt")){exit 1}', - provider => powershell, - } - MANIFEST - } - - it 'should not error on first run' do - # Run it twice and test for idempotency - execute_manifest_on(host, manifest, :catch_failures => true) - end + context "on machine" do + let(:manifest) { + <<-MANIFEST + exec{'TestPowershell': + command => 'Get-Process > c:/process.txt', + unless => 'if(!(test-path "c:/process.txt")){exit 1}', + provider => powershell, + } + MANIFEST + } - it 'should be idempotent' do - execute_manifest_on(host, manifest, :catch_chages => true) - end + it 'is idempotent' do + idempotent_apply(manifest) end end end describe 'should handle a try/catch successfully' do - windows_agents.each do |host| - context "on host with platform #{host.platform}" do - - let(:try_successfile) { 'C:\try_success.txt' } - let(:try_failfile) { 'C:\try_shouldntexist.txt' } - let(:catch_successfile) { 'C:\catch_success.txt' } - let(:catch_failfile) { 'C:\catch_shouldntexist.txt' } - let(:try_content) { 'try_executed' } - let(:catch_content) { 'catch_executed' } - - it 'should demonstrably execute PowerShell code inside a try block' do - - powershell_cmd = <<-CMD - try { - $foo = @(1, 2, 3).count - "#{try_content}" | Out-File -FilePath "#{try_successfile}" -Encoding "ASCII" - } catch { - "catch_executed" | Out-File -FilePath "#{catch_failfile}" -Encoding "ASCII" - } - CMD + context "on host with platform #{}" do + + let(:try_successfile) { 'C:\try_success.txt' } + let(:try_failfile) { 'C:\try_shouldntexist.txt' } + let(:catch_successfile) { 'C:\catch_success.txt' } + let(:catch_failfile) { 'C:\catch_shouldntexist.txt' } + let(:try_content) { 'try_executed' } + let(:catch_content) { 'catch_executed' } + + it 'should demonstrably execute PowerShell code inside a try block' do + + powershell_cmd = <<-CMD + try { + $foo = @(1, 2, 3).count + "#{try_content}" | Out-File -FilePath "#{try_successfile}" -Encoding "ASCII" + } catch { + "catch_executed" | Out-File -FilePath "#{catch_failfile}" -Encoding "ASCII" + } + CMD - p1 = <<-MANIFEST - exec{'TestPowershell': - command => '#{powershell_cmd}', - #{ps_environment} - provider => powershell, - } - MANIFEST + p1 = <<-MANIFEST + exec{'TestPowershell': + command => '#{powershell_cmd}', + #{ps_environment} + provider => powershell, + } + MANIFEST - execute_manifest_on(host, p1, :catch_failures => true) + apply_manifest(p1, catch_failures: true) - on(host, "cmd.exe /c \"type #{try_successfile}\"") do |result| - assert_match(/#{try_content}/, result.stdout, "Unexpected result for host '#{host}'") - end + run_shell("cmd.exe /c \"type #{try_successfile}\"") do |result| + expect(result.stdout).to match(try_content) + end - on(host, "cmd.exe /c \"type #{catch_failfile}\"", :acceptable_exit_codes => [1]) do |result| - assert_match(/^The system cannot find the file specified\./, result.stderr, "Unexpected file content #{result.stdout} on host '#{host}'") - end + run_shell("cmd.exe /c \"type #{catch_failfile}\"", expect_failures: true) do |result| + expect(result.stderr).to match(/The system cannot find the file specified/) end + end - it 'should demonstrably execute PowerShell code inside a catch block' do - powershell_cmd = <<-CMD - try { - throw "execute catch!" - "try_executed" | Out-File -FilePath "#{try_failfile}" -Encoding "ASCII" - } catch { - "#{catch_content}" | Out-File -FilePath "#{catch_successfile}" -Encoding "ASCII" - } - CMD + it 'should demonstrably execute PowerShell code inside a catch block' do + powershell_cmd = <<-CMD + try { + throw "execute catch!" + "try_executed" | Out-File -FilePath "#{try_failfile}" -Encoding "ASCII" + } catch { + "#{catch_content}" | Out-File -FilePath "#{catch_successfile}" -Encoding "ASCII" + } + CMD - p1 = <<-MANIFEST - exec{'TestPowershell': - command => '#{powershell_cmd}', - #{ps_environment} - provider => powershell, - } - MANIFEST + p1 = <<-MANIFEST + exec{'TestPowershell': + command => '#{powershell_cmd}', + #{ps_environment} + provider => powershell, + } + MANIFEST - execute_manifest_on(host, p1, :catch_failures => true) + apply_manifest(p1, catch_failures: true) - on(host, "cmd.exe /c \"type #{catch_successfile}\"") do |result| - assert_match(/#{catch_content}/, result.stdout, "Unexpected result for host '#{host}'") - end + run_shell("cmd.exe /c \"type #{catch_successfile}\"") do |result| + expect(result.stdout).to match(catch_content) + end - on(host, "cmd.exe /c \"type #{try_failfile}\"", :acceptable_exit_codes => [1]) do |result| - assert_match(/^The system cannot find the file specified\./, result.stderr, "Unexpected file content #{result.stdout} on host '#{host}'") - end + run_shell("cmd.exe /c \"type #{try_failfile}\"", expect_failures: true) do |result| + expect(result.stderr).to match(/The system cannot find the file specified/) end end end end describe 'should run commands that exit session' do - let(:exit_pp) { <<-MANIFEST exec{'TestPowershell': command => 'exit 0', @@ -153,19 +134,16 @@ } it 'should not error on first run' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, exit_pp, :expect_changes => true) } + apply_manifest(exit_pp, expect_changes: true) end it 'should run a second time' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, exit_pp, :expect_changes => true) } + apply_manifest(exit_pp, expect_changes: true) end end describe 'should run commands that break session' do - let(:break_pp) { <<-MANIFEST exec{'TestPowershell': command => 'Break', @@ -176,19 +154,16 @@ } it 'should not error on first run' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, break_pp, :expect_changes => true) } + apply_manifest(break_pp, expect_changes: true) end it 'should run a second time' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, break_pp, :expect_changes => true) } + apply_manifest(break_pp, expect_changes: true) end end describe 'should run commands that return from session' do - let(:return_pp) { <<-MANIFEST exec{'TestPowershell': command => 'return 0', @@ -199,13 +174,11 @@ } it 'should not error on first run' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, return_pp, :expect_changes => true) } + apply_manifest(return_pp, expect_changes: true) end it 'should run a second time' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, return_pp, :expect_changes => true) } + apply_manifest(return_pp, expect_changes: true) end end @@ -232,12 +205,10 @@ it 'should not see variable from previous run' do # Setup the variable - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, var_leak_setup_pp, :expect_changes => true) } + apply_manifest(var_leak_setup_pp, expect_changes: true) # Test to see if subsequent call sees the variable - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, var_leak_test_pp, :expect_changes => true) } + apply_manifest(var_leak_test_pp, expect_changes: true) end end @@ -272,38 +243,28 @@ } after(:each) do - # Due to https://tickets.puppetlabs.com/browse/BKR-1088, need to use different commands - windows_agents.each do |host| - on(host, powershell("'Remove-Item Env:\\superspecial -ErrorAction Ignore;exit 0'")) - on(host, powershell("'Remove-Item Env:\\outside -ErrorAction Ignore;exit 0'")) - end + run_shell(interpolate_powershell("Remove-Item Env:\\superspecial -ErrorAction Ignore;exit 0")) + run_shell(interpolate_powershell("Remove-Item Env:\\outside -ErrorAction Ignore;exit 0")) end it 'should not see environment variable from previous run' do # Setup the environment variable - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, envar_leak_setup_pp, :expect_changes => true) } + apply_manifest(envar_leak_setup_pp, expect_changes: true) # Test to see if subsequent call sees the environment variable - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, envar_leak_test_pp, :expect_changes => true) } + apply_manifest(envar_leak_test_pp, expect_changes: true) end it 'should see environment variables set outside of session' do # Setup the environment variable outside of Puppet - windows_agents.each do |host| - # Due to https://tickets.puppetlabs.com/browse/BKR-1088, need to use different commands - on(host, powershell("\\$env:outside='1'")) - end + run_shell(interpolate_powershell("$env:outside='1'")) # Test to see if initial run sees the environment variable - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, envar_leak_test_pp, :expect_changes => true) } + apply_manifest(envar_leak_test_pp, expect_changes: true) # Test to see if subsequent call sees the environment variable and environment purge - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, envar_leak_test_pp, :expect_changes => true) } + apply_manifest(envar_leak_test_pp, expect_changes: true) end end @@ -330,13 +291,11 @@ } it 'should RUN command if unless is NOT triggered' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, unless_not_triggered_pp, :expect_changes => true) } + apply_manifest(unless_not_triggered_pp, expect_changes: true) end it 'should NOT run command if unless IS triggered' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, unless_triggered_pp, :catch_changes => true) } + apply_manifest(unless_triggered_pp, catch_changes: true) end end @@ -364,13 +323,11 @@ } it 'should NOT run command if onlyif is NOT triggered' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, onlyif_not_triggered_pp, :catch_changes => true) } + apply_manifest(onlyif_not_triggered_pp, catch_changes: true) end it 'should RUN command if onlyif IS triggered' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, onlyif_triggered_pp, :expect_changes => true) } + apply_manifest(onlyif_triggered_pp, expect_changes: true) end end @@ -389,8 +346,7 @@ let(:file_path) { 'C:/services.txt' } it 'should apply the manifest' do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, p2, :catch_failures => true) } + apply_manifest(p2, catch_failures: true) end it { should be_file } @@ -434,10 +390,11 @@ } MANIFEST describe file('c:/temp/services.csv') do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, p2, :catch_failures => true) } + it 'applies' do + apply_manifest(p2, catch_failures: true) + end it { should be_file } - its(:content) { should match /puppet/ } + its(:content) { should match /WinRM/ } end end end @@ -459,8 +416,9 @@ } MANIFEST describe file(outfile) do - # Due to https://tickets.puppetlabs.com/browse/QA-3461 each host must be done one at a time - windows_agents.each { |hut| execute_manifest_on(hut, pp, :catch_failures => true) } + it 'applies' do + apply_manifest(pp, catch_failures: true) + end it { should be_file } its(:content) { should match /svchost/ } end @@ -481,7 +439,7 @@ provider => powershell } MANIFEST - it_should_behave_like 'apply success', p3, windows_agents + it_should_behave_like 'apply success', p3 end describe 'test admin rights' do @@ -491,7 +449,7 @@ $pr = New-Object Security.Principal.WindowsPrincipal $id if(!($pr.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))){Write-Error "Not in admin"} PS1 - it_should_behave_like 'standard exec', ps1, windows_agents + it_should_behave_like 'standard exec', ps1 end describe 'test import-module' do @@ -505,6 +463,6 @@ Write-Error "Failed to import module ${mods[0].Name}" } PS1 - it_should_behave_like 'standard exec', pimport, windows_agents + it_should_behave_like 'standard exec', pimport end end diff --git a/spec/acceptance/exec_pwsh_spec.rb b/spec/acceptance/exec_pwsh_spec.rb index c931f730..f024b4e7 100644 --- a/spec/acceptance/exec_pwsh_spec.rb +++ b/spec/acceptance/exec_pwsh_spec.rb @@ -1,56 +1,77 @@ require 'spec_helper_acceptance' -def windows_platform?(host) - !((host.platform =~ /^windows.*$/).nil?) +def windows_platform? + os[:family] == 'windows' end -powershell6_agents = hosts.select { |h| !(h['powershell'].nil?) } -posix6_agents = powershell6_agents.select { |a| !windows_platform?(a) } -windows6_agents = powershell6_agents.select { |a| windows_platform?(a) } +describe 'pwsh provider:' do + def platform_string(windows, posix) + windows_platform? ? windows : posix + end + + context 'when pwsh is not installed' do + before(:all) do + uninstall_pwsh if pwsh_installed? + raise 'failed to remove pwsh' if pwsh_installed? + end + + let(:manifest) { + <<-MANIFEST + exec{'TestPowershell': + command => 'Get-Process > /process.txt', + unless => 'if(!(test-path "/process.txt")){exit 1}', + provider => pwsh, + } + MANIFEST + } -describe 'pwsh provider:', :if => powershell6_agents.count > 0 do - def platform_string(host, windows, posix) - if windows_platform?(host) - windows - else - posix + it 'errors because pwsh is not in the path' do + fail 'pwsh not discovered in the path' unless pwsh_installed? == false + apply_manifest(manifest, expect_failures: true) do |result| + expect(result.stderr).to match(%r{Could not evaluate: No pwsh discovered!}) + end end end - shared_examples 'should fail' do |manifest, error_check| - it 'should throw an error' do - powershell6_agents.each do |hut| - result = execute_manifest_on(hut, manifest, :expect_failures => true) + # Skip during localhost testing on Windows because of issues with + # installing software and pathing during the same run. + context 'when pwsh is installed', unless: localhost_windows? do + before(:all) do + install_pwsh unless pwsh_installed? + raise 'failed to install pwsh' unless pwsh_installed? + end + + shared_examples 'should fail' do |manifest, error_check| + it 'should throw an error' do + result = apply_manifest(manifest, expect_failures: true) unless error_check.nil? expect(result.stderr).to match(error_check) end end end - end - - shared_examples 'apply success' do |manifest| - it 'should succeed' do - execute_manifest_on(powershell6_agents, manifest, :catch_failures => true) + + shared_examples 'apply success' do |manifest| + it 'should succeed' do + apply_manifest(manifest, catch_failures: true) + end end - end - - shared_examples 'standard exec' do |powershell_cmd, hosts| - padmin = <<-MANIFEST - exec{'no fail test': - command => '#{powershell_cmd}', - provider => pwsh, - } - MANIFEST - it 'should not fail' do - execute_manifest_on(hosts, padmin, :catch_failures => true) + + shared_examples 'standard exec' do |powershell_cmd| + padmin = <<-MANIFEST + exec{'no fail test': + command => '#{powershell_cmd}', + provider => pwsh, + } + MANIFEST + it 'should not fail' do + apply_manifest(padmin, catch_failures: true) + end end - end - - describe "should run successfully" do - powershell6_agents.each do |host| - context "on host with platform #{host.platform}" do + + describe "should run successfully" do + context "on #{os[:family]}" do let(:manifest) { - if windows_platform?(host) + if windows_platform? <<-MANIFEST exec{'TestPowershell': command => 'Get-Process > c:/process.txt', @@ -61,36 +82,29 @@ def platform_string(host, windows, posix) else <<-MANIFEST exec{'TestPowershell': - command => 'Get-Process > /process.txt', - unless => 'if(!(test-path "/process.txt")){exit 1}', + command => 'Get-Process > /tmp/process.txt', + unless => 'if(!(test-path "/tmp/process.txt")){exit 1}', provider => pwsh, } MANIFEST end } - - it 'should not error on first run' do - # Run it twice and test for idempotency - execute_manifest_on(host, manifest, :catch_failures => true) - end - - it 'should be idempotent' do - execute_manifest_on(host, manifest, :catch_chages => true) + + it 'is idempotent' do + idempotent_apply(manifest) end end end - end - - describe 'should handle a try/catch successfully' do - powershell6_agents.each do |host| - context "on host with platform #{host.platform}" do - let(:try_successfile) { platform_string(host,'C:\try_success.txt','/try_success.txt') } - let(:try_failfile) { platform_string(host,'C:\try_shouldntexist.txt','/try_shouldntexist.txt') } - let(:catch_successfile) { platform_string(host,'C:\catch_success.txt','/catch_success.txt') } - let(:catch_failfile) { platform_string(host,'C:\catch_shouldntexist.txt','/catch_shouldntexist.txt') } + + describe 'should handle a try/catch successfully' do + context "on #{os[:family]}" do + let(:try_successfile) { platform_string('C:\try_success.txt','/tmp/try_success.txt') } + let(:try_failfile) { platform_string('C:\try_shouldntexist.txt','/tmp/try_shouldntexist.txt') } + let(:catch_successfile) { platform_string('C:\catch_success.txt','/tmp/catch_success.txt') } + let(:catch_failfile) { platform_string('C:\catch_shouldntexist.txt','/tmp/catch_shouldntexist.txt') } let(:try_content) { 'try_executed' } let(:catch_content) { 'catch_executed' } - + it 'should demonstrably execute PowerShell code inside a try block' do powershell_cmd = <<-CMD try { @@ -100,29 +114,29 @@ def platform_string(host, windows, posix) "catch_executed" | Out-File -FilePath "#{catch_failfile}" -Encoding "ASCII" } CMD - + manifest = <<-MANIFEST exec{'TestPowershell': command => '#{powershell_cmd}', provider => pwsh, } MANIFEST - - execute_manifest_on(host, manifest, :catch_failures => true) - - on(host, platform_string(host,"cmd.exe /c \"type #{try_successfile}\"","cat #{try_successfile}")) do |result| - assert_match(/#{try_content}/, result.stdout, "Unexpected result for host '#{host}'") + + apply_manifest(manifest, catch_failures: true) + + run_shell(platform_string("cmd.exe /c \"type #{try_successfile}\"","cat #{try_successfile}")) do |result| + expect(result.stdout).to match(/#{try_content}/) end - - on(host, platform_string(host,"cmd.exe /c \"type #{catch_failfile}\"","cat #{catch_failfile}"), :acceptable_exit_codes => [1]) do |result| - if windows_platform?(host) - assert_match(/^The system cannot find the file specified\./, result.stderr, "Unexpected file content #{result.stdout} on host '#{host}'") + + run_shell(platform_string("cmd.exe /c \"type #{catch_failfile}\"","cat #{catch_failfile}"), expect_failures: true) do |result| + if windows_platform? + expect(result.stderr).to match(/The system cannot find the file specified\./) else - assert_match(/No such file or directory/, result.stderr, "Unexpected file content #{result.stdout} on host '#{host}'") + expect(result.stderr).to match(/No such file or directory/) end end end - + it 'should demonstrably execute PowerShell code inside a catch block' do powershell_cmd = <<-CMD try { @@ -132,386 +146,376 @@ def platform_string(host, windows, posix) "#{catch_content}" | Out-File -FilePath "#{catch_successfile}" -Encoding "ASCII" } CMD - + p1 = <<-MANIFEST exec{'TestPowershell': command => '#{powershell_cmd}', provider => pwsh, } MANIFEST - - execute_manifest_on(host, p1, :catch_failures => true) - - on(host, platform_string(host,"cmd.exe /c \"type #{catch_successfile}\"","cat #{catch_successfile}")) do |result| - assert_match(/#{catch_content}/, result.stdout, "Unexpected result for host '#{host}'") + + apply_manifest(p1, catch_failures: true) + + run_shell(platform_string("cmd.exe /c \"type #{catch_successfile}\"","cat #{catch_successfile}")) do |result| + expect(result.stdout).to match(/#{catch_content}/) end - - on(host, platform_string(host,"cmd.exe /c \"type #{try_failfile}\"","cat #{try_failfile}"), :acceptable_exit_codes => [1]) do |result| - if windows_platform?(host) - assert_match(/^The system cannot find the file specified\./, result.stderr, "Unexpected file content #{result.stdout} on host '#{host}'") + + run_shell(platform_string("cmd.exe /c \"type #{try_failfile}\"","cat #{try_failfile}"), expect_failures: true) do |result| + if windows_platform? + expect(result.stderr).to match(/The system cannot find the file specified\./) else - assert_match(/No such file or directory/, result.stderr, "Unexpected file content #{result.stdout} on host '#{host}'") + expect(result.stderr).to match(/No such file or directory/) end end end end end - end - - describe 'should run commands that exit session' do - let(:manifest) { <<-MANIFEST - exec{'TestPowershell': - command => 'exit 0', - provider => pwsh, + + describe 'should run commands that exit session' do + let(:manifest) { <<-MANIFEST + exec{'TestPowershell': + command => 'exit 0', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - it 'should not error on first run' do - execute_manifest_on(powershell6_agents, manifest, :expect_changes => true) - end - - it 'should run a second time' do - execute_manifest_on(powershell6_agents, manifest, :expect_changes => true) + + it 'should not error on first run' do + apply_manifest(manifest, expect_changes: true) + end + + it 'should run a second time' do + apply_manifest(manifest, expect_changes: true) + end end - end - - describe 'should run commands that break session' do - let(:manifest) { <<-MANIFEST - exec{'TestPowershell': - command => 'Break', - provider => pwsh, + + describe 'should run commands that break session' do + let(:manifest) { <<-MANIFEST + exec{'TestPowershell': + command => 'Break', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - it 'should not error on first run' do - execute_manifest_on(powershell6_agents, manifest, :expect_changes => true) - end - - it 'should run a second time' do - execute_manifest_on(powershell6_agents, manifest, :expect_changes => true) + + it 'should not error on first run' do + apply_manifest(manifest, expect_changes: true) + end + + it 'should run a second time' do + apply_manifest(manifest, expect_changes: true) + end end - end - - describe 'should run commands that return from session' do - let(:manifest) { <<-MANIFEST - exec{'TestPowershell': - command => 'return 0', - provider => pwsh, + + describe 'should run commands that return from session' do + let(:manifest) { <<-MANIFEST + exec{'TestPowershell': + command => 'return 0', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - it 'should not error on first run' do - execute_manifest_on(powershell6_agents, manifest, :expect_changes => true) - end - - it 'should run a second time' do - execute_manifest_on(powershell6_agents, manifest, :expect_changes => true) + + it 'should not error on first run' do + apply_manifest(manifest, expect_changes: true) + end + + it 'should run a second time' do + apply_manifest(manifest, expect_changes: true) + end + end - - end - - describe 'should not leak variables across calls to single session' do - let(:var_leak_setup) { <<-MANIFEST - exec{'TestPowershell': - command => '$special=1', - provider => pwsh, + + describe 'should not leak variables across calls to single session' do + let(:var_leak_setup) { <<-MANIFEST + exec{'TestPowershell': + command => '$special=1', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - let(:var_leak_test) { <<-MANIFEST - exec{'TestPowershell': - command => 'if ( $special -eq 1 ) { exit 1 } else { exit 0 }', - provider => pwsh, + + let(:var_leak_test) { <<-MANIFEST + exec{'TestPowershell': + command => 'if ( $special -eq 1 ) { exit 1 } else { exit 0 }', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - it 'should not see variable from previous run' do - # Setup the variable - execute_manifest_on(powershell6_agents, var_leak_setup, :expect_changes => true) - - # Test to see if subsequent call sees the variable - execute_manifest_on(powershell6_agents, var_leak_test, :expect_changes => true) + + it 'should not see variable from previous run' do + # Setup the variable + apply_manifest(var_leak_setup, expect_changes: true) + + # Test to see if subsequent call sees the variable + apply_manifest(var_leak_test, expect_changes: true) + end end - end - - describe 'should not leak environment variables across calls to single session' do - let(:envar_leak_setup) { <<-MANIFEST - exec{'TestPowershell': - command => "\\$env:superspecial='1'", - provider => pwsh, + + describe 'should not leak environment variables across calls to single session' do + let(:envar_leak_setup) { <<-MANIFEST + exec{'TestPowershell': + command => "\\$env:superspecial='1'", + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - let(:envar_leak_test) { <<-MANIFEST - exec{'TestPowershell': - command => "if ( \\$env:superspecial -eq '1' ) { exit 1 } else { exit 0 }", - provider => pwsh, + + let(:envar_leak_test) { <<-MANIFEST + exec{'TestPowershell': + command => "if ( \\$env:superspecial -eq '1' ) { exit 1 } else { exit 0 }", + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - let(:envar_ext_test) { <<-MANIFEST - exec{'TestPowershell': - command => "if ( \\$env:outside -eq '1' ) { exit 0 } else { exit 1 }", - provider => pwsh, + + let(:envar_ext_test) { <<-MANIFEST + exec{'TestPowershell': + command => "if ( \\$env:outside -eq '1' ) { exit 0 } else { exit 1 }", + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - after(:each) do - # Due to https://tickets.puppetlabs.com/browse/BKR-1088, need to use different commands - powershell6_agents.each do |host| - if windows_platform?(host) - on(host, powershell("'Remove-Item Env:\\superspecial -ErrorAction Ignore;exit 0'")) - on(host, powershell("'Remove-Item Env:\\outside -ErrorAction Ignore;exit 0'")) + + after(:each) do + # Due to https://tickets.puppetlabs.com/browse/BKR-1088, need to use different commands + if windows_platform? + run_shell(interpolate_powershell("Remove-Item Env:\\superspecial -ErrorAction Ignore;exit 0")) + run_shell(interpolate_powershell("Remove-Item Env:\\outside -ErrorAction Ignore;exit 0")) else - on(host, 'unset superspecial') - on(host, 'unset outside') + run_shell('unset superspecial') + run_shell('unset outside') end end - end - - it 'should not see environment variable from previous run' do - # Setup the environment variable - execute_manifest_on(powershell6_agents, envar_leak_setup, :expect_changes => true) - - # Test to see if subsequent call sees the environment variable - execute_manifest_on(powershell6_agents, envar_leak_test, :expect_changes => true) - end - - it 'should see environment variables set outside of session' do - # Setup the environment variable outside of Puppet - - powershell6_agents.each do |host| + + it 'should not see environment variable from previous run' do + # Setup the environment variable + apply_manifest(envar_leak_setup, expect_changes: true) + + # Test to see if subsequent call sees the environment variable + apply_manifest(envar_leak_test, expect_changes: true) + end + + it 'should see environment variables set outside of session' do + # Setup the environment variable outside of Puppet + # Due to https://tickets.puppetlabs.com/browse/BKR-1088, need to use different commands - if windows_platform?(host) - on(host, powershell("\\$env:outside='1'")) + if windows_platform? + run_shell(interpolate_powershell("\$env:outside='1'")) else - on(host, 'export outside=1') + run_shell('export outside=1') end + + # Test to see if initial run sees the environment variable + apply_manifest(envar_leak_test, expect_changes: true) + + # Test to see if subsequent call sees the environment variable and environment purge + apply_manifest(envar_leak_test, expect_changes: true) end - - # Test to see if initial run sees the environment variable - execute_manifest_on(powershell6_agents, envar_leak_test, :expect_changes => true) - - # Test to see if subsequent call sees the environment variable and environment purge - execute_manifest_on(powershell6_agents, envar_leak_test, :expect_changes => true) end - end - - describe 'should allow exit from unless' do - let(:unless_not_triggered) { <<-MANIFEST - exec{'TestPowershell': - command => 'exit 0', - unless => 'exit 1', - provider => pwsh, + + describe 'should allow exit from unless' do + let(:unless_not_triggered) { <<-MANIFEST + exec{'TestPowershell': + command => 'exit 0', + unless => 'exit 1', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - let(:unless_triggered) { <<-MANIFEST - exec{'TestPowershell': - command => 'exit 0', - unless => 'exit 0', - provider => pwsh, + + let(:unless_triggered) { <<-MANIFEST + exec{'TestPowershell': + command => 'exit 0', + unless => 'exit 0', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - it 'should RUN command if unless is NOT triggered' do - execute_manifest_on(powershell6_agents, unless_not_triggered, :expect_changes => true) - end - - it 'should NOT run command if unless IS triggered' do - execute_manifest_on(powershell6_agents, unless_triggered, :catch_changes => true) + + it 'should RUN command if unless is NOT triggered' do + apply_manifest(unless_not_triggered, expect_changes: true) + end + + it 'should NOT run command if unless IS triggered' do + apply_manifest(unless_triggered, catch_changes: true) + end end - end - - describe 'should allow exit from onlyif' do - let(:onlyif_not_triggered) { <<-MANIFEST - exec{'TestPowershell': - command => 'exit 0', - onlyif => 'exit 1', - provider => pwsh, + + describe 'should allow exit from onlyif' do + let(:onlyif_not_triggered) { <<-MANIFEST + exec{'TestPowershell': + command => 'exit 0', + onlyif => 'exit 1', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - let(:onlyif_triggered) { <<-MANIFEST - exec{'TestPowershell': - command => 'exit 0', - onlyif => 'exit 0', - provider => pwsh, + + let(:onlyif_triggered) { <<-MANIFEST + exec{'TestPowershell': + command => 'exit 0', + onlyif => 'exit 0', + provider => pwsh, + } + MANIFEST } - MANIFEST - } - - it 'should NOT run command if onlyif is NOT triggered' do - execute_manifest_on(powershell6_agents, onlyif_not_triggered, :catch_changes => true) - end - - it 'should RUN command if onlyif IS triggered' do - execute_manifest_on(powershell6_agents, onlyif_triggered, :expect_changes => true) + + it 'should NOT run command if onlyif is NOT triggered' do + apply_manifest(onlyif_not_triggered, catch_changes: true) + end + + it 'should RUN command if onlyif IS triggered' do + apply_manifest(onlyif_triggered, expect_changes: true) + end end - end - - describe 'should be able to access the files after execution' do - let(:manifest) { <<-MANIFEST - exec{"TestPowershell": - command => ' "puppet" | Out-File -FilePath #{file_path} -Encoding UTF8', - provider => pwsh + + describe 'should be able to access the files after execution' do + let(:manifest) { <<-MANIFEST + exec{"TestPowershell": + command => ' "puppet" | Out-File -FilePath #{file_path} -Encoding UTF8', + provider => pwsh + } + MANIFEST } - MANIFEST - } - - win_file = 'C:/services.txt' - posix_file = '/services.txt' - - powershell6_agents.each do |node| - describe file(windows_platform?(node) ? win_file : posix_file), :node => node do - let(:file_path) { windows_platform?(node) ? win_file : posix_file } - + + win_file = 'C:/services.txt' + posix_file = '/tmp/services.txt' + + describe file(windows_platform? ? win_file : posix_file) do + let(:file_path) { windows_platform? ? win_file : posix_file } + it 'should apply the manifest' do - execute_manifest_on(node, manifest, :catch_failures => true) + apply_manifest(manifest, catch_failures: true) end - + it { should be_file() } its(:content) { should match /puppet/ } end end - end - - describe 'should catch and rethrow exceptions up to puppet' do - pexception = <<-MANIFEST - exec{'PowershellException': + + describe 'should catch and rethrow exceptions up to puppet' do + pexception = <<-MANIFEST + exec{'PowershellException': + provider => pwsh, + command => 'throw "We are writing an error"', + } + MANIFEST + it_should_behave_like 'should fail', pexception, /We are writing an error/i + end + + describe 'should error if timeout is exceeded' do + ptimeoutexception = <<-MANIFEST + exec{'PowershellException': + command => 'Write-Host "Going to sleep now..."; Start-Sleep 5', + timeout => 2, + provider => pwsh, + } + MANIFEST + it_should_behave_like 'should fail', ptimeoutexception + end + + describe 'should be able to execute a ps1 file provided' do + let(:manifest) { <<-MANIFEST + file{'#{external_script}': + content => '#{File.open(File.join(File.dirname(__FILE__), external_fixture)).read()}' + } + exec{"TestPowershellPS1": + command => '#{external_script}', provider => pwsh, - command => 'throw "We are writing an error"', + require => File['#{external_script}'] } - MANIFEST - it_should_behave_like 'should fail', pexception, /We are writing an error/i - end - - describe 'should error if timeout is exceeded' do - ptimeoutexception = <<-MANIFEST - exec{'PowershellException': - command => 'Write-Host "Going to sleep now..."; Start-Sleep 5', - timeout => 2, - provider => pwsh, + MANIFEST } - MANIFEST - it_should_behave_like 'should fail', ptimeoutexception - end - - describe 'should be able to execute a ps1 file provided' do - let(:manifest) { <<-MANIFEST - file{'#{external_script}': - content => '#{File.open(File.join(File.dirname(__FILE__), external_fixture)).read()}' - } - exec{"TestPowershellPS1": - command => '#{external_script}', - provider => pwsh, - require => File['#{external_script}'] - } - MANIFEST - } - - win_file = 'c:/temp/commands.csv' - posix_file = '/tmp/commands.csv' - - powershell6_agents.each do |node| - describe file(windows_platform?(node) ? win_file : posix_file), :node => node do - let(:external_script) { windows_platform?(node) ? 'c:/external-script.ps1' : '/external-script.ps1' } - let(:external_fixture) { "files/get-command-#{platform_string(node, 'win', 'posix')}.ps1" } - + + win_file = 'c:/temp/commands.csv' + posix_file = '/tmp/commands.csv' + + describe file(windows_platform? ? win_file : posix_file) do + let(:external_script) { windows_platform? ? 'c:/external-script.ps1' : '/tmp/external-script.ps1' } + let(:external_fixture) { "files/get-command-#{platform_string('win', 'posix')}.ps1" } + it 'should apply the manifest' do - execute_manifest_on(node, manifest, :catch_failures => true) + apply_manifest(manifest, catch_failures: true) end - + it { should be_file } its(:content) { should match /Get-Command/ } end end - end - - describe 'passing parameters to the ps1 file' do - let(:manifest) { <<-MANIFEST - $commandName = '#{commandName}' - $outFile = '#{outfile}' - - file{'#{external_script}': - content => '#{File.open(File.join(File.dirname(__FILE__), 'files/param_script-posix.ps1')).read()}' + + describe 'passing parameters to the ps1 file' do + let(:manifest) { <<-MANIFEST + $commandName = '#{commandName}' + $outFile = '#{outfile}' + + file{'#{external_script}': + content => '#{File.open(File.join(File.dirname(__FILE__), 'files/param_script-posix.ps1')).read()}' + } + exec{'run this with param': + provider => pwsh, + command => "#{external_script} -CommandName '$commandName' -FileOut '$outFile'", + require => File['#{external_script}'], } - exec{'run this with param': - provider => pwsh, - command => "#{external_script} -CommandName '$commandName' -FileOut '$outFile'", - require => File['#{external_script}'], - } - MANIFEST - } - - win_file = 'c:/temp/params.csv' - posix_file = '/tmp/params.csv' - - powershell6_agents.each do |node| - describe file(windows_platform?(node) ? win_file : posix_file), :node => node do - let(:external_script) { windows_platform?(node) ? 'C:\\param_script.ps1' : '/param_script.ps1' } - let(:outfile) { windows_platform?(node) ? win_file : posix_file } + MANIFEST + } + + win_file = 'c:/temp/params.csv' + posix_file = '/tmp/params.csv' + + describe file(windows_platform? ? win_file : posix_file) do + let(:external_script) { windows_platform? ? 'C:\\param_script.ps1' : '/tmp/param_script.ps1' } + let(:outfile) { windows_platform? ? win_file : posix_file } let(:commandName) { 'Export-Csv' } - - + + it 'should apply the manifest' do - execute_manifest_on(node, manifest, :catch_failures => true) + apply_manifest(manifest, catch_failures: true) end - + it { should be_file } its(:content) { should match /#{commandName}/ } end end - end - - describe 'should execute using 64 bit powershell', :if => windows6_agents.count > 0 do - # Only applicable to Windows platforms - p3 = <<-MANIFEST - $maxArchNumber = $::architecture? { - /(?i)(i386|i686|x86)$/ => 4, - /(?i)(x64|x86_64)/=> 8, - default => 0 - } - exec{'Test64bit': - command => "if([IntPtr]::Size -eq $maxArchNumber) { exit 0 } else { Write-Error 'Architecture mismatch' }", - provider => pwsh - } - MANIFEST - it_should_behave_like 'apply success', p3, windows6_agents - end - - describe 'test admin rights', :if => windows6_agents.count > 0 do - # Only applicable to Windows platforms - ps1 = <<-PS1 - $id = [Security.Principal.WindowsIdentity]::GetCurrent() - $pr = New-Object Security.Principal.WindowsPrincipal $id - if(!($pr.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))){Write-Error "Not in admin"} - PS1 - it_should_behave_like 'standard exec', ps1, windows6_agents - end - - describe 'test import-module' do - pimport = <<-PS1 - $mods = Get-Module -ListAvailable - if($mods.Length -lt 1) { - Write-Error "Expected to get at least one module, but none were listed" + + describe 'should execute using 64 bit powershell', if: windows_platform? do + # Only applicable to Windows platforms + p3 = <<-MANIFEST + $maxArchNumber = $::architecture? { + /(?i)(i386|i686|x86)$/ => 4, + /(?i)(x64|x86_64)/=> 8, + default => 0 } - Import-Module $mods[0].Name - if(-not (Get-Module $mods[0].Name)){ - Write-Error "Failed to import module ${mods[0].Name}" + exec{'Test64bit': + command => "if([IntPtr]::Size -eq $maxArchNumber) { exit 0 } else { Write-Error 'Architecture mismatch' }", + provider => pwsh } - PS1 - it_should_behave_like 'standard exec', pimport, powershell6_agents + MANIFEST + it_should_behave_like 'apply success', p3 + end + + describe 'test admin rights', if: windows_platform? do + # Only applicable to Windows platforms + ps1 = <<-PS1 + $id = [Security.Principal.WindowsIdentity]::GetCurrent() + $pr = New-Object Security.Principal.WindowsPrincipal $id + if(!($pr.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))){Write-Error "Not in admin"} + PS1 + it_should_behave_like 'standard exec', ps1 + end + + describe 'test import-module' do + pimport = <<-PS1 + $mods = Get-Module -ListAvailable + if($mods.Length -lt 1) { + Write-Error "Expected to get at least one module, but none were listed" + } + Import-Module $mods[0].Name + if(-not (Get-Module $mods[0].Name)){ + Write-Error "Failed to import module ${mods[0].Name}" + } + PS1 + it_should_behave_like 'standard exec', pimport + end end end diff --git a/spec/acceptance/files/services.ps1 b/spec/acceptance/files/services.ps1 index 01ab8a67..6adff2df 100644 --- a/spec/acceptance/files/services.ps1 +++ b/spec/acceptance/files/services.ps1 @@ -2,4 +2,4 @@ $temp = "C:/temp" if(!(Test-Path $temp)){ mkdir $temp } -Get-Service *puppet* | Export-Csv "$temp\services.csv" +Get-Service WinRM | Export-Csv "$temp\services.csv" diff --git a/spec/fixtures/scripts/install_pwsh/darwin.sh b/spec/fixtures/scripts/install_pwsh/darwin.sh new file mode 100644 index 00000000..b67fcb00 --- /dev/null +++ b/spec/fixtures/scripts/install_pwsh/darwin.sh @@ -0,0 +1 @@ +brew cask install powershell diff --git a/spec/fixtures/scripts/install_pwsh/debian_8.sh b/spec/fixtures/scripts/install_pwsh/debian_8.sh new file mode 100644 index 00000000..06f2d046 --- /dev/null +++ b/spec/fixtures/scripts/install_pwsh/debian_8.sh @@ -0,0 +1,18 @@ +# Install system components +apt-get update +apt-get install -y curl apt-transport-https + +# Import the public repository GPG keys +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + +# Register the Microsoft Product feed +sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/microsoft.list' + +# Update the list of products +apt-get update + +# Install PowerShell +apt-get install -y powershell + +# List version +pwsh -v diff --git a/spec/fixtures/scripts/install_pwsh/debian_9.sh b/spec/fixtures/scripts/install_pwsh/debian_9.sh new file mode 100644 index 00000000..f6ce3ccd --- /dev/null +++ b/spec/fixtures/scripts/install_pwsh/debian_9.sh @@ -0,0 +1,18 @@ +# Install system components +apt-get update +apt-get install -y curl gnupg apt-transport-https + +# Import the public repository GPG keys +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + +# Register the Microsoft Product feed +sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list' + +# Update the list of products +apt-get update + +# Install PowerShell +apt-get install -y powershell + +# List version +pwsh -v diff --git a/spec/fixtures/scripts/install_pwsh/rhel.sh b/spec/fixtures/scripts/install_pwsh/rhel.sh new file mode 100644 index 00000000..609ad96d --- /dev/null +++ b/spec/fixtures/scripts/install_pwsh/rhel.sh @@ -0,0 +1,8 @@ +# Register the Microsoft RedHat repository +curl https://packages.microsoft.com/config/rhel/7/prod.repo | tee /etc/yum.repos.d/microsoft.repo + +# Install PowerShell +yum install -y powershell + +# List version +pwsh -v diff --git a/spec/fixtures/scripts/install_pwsh/ubuntu_16.04.sh b/spec/fixtures/scripts/install_pwsh/ubuntu_16.04.sh new file mode 100644 index 00000000..1cf577c0 --- /dev/null +++ b/spec/fixtures/scripts/install_pwsh/ubuntu_16.04.sh @@ -0,0 +1,17 @@ +# Download the Microsoft repository GPG keys +wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb + +# Register the Microsoft repository GPG keys +dpkg -i packages-microsoft-prod.deb + +# Make sure apt-get update works +apt-get install -y apt-transport-https + +# Update the list of products +apt-get update + +# Install PowerShell +apt-get install -y powershell + +# List version +pwsh -v diff --git a/spec/fixtures/scripts/install_pwsh/ubuntu_18.04.sh b/spec/fixtures/scripts/install_pwsh/ubuntu_18.04.sh new file mode 100644 index 00000000..1c737c26 --- /dev/null +++ b/spec/fixtures/scripts/install_pwsh/ubuntu_18.04.sh @@ -0,0 +1,17 @@ +# Download the Microsoft repository GPG keys +wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb + +# Register the Microsoft repository GPG keys +dpkg -i packages-microsoft-prod.deb + +# Update the list of products +apt-get update + +# Enable the "universe" repositories +add-apt-repository universe + +# Install PowerShell +apt-get install -y powershell + +# List version +pwsh -v diff --git a/spec/fixtures/scripts/install_pwsh/windows.ps1 b/spec/fixtures/scripts/install_pwsh/windows.ps1 new file mode 100644 index 00000000..19ce5caf --- /dev/null +++ b/spec/fixtures/scripts/install_pwsh/windows.ps1 @@ -0,0 +1,7 @@ +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +Invoke-WebRequest -Uri https://github.com/PowerShell/PowerShell/raw/master/tools/install-powershell.ps1 -UseBasicParsing -OutFile install-pwsh.ps1 + +& ./install-pwsh.ps1 -AddToPath + +# List version +pwsh -v diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index eec2214f..4ac8d7e0 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,88 +1,6 @@ -require 'beaker-pe' -require 'beaker-puppet' -require 'beaker-rspec/spec_helper' -require 'beaker-rspec/helpers/serverspec' -require 'beaker/puppet_install_helper' -require 'beaker/testmode_switcher/dsl' -require 'beaker/module_install_helper' +# frozen_string_literal: true -UNSUPPORTED_PLATFORMS = ['debian', 'ubuntu', 'Solaris'] -FUTURE_PARSER = ENV['FUTURE_PARSER'] == 'true' || false +require 'puppet_litmus' +require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) -run_puppet_install_helper -configure_type_defaults_on(hosts) - -unless ENV['MODULE_provision'] == 'no' - # Due to a bug in beaker-puppet, passing in a hosts array with differing architectures does - # weird things e.g. uses windows paths in linux. Best to just pass in one host at a time. - hosts.each do |host| - install_module_on(host) - install_module_dependencies_on(host) - end - - # Install PowerShell on hosts that are not a Master, Dashboard or Database - agents.each do |host| - ps_version = host['powershell'] - if not_controller(host) - case host.platform - when "ubuntu-14.04-amd64" - # Instructions for installing on Ubuntu 14 from - # https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#ubuntu-1404 - on(host,'curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -') - on(host,'curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list') - on(host,'sudo apt-get update') - # e.g. sudo apt-get install -y powershell=6.1.2-1.ubuntu.14.04 - apt_text = "=#{ps_version}-1.ubuntu.14.04" unless ps_version.nil? - on(host,"sudo apt-get install -y powershell#{apt_text}") - when "ubuntu-16.04-amd64" - # Instructions for installing on Ubuntu 16 from - # https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#ubuntu-1604 - on(host,'curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -') - on(host,'curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list') - on(host,'sudo apt-get update') - # e.g. sudo apt-get install -y powershell=6.1.2-1.ubuntu.16.04 - apt_text = "=#{ps_version}-1.ubuntu.16.04" unless ps_version.nil? - on(host,"sudo apt-get install -y powershell#{apt_text}") - when "el-7-x86_64" - # Instructions for installing on CentOS 7, Oracle Linux7, RHEL 7 from - # https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#centos-7 - # sudo is not required and seems to throw errors when running under beaker `sudo: sorry, you must have a tty to run sudo` - on(host,'curl https://packages.microsoft.com/config/rhel/7/prod.repo | tee /etc/yum.repos.d/microsoft.repo') - # e.g. yum install -y powershell-6.1.2 - yum_text = "-#{ps_version}" unless ps_version.nil? - on(host,"yum install -y powershell#{yum_text}") - when /^windows/ - # Install PowerShell 6 if needed - unless ps_version.nil? - on(host,"powershell -NoLogo -NoProfile -Command \"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri https://github.com/PowerShell/PowerShell/releases/download/v#{ps_version}/PowerShell-#{ps_version}-win-x64.msi -OutFile C:\\PSPkg.msi -UseBasicParsing\"") - on(host,'msiexec.exe /i C:\\\\PSPkg.msi /qn ALLUSERS=1 /l*v C:\\\\PSPkg-install.log') - end - else - raise("Unable to install PowerShell on host '#{host.name}' with platform '#{host.platform}'") - end - end - end -end - -RSpec.configure do |c| - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - - # Readable test descriptions - c.formatter = :documentation - - # Configure all nodes in nodeset - c.before :suite do - shell("/bin/touch #{default['puppetpath']}/hiera.yaml") - - powershell_agents = agents.select { |a| not_controller(a) } - posix_agents = powershell_agents.select { |a| a.platform =~ /^(?!windows).*$/ } - windows_agents = powershell_agents.select { |a| a.platform =~ /^windows.*$/ } - - # Ensure test files don't exist before we run the test suite - absent_files = 'file{["c:/services.txt","c:/process.txt","c:/try_success.txt","c:/catch_shouldntexist.txt","c:/try_shouldntexist.txt","c:/catch_success.txt"]: ensure => absent }' - apply_manifest_on(windows_agents, absent_files, :catch_failures => true) if windows_agents.count > 0 - - absent_files = 'file{["/services.txt","/process.txt","/try_success.txt","/catch_shouldntexist.txt","/try_shouldntexist.txt","/catch_success.txt"]: ensure => absent }' - apply_manifest_on(posix_agents, absent_files, :catch_failures => true) if posix_agents.count > 0 - end -end +PuppetLitmus.configure! diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb new file mode 100644 index 00000000..78e67bd7 --- /dev/null +++ b/spec/spec_helper_acceptance_local.rb @@ -0,0 +1,67 @@ +require 'puppet_litmus' +require 'singleton' + +class Helper + include Singleton + include PuppetLitmus +end + +def install_pwsh + script_folder = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/scripts/install_pwsh')) + script_path = case os[:family] + when 'ubuntu' + File.join(script_folder, "ubuntu_#{os[:release].to_f}.sh") + when 'redhat' + File.join(script_folder, "rhel.sh") + when 'debian' + File.join(script_folder, "debian_#{os[:release].to_i}.sh") + when 'darwin' + File.join(script_folder, "darwin.sh") + when 'windows' + File.join(script_folder, "windows.ps1") + end + Helper.instance.bolt_run_script(script_path) +end + +def uninstall_pwsh + command = case os[:family] + when 'ubuntu', 'debian' + 'apt-get remove powershell -y' + when 'redhat' + 'yum remove powershell -y' + when 'darwin' + 'brew cask uninstall powershell' + when 'windows' + interpolate_powershell('Get-Command pwsh | ForEach-Object { Remove-Item -Path (Split-Path -Parent $_.Path) -Recurse -Force }') + end + Helper.instance.run_shell(command) +end + +def pwsh_installed? + Helper.instance.run_shell('pwsh -v', expect_failures: true).exit_code == 0 +end + +def cleanup_files + absent_files_manifest = if os[:family] == 'windows' + 'file{["c:/services.txt","c:/process.txt","c:/try_success.txt","c:/catch_shouldntexist.txt","c:/try_shouldntexist.txt","c:/catch_success.txt"]: ensure => absent }' + else + 'file{["/tmp/services.txt","/tmp/process.txt","/tmp/try_success.txt","/tmp/catch_shouldntexist.txt","/tmp/try_shouldntexist.txt","/tmp/catch_success.txt"]: ensure => absent }' + end + Helper.instance.apply_manifest(absent_files_manifest, catch_failures: true) +end + +def interpolate_powershell(command) + encoded_command = Base64.strict_encode64(command.encode('UTF-16LE')) + "powershell.exe -NoProfile -EncodedCommand #{encoded_command}" +end + +def localhost_windows? + os[:family] == 'windows' && ENV['TARGET_HOST'] == 'localhost' +end + +RSpec.configure do |c| + c.before :suite do + Helper.instance.run_shell('puppet module install puppetlabs/pwshlib') + cleanup_files + end +end From c81e7c7a5697f20293ab6ba578e9911100720ab8 Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Thu, 20 Feb 2020 11:36:34 +0200 Subject: [PATCH 06/20] Add weekly workflow on default branch --- .github/workflows/weekly.yml | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/weekly.yml diff --git a/.github/workflows/weekly.yml b/.github/workflows/weekly.yml new file mode 100644 index 00000000..3be2e052 --- /dev/null +++ b/.github/workflows/weekly.yml @@ -0,0 +1,42 @@ +name: "weekly" + +on: + schedule: + - cron: '0 0 * * 6' + +jobs: + LitmusAcceptance: + runs-on: self-hosted + strategy: + matrix: + ruby_version: [2.5.x] + puppet_gem_version: [~> 6.0] + platform: [release_checks] + agent_family: ['puppet5', 'puppet6'] + + steps: + - uses: actions/checkout@v1 + - name: Litmus Parallel + uses: puppetlabs/action-litmus_parallel@master + with: + platform: ${{ matrix.platform }} + agent_family: ${{ matrix.agent_family }} + Spec: + runs-on: self-hosted + strategy: + matrix: + check: [spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'] + ruby_version: [2.5.x] + puppet_gem_version: [~> 5.0, ~> 6.0] + exclude: + - puppet_gem_version: ~> 5.0 + check: 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop' + - ruby_version: 2.5.x + puppet_gem_version: ~> 5.0 + steps: + - uses: actions/checkout@v1 + - name: Spec Tests + uses: puppetlabs/action-litmus_spec@master + with: + puppet_gem_version: ${{ matrix.puppet_gem_version }} + check: ${{ matrix.check }} From dbd75f466ed7c8cd135edc9f1be4fe78590729b0 Mon Sep 17 00:00:00 2001 From: sheena Date: Fri, 21 Feb 2020 16:27:39 +0000 Subject: [PATCH 07/20] (maint) remove nodesets,module is ported to litmus. --- spec/acceptance/nodesets/centos-7-x64.yml | 10 -------- spec/acceptance/nodesets/debian-8-x64.yml | 10 -------- spec/acceptance/nodesets/default.yml | 18 -------------- spec/acceptance/nodesets/docker/centos-7.yml | 12 ---------- spec/acceptance/nodesets/docker/debian-8.yml | 11 --------- .../nodesets/docker/ubuntu-14.04.yml | 12 ---------- .../acceptance/nodesets/windows-2003-i386.yml | 24 ------------------- .../nodesets/windows-2003-x86_64.yml | 24 ------------------- .../nodesets/windows-2008-x86_64.yml | 24 ------------------- .../nodesets/windows-2008r2-x86_64.yml | 24 ------------------- .../nodesets/windows-2012-x86_64.yml | 24 ------------------- .../nodesets/windows-2012r2-x86_64.yml | 24 ------------------- 12 files changed, 217 deletions(-) delete mode 100644 spec/acceptance/nodesets/centos-7-x64.yml delete mode 100644 spec/acceptance/nodesets/debian-8-x64.yml delete mode 100644 spec/acceptance/nodesets/default.yml delete mode 100644 spec/acceptance/nodesets/docker/centos-7.yml delete mode 100644 spec/acceptance/nodesets/docker/debian-8.yml delete mode 100644 spec/acceptance/nodesets/docker/ubuntu-14.04.yml delete mode 100644 spec/acceptance/nodesets/windows-2003-i386.yml delete mode 100644 spec/acceptance/nodesets/windows-2003-x86_64.yml delete mode 100644 spec/acceptance/nodesets/windows-2008-x86_64.yml delete mode 100644 spec/acceptance/nodesets/windows-2008r2-x86_64.yml delete mode 100644 spec/acceptance/nodesets/windows-2012-x86_64.yml delete mode 100644 spec/acceptance/nodesets/windows-2012r2-x86_64.yml diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml deleted file mode 100644 index 5eebdefb..00000000 --- a/spec/acceptance/nodesets/centos-7-x64.yml +++ /dev/null @@ -1,10 +0,0 @@ -HOSTS: - centos-7-x64: - roles: - - agent - - default - platform: el-7-x86_64 - hypervisor: vagrant - box: puppetlabs/centos-7.2-64-nocm -CONFIG: - type: foss diff --git a/spec/acceptance/nodesets/debian-8-x64.yml b/spec/acceptance/nodesets/debian-8-x64.yml deleted file mode 100644 index fef6e63c..00000000 --- a/spec/acceptance/nodesets/debian-8-x64.yml +++ /dev/null @@ -1,10 +0,0 @@ -HOSTS: - debian-8-x64: - roles: - - agent - - default - platform: debian-8-amd64 - hypervisor: vagrant - box: puppetlabs/debian-8.2-64-nocm -CONFIG: - type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml deleted file mode 100644 index 6f602319..00000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -HOSTS: - windows2012-64-1: - pe_dir: - pe_ver: - pe_upgrade_dir: - pe_upgrade_ver: - hypervisor: vmpooler - platform: windows-2012-64 - ruby_arch: x64 - template: win-2012-x86_64 - roles: - - agent - - default -CONFIG: - nfs_server: none - consoleport: 443 - pooling_api: http://vmpooler.delivery.puppetlabs.net/ diff --git a/spec/acceptance/nodesets/docker/centos-7.yml b/spec/acceptance/nodesets/docker/centos-7.yml deleted file mode 100644 index a3333aac..00000000 --- a/spec/acceptance/nodesets/docker/centos-7.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - centos-7-x64: - platform: el-7-x86_64 - hypervisor: docker - image: centos:7 - docker_preserve_image: true - docker_cmd: '["/usr/sbin/init"]' - # install various tools required to get the image up to usable levels - docker_image_commands: - - 'yum install -y crontabs tar wget openssl sysvinit-tools iproute which initscripts' -CONFIG: - trace_limit: 200 diff --git a/spec/acceptance/nodesets/docker/debian-8.yml b/spec/acceptance/nodesets/docker/debian-8.yml deleted file mode 100644 index df5c3194..00000000 --- a/spec/acceptance/nodesets/docker/debian-8.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - debian-8-x64: - platform: debian-8-amd64 - hypervisor: docker - image: debian:8 - docker_preserve_image: true - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - 'apt-get update && apt-get install -y net-tools wget locales strace lsof && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen' -CONFIG: - trace_limit: 200 diff --git a/spec/acceptance/nodesets/docker/ubuntu-14.04.yml b/spec/acceptance/nodesets/docker/ubuntu-14.04.yml deleted file mode 100644 index b1efa583..00000000 --- a/spec/acceptance/nodesets/docker/ubuntu-14.04.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - ubuntu-1404-x64: - platform: ubuntu-14.04-amd64 - hypervisor: docker - image: ubuntu:14.04 - docker_preserve_image: true - docker_cmd: '["/sbin/init"]' - docker_image_commands: - # ensure that upstart is booting correctly in the container - - 'rm /usr/sbin/policy-rc.d && rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl && apt-get update && apt-get install -y net-tools wget && locale-gen en_US.UTF-8' -CONFIG: - trace_limit: 200 diff --git a/spec/acceptance/nodesets/windows-2003-i386.yml b/spec/acceptance/nodesets/windows-2003-i386.yml deleted file mode 100644 index eb571eea..00000000 --- a/spec/acceptance/nodesets/windows-2003-i386.yml +++ /dev/null @@ -1,24 +0,0 @@ -HOSTS: - ubuntu1204: - roles: - - master - - database - - dashboard - platform: ubuntu-12.04-amd64 - template: ubuntu-1204-x86_64 - hypervisor: vcloud - win2003_i386: - roles: - - agent - - default - platform: windows-2003-i386 - template: win-2003-i386 - hypervisor: vcloud -CONFIG: - nfs_server: none - consoleport: 443 - datastore: instance0 - folder: Delivery/Quality Assurance/Enterprise/Dynamic - resourcepool: delivery/Quality Assurance/Enterprise/Dynamic - pooling_api: http://vcloud.delivery.puppetlabs.net/ - pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2003-x86_64.yml b/spec/acceptance/nodesets/windows-2003-x86_64.yml deleted file mode 100644 index 5c3e8352..00000000 --- a/spec/acceptance/nodesets/windows-2003-x86_64.yml +++ /dev/null @@ -1,24 +0,0 @@ -HOSTS: - ubuntu1204: - roles: - - master - - database - - dashboard - platform: ubuntu-12.04-amd64 - template: ubuntu-1204-x86_64 - hypervisor: vcloud - win2003_x86_64: - roles: - - agent - - default - platform: windows-2003-x86_64 - template: win-2003-x86_64 - hypervisor: vcloud -CONFIG: - nfs_server: none - consoleport: 443 - datastore: instance0 - folder: Delivery/Quality Assurance/Enterprise/Dynamic - resourcepool: delivery/Quality Assurance/Enterprise/Dynamic - pooling_api: http://vcloud.delivery.puppetlabs.net/ - pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2008-x86_64.yml b/spec/acceptance/nodesets/windows-2008-x86_64.yml deleted file mode 100644 index e9d6d4dc..00000000 --- a/spec/acceptance/nodesets/windows-2008-x86_64.yml +++ /dev/null @@ -1,24 +0,0 @@ -HOSTS: - ubuntu1204: - roles: - - master - - database - - dashboard - platform: ubuntu-12.04-amd64 - template: ubuntu-1204-x86_64 - hypervisor: vcloud - win2008_x86_64: - roles: - - agent - - default - platform: windows-2008-x86_64 - template: win-2008-x86_64 - hypervisor: vcloud -CONFIG: - nfs_server: none - consoleport: 443 - datastore: instance0 - folder: Delivery/Quality Assurance/Enterprise/Dynamic - resourcepool: delivery/Quality Assurance/Enterprise/Dynamic - pooling_api: http://vcloud.delivery.puppetlabs.net/ - pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2008r2-x86_64.yml b/spec/acceptance/nodesets/windows-2008r2-x86_64.yml deleted file mode 100644 index ab9c70f7..00000000 --- a/spec/acceptance/nodesets/windows-2008r2-x86_64.yml +++ /dev/null @@ -1,24 +0,0 @@ -HOSTS: - ubuntu1204: - roles: - - master - - database - - dashboard - platform: ubuntu-12.04-amd64 - template: ubuntu-1204-x86_64 - hypervisor: vcloud - win2008r2: - roles: - - agent - - default - platform: windows-2008r2-x86_64 - template: win-2008r2-x86_64 - hypervisor: vcloud -CONFIG: - nfs_server: none - consoleport: 443 - datastore: instance0 - folder: Delivery/Quality Assurance/Enterprise/Dynamic - resourcepool: delivery/Quality Assurance/Enterprise/Dynamic - pooling_api: http://vcloud.delivery.puppetlabs.net/ - pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2012-x86_64.yml b/spec/acceptance/nodesets/windows-2012-x86_64.yml deleted file mode 100644 index 05866545..00000000 --- a/spec/acceptance/nodesets/windows-2012-x86_64.yml +++ /dev/null @@ -1,24 +0,0 @@ -HOSTS: - ubuntu1204: - roles: - - master - - database - - dashboard - platform: ubuntu-12.04-amd64 - template: ubuntu-1204-x86_64 - hypervisor: vcloud - win2012: - roles: - - agent - - default - platform: windows-2012-x86_64 - template: win-2012-x86_64 - hypervisor: vcloud -CONFIG: - nfs_server: none - consoleport: 443 - datastore: instance0 - folder: Delivery/Quality Assurance/Enterprise/Dynamic - resourcepool: delivery/Quality Assurance/Enterprise/Dynamic - pooling_api: http://vcloud.delivery.puppetlabs.net/ - pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2012r2-x86_64.yml b/spec/acceptance/nodesets/windows-2012r2-x86_64.yml deleted file mode 100644 index ef06e40c..00000000 --- a/spec/acceptance/nodesets/windows-2012r2-x86_64.yml +++ /dev/null @@ -1,24 +0,0 @@ -HOSTS: - ubuntu1204: - roles: - - master - - database - - dashboard - platform: ubuntu-12.04-amd64 - template: ubuntu-1204-x86_64 - hypervisor: vcloud - win2012r2: - roles: - - agent - - default - platform: windows-2012r2-x86_64 - template: win-2012r2-x86_64 - hypervisor: vcloud -CONFIG: - nfs_server: none - consoleport: 443 - datastore: instance0 - folder: Delivery/Quality Assurance/Enterprise/Dynamic - resourcepool: delivery/Quality Assurance/Enterprise/Dynamic - pooling_api: http://vcloud.delivery.puppetlabs.net/ - pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ From 85b483efbf4559d90b787a5ac74a32be5795e9cf Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Wed, 26 Feb 2020 11:41:06 +0200 Subject: [PATCH 08/20] Update weekly workflow schedule --- .github/workflows/weekly.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly.yml b/.github/workflows/weekly.yml index 3be2e052..471f6045 100644 --- a/.github/workflows/weekly.yml +++ b/.github/workflows/weekly.yml @@ -2,10 +2,13 @@ name: "weekly" on: schedule: - - cron: '0 0 * * 6' + - cron: '0 5 * * 1' jobs: LitmusAcceptance: + env: + HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 + HONEYCOMB_DATASET: litmus tests runs-on: self-hosted strategy: matrix: @@ -25,7 +28,7 @@ jobs: runs-on: self-hosted strategy: matrix: - check: [spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'] + check: [parallel_spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'] ruby_version: [2.5.x] puppet_gem_version: [~> 5.0, ~> 6.0] exclude: From c92ee6189c2767c759ad45e3405e506f866e95da Mon Sep 17 00:00:00 2001 From: Michael T Lombardi Date: Thu, 13 Feb 2020 00:13:25 -0600 Subject: [PATCH 09/20] (MODULES-10539) Remove commands idiom from PowerShell provider Prior to this commit the PowerShell exec provider used the commands idiom to load the PowerShell executable path for use. Once the module was refactored to rely on the ruby-pwsh gem via the puppetlabs/pwshlib module, the code for determining the path was updated to depend on a helper function. However, the commands method is (apparently?) evaluated during catalogue compilation, causing the Puppet run to explode unexpectedly if the dependent module is not available. This commit removes the commands idiom and relies on the feature confine which should evaluate during a Puppet run and, when that feature is not found (because puppetlabs/pwshlib is not installed) it will report that the provider is not functional rather than blow up the entire Puppet run. --- lib/puppet/provider/exec/powershell.rb | 14 ++--------- spec/acceptance/exec_powershell_spec.rb | 27 ++++++++++++++++++++++ spec/acceptance/exec_pwsh_spec.rb | 27 ++++++++++++++++++++++ spec/spec_helper_acceptance_local.rb | 21 ++++++++++++++++- spec/unit/provider/exec/powershell_spec.rb | 1 + spec/unit/provider/exec/pwsh_spec.rb | 1 + 6 files changed, 78 insertions(+), 13 deletions(-) diff --git a/lib/puppet/provider/exec/powershell.rb b/lib/puppet/provider/exec/powershell.rb index 32df6751..881fd4ab 100644 --- a/lib/puppet/provider/exec/powershell.rb +++ b/lib/puppet/provider/exec/powershell.rb @@ -4,16 +4,6 @@ confine :operatingsystem => :windows confine :feature => :pwshlib - def self.powershell_path - begin - require 'ruby-pwsh' - Pwsh::Manager.powershell_path - rescue - nil - end - end - commands :powershell => self.powershell_path - desc <<-EOT Executes Powershell commands. One of the `onlyif`, `unless`, or `creates` parameters should be specified to ensure the command is idempotent. @@ -57,7 +47,7 @@ def self.upgrade_message def ps_manager debug_output = Puppet::Util::Log.level == :debug - Pwsh::Manager.instance(command(:powershell), Pwsh::Manager.powershell_args, debug: debug_output) + Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args, debug: debug_output) end def run(command, check = false) @@ -72,7 +62,7 @@ def run(command, check = false) # we redirect powershell's stdin to read from the file. Current # versions of Windows use per-user temp directories with strong # permissions, but I'd rather not make (poor) assumptions. - return super("cmd.exe /c \"\"#{native_path(command(:powershell))}\" #{legacy_args} -Command - < \"#{native_path}\"\"", check) + return super("cmd.exe /c \"\"#{native_path(Pwsh::Manager.powershell_path)}\" #{legacy_args} -Command - < \"#{native_path}\"\"", check) end else return execute_resource(command, resource) diff --git a/spec/acceptance/exec_powershell_spec.rb b/spec/acceptance/exec_powershell_spec.rb index 7253a451..d1df8833 100644 --- a/spec/acceptance/exec_powershell_spec.rb +++ b/spec/acceptance/exec_powershell_spec.rb @@ -465,4 +465,31 @@ PS1 it_should_behave_like 'standard exec', pimport end + + # TODO: For some reason, Puppet still sees the dependent module as available during + # a localhost run, but not when testing against a remote target. + context 'without pwshlib available', unless: (ENV['TARGET_HOST'] == 'localhost') do + before(:all) do + remove_pwshlib + end + after(:all) do + install_pwshlib + end + + let(:manifest) { + <<-MANIFEST + exec{'TestPowershell': + command => 'Get-Process > c:/process.txt', + unless => 'if(!(test-path "c:/process.txt")){exit 1}', + provider => powershell, + } + MANIFEST + } + + it "Errors predictably" do + apply_manifest(manifest, expect_failures: true) do |result| + expect(result.stderr).to match(/Provider powershell is not functional on this host/) + end + end + end end diff --git a/spec/acceptance/exec_pwsh_spec.rb b/spec/acceptance/exec_pwsh_spec.rb index f024b4e7..d7bf30f9 100644 --- a/spec/acceptance/exec_pwsh_spec.rb +++ b/spec/acceptance/exec_pwsh_spec.rb @@ -517,5 +517,32 @@ def platform_string(windows, posix) PS1 it_should_behave_like 'standard exec', pimport end + + # TODO: For some reason, Puppet still sees the dependent module as available during + # a localhost run, but not when testing against a remote target. + describe 'without pwshlib available', unless: (ENV['TARGET_HOST'] == 'localhost') do + before(:all) do + remove_pwshlib + end + after(:all) do + install_pwshlib + end + + let(:manifest) { + <<-MANIFEST + exec{'TestPowershell': + command => 'Get-Process > /process.txt', + unless => 'if(!(test-path "/process.txt")){exit 1}', + provider => pwsh, + } + MANIFEST + } + + it "Errors predictably" do + apply_manifest(manifest, expect_failures: true) do |result| + expect(result.stderr).to match(/Provider pwsh is not functional on this host/) + end + end + end end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 78e67bd7..acef323d 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -55,13 +55,32 @@ def interpolate_powershell(command) "powershell.exe -NoProfile -EncodedCommand #{encoded_command}" end +def relative_folder(relative_path) + expanded_path = File.expand_path(File.join(File.dirname(__FILE__), relative_path)) + Dir.open(expanded_path) if File.exist?(expanded_path) +end + +def remove_pwshlib + uninstall_command = 'puppet module uninstall puppetlabs/pwshlib --force' + uninstall_command += " --modulepath #{relative_folder('fixtures/modules').path}" if ENV['TARGET_HOST'] == 'localhost' + Helper.instance.run_shell(uninstall_command, expect_failures: true) do |result| + raise "Failed to uninstall puppetlabs/pwshlib" unless result.stderr =~ /Module 'puppetlabs-pwshlib' is not installed/ || result.exit_code == 0 + end +end + +def install_pwshlib + install_command = 'puppet module install puppetlabs/pwshlib' + install_command += " --modulepath #{relative_folder('fixtures/modules').path}" if ENV['TARGET_HOST'] == 'localhost' + Helper.instance.run_shell(install_command) +end + def localhost_windows? os[:family] == 'windows' && ENV['TARGET_HOST'] == 'localhost' end RSpec.configure do |c| c.before :suite do - Helper.instance.run_shell('puppet module install puppetlabs/pwshlib') + install_pwshlib cleanup_files end end diff --git a/spec/unit/provider/exec/powershell_spec.rb b/spec/unit/provider/exec/powershell_spec.rb index 41d67622..44cf74d4 100644 --- a/spec/unit/provider/exec/powershell_spec.rb +++ b/spec/unit/provider/exec/powershell_spec.rb @@ -38,6 +38,7 @@ describe "#run" do context "stubbed calls" do before :each do + require 'ruby-pwsh' Pwsh::Manager.stubs(:windows_powershell_supported?).returns(false) Puppet::Provider::Exec.any_instance.stubs(:run) end diff --git a/spec/unit/provider/exec/pwsh_spec.rb b/spec/unit/provider/exec/pwsh_spec.rb index 4a30720f..eb7f0a91 100644 --- a/spec/unit/provider/exec/pwsh_spec.rb +++ b/spec/unit/provider/exec/pwsh_spec.rb @@ -1,6 +1,7 @@ #! /usr/bin/env ruby require 'spec_helper' require 'puppet/util' +require 'ruby-pwsh' describe Puppet::Type.type(:exec).provider(:pwsh) do # Override the run value so we can test the super call From 68e31b3db05170f44ea55afad10d944b43b8b062 Mon Sep 17 00:00:00 2001 From: David Swan Date: Thu, 27 Feb 2020 13:15:26 +0000 Subject: [PATCH 10/20] (maint) - Pdk Update --- .travis.yml | 46 ++++++++++++++++++++-------------------------- metadata.json | 4 ++-- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1df32765..ce91d824 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ script: - 'SIMPLECOV=yes bundle exec rake $CHECK' bundler_args: --without system_tests rvm: - - 2.5.3 + - 2.5.7 env: global: - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" @@ -32,11 +32,10 @@ jobs: - "bundle exec rake 'litmus:provision_list[travis_deb]'" - "bundle exec rake 'litmus:install_agent[puppet5]'" - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty + bundler_args: env: PLATFORMS=travis_deb_puppet5 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - @@ -44,11 +43,10 @@ jobs: - "bundle exec rake 'litmus:provision_list[travis_el]'" - "bundle exec rake 'litmus:install_agent[puppet5]'" - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty + bundler_args: env: PLATFORMS=travis_el_puppet5 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - @@ -56,11 +54,10 @@ jobs: - "bundle exec rake 'litmus:provision_list[travis_ub]'" - "bundle exec rake 'litmus:install_agent[puppet5]'" - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty + bundler_args: env: PLATFORMS=travis_ub_puppet5 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - @@ -68,11 +65,10 @@ jobs: - "bundle exec rake 'litmus:provision_list[travis_deb]'" - "bundle exec rake 'litmus:install_agent[puppet6]'" - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty + bundler_args: env: PLATFORMS=travis_deb_puppet6 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - @@ -80,11 +76,10 @@ jobs: - "bundle exec rake 'litmus:provision_list[travis_el]'" - "bundle exec rake 'litmus:install_agent[puppet6]'" - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty + bundler_args: env: PLATFORMS=travis_el_puppet6 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - @@ -92,11 +87,10 @@ jobs: - "bundle exec rake 'litmus:provision_list[travis_ub]'" - "bundle exec rake 'litmus:install_agent[puppet6]'" - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty + bundler_args: env: PLATFORMS=travis_ub_puppet6 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - @@ -108,7 +102,7 @@ jobs: stage: spec - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec - rvm: 2.5.3 + rvm: 2.5.7 stage: spec - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec diff --git a/metadata.json b/metadata.json index 5f748358..82932619 100644 --- a/metadata.json +++ b/metadata.json @@ -77,7 +77,7 @@ "version_requirement": ">= 5.5.0 < 7.0.0" } ], - "pdk-version": "1.16.0", + "pdk-version": "1.17.0", "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "heads/master-0-g88c96ab" + "template-ref": "1.17.0-0-gd3a4319" } From 693b26731f3db7d04f1dba5ba83fe760ceda36a3 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 1 Apr 2020 19:29:37 +0100 Subject: [PATCH 11/20] Remove system-tests group from Gemfile Neither beaker nor puppet-blacksmith is used anymore. --- .sync.yml | 14 -------------- Gemfile | 7 ------- 2 files changed, 21 deletions(-) diff --git a/.sync.yml b/.sync.yml index b08c4ab4..c19c02e7 100644 --- a/.sync.yml +++ b/.sync.yml @@ -56,19 +56,5 @@ Gemfile: git: https://github.com/skywinder/github-changelog-generator ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') - required: - ":system_tests": - - gem: puppet-module-posix-system-r#{minor_version} - platforms: ruby - - gem: puppet-module-win-system-r#{minor_version} - platforms: - - mswin - - mingw - - x64_mingw - - gem: beaker-testmode_switcher - version: "~> 0.4" - - gem: master_manipulator - - gem: puppet-blacksmith - version: "~> 3.4" spec/spec_helper.rb: coverage_report: true diff --git a/Gemfile b/Gemfile index 75c4a1f3..3378919b 100644 --- a/Gemfile +++ b/Gemfile @@ -31,13 +31,6 @@ group :development do gem "ruby-pwsh", require: false gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') end -group :system_tests do - gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "beaker-testmode_switcher", '~> 0.4', require: false - gem "master_manipulator", require: false - gem "puppet-blacksmith", '~> 3.4', require: false -end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] From 6c440c9696651722461f0eb348c79f24ac2013f1 Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Tue, 5 May 2020 10:06:39 +0300 Subject: [PATCH 12/20] Add net-ssh dependency gems to development group --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index 3378919b..0495f8b3 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,8 @@ group :development do gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "ruby-pwsh", require: false gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') + gem 'ed25519', '>= 1.2', '< 2.0' + gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0' end puppet_version = ENV['PUPPET_GEM_VERSION'] From 812155b7a19259627e7d752e1fa836aa787b4032 Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Mon, 18 May 2020 09:55:48 +0300 Subject: [PATCH 13/20] Change provision from vmpooler to abs --- provision.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provision.yaml b/provision.yaml index 3d0cbbc2..b72870fe 100644 --- a/provision.yaml +++ b/provision.yaml @@ -15,5 +15,5 @@ travis_el: provisioner: docker images: ['waffleimage/centos7'] release_checks: - provisioner: vmpooler + provisioner: abs images: ['redhat-7-x86_64', 'redhat-8-x86_64', 'centos-7-x86_64', 'centos-8-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64', 'win-2012r2-x86_64', 'win-2016-core-x86_64', 'win-2019-core-x86_64'] From cc6ae5edf78009a92d0397b1a393a8d02bd336f4 Mon Sep 17 00:00:00 2001 From: sheena Date: Tue, 26 May 2020 13:46:16 +0100 Subject: [PATCH 14/20] (maint) fix appveyor failures for apply_manifest --- .rubocop.yml | 2 -- .sync.yml | 7 +++++++ .vscode/extensions.json | 2 +- Gemfile | 3 +-- metadata.json | 4 ++-- spec/spec_helper.rb | 1 + 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 0da419f6..055207f5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -465,8 +465,6 @@ Style/BlockComments: Enabled: false Style/BlockDelimiters: Enabled: false -Style/BracesAroundHashParameters: - Enabled: false Style/CaseEquality: Enabled: false Style/CharacterLiteral: diff --git a/.sync.yml b/.sync.yml index c19c02e7..4985728c 100644 --- a/.sync.yml +++ b/.sync.yml @@ -56,5 +56,12 @@ Gemfile: git: https://github.com/skywinder/github-changelog-generator ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') + - gem: bolt + version: = 2.6.0 + condition: Gem::Version.new(RUBY_VERSION.dup) > Gem::Version.new('2.5.0') + platforms: + - mswin + - mingw + - x64_mingw spec/spec_helper.rb: coverage_report: true diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 61777827..2f1e4f73 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,6 @@ { "recommendations": [ - "jpogran.puppet-vscode", + "puppet.puppet-vscode", "rebornix.Ruby" ] } diff --git a/Gemfile b/Gemfile index 0495f8b3..8df55a61 100644 --- a/Gemfile +++ b/Gemfile @@ -30,8 +30,7 @@ group :development do gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "ruby-pwsh", require: false gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') - gem 'ed25519', '>= 1.2', '< 2.0' - gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0' + gem "bolt", '= 2.6.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] if Gem::Version.new(RUBY_VERSION.dup) > Gem::Version.new('2.5.0') end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/metadata.json b/metadata.json index 82932619..791b6d8e 100644 --- a/metadata.json +++ b/metadata.json @@ -77,7 +77,7 @@ "version_requirement": ">= 5.5.0 < 7.0.0" } ], - "pdk-version": "1.17.0", + "pdk-version": "1.18.0", "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "1.17.0-0-gd3a4319" + "template-ref": "heads/master-0-g88b05c7" } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f028d577..1ab2e123 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,6 +38,7 @@ # set to strictest setting for testing # by default Puppet runs at warning level Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do From dc8cdb8f8bdd137b6f1e05e3b9ed647511f08b0d Mon Sep 17 00:00:00 2001 From: sheena Date: Fri, 19 Jun 2020 17:20:58 +0100 Subject: [PATCH 15/20] (maint) Remove bolt gem from sync.yaml file --- .sync.yml | 7 ------- Gemfile | 1 - metadata.json | 2 +- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.sync.yml b/.sync.yml index 4985728c..c19c02e7 100644 --- a/.sync.yml +++ b/.sync.yml @@ -56,12 +56,5 @@ Gemfile: git: https://github.com/skywinder/github-changelog-generator ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') - - gem: bolt - version: = 2.6.0 - condition: Gem::Version.new(RUBY_VERSION.dup) > Gem::Version.new('2.5.0') - platforms: - - mswin - - mingw - - x64_mingw spec/spec_helper.rb: coverage_report: true diff --git a/Gemfile b/Gemfile index 8df55a61..3378919b 100644 --- a/Gemfile +++ b/Gemfile @@ -30,7 +30,6 @@ group :development do gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "ruby-pwsh", require: false gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') - gem "bolt", '= 2.6.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] if Gem::Version.new(RUBY_VERSION.dup) > Gem::Version.new('2.5.0') end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/metadata.json b/metadata.json index 791b6d8e..7f81526e 100644 --- a/metadata.json +++ b/metadata.json @@ -79,5 +79,5 @@ ], "pdk-version": "1.18.0", "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "heads/master-0-g88b05c7" + "template-ref": "heads/master-0-g9c14433" } From 9c9b5427fa8467889c5b0238c16336b4dc019d27 Mon Sep 17 00:00:00 2001 From: sanfrancrisko <55992494+sanfrancrisko@users.noreply.github.com> Date: Mon, 30 Mar 2020 10:11:16 +0100 Subject: [PATCH 16/20] (maint) Remove interpolate_powershell method This was added to Litmus so we can remove it here. Also keeps this one from diverging if the Litmus version changes. Use full namespace method call Convert to fully qualified namespace method calls Include 'puppet_litmus/util' Fix interpolate_powershell method ref (maint) Fix typo (maint) Fix another typo! --- spec/acceptance/exec_powershell_spec.rb | 6 +++--- spec/acceptance/exec_pwsh_spec.rb | 6 +++--- spec/spec_helper_acceptance_local.rb | 8 ++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/spec/acceptance/exec_powershell_spec.rb b/spec/acceptance/exec_powershell_spec.rb index d1df8833..1ebc4537 100644 --- a/spec/acceptance/exec_powershell_spec.rb +++ b/spec/acceptance/exec_powershell_spec.rb @@ -243,8 +243,8 @@ } after(:each) do - run_shell(interpolate_powershell("Remove-Item Env:\\superspecial -ErrorAction Ignore;exit 0")) - run_shell(interpolate_powershell("Remove-Item Env:\\outside -ErrorAction Ignore;exit 0")) + run_shell(PuppetLitmus::Util.interpolate_powershell("Remove-Item Env:\\superspecial -ErrorAction Ignore;exit 0")) + run_shell(PuppetLitmus::Util.interpolate_powershell("Remove-Item Env:\\outside -ErrorAction Ignore;exit 0")) end it 'should not see environment variable from previous run' do @@ -258,7 +258,7 @@ it 'should see environment variables set outside of session' do # Setup the environment variable outside of Puppet - run_shell(interpolate_powershell("$env:outside='1'")) + run_shell(PuppetLitmus::Util.interpolate_powershell("$env:outside='1'")) # Test to see if initial run sees the environment variable apply_manifest(envar_leak_test_pp, expect_changes: true) diff --git a/spec/acceptance/exec_pwsh_spec.rb b/spec/acceptance/exec_pwsh_spec.rb index d7bf30f9..afccb888 100644 --- a/spec/acceptance/exec_pwsh_spec.rb +++ b/spec/acceptance/exec_pwsh_spec.rb @@ -280,8 +280,8 @@ def platform_string(windows, posix) after(:each) do # Due to https://tickets.puppetlabs.com/browse/BKR-1088, need to use different commands if windows_platform? - run_shell(interpolate_powershell("Remove-Item Env:\\superspecial -ErrorAction Ignore;exit 0")) - run_shell(interpolate_powershell("Remove-Item Env:\\outside -ErrorAction Ignore;exit 0")) + run_shell(PuppetLitmus::Util.interpolate_powershell("Remove-Item Env:\\superspecial -ErrorAction Ignore;exit 0")) + run_shell(PuppetLitmus::Util.interpolate_powershell("Remove-Item Env:\\outside -ErrorAction Ignore;exit 0")) else run_shell('unset superspecial') run_shell('unset outside') @@ -301,7 +301,7 @@ def platform_string(windows, posix) # Due to https://tickets.puppetlabs.com/browse/BKR-1088, need to use different commands if windows_platform? - run_shell(interpolate_powershell("\$env:outside='1'")) + run_shell(PuppetLitmus::Util.interpolate_powershell("\$env:outside='1'")) else run_shell('export outside=1') end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index acef323d..3fb5a1d4 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -1,4 +1,5 @@ require 'puppet_litmus' +require 'puppet_litmus/util' require 'singleton' class Helper @@ -32,7 +33,7 @@ def uninstall_pwsh when 'darwin' 'brew cask uninstall powershell' when 'windows' - interpolate_powershell('Get-Command pwsh | ForEach-Object { Remove-Item -Path (Split-Path -Parent $_.Path) -Recurse -Force }') + PuppetLitmus::Util.interpolate_powershell('Get-Command pwsh | ForEach-Object { Remove-Item -Path (Split-Path -Parent $_.Path) -Recurse -Force }') end Helper.instance.run_shell(command) end @@ -50,11 +51,6 @@ def cleanup_files Helper.instance.apply_manifest(absent_files_manifest, catch_failures: true) end -def interpolate_powershell(command) - encoded_command = Base64.strict_encode64(command.encode('UTF-16LE')) - "powershell.exe -NoProfile -EncodedCommand #{encoded_command}" -end - def relative_folder(relative_path) expanded_path = File.expand_path(File.join(File.dirname(__FILE__), relative_path)) Dir.open(expanded_path) if File.exist?(expanded_path) From 4dc69baa9d79434cbc697578aec66cc63e51d1fd Mon Sep 17 00:00:00 2001 From: David Swan Date: Tue, 2 Jun 2020 10:08:45 +0100 Subject: [PATCH 17/20] (IAC-848) - Support added for CentOS 8 and RHEL 8 --- metadata.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/metadata.json b/metadata.json index 7f81526e..643259d9 100644 --- a/metadata.json +++ b/metadata.json @@ -31,7 +31,8 @@ { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "7" + "7", + "8" ] }, { @@ -59,7 +60,8 @@ { "operatingsystem": "RedHat", "operatingsystemrelease": [ - "7" + "7", + "8" ] }, { From 252caa89f0126389d79558e6861f16492d66e38a Mon Sep 17 00:00:00 2001 From: David Swan Date: Tue, 2 Jun 2020 11:37:13 +0100 Subject: [PATCH 18/20] (IAC-847) - Support added for Debian 10 --- metadata.json | 3 ++- .../fixtures/scripts/install_pwsh/debian_10.sh | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/scripts/install_pwsh/debian_10.sh diff --git a/metadata.json b/metadata.json index 643259d9..7124c765 100644 --- a/metadata.json +++ b/metadata.json @@ -39,7 +39,8 @@ "operatingsystem": "Debian", "operatingsystemrelease": [ "8", - "9" + "9", + "10" ] }, { diff --git a/spec/fixtures/scripts/install_pwsh/debian_10.sh b/spec/fixtures/scripts/install_pwsh/debian_10.sh new file mode 100644 index 00000000..a16d61fc --- /dev/null +++ b/spec/fixtures/scripts/install_pwsh/debian_10.sh @@ -0,0 +1,18 @@ +# Install system components +apt-get update +apt-get install -y curl gnupg apt-transport-https + +# Import the public repository GPG keys +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + +# Register the Microsoft Product feed +sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-buster-prod buster main" > /etc/apt/sources.list.d/microsoft.list' + +# Update the list of products +apt-get update + +# Install PowerShell +apt-get install -y powershell + +# List version +pwsh -v From 6b7b6eac9794d323a46175037d119e944b6d1527 Mon Sep 17 00:00:00 2001 From: David Swan Date: Tue, 2 Jun 2020 11:37:55 +0100 Subject: [PATCH 19/20] (maint) - provision/travis cleanup --- .sync.yml | 2 +- .travis.yml | 8 ++++---- provision.yaml | 13 ++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.sync.yml b/.sync.yml index c19c02e7..b0b21a79 100644 --- a/.sync.yml +++ b/.sync.yml @@ -15,7 +15,7 @@ provision_list: - travis_deb - travis_ub - - travis_el + - travis_el7 includes: - os: osx env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec diff --git a/.travis.yml b/.travis.yml index ce91d824..30150baf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,11 +40,11 @@ jobs: stage: acceptance - before_script: - - "bundle exec rake 'litmus:provision_list[travis_el]'" + - "bundle exec rake 'litmus:provision_list[travis_el7]'" - "bundle exec rake 'litmus:install_agent[puppet5]'" - "bundle exec rake litmus:install_module" bundler_args: - env: PLATFORMS=travis_el_puppet5 + env: PLATFORMS=travis_el7_puppet5 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker @@ -73,11 +73,11 @@ jobs: stage: acceptance - before_script: - - "bundle exec rake 'litmus:provision_list[travis_el]'" + - "bundle exec rake 'litmus:provision_list[travis_el7]'" - "bundle exec rake 'litmus:install_agent[puppet6]'" - "bundle exec rake litmus:install_module" bundler_args: - env: PLATFORMS=travis_el_puppet6 + env: PLATFORMS=travis_el7_puppet6 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker diff --git a/provision.yaml b/provision.yaml index b72870fe..99bc1752 100644 --- a/provision.yaml +++ b/provision.yaml @@ -7,13 +7,16 @@ vagrant: images: ['centos/7', 'generic/ubuntu1804', 'generic/debian8', 'gusztavvargadr/windows-server'] travis_deb: provisioner: docker - images: ['waffleimage/debian8', 'waffleimage/debian9'] + images: ['litmusimage/debian:8', 'litmusimage/debian:9', 'litmusimage/debian:10'] travis_ub: provisioner: docker - images: ['waffleimage/ubuntu16.04', 'waffleimage/ubuntu18.04'] -travis_el: + images: ['litmusimage/ubuntu:16.04', 'litmusimage/ubuntu:18.04'] +travis_el6: provisioner: docker - images: ['waffleimage/centos7'] + images: [] +travis_el7: + provisioner: docker + images: ['litmusimage/centos:7'] release_checks: provisioner: abs - images: ['redhat-7-x86_64', 'redhat-8-x86_64', 'centos-7-x86_64', 'centos-8-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64', 'win-2012r2-x86_64', 'win-2016-core-x86_64', 'win-2019-core-x86_64'] + images: ['redhat-7-x86_64', 'redhat-8-x86_64', 'centos-7-x86_64', 'centos-8-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64', 'win-2012r2-x86_64', 'win-2016-core-x86_64', 'win-2019-core-x86_64'] From f1066cb350370fc05a8e177c9080c51e9eb3d7ca Mon Sep 17 00:00:00 2001 From: Michael T Lombardi Date: Tue, 7 Jul 2020 12:04:40 -0500 Subject: [PATCH 20/20] (IAC-949) Release prep for 4.0.0 --- CHANGELOG.md | 16 ++++++++++++++++ metadata.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4c2c596..e2a48ba5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). +## [v4.0.0](https://github.com/puppetlabs/puppetlabs-powershell/tree/v4.0.0) (2020-07-07) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-powershell/compare/v3.0.1...v4.0.0) + +### Changed + +- Correct supported Puppet lower bound to 5.5.0 [\#282](https://github.com/puppetlabs/puppetlabs-powershell/pull/282) ([michaeltlombardi](https://github.com/michaeltlombardi)) + +### Added + +- \(IAC-835\) Support added for Debian 10 and CentOS/RHEL 8 [\#306](https://github.com/puppetlabs/puppetlabs-powershell/pull/306) ([david22swan](https://github.com/david22swan)) + +### Fixed + +- \(MODULES-10539\) Remove commands idiom from PowerShell provider [\#287](https://github.com/puppetlabs/puppetlabs-powershell/pull/287) ([michaeltlombardi](https://github.com/michaeltlombardi)) + ## [v3.0.1](https://github.com/puppetlabs/puppetlabs-powershell/tree/v3.0.1) (2020-01-15) [Full Changelog](https://github.com/puppetlabs/puppetlabs-powershell/compare/v3.0.0...v3.0.1) diff --git a/metadata.json b/metadata.json index 7124c765..55595cde 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-powershell", - "version": "3.0.1", + "version": "4.0.0", "author": "puppetlabs", "summary": "Adds a new exec provider for executing PowerShell commands.", "license": "Apache-2.0",