Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package pre-install check for java binary #31343

Merged
merged 5 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

[ "$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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

[ "$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 @@ -578,3 +581,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
}