Skip to content

Commit

Permalink
(MODULES-8358) Modify acceptance tests for specific PowerShell Core v…
Browse files Browse the repository at this point in the history
…ersion

Previously the acceptance tests were gated on the `powershell6` role within the
beaker hosts file.  However Beaker Host Generator doesn't understand numbers in
the role name [1].  This commit changes the PowerShell core detection to use
the key/value property `powershell` for each host.  This has the added benefit
to be able to specify the version of powershell core to be tested, not just
latest.

[1] voxpupuli/beaker-hostgenerator#149
  • Loading branch information
glennsarti committed Feb 21, 2019
1 parent b8db256 commit 00ea7b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion spec/acceptance/exec_pwsh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def windows_platform?(host)
!((host.platform =~ /^windows.*$/).nil?)
end

powershell6_agents = hosts_as('powershell6')
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) }

Expand Down
20 changes: 13 additions & 7 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

# 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"
Expand All @@ -30,25 +31,31 @@
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')
on(host,'sudo apt-get install -y powershell')
# 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')
on(host,'sudo apt-get install -y powershell')
# 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')
on(host,'yum install -y powershell')
# e.g. yum install -y powershell-6.1.2
yum_text = "-#{ps_version}" unless ps_version.nil?
on(host,"sudo apt-get install -y powershell#{yum_text}")
when /^windows/
# Install PowerShell 6 if needed
if hosts_as('powershell6').map { |item| item.name }.include?(host.name)
on(host,'powershell -NoLogo -NoProfile -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri https://github.com/PowerShell/PowerShell/releases/download/v6.1.2/PowerShell-6.1.2-win-x64.msi -OutFile C:\\PS612.msi -UseBasicParsing"')
on(host,'msiexec.exe /i C:\\\\PS612.msi /qn ALLUSERS=1 /l*v C:\\\\PS612-install.log')
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}'")
Expand Down Expand Up @@ -79,4 +86,3 @@
apply_manifest_on(posix_agents, absent_files, :catch_failures => true) if posix_agents.count > 0
end
end

0 comments on commit 00ea7b4

Please sign in to comment.