2016-05-18 11:03:00 -04:00
|
|
|
#!/bin/bash
|
2015-08-21 16:05:50 -04:00
|
|
|
|
2017-04-26 10:40:35 -04:00
|
|
|
# This file contains some utilities to test the elasticsearch
|
|
|
|
# plugin installation and uninstallation process.
|
2015-08-21 16:05:50 -04:00
|
|
|
|
|
|
|
# WARNING: This testing file must be executed as root and can
|
2017-04-26 10:40:35 -04:00
|
|
|
# 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
|
|
|
|
}
|
2015-08-21 16:05:50 -04:00
|
|
|
|
|
|
|
# Licensed to Elasticsearch under one or more contributor
|
|
|
|
# license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright
|
|
|
|
# ownership. Elasticsearch licenses this file to you under
|
|
|
|
# the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2018-01-25 02:50:16 -05:00
|
|
|
# Install a plugin
|
2015-08-21 16:05:50 -04:00
|
|
|
install_plugin() {
|
|
|
|
local name=$1
|
|
|
|
local path="$2"
|
2017-05-06 13:25:10 -04:00
|
|
|
local umask="$3"
|
2015-08-21 16:05:50 -04:00
|
|
|
|
|
|
|
assert_file_exist "$path"
|
|
|
|
|
2017-08-14 17:19:06 -04:00
|
|
|
if [ ! -z "$ES_PATH_CONF" ] ; then
|
2017-07-20 20:38:49 -04:00
|
|
|
if is_dpkg; then
|
2017-08-14 17:19:06 -04:00
|
|
|
echo "ES_PATH_CONF=$ES_PATH_CONF" >> /etc/default/elasticsearch;
|
2017-07-20 20:38:49 -04:00
|
|
|
elif is_rpm; then
|
2017-08-14 17:19:06 -04:00
|
|
|
echo "ES_PATH_CONF=$ES_PATH_CONF" >> /etc/sysconfig/elasticsearch;
|
2017-07-20 20:38:49 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-05-06 13:25:10 -04:00
|
|
|
if [ -z "$umask" ]; then
|
2018-04-03 21:23:01 -04:00
|
|
|
sudo -E -u $ESPLUGIN_COMMAND_USER "$ESHOME/bin/elasticsearch-plugin" install --batch "file://$path"
|
2017-05-06 13:25:10 -04:00
|
|
|
else
|
2018-04-03 21:23:01 -04:00
|
|
|
sudo -E -u $ESPLUGIN_COMMAND_USER bash -c "umask $umask && \"$ESHOME/bin/elasticsearch-plugin\" install --batch \"file://$path\""
|
2017-05-06 13:25:10 -04:00
|
|
|
fi
|
2015-08-21 16:05:50 -04:00
|
|
|
|
2015-10-06 08:13:24 -04:00
|
|
|
#check we did not accidentially create a log file as root as /usr/share/elasticsearch
|
|
|
|
assert_file_not_exist "/usr/share/elasticsearch/logs"
|
2015-09-15 11:33:39 -04:00
|
|
|
|
|
|
|
# At some point installing or removing plugins caused elasticsearch's logs
|
|
|
|
# to be owned by root. This is bad so we want to make sure it doesn't
|
|
|
|
# happen.
|
|
|
|
if [ -e "$ESLOG" ] && [ $(stat "$ESLOG" --format "%U") == "root" ]; then
|
|
|
|
echo "$ESLOG is now owned by root! That'll break logging when elasticsearch tries to start."
|
|
|
|
false
|
|
|
|
fi
|
2015-09-01 16:56:36 -04:00
|
|
|
}
|
|
|
|
|
2015-08-21 16:05:50 -04:00
|
|
|
# Remove a plugin and make sure its plugin directory is removed.
|
|
|
|
remove_plugin() {
|
|
|
|
local name=$1
|
|
|
|
|
|
|
|
echo "Removing $name...."
|
2016-02-04 10:00:55 -05:00
|
|
|
sudo -E -u $ESPLUGIN_COMMAND_USER "$ESHOME/bin/elasticsearch-plugin" remove $name
|
2015-08-21 16:05:50 -04:00
|
|
|
|
|
|
|
assert_file_not_exist "$ESPLUGINS/$name"
|
2015-09-15 11:33:39 -04:00
|
|
|
|
|
|
|
# At some point installing or removing plugins caused elasticsearch's logs
|
|
|
|
# to be owned by root. This is bad so we want to make sure it doesn't
|
|
|
|
# happen.
|
|
|
|
if [ -e "$ESLOG" ] && [ $(stat "$ESLOG" --format "%U") == "root" ]; then
|
|
|
|
echo "$ESLOG is now owned by root! That'll break logging when elasticsearch tries to start."
|
|
|
|
false
|
|
|
|
fi
|
2015-08-21 16:05:50 -04:00
|
|
|
}
|
|
|
|
|
2018-01-26 11:34:24 -05:00
|
|
|
# Install a sample plugin which fully exercises the special case file placements.
|
|
|
|
install_plugin_example() {
|
2019-08-13 15:45:29 -04:00
|
|
|
local relativePath=${1:-$(readlink -m $BATS_PLUGINS/custom-settings-*.zip)}
|
2018-01-26 11:34:24 -05:00
|
|
|
install_plugin custom-settings "$relativePath" $2
|
2015-08-21 16:05:50 -04:00
|
|
|
|
2015-10-13 11:34:56 -04:00
|
|
|
bin_user=$(find "$ESHOME/bin" -maxdepth 0 -printf "%u")
|
|
|
|
bin_owner=$(find "$ESHOME/bin" -maxdepth 0 -printf "%g")
|
2017-05-06 13:25:10 -04:00
|
|
|
|
2018-01-26 11:34:24 -05:00
|
|
|
assert_file "$ESHOME/plugins/custom-settings" d $bin_user $bin_owner 755
|
|
|
|
assert_file "$ESHOME/plugins/custom-settings/custom-settings-$(cat version).jar" f $bin_user $bin_owner 644
|
2017-05-06 13:25:10 -04:00
|
|
|
|
|
|
|
#owner group and permissions vary depending on how es was installed
|
|
|
|
#just make sure that everything is the same as the parent bin dir, which was properly set up during install
|
2018-01-26 11:34:24 -05:00
|
|
|
assert_file "$ESHOME/bin/custom-settings" d $bin_user $bin_owner 755
|
|
|
|
assert_file "$ESHOME/bin/custom-settings/test" f $bin_user $bin_owner 755
|
2015-10-09 10:52:05 -04:00
|
|
|
|
|
|
|
#owner group and permissions vary depending on how es was installed
|
|
|
|
#just make sure that everything is the same as $CONFIG_DIR, which was properly set up during install
|
|
|
|
config_user=$(find "$ESCONFIG" -maxdepth 0 -printf "%u")
|
|
|
|
config_owner=$(find "$ESCONFIG" -maxdepth 0 -printf "%g")
|
2016-03-16 23:10:30 -04:00
|
|
|
# directories should user the user file-creation mask
|
2018-01-26 11:34:24 -05:00
|
|
|
assert_file "$ESCONFIG/custom-settings" d $config_user $config_owner 750
|
|
|
|
assert_file "$ESCONFIG/custom-settings/custom.yml" f $config_user $config_owner 660
|
2016-10-24 03:42:03 -04:00
|
|
|
|
2018-01-26 11:34:24 -05:00
|
|
|
run sudo -E -u vagrant LANG="en_US.UTF-8" cat "$ESCONFIG/custom-settings/custom.yml"
|
2016-10-24 03:42:03 -04:00
|
|
|
[ $status = 1 ]
|
|
|
|
[[ "$output" == *"Permission denied"* ]] || {
|
|
|
|
echo "Expected permission denied but found $output:"
|
|
|
|
false
|
|
|
|
}
|
2015-08-21 16:05:50 -04:00
|
|
|
|
2018-01-26 11:34:24 -05:00
|
|
|
echo "Running sample plugin bin script...."
|
|
|
|
"$ESHOME/bin/custom-settings/test" | grep test
|
2015-08-21 16:05:50 -04:00
|
|
|
}
|
|
|
|
|
2018-01-26 11:34:24 -05:00
|
|
|
# Remove the sample plugin which fully exercises the special cases of
|
2015-08-21 16:05:50 -04:00
|
|
|
# removing bin and not removing config.
|
2018-01-26 11:34:24 -05:00
|
|
|
remove_plugin_example() {
|
|
|
|
remove_plugin custom-settings
|
2015-08-21 16:05:50 -04:00
|
|
|
|
2018-01-26 11:34:24 -05:00
|
|
|
assert_file_not_exist "$ESHOME/bin/custom-settings"
|
|
|
|
assert_file_exist "$ESCONFIG/custom-settings"
|
|
|
|
assert_file_exist "$ESCONFIG/custom-settings/custom.yml"
|
2015-08-21 16:05:50 -04:00
|
|
|
}
|
|
|
|
|
2015-09-01 16:56:36 -04:00
|
|
|
# Install a plugin with a special prefix. For the most part prefixes are just
|
|
|
|
# useful for grouping but the "analysis" prefix is special because all
|
2015-08-21 16:05:50 -04:00
|
|
|
# analysis plugins come with a corresponding lucene-analyzers jar.
|
|
|
|
# $1 - the prefix
|
|
|
|
# $2 - the plugin name
|
|
|
|
# $@ - all remaining arguments are jars that must exist in the plugin's
|
|
|
|
# installation directory
|
2015-09-01 16:56:36 -04:00
|
|
|
install_and_check_plugin() {
|
2015-08-21 16:05:50 -04:00
|
|
|
local prefix=$1
|
|
|
|
shift
|
|
|
|
local name=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [ "$prefix" == "-" ]; then
|
2016-10-31 16:38:33 -04:00
|
|
|
local full_name="$name"
|
2015-08-21 16:05:50 -04:00
|
|
|
else
|
2016-10-31 16:38:33 -04:00
|
|
|
local full_name="$prefix-$name"
|
2015-08-21 16:05:50 -04:00
|
|
|
fi
|
|
|
|
|
2019-08-13 15:45:29 -04:00
|
|
|
install_plugin $full_name "$(readlink -m $BATS_PLUGINS/$full_name-*.zip)"
|
2016-03-17 22:11:59 -04:00
|
|
|
|
2016-10-31 16:38:33 -04:00
|
|
|
assert_module_or_plugin_directory "$ESPLUGINS/$full_name"
|
2018-01-25 02:50:16 -05:00
|
|
|
assert_file_exist "$ESPLUGINS/$full_name/plugin-descriptor.properties"
|
|
|
|
assert_file_exist "$ESPLUGINS/$full_name/$full_name"*".jar"
|
2016-03-17 22:11:59 -04:00
|
|
|
|
2016-10-31 16:38:33 -04:00
|
|
|
# analysis plugins have a corresponding analyzers jar
|
2015-08-21 16:05:50 -04:00
|
|
|
if [ $prefix == 'analysis' ]; then
|
2016-10-31 16:38:33 -04:00
|
|
|
local analyzer_jar_suffix=$name
|
|
|
|
# the name of the analyzer jar for the ukrainian plugin does
|
|
|
|
# not match the name of the plugin, so we have to make an
|
|
|
|
# exception
|
|
|
|
if [ $name == 'ukrainian' ]; then
|
|
|
|
analyzer_jar_suffix='morfologik'
|
|
|
|
fi
|
|
|
|
assert_module_or_plugin_file "$ESPLUGINS/$full_name/lucene-analyzers-$analyzer_jar_suffix-*.jar"
|
2015-08-21 16:05:50 -04:00
|
|
|
fi
|
|
|
|
for file in "$@"; do
|
2016-10-31 16:38:33 -04:00
|
|
|
assert_module_or_plugin_file "$ESPLUGINS/$full_name/$file"
|
2015-08-21 16:05:50 -04:00
|
|
|
done
|
|
|
|
}
|
2015-09-16 11:11:49 -04:00
|
|
|
|
2018-01-25 02:50:16 -05:00
|
|
|
# Install a meta plugin
|
|
|
|
# $1 - the plugin name
|
|
|
|
# $@ - all remaining arguments are jars that must exist in the plugin's
|
|
|
|
# installation directory
|
|
|
|
install_meta_plugin() {
|
|
|
|
local name=$1
|
|
|
|
|
2019-08-13 15:45:29 -04:00
|
|
|
install_plugin $name "$(readlink -m $BATS_PLUGINS/$name-*.zip)"
|
2018-01-25 02:50:16 -05:00
|
|
|
assert_module_or_plugin_directory "$ESPLUGINS/$name"
|
|
|
|
}
|
|
|
|
|
2015-09-16 11:11:49 -04:00
|
|
|
# Compare a list of plugin names to the plugins in the plugins pom and see if they are the same
|
|
|
|
# $1 the file containing the list of plugins we want to compare to
|
|
|
|
# $2 description of the source of the plugin list
|
|
|
|
compare_plugins_list() {
|
|
|
|
cat $1 | sort > /tmp/plugins
|
|
|
|
echo "Checking plugins from $2 (<) against expected plugins (>):"
|
2017-05-15 15:58:11 -04:00
|
|
|
diff -w /elasticsearch/qa/vagrant/build/plugins/expected /tmp/plugins
|
2015-09-16 11:11:49 -04:00
|
|
|
}
|