From b1895c00ffb91fc670b821b94968cda8ed9cb3a6 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Thu, 9 Feb 2017 14:14:31 -0800 Subject: [PATCH 1/3] (maint) Change InstallChocolatey ERB to be LF line endings Previously in commit d102498b98, the git attributes file was modified to enforce all ERB files have LF line endings. However the InstallChocolatey.ps.erb file had already been checked in with CRLF. This caused the file to always be marked as changed when checked out on Windows. This commit changes the line ending to be LF instead of CRLF, to be inline with .gitattributes. --- templates/InstallChocolatey.ps1.erb | 302 ++++++++++++++-------------- 1 file changed, 151 insertions(+), 151 deletions(-) diff --git a/templates/InstallChocolatey.ps1.erb b/templates/InstallChocolatey.ps1.erb index d9ca5921..5a2bff64 100644 --- a/templates/InstallChocolatey.ps1.erb +++ b/templates/InstallChocolatey.ps1.erb @@ -1,151 +1,151 @@ -# ============================================================================== -# Copyright 2011 - Present RealDimensions Software, LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# ============================================================================== - -$ErrorActionPreference = 'Stop' - -# For some reason try/catch wrapping only ensures -# that none of this script runs at all -# https://tickets.puppetlabs.com/browse/MODULES-2634 -#try { - -# variables -$url = '<%= @download_url %>' -$unzipMethod = '<%= @unzip_type %>' -if ($env:TEMP -eq $null) { - $env:TEMP = Join-Path $env:SystemDrive 'temp' -} -$chocTempDir = Join-Path $env:TEMP "chocolatey" -$tempDir = Join-Path $chocTempDir "chocInstall" -if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateDirectory($tempDir)} -$file = Join-Path $tempDir "chocolatey.zip" -$chocErrorLog = Join-Path $tempDir "chocError.log" - -# PowerShell v2/3 caches the output stream. Then it throws errors due -# to the FileStream not being what is expected. Fixes "The OS handle's -# position is not what FileStream expected. Do not use a handle -# simultaneously in one FileStream and in Win32 code or another -# FileStream." - -# This only works with the ConsoleHost (PowerShell InternalHost) -function Fix-PowerShellOutputRedirectionBug { - try{ - # http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments - $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" - $objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host) - $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty" - $consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @()) - [void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @()) - $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" - $field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags) - $field.SetValue($consoleHost, [Console]::Out) - [void] $consoleHost.GetType().GetProperty("IsStandardErrorRedirected", $bindingFlags).GetValue($consoleHost, @()) - $field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags) - $field2.SetValue($consoleHost, [Console]::Error) - } catch { - Write-Output "Unable to apply redirection fix. Error: $_" - } -} - -Fix-PowerShellOutputRedirectionBug - -# This should help when certain organizations have issues installing Chocolatey -# Attempt to set highest encryption available for SecurityProtocol. -# PowerShell will not set this by default (until maybe .NET 4.6.x). This -# will typically produce a message for PowerShell v2 (just an info -# message though) -try { - # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48) - # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't - # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is - # installed (.NET 4.5 is an in-place upgrade). - [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48 -} catch { - Write-Output "Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to do one or more of the following: (1) upgrade to .NET Framework 4.5 and PowerShell v3 and/or (2) specify internal Chocolatey package location (see https://forge.puppet.com/puppetlabs/chocolatey#manage-chocolatey-installation)." -} - -function Download-File { -param ( - [string]$url, - [string]$file - ) - Write-Output "Downloading $url to $file" - $downloader = new-object System.Net.WebClient - $downloader.Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials; - $downloader.DownloadFile($url, $file) -} - -# download the package -Download-File $url $file - -if ($unzipMethod -eq '7zip') { - # download 7zip - Write-Output "Download 7Zip commandline tool" - $7zaExe = Join-Path $tempDir '7za.exe' - - Download-File 'https://chocolatey.org/7za.exe' "$7zaExe" - - # unzip the package - Write-Output "Extracting $file to $tempDir..." - Start-Process "$7zaExe" -ArgumentList "x -o`"$tempDir`" -y `"$file`"" -Wait -NoNewWindow -} else { - if ($PSVersionTable.PSVersion.Major -lt 5) { - $shellApplication = new-object -com shell.application - $zipPackage = $shellApplication.NameSpace($file) - $destinationFolder = $shellApplication.NameSpace($tempDir) - $destinationFolder.CopyHere($zipPackage.Items(),0x10) - } else { - Expand-Archive -Path "$file" -DestinationPath "$tempDir" -Force | Out-Null - } -} - -# call chocolatey install -Write-Output "Installing chocolatey on this machine" -$toolsFolder = Join-Path $tempDir "tools" -$chocInstallPS1 = Join-Path $toolsFolder "chocolateyInstall.ps1" - -if ($PSVersionTable.PSVersion.Major -gt 2) { - & $chocInstallPS1 -} else { - $output = Invoke-Expression $chocInstallPS1 - $output - Write-Output "Any errors that occured during install or upgrade are logged here: $chocoErrorLog" - $error | out-file $chocErrorLog -} - -Write-Output 'Ensuring chocolatey commands are on the path' -$chocInstallVariableName = "ChocolateyInstall" -$chocoPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::User) -if ($chocoPath -eq $null -or $chocoPath -eq '') { - $chocoPath = 'C:\ProgramData\Chocolatey' -} - -$chocoBinPath = Join-Path $chocoPath 'bin' - -if ($($env:Path).ToLower().Contains($($chocoBinPath).ToLower()) -eq $false) { - $env:Path = [Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine); -} - -Write-Output 'Ensuring chocolatey.nupkg is in the lib folder' -$chocoPkgDir = Join-Path $chocoPath 'lib\chocolatey' -$nupkg = Join-Path $chocoPkgDir 'chocolatey.nupkg' -if (![System.IO.Directory]::Exists($chocoPkgDir)) { [System.IO.Directory]::CreateDirectory($chocoPkgDir); } -Copy-Item "$file" "$nupkg" -Force -ErrorAction SilentlyContinue - -#} -#catch -#{ -# Write-Host "$($_.Exception.Message)" -# exit 1 -#} +# ============================================================================== +# Copyright 2011 - Present RealDimensions Software, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# ============================================================================== + +$ErrorActionPreference = 'Stop' + +# For some reason try/catch wrapping only ensures +# that none of this script runs at all +# https://tickets.puppetlabs.com/browse/MODULES-2634 +#try { + +# variables +$url = '<%= @download_url %>' +$unzipMethod = '<%= @unzip_type %>' +if ($env:TEMP -eq $null) { + $env:TEMP = Join-Path $env:SystemDrive 'temp' +} +$chocTempDir = Join-Path $env:TEMP "chocolatey" +$tempDir = Join-Path $chocTempDir "chocInstall" +if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateDirectory($tempDir)} +$file = Join-Path $tempDir "chocolatey.zip" +$chocErrorLog = Join-Path $tempDir "chocError.log" + +# PowerShell v2/3 caches the output stream. Then it throws errors due +# to the FileStream not being what is expected. Fixes "The OS handle's +# position is not what FileStream expected. Do not use a handle +# simultaneously in one FileStream and in Win32 code or another +# FileStream." + +# This only works with the ConsoleHost (PowerShell InternalHost) +function Fix-PowerShellOutputRedirectionBug { + try{ + # http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" + $objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host) + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty" + $consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @()) + [void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @()) + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" + $field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags) + $field.SetValue($consoleHost, [Console]::Out) + [void] $consoleHost.GetType().GetProperty("IsStandardErrorRedirected", $bindingFlags).GetValue($consoleHost, @()) + $field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags) + $field2.SetValue($consoleHost, [Console]::Error) + } catch { + Write-Output "Unable to apply redirection fix. Error: $_" + } +} + +Fix-PowerShellOutputRedirectionBug + +# This should help when certain organizations have issues installing Chocolatey +# Attempt to set highest encryption available for SecurityProtocol. +# PowerShell will not set this by default (until maybe .NET 4.6.x). This +# will typically produce a message for PowerShell v2 (just an info +# message though) +try { + # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48) + # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't + # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is + # installed (.NET 4.5 is an in-place upgrade). + [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48 +} catch { + Write-Output "Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to do one or more of the following: (1) upgrade to .NET Framework 4.5 and PowerShell v3 and/or (2) specify internal Chocolatey package location (see https://forge.puppet.com/puppetlabs/chocolatey#manage-chocolatey-installation)." +} + +function Download-File { +param ( + [string]$url, + [string]$file + ) + Write-Output "Downloading $url to $file" + $downloader = new-object System.Net.WebClient + $downloader.Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials; + $downloader.DownloadFile($url, $file) +} + +# download the package +Download-File $url $file + +if ($unzipMethod -eq '7zip') { + # download 7zip + Write-Output "Download 7Zip commandline tool" + $7zaExe = Join-Path $tempDir '7za.exe' + + Download-File 'https://chocolatey.org/7za.exe' "$7zaExe" + + # unzip the package + Write-Output "Extracting $file to $tempDir..." + Start-Process "$7zaExe" -ArgumentList "x -o`"$tempDir`" -y `"$file`"" -Wait -NoNewWindow +} else { + if ($PSVersionTable.PSVersion.Major -lt 5) { + $shellApplication = new-object -com shell.application + $zipPackage = $shellApplication.NameSpace($file) + $destinationFolder = $shellApplication.NameSpace($tempDir) + $destinationFolder.CopyHere($zipPackage.Items(),0x10) + } else { + Expand-Archive -Path "$file" -DestinationPath "$tempDir" -Force | Out-Null + } +} + +# call chocolatey install +Write-Output "Installing chocolatey on this machine" +$toolsFolder = Join-Path $tempDir "tools" +$chocInstallPS1 = Join-Path $toolsFolder "chocolateyInstall.ps1" + +if ($PSVersionTable.PSVersion.Major -gt 2) { + & $chocInstallPS1 +} else { + $output = Invoke-Expression $chocInstallPS1 + $output + Write-Output "Any errors that occured during install or upgrade are logged here: $chocoErrorLog" + $error | out-file $chocErrorLog +} + +Write-Output 'Ensuring chocolatey commands are on the path' +$chocInstallVariableName = "ChocolateyInstall" +$chocoPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::User) +if ($chocoPath -eq $null -or $chocoPath -eq '') { + $chocoPath = 'C:\ProgramData\Chocolatey' +} + +$chocoBinPath = Join-Path $chocoPath 'bin' + +if ($($env:Path).ToLower().Contains($($chocoBinPath).ToLower()) -eq $false) { + $env:Path = [Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine); +} + +Write-Output 'Ensuring chocolatey.nupkg is in the lib folder' +$chocoPkgDir = Join-Path $chocoPath 'lib\chocolatey' +$nupkg = Join-Path $chocoPkgDir 'chocolatey.nupkg' +if (![System.IO.Directory]::Exists($chocoPkgDir)) { [System.IO.Directory]::CreateDirectory($chocoPkgDir); } +Copy-Item "$file" "$nupkg" -Force -ErrorAction SilentlyContinue + +#} +#catch +#{ +# Write-Host "$($_.Exception.Message)" +# exit 1 +#} From 93f696aad7f4c903623c7f3f7b4c52d2a55a3fff Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Thu, 9 Feb 2017 09:02:32 -0800 Subject: [PATCH 2/3] Revert "MODULES-3302 add Rototiller to Rakefile" This reverts commit f345f5e697ece4dc23e07af0f001188cc4634d85. --- Gemfile | 2 - Rakefile | 164 ++++++++------------- tests/test_run_scripts/acceptance_tests.sh | 68 +++++++++ tests/test_run_scripts/reference_tests.sh | 65 ++++++++ 4 files changed, 191 insertions(+), 108 deletions(-) create mode 100644 tests/test_run_scripts/acceptance_tests.sh create mode 100644 tests/test_run_scripts/reference_tests.sh diff --git a/Gemfile b/Gemfile index 6aeb7a9a..4c2843d2 100644 --- a/Gemfile +++ b/Gemfile @@ -72,8 +72,6 @@ group :system_tests do gem 'beaker-hostgenerator', *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION']) gem 'beaker-abs', *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1') gem 'beaker-windows', '~> 0.6', :require => false - gem 'rototiller', '~> 1.0.0', :require => false - end gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION']) diff --git a/Rakefile b/Rakefile index 2705e1a7..a93ef41b 100644 --- a/Rakefile +++ b/Rakefile @@ -39,115 +39,67 @@ RSpec::Core::RakeTask.new(:coverage) do |t| t.rcov_opts = ['--exclude', 'spec'] end + +platform = ENV["PLATFORM"] + +# Create the directory, if it exists already you'll get an error, but this should not stop the execution begin - require 'rototiller' - default_reference_platform = 'windows2012r2-64' - default_acceptance_platform = 'centos7-64mdca-windows2012r2-64a' - internal_pe_host_location = 'http://neptune.puppetlabs.lan/' - internal_pe_version = '2016.5/ci-ready/' - - # Modify a rototiller command and add the common testing options - def add_common_beaker_options_to(command) - command.add_option do |debug| - debug.name = '--debug' - end - command.add_option do |preserve_hosts| - preserve_hosts.name = '--preserve-hosts' - preserve_hosts.add_argument do |arg| - arg.name = 'never' - arg.add_env({:name => 'BEAKER_PRESERVEHOSTS', :message => 'Override the --preserve-hosts option'}) - end - end - command.add_option do |config| - config.name = '--config' - config.add_argument do |arg| - arg.name = "tests/configs/#{ENV['PLATFORM']}" - end - end - command.add_option do |keyfile| - keyfile.name = '--keyfile' - keyfile.add_argument do |arg| - arg.name = "#{ENV['HOME']}/.ssh/id_rsa-acceptance" - arg.add_env({:name => 'BEAKER_KEYFILE', :message => 'Override the --keyfile option'}) - end - end - command.add_option do |loadpath| - loadpath.name = '--load-path' - loadpath.add_argument do |arg| - arg.name = 'tests/lib' - arg.add_env({:name => 'BEAKER_LOADPATH', :message => 'Override the --load-path option' }) - end - end - end + sh 'mkdir tests/configs' +rescue => e + puts e.message +end - desc 'Generate Beaker Host config' - rototiller_task :host_config, [:default_platform] do |t, args| - t.add_env({:name => 'PLATFORM', :message => 'PLATFORM Must be set. For example "windows2012r2-64"', :default => args[:default_platform]}) - hosts_file = "tests/configs/#{ENV['PLATFORM']}" - t.add_command do |cmd| - cmd.name = 'bundle exec beaker-hostgenerator' - cmd.add_argument({:name => "#{ENV['PLATFORM']} > #{hosts_file}"}) - end - end +desc 'Executes reference tests (agent only) intended for use in CI' +task :reference_tests do + command = "bundle exec beaker-hostgenerator --global-config {masterless=true} #{platform} > tests/configs/#{platform}" # should we assume the "configs" directory is present? + sh command - # Runs the reference tests in agent only configuration - desc 'Executes reference tests (agent only) intended for use in CI' - rototiller_task :reference_tests do |task| - Rake::Task[:host_config].invoke("#{default_reference_platform}") # pass the default_reference_platform to the host_config task - task.add_command do |cmd| - cmd.name = 'bundle exec beaker' - - add_common_beaker_options_to(cmd) - - cmd.add_option do |presuite| - presuite.name = '--pre-suite' - presuite.add_argument do |arg| - arg.name = 'tests/reference/pre-suite' - arg.add_env({:name => 'BEAKER_PRESUITE', :message => 'Override the --pre-suite option'}) - end - end - cmd.add_option do |tests| - tests.name = '--tests' - tests.add_argument do |arg| - arg.name = 'tests/reference/tests' - arg.add_env({:name => 'BEAKER_TESTSUITE', :message => 'Override the --tests option'}) - end - end - cmd.add_option do |type| - type.name = '--type' - type.add_argument do |arg| - arg.name = 'aio' - arg.add_env({:name => 'PLATFORM_TYPE', :message => 'Override the --type option'}) - end - end - end - end + command =<<-EOS +bundle exec beaker \ + --debug \ + --preserve-hosts never \ + --config tests/configs/$PLATFORM \ + --keyfile ~/.ssh/id_rsa-acceptance \ + --load-path tests/lib \ + --type aio \ + --pre-suite tests/reference/pre-suite \ + --tests tests/reference/tests + EOS + sh command +end + +desc 'Executes acceptance tests (master and agent) intended for use in CI' +task :acceptance_tests do + command = "bundle exec beaker-hostgenerator #{platform} > tests/configs/#{platform}" + sh command - desc 'Executes acceptance tests (master and agent) intended for use in CI' - rototiller_task :acceptance_tests do |task| - Rake::Task[:host_config].invoke("#{default_acceptance_platform}") # pass the default_acceptance_platform to the host_config task - task.add_env({:name => 'BEAKER_PE_DIR', :message => 'BEAKER_PE_DIR Must be set.', :default => internal_pe_host_location + internal_pe_version}) - task.add_command do |cmd| - cmd.name = 'bundle exec beaker' - - add_common_beaker_options_to(cmd) - - cmd.add_option do |presuite| - presuite.name = '--pre-suite' - presuite.add_argument do |arg| - arg.name = 'tests/acceptance/pre-suite' - arg.add_env({:name => 'BEAKER_PRESUITE', :message => 'Override the --pre-suite option'}) - end - end - cmd.add_option do |tests| - tests.name = '--tests' - tests.add_argument do |arg| - arg.name = 'tests/acceptance/tests' - arg.add_env({:name => 'BEAKER_TESTSUITE', :message => 'Override the --tests option'}) - end - end - end + command =<<-EOS +bundle exec beaker \ + --debug \ + --preserve-hosts never \ + --config tests/configs/$PLATFORM \ + --keyfile ~/.ssh/id_rsa-acceptance \ + --load-path tests/lib \ + --pre-suite tests/acceptance/pre-suite \ + --tests tests/acceptance/tests + EOS + sh command +end + +task :acceptance_tests => [:basic_enviroment_variable_check, :acceptance_enviroment_varible_check] +task :reference_tests => [:basic_enviroment_variable_check] + +task :basic_enviroment_variable_check do + abort('PLATFORM variable not present, aborting test.') unless ENV["PLATFORM"] + abort('MODULE_VERSION variable not present, aborting test.') unless ENV["MODULE_VERSION"] +end + +task :acceptance_enviroment_varible_check do + if ENV["BEAKER_PE_DIR"] && ENV["PE_DIST_DIR"] + abort('Either BEAKER_PE_DIR or PE_DIST_DIR variable should be set but not both, aborting test.') + end + if !ENV["BEAKER_PE_DIR"] && !ENV["PE_DIST_DIR"] + abort('Neither BEAKER_PE_DIR or PE_DIST_DIR variable is set, aborting test.') end -rescue LoadError - #Do nothing, rototiller only installed with system_tests group end + diff --git a/tests/test_run_scripts/acceptance_tests.sh b/tests/test_run_scripts/acceptance_tests.sh new file mode 100644 index 00000000..d1c11a4e --- /dev/null +++ b/tests/test_run_scripts/acceptance_tests.sh @@ -0,0 +1,68 @@ +#!/bin/bash +set -e + +# Init +SCRIPT_PATH=$(pwd) +BASENAME_CMD="basename ${SCRIPT_PATH}" +SCRIPT_BASE_PATH=`eval ${BASENAME_CMD}` +declare -a ARGS + +# Argument Parsing +if [ $# -eq 0 ]; then + ARGS[0]='windows-2012r2-64mda' + ARGS[1]='http://pe-releases.puppetlabs.lan/2016.1.1/' + ARGS[2]='forge' +elif [[ $# -lt 3 || $# -gt 4 ]]; then + echo 'USAGE acceptance_tests.sh ' + exit 1 +else + ARGS=("$@") +fi + +# Figure out where we are in the directory hierarchy +if [ $SCRIPT_BASE_PATH = "test_run_scripts" ]; then + cd ../../ +fi + +# Determine if the forge is needed for the test. +if [ ${ARGS[2]} == 'forge' ]; then + echo 'Testing Module Using Forge Package' + export BEAKER_FORGE_HOST=api-module-staging.puppetlabs.com +elif [ ${ARGS[2]} == 'local' ]; then + echo 'Testing Module Using Local Code' +else + echo 'You must specify "forge" or "local" for test type!' + echo 'USAGE acceptance_tests.sh ' + exit 1 +fi + +# Determine if a module version was specified. +if [ -n "${ARGS[3]}" ]; then + echo "Using Module Version: ${ARGS[3]}" + export MODULE_VERSION=${ARGS[3]} +elif [[ $# -eq 3 && ${ARGS[2]} == 'forge' ]]; then + echo 'WARNING: Running Acceptance Tests from Forge without Module Version!' +fi + +# Sleep so the user has time to read script messages. +sleep 2 + +export pe_dist_dir=${ARGS[1]} +export GEM_SOURCE=http://rubygems.delivery.puppetlabs.net + +bundle install --without build development test --path .bundle/gems + +bundle exec beaker \ + --preserve-hosts onfail \ + --config tests/configs/${ARGS[0]} \ + --debug \ + --tests tests/acceptance/tests \ + --keyfile ~/.ssh/id_rsa-acceptance \ + --pre-suite tests/acceptance/pre-suite \ + --load-path tests/lib + +TEST_RESULT=$? + +rm -rf tmp + +exit $TEST_RESULT diff --git a/tests/test_run_scripts/reference_tests.sh b/tests/test_run_scripts/reference_tests.sh new file mode 100644 index 00000000..f48088eb --- /dev/null +++ b/tests/test_run_scripts/reference_tests.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +set -e + +# Init +SCRIPT_PATH=$(pwd) +BASENAME_CMD="basename ${SCRIPT_PATH}" +SCRIPT_BASE_PATH=`eval ${BASENAME_CMD}` +declare -a ARGS + +# Argument Parsing +if [ $# -eq 0 ]; then + ARGS[0]='windows-2012r2-64a' + ARGS[1]='1.4.1' + ARGS[2]='local' +elif [[ $# -lt 3 || $# -gt 4 ]]; then + echo 'USAGE reference_tests.sh ' + exit 1 +else + ARGS=("$@") +fi + +# Figure out where we are in the directory hierarchy +if [ $SCRIPT_BASE_PATH = "test_run_scripts" ]; then + cd ../../ +fi + +# Determine if the forge is needed for the test. +if [ ${ARGS[2]} == 'forge' ]; then + echo 'Testing Module Using Forge Package' + export BEAKER_FORGE_HOST=api-module-staging.puppetlabs.com +elif [ ${ARGS[2]} == 'local' ]; then + echo 'Testing Module Using Local Code' +else + echo 'You must specify "forge" or "local" for test type!' + echo 'USAGE reference_tests.sh ' + exit 1 +fi + +# Determine if a module version was specified. +if [ -n "${ARGS[3]}" ]; then + echo "Using Module Version: ${ARGS[3]}" + export MODULE_VERSION=${ARGS[3]} +elif [[ $# -eq 3 && ${ARGS[2]} == 'forge' ]]; then + echo 'WARNING: Running Reference Tests from Forge without Module Version!' +fi + +# Sleep so the user has time to read script messages. +sleep 2 + +export BEAKER_PUPPET_AGENT_VERSION=${ARGS[1]} +export GEM_SOURCE=http://rubygems.delivery.puppetlabs.net + +bundle install --without build development test --path .bundle/gems + +bundle exec beaker \ + --preserve-hosts onfail \ + --config tests/configs/${ARGS[0]} \ + --debug \ + --tests tests/reference/tests \ + --keyfile ~/.ssh/id_rsa-acceptance \ + --pre-suite tests/reference/pre-suite \ + --load-path tests/lib \ + --type aio + \ No newline at end of file From 7989b4eee7c4718a88c29fe80054c75bcb100f1f Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Thu, 9 Feb 2017 11:47:40 -0800 Subject: [PATCH 3/3] (maint) Only create tests/configs directory when needed Previously the Rakefile would try and create the `tests/configs` directory when invoked regardless whether it was required or not. This also caused issues with other rake tasks which expect to output information to STDOUT but get's polluted by the error message `mkdir: cannot create directory `tests/configs': File exists` because that directory is already in the repository. This commit: - Only creates the directory if it doesn't exist already - Uses the ruby implementation instead of shell commands so that it works on Windows --- Rakefile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index a93ef41b..31205a6d 100644 --- a/Rakefile +++ b/Rakefile @@ -43,11 +43,8 @@ end platform = ENV["PLATFORM"] # Create the directory, if it exists already you'll get an error, but this should not stop the execution -begin - sh 'mkdir tests/configs' -rescue => e - puts e.message -end +test_configpath = File.join(File.join(Pathname.new(__FILE__).dirname,'tests'),'configs') +FileUtils.mkdir_p(test_configpath) unless Dir.exist? test_configpath desc 'Executes reference tests (agent only) intended for use in CI' task :reference_tests do