[TEST] packaging tests: clean up Vagrantfile (#28173)

* Consolidates provision steps so it's more clear which steps are
applied to all boxes
* Removes duplicate configuration that was being stomped
* Ensure rsync, a dependency for platform steps, is installed on linux
* Ruby style changes

For #26741
This commit is contained in:
Andy Bristol 2018-02-02 12:04:45 -08:00 committed by GitHub
parent 875bbfe699
commit 13083e27da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 209 additions and 156 deletions

361
Vagrantfile vendored
View File

@ -21,83 +21,226 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
define_opts = {
autostart: false
}.freeze
Vagrant.configure(2) do |config| Vagrant.configure(2) do |config|
config.vm.define "ubuntu-1404" do |config|
config.vm.box = "elastic/ubuntu-14.04-x86_64" config.vm.provider 'virtualbox' do |vbox|
ubuntu_common config # Give the box more memory and cpu because our tests are beasts!
vbox.memory = Integer(ENV['VAGRANT_MEMORY'] || 8192)
vbox.cpus = Integer(ENV['VAGRANT_CPUS'] || 4)
end end
config.vm.define "ubuntu-1604" do |config|
config.vm.box = "elastic/ubuntu-16.04-x86_64" # Switch the default share for the project root from /vagrant to
ubuntu_common config, extra: <<-SHELL # /elasticsearch because /vagrant is confusing when there is a project inside
# the elasticsearch project called vagrant....
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.synced_folder '.', '/elasticsearch'
# Expose project directory. Note that VAGRANT_CWD may not be the same as Dir.pwd
PROJECT_DIR = ENV['VAGRANT_PROJECT_DIR'] || Dir.pwd
config.vm.synced_folder PROJECT_DIR, '/project'
'ubuntu-1404'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = 'elastic/ubuntu-14.04-x86_64'
deb_common config, box
end
end
'ubuntu-1604'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = 'elastic/ubuntu-16.04-x86_64'
deb_common config, box, extra: <<-SHELL
# Install Jayatana so we can work around it being present. # Install Jayatana so we can work around it being present.
[ -f /usr/share/java/jayatanaag.jar ] || install jayatana [ -f /usr/share/java/jayatanaag.jar ] || install jayatana
SHELL SHELL
end end
end
# Wheezy's backports don't contain Openjdk 8 and the backflips # Wheezy's backports don't contain Openjdk 8 and the backflips
# required to get the sun jdk on there just aren't worth it. We have # required to get the sun jdk on there just aren't worth it. We have
# jessie and stretch for testing debian and it works fine. # jessie and stretch for testing debian and it works fine.
config.vm.define "debian-8" do |config| 'debian-8'.tap do |box|
config.vm.box = "elastic/debian-8-x86_64" config.vm.define box, define_opts do |config|
deb_common config config.vm.box = 'elastic/debian-8-x86_64'
deb_common config, box
end end
config.vm.define "debian-9" do |config|
config.vm.box = "elastic/debian-9-x86_64"
deb_common config
end end
config.vm.define "centos-6" do |config| 'debian-9'.tap do |box|
config.vm.box = "elastic/centos-6-x86_64" config.vm.define box, define_opts do |config|
rpm_common config config.vm.box = 'elastic/debian-9-x86_64'
deb_common config, box
end end
config.vm.define "centos-7" do |config|
config.vm.box = "elastic/centos-7-x86_64"
rpm_common config
end end
config.vm.define "oel-6" do |config| 'centos-6'.tap do |box|
config.vm.box = "elastic/oraclelinux-6-x86_64" config.vm.define box, define_opts do |config|
rpm_common config config.vm.box = 'elastic/centos-6-x86_64'
rpm_common config, box
end end
config.vm.define "oel-7" do |config|
config.vm.box = "elastic/oraclelinux-7-x86_64"
rpm_common config
end end
config.vm.define "fedora-26" do |config| 'centos-7'.tap do |box|
config.vm.box = "elastic/fedora-26-x86_64" config.vm.define box, define_opts do |config|
dnf_common config config.vm.box = 'elastic/centos-7-x86_64'
rpm_common config, box
end end
config.vm.define "fedora-27" do |config|
config.vm.box = "elastic/fedora-27-x86_64"
dnf_common config
end end
config.vm.define "opensuse-42" do |config| 'oel-6'.tap do |box|
config.vm.box = "elastic/opensuse-42-x86_64" config.vm.define box, define_opts do |config|
opensuse_common config config.vm.box = 'elastic/oraclelinux-6-x86_64'
rpm_common config, box
end end
config.vm.define "sles-12" do |config|
config.vm.box = "elastic/sles-12-x86_64"
sles_common config
end end
# Switch the default share for the project root from /vagrant to 'oel-7'.tap do |box|
# /elasticsearch because /vagrant is confusing when there is a project inside config.vm.define box, define_opts do |config|
# the elasticsearch project called vagrant.... config.vm.box = 'elastic/oraclelinux-7-x86_64'
config.vm.synced_folder ".", "/vagrant", disabled: true rpm_common config, box
config.vm.synced_folder ".", "/elasticsearch"
# Expose project directory
PROJECT_DIR = ENV['VAGRANT_PROJECT_DIR'] || Dir.pwd
config.vm.synced_folder PROJECT_DIR, "/project"
config.vm.provider "virtualbox" do |v|
# Give the boxes 3GB because Elasticsearch defaults to using 2GB
v.memory = 3072
end end
if Vagrant.has_plugin?("vagrant-cachier") end
'fedora-26'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = 'elastic/fedora-26-x86_64'
dnf_common config, box
end
end
'fedora-27'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = 'elastic/fedora-27-x86_64'
dnf_common config, box
end
end
'opensuse-42'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = 'elastic/opensuse-42-x86_64'
suse_common config, box
end
end
'sles-12'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = 'elastic/sles-12-x86_64'
sles_common config, box
end
end
end
def deb_common(config, name, extra: '')
# http://foo-o-rama.com/vagrant--stdin-is-not-a-tty--fix.html
config.vm.provision 'fix-no-tty', type: 'shell' do |s|
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
linux_common(
config,
name,
update_command: 'apt-get update',
update_tracking_file: '/var/cache/apt/archives/last_update',
install_command: 'apt-get install -y',
extra: extra
)
end
def rpm_common(config, name)
linux_common(
config,
name,
update_command: 'yum check-update',
update_tracking_file: '/var/cache/yum/last_update',
install_command: 'yum install -y'
)
end
def dnf_common(config, name)
# Autodetect doesn't work....
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.auto_detect = false
config.cache.enable :generic, { :cache_dir => '/var/cache/dnf' }
end
linux_common(
config,
name,
update_command: 'dnf check-update',
update_tracking_file: '/var/cache/dnf/last_update',
install_command: 'dnf install -y',
install_command_retries: 5
)
end
def suse_common(config, name, extra: '')
linux_common(
config,
name,
update_command: 'zypper --non-interactive list-updates',
update_tracking_file: '/var/cache/zypp/packages/last_update',
install_command: 'zypper --non-interactive --quiet install --no-recommends',
extra: extra
)
end
def sles_common(config, name)
extra = <<-SHELL
zypper rr systemsmanagement_puppet puppetlabs-pc1
zypper --non-interactive install git-core
SHELL
suse_common config, name, extra: extra
end
# Configuration needed for all linux boxes
# @param config Vagrant's config object. Required.
# @param name [String] The box name. Required.
# @param update_command [String] The command used to update the package
# manager. Required. Think `apt-get update`.
# @param update_tracking_file [String] The location of the file tracking the
# last time the update command was run. Required. Should be in a place that
# is cached by vagrant-cachier.
# @param install_command [String] The command used to install a package.
# Required. Think `apt-get install #{package}`.
# @param install_command_retries [Integer] Number of times to retry
# a failed install command
# @param extra [String] Additional script to run before installing
# dependencies
#
def linux_common(config,
name,
update_command: 'required',
update_tracking_file: 'required',
install_command: 'required',
install_command_retries: 0,
extra: '')
raise ArgumentError, 'update_command is required' if update_command == 'required'
raise ArgumentError, 'update_tracking_file is required' if update_tracking_file == 'required'
raise ArgumentError, 'install_command is required' if install_command == 'required'
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :box config.cache.scope = :box
end end
config.vm.defined_vms.each do |name, config|
config.options[:autostart] = false config.vm.provision 'markerfile', type: 'shell', inline: <<-SHELL
set_prompt = lambda do |config| touch /etc/is_vagrant_vm
# Sets up a consistent prompt for all users. Or tries to. The VM might SHELL
# contain overrides for root and vagrant but this attempts to work around
# them by re-source-ing the standard prompt file. # This prevents leftovers from previous tests using the
config.vm.provision "prompt", type: "shell", inline: <<-SHELL # same VM from messing up the current test
config.vm.provision 'clean es installs in tmp', run: 'always', type: 'shell', inline: <<-SHELL
rm -rf /tmp/elasticsearch*
SHELL
sh_set_prompt config, name
sh_install_deps(
config,
update_command,
update_tracking_file,
install_command,
install_command_retries,
extra
)
end
# Sets up a consistent prompt for all users. Or tries to. The VM might
# contain overrides for root and vagrant but this attempts to work around
# them by re-source-ing the standard prompt file.
def sh_set_prompt(config, name)
config.vm.provision 'set prompt', type: 'shell', inline: <<-SHELL
cat \<\<PROMPT > /etc/profile.d/elasticsearch_prompt.sh cat \<\<PROMPT > /etc/profile.d/elasticsearch_prompt.sh
export PS1='#{name}:\\w$ ' export PS1='#{name}:\\w$ '
PROMPT PROMPT
@ -112,101 +255,15 @@ SOURCE_PROMPT
source /etc/profile.d/elasticsearch_prompt.sh source /etc/profile.d/elasticsearch_prompt.sh
SOURCE_PROMPT SOURCE_PROMPT
SHELL SHELL
# Creates a file to mark the machine as created by vagrant. Tests check
# for this file and refuse to run if it is not present so that they can't
# be run unexpectedly.
config.vm.provision "markerfile", type: "shell", inline: <<-SHELL
touch /etc/is_vagrant_vm
SHELL
end
config.config_procs.push ['2', set_prompt]
end
end end
def ubuntu_common(config, extra: '') def sh_install_deps(config,
deb_common config, extra: extra update_command,
end update_tracking_file,
install_command,
def deb_common(config, extra: '') install_command_retries,
# http://foo-o-rama.com/vagrant--stdin-is-not-a-tty--fix.html extra)
config.vm.provision "fix-no-tty", type: "shell" do |s| config.vm.provision 'install dependencies', type: 'shell', inline: <<-SHELL
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
provision(config,
update_command: "apt-get update",
update_tracking_file: "/var/cache/apt/archives/last_update",
install_command: "apt-get install -y",
extra: extra)
end
def rpm_common(config)
provision(config,
update_command: "yum check-update",
update_tracking_file: "/var/cache/yum/last_update",
install_command: "yum install -y")
end
def dnf_common(config)
provision(config,
update_command: "dnf check-update",
update_tracking_file: "/var/cache/dnf/last_update",
install_command: "dnf install -y",
install_command_retries: 5)
if Vagrant.has_plugin?("vagrant-cachier")
# Autodetect doesn't work....
config.cache.auto_detect = false
config.cache.enable :generic, { :cache_dir => "/var/cache/dnf" }
end
end
def opensuse_common(config)
suse_common config, ''
end
def suse_common(config, extra)
provision(config,
update_command: "zypper --non-interactive list-updates",
update_tracking_file: "/var/cache/zypp/packages/last_update",
install_command: "zypper --non-interactive --quiet install --no-recommends",
extra: extra)
end
def sles_common(config)
extra = <<-SHELL
zypper rr systemsmanagement_puppet puppetlabs-pc1
zypper --non-interactive install git-core
SHELL
suse_common config, extra
end
# Register the main box provisioning script.
# @param config Vagrant's config object. Required.
# @param update_command [String] The command used to update the package
# manager. Required. Think `apt-get update`.
# @param update_tracking_file [String] The location of the file tracking the
# last time the update command was run. Required. Should be in a place that
# is cached by vagrant-cachier.
# @param install_command [String] The command used to install a package.
# Required. Think `apt-get install #{package}`.
# @param extra [String] Extra provisioning commands run before anything else.
# Optional. Used for things like setting up the ppa for Java 8.
def provision(config,
update_command: 'required',
update_tracking_file: 'required',
install_command: 'required',
install_command_retries: 0,
extra: '')
# Vagrant run ruby 2.0.0 which doesn't have required named parameters....
raise ArgumentError.new('update_command is required') if update_command == 'required'
raise ArgumentError.new('update_tracking_file is required') if update_tracking_file == 'required'
raise ArgumentError.new('install_command is required') if install_command == 'required'
config.vm.provider "virtualbox" do |v|
# Give the box more memory and cpu because our tests are beasts!
v.memory = Integer(ENV['VAGRANT_MEMORY'] || 8192)
v.cpus = Integer(ENV['VAGRANT_CPUS'] || 4)
end
config.vm.provision "dependencies", type: "shell", inline: <<-SHELL
set -e set -e
set -o pipefail set -o pipefail
@ -253,12 +310,13 @@ def provision(config,
#{extra} #{extra}
installed java || { installed java || {
echo "==> Java is not installed on vagrant box ${config.vm.box}" echo "==> Java is not installed"
return 1 return 1
} }
ensure tar ensure tar
ensure curl ensure curl
ensure unzip ensure unzip
ensure rsync
installed bats || { installed bats || {
# Bats lives in a git repository.... # Bats lives in a git repository....
@ -292,9 +350,4 @@ Defaults env_keep += "BATS_ARCHIVES"
SUDOERS_VARS SUDOERS_VARS
chmod 0440 /etc/sudoers.d/elasticsearch_vars chmod 0440 /etc/sudoers.d/elasticsearch_vars
SHELL SHELL
# This prevents leftovers from previous tests using the
# same VM from messing up the current test
config.vm.provision "clean_tmp", run: "always", type: "shell", inline: <<-SHELL
rm -rf /tmp/elasticsearch*
SHELL
end end