Skip to content

Commit

Permalink
Add package pre-install check for java binary (#31343)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hub-cap committed Jun 25, 2018
1 parent 3f95415 commit a465429
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
12 changes: 12 additions & 0 deletions distribution/packages/src/common/scripts/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
# $1=1 : indicates an new install
# $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

# Debian ####################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ setup() {
[ "$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" {
dpkg -i elasticsearch-oss-$(cat version).deb
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ setup() {
[ "$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" {
rpm -i elasticsearch-oss-$(cat version).rpm
}
Expand Down
21 changes: 19 additions & 2 deletions qa/vagrant/src/test/resources/packaging/utils/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ if [ ! -x "`which unzip 2>/dev/null`" ]; then
fi

if [ ! -x "`which java 2>/dev/null`" ]; then
echo "'java' command is mandatory to run the tests"
exit 1
# there are some tests that move java temporarily
if [ ! -x "`command -v java.bak 2>/dev/null`" ]; then
echo "'java' command is mandatory to run the tests"
exit 1
fi
fi

# Returns 0 if the 'dpkg' command is available
Expand Down Expand Up @@ -525,3 +528,17 @@ file_privileges_for_user_from_umask() {

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
}

0 comments on commit a465429

Please sign in to comment.