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:
parent
91b61ce569
commit
0c12d0ce37
|
@ -104,6 +104,12 @@ SOURCE_PROMPT
|
|||
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
|
||||
config.config_procs.push ['2', set_prompt]
|
||||
end
|
||||
|
@ -263,7 +269,7 @@ def provision(config,
|
|||
echo "==> Installing Gradle"
|
||||
curl -sS -o /tmp/gradle.zip -L https://services.gradle.org/distributions/gradle-3.3-bin.zip
|
||||
unzip /tmp/gradle.zip -d /opt
|
||||
rm -rf /tmp/gradle.zip
|
||||
rm -rf /tmp/gradle.zip
|
||||
ln -s /opt/gradle-3.3/bin/gradle /usr/bin/gradle
|
||||
# make nfs mounted gradle home dir writeable
|
||||
chown vagrant:vagrant /home/vagrant/.gradle
|
||||
|
|
|
@ -3,9 +3,14 @@
|
|||
# This file is used to test the tar gz package.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
|
|
@ -4,9 +4,14 @@
|
|||
# of a Debian package.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
|
|
@ -3,9 +3,14 @@
|
|||
# This file is used to test the installation of a RPM package.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
|
|
@ -3,9 +3,14 @@
|
|||
# This file is used to test the elasticsearch Systemd setup.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
|
|
@ -3,9 +3,14 @@
|
|||
# This file is used to test the elasticsearch init.d scripts.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
@ -60,11 +65,11 @@ setup() {
|
|||
@test "[INIT.D] elasticsearch fails if startup script is not executable" {
|
||||
local INIT="/etc/init.d/elasticsearch"
|
||||
local DAEMON="$ESHOME/bin/elasticsearch"
|
||||
|
||||
|
||||
sudo chmod -x "$DAEMON"
|
||||
run "$INIT"
|
||||
sudo chmod +x "$DAEMON"
|
||||
|
||||
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON"* ]]
|
||||
}
|
||||
|
|
|
@ -4,9 +4,14 @@
|
|||
# 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
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
# fancy rolling restarts.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
# fancy rolling restarts.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
# rpm, and deb.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# Testing System tool available at https://github.com/sstephenson/bats
|
||||
|
|
|
@ -4,9 +4,14 @@
|
|||
# the .deb/.rpm packages and the SysV/Systemd scripts.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# license agreements. See the NOTICE file distributed with
|
||||
|
@ -41,4 +46,4 @@ check_module() {
|
|||
|
||||
check_secure_module() {
|
||||
check_module "$@" plugin-security.policy
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,14 @@
|
|||
# the .deb/.rpm packages.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# license agreements. See the NOTICE file distributed with
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
# This file contains some utilities to test the elasticsearch scripts,
|
||||
# the .deb/.rpm packages and the SysV/Systemd scripts.
|
||||
# This file contains some utilities to test the elasticsearch
|
||||
# plugin installation and uninstallation process.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# license agreements. See the NOTICE file distributed with
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
# This file contains some utilities to test the elasticsearch scripts,
|
||||
# the .deb/.rpm packages and the SysV/Systemd scripts.
|
||||
# This file contains some utilities to test the elasticsearch
|
||||
# tar distribution.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# license agreements. See the NOTICE file distributed with
|
||||
|
|
|
@ -4,9 +4,14 @@
|
|||
# the .deb/.rpm packages and the SysV/Systemd scripts.
|
||||
|
||||
# WARNING: This testing file must be executed as root and can
|
||||
# dramatically change your system. It removes the 'elasticsearch'
|
||||
# user/group and also many directories. Do not execute this file
|
||||
# unless you know exactly what you are doing.
|
||||
# dramatically change your system. It should only be executed
|
||||
# in a throw-away VM like those made by the Vagrantfile at
|
||||
# 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
|
||||
# license agreements. See the NOTICE file distributed with
|
||||
|
|
Loading…
Reference in New Issue