[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

365
Vagrantfile vendored
View File

@ -21,167 +21,172 @@
# 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
# Install Jayatana so we can work around it being present. # the elasticsearch project called vagrant....
[ -f /usr/share/java/jayatanaag.jar ] || install jayatana config.vm.synced_folder '.', '/vagrant', disabled: true
SHELL 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.
[ -f /usr/share/java/jayatanaag.jar ] || install jayatana
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'
end deb_common config, box
config.vm.define "debian-9" do |config| end
config.vm.box = "elastic/debian-9-x86_64" end
deb_common config 'debian-9'.tap do |box|
end config.vm.define box, define_opts do |config|
config.vm.define "centos-6" do |config| config.vm.box = 'elastic/debian-9-x86_64'
config.vm.box = "elastic/centos-6-x86_64" deb_common config, box
rpm_common config end
end end
config.vm.define "centos-7" do |config| 'centos-6'.tap do |box|
config.vm.box = "elastic/centos-7-x86_64" config.vm.define box, define_opts do |config|
rpm_common config config.vm.box = 'elastic/centos-6-x86_64'
end rpm_common config, box
config.vm.define "oel-6" do |config| end
config.vm.box = "elastic/oraclelinux-6-x86_64" end
rpm_common config 'centos-7'.tap do |box|
end config.vm.define box, define_opts do |config|
config.vm.define "oel-7" do |config| config.vm.box = 'elastic/centos-7-x86_64'
config.vm.box = "elastic/oraclelinux-7-x86_64" rpm_common config, box
rpm_common config end
end end
config.vm.define "fedora-26" do |config| 'oel-6'.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/oraclelinux-6-x86_64'
end rpm_common config, box
config.vm.define "fedora-27" do |config| end
config.vm.box = "elastic/fedora-27-x86_64" end
dnf_common config 'oel-7'.tap do |box|
end config.vm.define box, define_opts do |config|
config.vm.define "opensuse-42" do |config| config.vm.box = 'elastic/oraclelinux-7-x86_64'
config.vm.box = "elastic/opensuse-42-x86_64" rpm_common config, box
opensuse_common config end
end end
config.vm.define "sles-12" do |config| 'fedora-26'.tap do |box|
config.vm.box = "elastic/sles-12-x86_64" config.vm.define box, define_opts do |config|
sles_common config config.vm.box = 'elastic/fedora-26-x86_64'
end dnf_common config, box
# Switch the default share for the project root from /vagrant to end
# /elasticsearch because /vagrant is confusing when there is a project inside end
# the elasticsearch project called vagrant.... 'fedora-27'.tap do |box|
config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.define box, define_opts do |config|
config.vm.synced_folder ".", "/elasticsearch" config.vm.box = 'elastic/fedora-27-x86_64'
# Expose project directory dnf_common config, box
PROJECT_DIR = ENV['VAGRANT_PROJECT_DIR'] || Dir.pwd end
config.vm.synced_folder PROJECT_DIR, "/project" end
config.vm.provider "virtualbox" do |v| 'opensuse-42'.tap do |box|
# Give the boxes 3GB because Elasticsearch defaults to using 2GB config.vm.define box, define_opts do |config|
v.memory = 3072 config.vm.box = 'elastic/opensuse-42-x86_64'
end suse_common config, box
if Vagrant.has_plugin?("vagrant-cachier") end
config.cache.scope = :box end
end 'sles-12'.tap do |box|
config.vm.defined_vms.each do |name, config| config.vm.define box, define_opts do |config|
config.options[:autostart] = false config.vm.box = 'elastic/sles-12-x86_64'
set_prompt = lambda do |config| sles_common config, box
# 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.
config.vm.provision "prompt", type: "shell", inline: <<-SHELL
cat \<\<PROMPT > /etc/profile.d/elasticsearch_prompt.sh
export PS1='#{name}:\\w$ '
PROMPT
grep 'source /etc/profile.d/elasticsearch_prompt.sh' ~/.bashrc |
cat \<\<SOURCE_PROMPT >> ~/.bashrc
# Replace the standard prompt with a consistent one
source /etc/profile.d/elasticsearch_prompt.sh
SOURCE_PROMPT
grep 'source /etc/profile.d/elasticsearch_prompt.sh' ~vagrant/.bashrc |
cat \<\<SOURCE_PROMPT >> ~vagrant/.bashrc
# Replace the standard prompt with a consistent one
source /etc/profile.d/elasticsearch_prompt.sh
SOURCE_PROMPT
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 end
config.config_procs.push ['2', set_prompt]
end end
end end
def ubuntu_common(config, extra: '') def deb_common(config, name, extra: '')
deb_common config, extra: extra
end
def deb_common(config, extra: '')
# http://foo-o-rama.com/vagrant--stdin-is-not-a-tty--fix.html # http://foo-o-rama.com/vagrant--stdin-is-not-a-tty--fix.html
config.vm.provision "fix-no-tty", type: "shell" do |s| config.vm.provision 'fix-no-tty', type: 'shell' do |s|
s.privileged = false s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile" s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end end
provision(config, linux_common(
update_command: "apt-get update", config,
update_tracking_file: "/var/cache/apt/archives/last_update", name,
install_command: "apt-get install -y", update_command: 'apt-get update',
extra: extra) update_tracking_file: '/var/cache/apt/archives/last_update',
install_command: 'apt-get install -y',
extra: extra
)
end end
def rpm_common(config) def rpm_common(config, name)
provision(config, linux_common(
update_command: "yum check-update", config,
update_tracking_file: "/var/cache/yum/last_update", name,
install_command: "yum install -y") update_command: 'yum check-update',
update_tracking_file: '/var/cache/yum/last_update',
install_command: 'yum install -y'
)
end end
def dnf_common(config) def dnf_common(config, name)
provision(config, # Autodetect doesn't work....
update_command: "dnf check-update", if Vagrant.has_plugin?('vagrant-cachier')
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.auto_detect = false
config.cache.enable :generic, { :cache_dir => "/var/cache/dnf" } config.cache.enable :generic, { :cache_dir => '/var/cache/dnf' }
end 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 end
def opensuse_common(config) def suse_common(config, name, extra: '')
suse_common config, '' 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 end
def suse_common(config, extra) def sles_common(config, name)
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 extra = <<-SHELL
zypper rr systemsmanagement_puppet puppetlabs-pc1 zypper rr systemsmanagement_puppet puppetlabs-pc1
zypper --non-interactive install git-core zypper --non-interactive install git-core
SHELL SHELL
suse_common config, extra suse_common config, name, extra: extra
end end
# Register the main box provisioning script. # Configuration needed for all linux boxes
# @param config Vagrant's config object. Required. # @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 # @param update_command [String] The command used to update the package
# manager. Required. Think `apt-get update`. # manager. Required. Think `apt-get update`.
# @param update_tracking_file [String] The location of the file tracking the # @param update_tracking_file [String] The location of the file tracking the
@ -189,24 +194,76 @@ end
# is cached by vagrant-cachier. # is cached by vagrant-cachier.
# @param install_command [String] The command used to install a package. # @param install_command [String] The command used to install a package.
# Required. Think `apt-get install #{package}`. # Required. Think `apt-get install #{package}`.
# @param extra [String] Extra provisioning commands run before anything else. # @param install_command_retries [Integer] Number of times to retry
# Optional. Used for things like setting up the ppa for Java 8. # a failed install command
def provision(config, # @param extra [String] Additional script to run before installing
update_command: 'required', # dependencies
update_tracking_file: 'required', #
install_command: 'required', def linux_common(config,
install_command_retries: 0, name,
extra: '') update_command: 'required',
# Vagrant run ruby 2.0.0 which doesn't have required named parameters.... update_tracking_file: 'required',
raise ArgumentError.new('update_command is required') if update_command == 'required' install_command: 'required',
raise ArgumentError.new('update_tracking_file is required') if update_tracking_file == 'required' install_command_retries: 0,
raise ArgumentError.new('install_command is required') if install_command == 'required' extra: '')
config.vm.provider "virtualbox" do |v|
# Give the box more memory and cpu because our tests are beasts! raise ArgumentError, 'update_command is required' if update_command == 'required'
v.memory = Integer(ENV['VAGRANT_MEMORY'] || 8192) raise ArgumentError, 'update_tracking_file is required' if update_tracking_file == 'required'
v.cpus = Integer(ENV['VAGRANT_CPUS'] || 4) raise ArgumentError, 'install_command is required' if install_command == 'required'
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :box
end end
config.vm.provision "dependencies", type: "shell", inline: <<-SHELL
config.vm.provision 'markerfile', type: 'shell', inline: <<-SHELL
touch /etc/is_vagrant_vm
SHELL
# This prevents leftovers from previous tests using the
# 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
export PS1='#{name}:\\w$ '
PROMPT
grep 'source /etc/profile.d/elasticsearch_prompt.sh' ~/.bashrc |
cat \<\<SOURCE_PROMPT >> ~/.bashrc
# Replace the standard prompt with a consistent one
source /etc/profile.d/elasticsearch_prompt.sh
SOURCE_PROMPT
grep 'source /etc/profile.d/elasticsearch_prompt.sh' ~vagrant/.bashrc |
cat \<\<SOURCE_PROMPT >> ~vagrant/.bashrc
# Replace the standard prompt with a consistent one
source /etc/profile.d/elasticsearch_prompt.sh
SOURCE_PROMPT
SHELL
end
def sh_install_deps(config,
update_command,
update_tracking_file,
install_command,
install_command_retries,
extra)
config.vm.provision 'install dependencies', type: 'shell', inline: <<-SHELL
set -e set -e
set -o pipefail set -o pipefail
@ -240,9 +297,9 @@ def provision(config,
echo "==> Installing $1" echo "==> Installing $1"
if [ #{install_command_retries} -eq 0 ] if [ #{install_command_retries} -eq 0 ]
then then
#{install_command} $1 #{install_command} $1
else else
retry_installcommand $1 #{install_command_retries} retry_installcommand $1 #{install_command_retries}
fi fi
} }
@ -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