Add package pre-install check for java binary (#31343)

The package installation relies on java being in the path. If java is
not in the path, the tests fail at post-install time. This commit adds a
pre-install check to validate that java exists, and if it fails, the
package is never installed, and thus keeps a system clean, rather than
aborting at post-install and leaving behind a mess.

Closes #29665
This commit is contained in:
Michael Basnight 2018-06-25 10:54:39 -05:00 committed by GitHub
parent 86ab3a2d1a
commit adfcea2af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 2 deletions

View File

@ -9,6 +9,18 @@
# $1=1 : indicates an new install # $1=1 : indicates an new install
# $1=2 : indicates an upgrade # $1=2 : indicates an upgrade
# Check for these at preinst time due to failures in postinst if they do not exist
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA=`which java`
fi
if [ -z "$JAVA" ]; then
echo "could not find java; set JAVA_HOME or ensure java is in PATH"
exit 1
fi
case "$1" in case "$1" in
# Debian #################################################### # Debian ####################################################

View File

@ -72,6 +72,14 @@ setup() {
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@test "[DEB] temporarily remove java and ensure the install fails" {
move_java
run dpkg -i elasticsearch-oss-$(cat version).deb
output=$status
unmove_java
[ "$output" -eq 1 ]
}
@test "[DEB] install package" { @test "[DEB] install package" {
dpkg -i elasticsearch-oss-$(cat version).deb dpkg -i elasticsearch-oss-$(cat version).deb
} }

View File

@ -71,6 +71,14 @@ setup() {
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@test "[RPM] temporarily remove java and ensure the install fails" {
move_java
run rpm -i elasticsearch-oss-$(cat version).rpm
output=$status
unmove_java
[ "$output" -eq 1 ]
}
@test "[RPM] install package" { @test "[RPM] install package" {
rpm -i elasticsearch-oss-$(cat version).rpm rpm -i elasticsearch-oss-$(cat version).rpm
} }

View File

@ -68,8 +68,11 @@ if [ ! -x "`which unzip 2>/dev/null`" ]; then
fi fi
if [ ! -x "`which java 2>/dev/null`" ]; then if [ ! -x "`which java 2>/dev/null`" ]; then
echo "'java' command is mandatory to run the tests" # there are some tests that move java temporarily
exit 1 if [ ! -x "`command -v java.bak 2>/dev/null`" ]; then
echo "'java' command is mandatory to run the tests"
exit 1
fi
fi fi
# Returns 0 if the 'dpkg' command is available # Returns 0 if the 'dpkg' command is available
@ -578,3 +581,17 @@ file_privileges_for_user_from_umask() {
echo $((0777 & ~$(sudo -E -u $user sh -c umask) & ~0111)) echo $((0777 & ~$(sudo -E -u $user sh -c umask) & ~0111))
} }
# move java to simulate it not being in the path
move_java() {
which_java=`command -v java`
assert_file_exist $which_java
mv $which_java ${which_java}.bak
}
# move java back to its original location
unmove_java() {
which_java=`command -v java.bak`
assert_file_exist $which_java
mv $which_java `dirname $which_java`/java
}