Make bats tests refuse to start on non-VMs (#24315)

The bats tests are descructive and must be run as root. This is a
horrible combination on any sane system but perfectly fine to do
in a VM. This change modifies the tests so they revuse to start
unless they are in an environment with an `/etc/is_vagrant_vm`
file. The Vagrantfile creates it on startup.

Closes #24137
This commit is contained in:
Nik Everett 2017-04-26 10:40:35 -04:00 committed by GitHub
parent 91b61ce569
commit 0c12d0ce37
15 changed files with 126 additions and 50 deletions

6
Vagrantfile vendored
View File

@ -104,6 +104,12 @@ 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 end
config.config_procs.push ['2', set_prompt] config.config_procs.push ['2', set_prompt]
end end

View File

@ -3,9 +3,14 @@
# This file is used to test the tar gz package. # This file is used to test the tar gz package.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -4,9 +4,14 @@
# of a Debian package. # of a Debian package.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -3,9 +3,14 @@
# This file is used to test the installation of a RPM package. # This file is used to test the installation of a RPM package.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -3,9 +3,14 @@
# This file is used to test the elasticsearch Systemd setup. # This file is used to test the elasticsearch Systemd setup.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -3,9 +3,14 @@
# This file is used to test the elasticsearch init.d scripts. # This file is used to test the elasticsearch init.d scripts.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -4,9 +4,14 @@
# default.data.path setting into the data.path even when it doesn't belong. # default.data.path setting into the data.path even when it doesn't belong.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -5,9 +5,14 @@
# fancy rolling restarts. # fancy rolling restarts.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -5,9 +5,14 @@
# fancy rolling restarts. # fancy rolling restarts.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -5,9 +5,14 @@
# rpm, and deb. # rpm, and deb.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# The test case can be executed with the Bash Automated # The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats # Testing System tool available at https://github.com/sstephenson/bats

View File

@ -4,9 +4,14 @@
# the .deb/.rpm packages and the SysV/Systemd scripts. # the .deb/.rpm packages and the SysV/Systemd scripts.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# Licensed to Elasticsearch under one or more contributor # Licensed to Elasticsearch under one or more contributor
# license agreements. See the NOTICE file distributed with # license agreements. See the NOTICE file distributed with

View File

@ -4,9 +4,14 @@
# the .deb/.rpm packages. # the .deb/.rpm packages.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# Licensed to Elasticsearch under one or more contributor # Licensed to Elasticsearch under one or more contributor
# license agreements. See the NOTICE file distributed with # license agreements. See the NOTICE file distributed with

View File

@ -1,12 +1,17 @@
#!/bin/bash #!/bin/bash
# This file contains some utilities to test the elasticsearch scripts, # This file contains some utilities to test the elasticsearch
# the .deb/.rpm packages and the SysV/Systemd scripts. # plugin installation and uninstallation process.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# Licensed to Elasticsearch under one or more contributor # Licensed to Elasticsearch under one or more contributor
# license agreements. See the NOTICE file distributed with # license agreements. See the NOTICE file distributed with

View File

@ -1,12 +1,17 @@
#!/bin/bash #!/bin/bash
# This file contains some utilities to test the elasticsearch scripts, # This file contains some utilities to test the elasticsearch
# the .deb/.rpm packages and the SysV/Systemd scripts. # tar distribution.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# Licensed to Elasticsearch under one or more contributor # Licensed to Elasticsearch under one or more contributor
# license agreements. See the NOTICE file distributed with # license agreements. See the NOTICE file distributed with

View File

@ -4,9 +4,14 @@
# the .deb/.rpm packages and the SysV/Systemd scripts. # the .deb/.rpm packages and the SysV/Systemd scripts.
# WARNING: This testing file must be executed as root and can # WARNING: This testing file must be executed as root and can
# dramatically change your system. It removes the 'elasticsearch' # dramatically change your system. It should only be executed
# user/group and also many directories. Do not execute this file # in a throw-away VM like those made by the Vagrantfile at
# unless you know exactly what you are doing. # the root of the Elasticsearch source code. This should
# cause the script to fail if it is executed any other way:
[ -f /etc/is_vagrant_vm ] || {
>&2 echo "must be run on a vagrant VM"
exit 1
}
# Licensed to Elasticsearch under one or more contributor # Licensed to Elasticsearch under one or more contributor
# license agreements. See the NOTICE file distributed with # license agreements. See the NOTICE file distributed with