Merge pull request #13076 from nik9000/bats_plugins

Packaging: Install all plugins during bats tests
This commit is contained in:
Nik Everett 2015-09-01 13:44:15 -04:00
commit 69b7feeb78
8 changed files with 493 additions and 644 deletions

View File

@ -98,6 +98,90 @@
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>analysis-icu</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>analysis-kuromoji</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>analysis-phonetic</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>analysis-smartcn</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>analysis-stempel</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>cloud-aws</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>cloud-azure</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>cloud-gce</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>delete-by-query</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>lang-javascript</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>lang-python</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>mapper-size</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>mapper-murmur3</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>site-example</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
@ -192,14 +276,6 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.elasticsearch.distribution</groupId>
<artifactId>elasticsearch-rpm</artifactId>
<version>${elasticsearch.version}</version>
<type>rpm</type>
</dependency>
</dependencies>
<properties>
<rpmOk>ok</rpmOk>
</properties>

View File

@ -30,6 +30,7 @@
# Load test utilities
load packaging_test_utils
load tar
setup() {
skip_not_tar_gz
@ -61,13 +62,12 @@ setup() {
count=$(find /tmp -type d -name 'elasticsearch*' | wc -l)
[ "$count" -eq 1 ]
}
##################################
# Check that the archive is correctly installed
##################################
@test "[TAR] verify archive installation" {
verify_archive_installation "/tmp/elasticsearch"
# Its simpler to check that the install was correct in this test rather
# than in another test because install_archive sets a number of path
# variables that verify_archive_installation reads. To separate this into
# another test you'd have to recreate the variables.
verify_archive_installation
}
##################################

View File

@ -1,315 +0,0 @@
#!/usr/bin/env bats
# This file is used to test the installation and removal
# of plugins with a tar gz archive.
# 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.
# The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats
# Thanks to Sam Stephenson!
# 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.
# Load test utilities
load packaging_test_utils
setup() {
# Cleans everything for every test execution
clean_before_test
}
##################################
# Install plugins with a tar archive
##################################
@test "[TAR] install jvm-example plugin" {
# Install the archive
install_archive
# Checks that the archive is correctly installed
verify_archive_installation
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-example
run /tmp/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that the plugin is correctly installed
assert_file_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "/tmp/elasticsearch/bin/jvm-example/test"
assert_file_exist "/tmp/elasticsearch/config/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/plugin-descriptor.properties"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/jvm-example-"*".jar"
echo "Running jvm-example's bin script...."
/tmp/elasticsearch/bin/jvm-example/test | grep test
# Remove the plugin
run /tmp/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml"
assert_file_not_exist "/tmp/elasticsearch/plugins/jvm-example"
}
@test "[TAR] install jvm-example plugin with a custom path.plugins" {
# Install the archive
install_archive
# Checks that the archive is correctly installed
verify_archive_installation
# Creates a temporary directory
TEMP_PLUGINS_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmp'`
# Modify the path.plugins setting in configuration file
echo "path.plugins: $TEMP_PLUGINS_DIR" >> "/tmp/elasticsearch/config/elasticsearch.yml"
run chown -R elasticsearch:elasticsearch "$TEMP_PLUGINS_DIR"
[ "$status" -eq 0 ]
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-example
run /tmp/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that the plugin is correctly installed
assert_file_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "/tmp/elasticsearch/bin/jvm-example/test"
assert_file_exist "/tmp/elasticsearch/config/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml"
assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example"
assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/plugin-descriptor.properties"
assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run /tmp/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml"
assert_file_not_exist "$TEMP_PLUGINS_DIR/jvm-example"
# Delete the custom plugins directory
run rm -rf "$TEMP_PLUGINS_DIR"
[ "$status" -eq 0 ]
}
@test "[TAR] install jvm-example plugin with a custom CONFIG_DIR" {
# Install the archive
install_archive
# Checks that the archive is correctly installed
verify_archive_installation
# Creates a temporary directory
TEMP_CONFIG_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmp'`
# Move configuration files to the new configuration directory
run mv /tmp/elasticsearch/config/* $TEMP_CONFIG_DIR
[ "$status" -eq 0 ]
run chown -R elasticsearch:elasticsearch "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
assert_file_exist "$TEMP_CONFIG_DIR/elasticsearch.yml"
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-example with the CONF_DIR environment variable
run env "CONF_DIR=$TEMP_CONFIG_DIR" /tmp/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that jvm-example is correctly installed
assert_file_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "/tmp/elasticsearch/bin/jvm-example/test"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/plugin-descriptor.properties"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run /tmp/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml"
assert_file_not_exist "/tmp/elasticsearch/plugins/jvm-example"
# Delete the custom plugins directory
run rm -rf "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
}
@test "[TAR] install jvm-example plugin with a custom ES_JAVA_OPTS" {
# Install the archive
install_archive
# Checks that the archive is correctly installed
verify_archive_installation
# Creates a temporary directory
TEMP_CONFIG_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmp'`
# Move configuration files to the new configuration directory
run mv /tmp/elasticsearch/config/* $TEMP_CONFIG_DIR
[ "$status" -eq 0 ]
run chown -R elasticsearch:elasticsearch "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
assert_file_exist "$TEMP_CONFIG_DIR/elasticsearch.yml"
# Export ES_JAVA_OPTS
export ES_JAVA_OPTS="-Des.path.conf=$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-example
run /tmp/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that jvm-example is correctly installed
assert_file_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "/tmp/elasticsearch/bin/jvm-example/test"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/plugin-descriptor.properties"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run /tmp/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml"
assert_file_not_exist "/tmp/elasticsearch/plugins/jvm-example"
# Delete the custom plugins directory
run rm -rf "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
}
@test "[TAR] install jvm-example plugin to elasticsearch directory with a space" {
export ES_DIR="/tmp/elastic search"
# Install the archive
install_archive
# Checks that the archive is correctly installed
verify_archive_installation
# Move the Elasticsearch installation to a directory with a space in it
rm -rf "$ES_DIR"
mv /tmp/elasticsearch "$ES_DIR"
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-example
run "$ES_DIR/bin/plugin" install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that jvm-example is correctly installed
assert_file_exist "$ES_DIR/bin/jvm-example"
assert_file_exist "$ES_DIR/bin/jvm-example/test"
assert_file_exist "$ES_DIR/config/jvm-example"
assert_file_exist "$ES_DIR/config/jvm-example/example.yaml"
assert_file_exist "$ES_DIR/plugins/jvm-example"
assert_file_exist "$ES_DIR/plugins/jvm-example/plugin-descriptor.properties"
assert_file_exist "$ES_DIR/plugins/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run "$ES_DIR/bin/plugin" remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "$ES_DIR/bin/jvm-example"
assert_file_exist "$ES_DIR/config/jvm-example"
assert_file_exist "$ES_DIR/config/jvm-example/example.yaml"
assert_file_not_exist "$ES_DIR/plugins/jvm-example"
#Cleanup our temporary Elasticsearch installation
rm -rf "$ES_DIR"
}
@test "[TAR] install jvm-example plugin from a directory with a space" {
export EXAMPLE_PLUGIN_ZIP_WITH_SPACE="/tmp/plugins with space/jvm-example.zip"
# Install the archive
install_archive
# Checks that the archive is correctly installed
verify_archive_installation
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Copy the jvm-example plugin to a directory with a space in it
rm -f "$EXAMPLE_PLUGIN_ZIP_WITH_SPACE"
mkdir -p "$(dirname "$EXAMPLE_PLUGIN_ZIP_WITH_SPACE")"
cp $EXAMPLE_PLUGIN_ZIP "$EXAMPLE_PLUGIN_ZIP_WITH_SPACE"
# Install jvm-example
run /tmp/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP_WITH_SPACE"
[ "$status" -eq 0 ]
# Checks that the plugin is correctly installed
assert_file_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "/tmp/elasticsearch/bin/jvm-example/test"
assert_file_exist "/tmp/elasticsearch/config/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/plugin-descriptor.properties"
assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run /tmp/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/tmp/elasticsearch/bin/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example"
assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml"
assert_file_not_exist "/tmp/elasticsearch/plugins/jvm-example"
#Cleanup our plugin directory with a space
rm -rf "$EXAMPLE_PLUGIN_ZIP_WITH_SPACE"
}

View File

@ -0,0 +1 @@
plugin_test_cases.bash

View File

@ -1,259 +0,0 @@
#!/usr/bin/env bats
# This file is used to test the installation and removal
# of plugins when Elasticsearch is installed as a DEB/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.
# The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats
# Thanks to Sam Stephenson!
# 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.
# Load test utilities
load packaging_test_utils
setup() {
# Cleans everything for every test execution
clean_before_test
}
# Install a deb or rpm package
install_package() {
if is_rpm; then
run rpm -i elasticsearch*.rpm >&2
[ "$status" -eq 0 ]
elif is_dpkg; then
run dpkg -i elasticsearch*.deb >&2
[ "$status" -eq 0 ]
fi
}
##################################
# Install plugins with DEB/RPM package
##################################
@test "[PLUGINS] install jvm-example plugin" {
# Install the package
install_package
# Checks that the package is correctly installed
verify_package_installation
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-example
run /usr/share/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that jvm-example is correctly installed
assert_file_exist "/usr/share/elasticsearch/bin/jvm-example"
assert_file_exist "/usr/share/elasticsearch/bin/jvm-example/test"
assert_file_exist "/etc/elasticsearch/jvm-example"
assert_file_exist "/etc/elasticsearch/jvm-example/example.yaml"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/plugin-descriptor.properties"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run /usr/share/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/usr/share/elasticsearch/bin/jvm-example"
assert_file_exist "/etc/elasticsearch/jvm-example"
assert_file_exist "/etc/elasticsearch/jvm-example/example.yaml"
assert_file_not_exist "/usr/share/elasticsearch/plugins/jvm-example"
}
@test "[PLUGINS] install jvm-example plugin with a custom path.plugins" {
# Install the package
install_package
# Checks that the package is correctly installed
verify_package_installation
# Creates a temporary directory
TEMP_PLUGINS_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmp'`
# Modify the path.plugins setting in configuration file
echo "path.plugins: $TEMP_PLUGINS_DIR" >> "/etc/elasticsearch/elasticsearch.yml"
# Sets privileges
run chown -R root:elasticsearch "$TEMP_PLUGINS_DIR"
[ "$status" -eq 0 ]
run chmod -R 750 "$TEMP_PLUGINS_DIR"
[ "$status" -eq 0 ]
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-example
run /usr/share/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that jvm-example is correctly installed
assert_file_exist "/usr/share/elasticsearch/bin/jvm-example"
assert_file_exist "/usr/share/elasticsearch/bin/jvm-example/test"
assert_file_exist "/etc/elasticsearch/jvm-example"
assert_file_exist "/etc/elasticsearch/jvm-example/example.yaml"
assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example"
assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/plugin-descriptor.properties"
assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run /usr/share/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/usr/share/elasticsearch/bin/jvm-example"
assert_file_exist "/etc/elasticsearch/jvm-example"
assert_file_exist "/etc/elasticsearch/jvm-example/example.yaml"
assert_file_not_exist "$TEMP_PLUGINS_DIR/jvm-example"
# Delete the custom plugins directory
run rm -rf "$TEMP_PLUGINS_DIR"
[ "$status" -eq 0 ]
}
@test "[PLUGINS] install jvm-example plugin with a custom CONFIG_DIR" {
# Install the package
install_package
# Checks that the package is correctly installed
verify_package_installation
# Creates a temporary directory
TEMP_CONFIG_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmp'`
# Modify the CONF_DIR variable in environment file
if is_rpm; then
echo "CONF_DIR=$TEMP_CONFIG_DIR" >> "/etc/sysconfig/elasticsearch"
elif is_dpkg; then
echo "CONF_DIR=$TEMP_CONFIG_DIR" >> "/etc/default/elasticsearch"
fi
# Move configuration files to the new configuration directory
run mv /etc/elasticsearch/* $TEMP_CONFIG_DIR
[ "$status" -eq 0 ]
assert_file_exist "$TEMP_CONFIG_DIR/elasticsearch.yml"
# Sets privileges
run chown -R root:elasticsearch "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
run chmod -R 750 "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-exampel
run /usr/share/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that jvm-example is correctly installed
assert_file_exist "/usr/share/elasticsearch/bin/jvm-example"
assert_file_exist "/usr/share/elasticsearch/bin/jvm-example/test"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/plugin-descriptor.properties"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run /usr/share/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/usr/share/elasticsearch/bin/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml"
assert_file_not_exist "/usr/share/elasticsearch/plugins/jvm-example"
# Delete the custom plugins directory
run rm -rf "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
}
@test "[PLUGINS] install jvm-example plugin with a custom ES_JAVA_OPTS" {
# Install the package
install_package
# Checks that the package is correctly installed
verify_package_installation
# Creates a temporary directory
TEMP_CONFIG_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmp'`
# Move configuration files to the new configuration directory
run mv /etc/elasticsearch/* $TEMP_CONFIG_DIR
[ "$status" -eq 0 ]
assert_file_exist "$TEMP_CONFIG_DIR/elasticsearch.yml"
# Sets privileges
run chown -R root:elasticsearch "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
run chmod -R 750 "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
# Export ES_JAVA_OPTS
export ES_JAVA_OPTS="-Des.path.conf=$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
# Checks that plugin archive is available
[ -e "$EXAMPLE_PLUGIN_ZIP" ]
# Install jvm-example
run /usr/share/elasticsearch/bin/plugin install jvm-example -u "file://$EXAMPLE_PLUGIN_ZIP"
[ "$status" -eq 0 ]
# Checks that jvm-example is correctly installed
assert_file_exist "/usr/share/elasticsearch/bin/jvm-example"
assert_file_exist "/usr/share/elasticsearch/bin/jvm-example/test"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/plugin-descriptor.properties"
assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/jvm-example-"*".jar"
# Remove the plugin
run /usr/share/elasticsearch/bin/plugin remove jvm-example
[ "$status" -eq 0 ]
# Checks that the plugin is correctly removed
assert_file_not_exist "/usr/share/elasticsearch/bin/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example"
assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml"
assert_file_not_exist "/usr/share/elasticsearch/plugins/jvm-example"
# Delete the custom plugins directory
run rm -rf "$TEMP_CONFIG_DIR"
[ "$status" -eq 0 ]
}

View File

@ -0,0 +1 @@
plugin_test_cases.bash

View File

@ -25,10 +25,6 @@
# specific language governing permissions and limitations
# under the License.
# Variables used by tests
EXAMPLE_PLUGIN_ZIP=$(readlink -m jvm-example-*.zip)
# Checks if necessary commands are available to run the tests
if [ ! -x /usr/bin/which ]; then
@ -151,16 +147,18 @@ assert_file_not_exist() {
}
assert_file() {
local file=$1
local file="$1"
local type=$2
local user=$3
local privileges=$4
[ -n "$file" ] && [ -e "$file" ]
assert_file_exist "$file"
if [ "$type" = "d" ]; then
echo "And be a directory...."
[ -d "$file" ]
else
echo "And be a regular file...."
[ -f "$file" ]
fi
@ -179,6 +177,17 @@ assert_output() {
echo "$output" | grep -E "$1"
}
# Install the rpm or deb package
install_package() {
if is_rpm; then
rpm -i elasticsearch*.rpm
elif is_dpkg; then
dpkg -i elasticsearch*.deb
else
skip "Only rpm or deb supported"
fi
}
# Checks that all directories & files are correctly installed
# after a package (deb/rpm) install
verify_package_installation() {
@ -234,59 +243,21 @@ verify_package_installation() {
fi
}
# Install the tar.gz archive
install_archive() {
local eshome="/tmp"
if [ "x$1" != "x" ]; then
eshome="$1"
fi
tar -xzvf elasticsearch*.tar.gz -C "$eshome"
find "$eshome" -depth -type d -name 'elasticsearch*' -exec mv {} "$eshome/elasticsearch" \;
# ES cannot run as root so create elasticsearch user & group if needed
if ! getent group "elasticsearch" > /dev/null 2>&1 ; then
if is_dpkg; then
addgroup --system "elasticsearch"
else
groupadd -r "elasticsearch"
fi
fi
if ! id "elasticsearch" > /dev/null 2>&1 ; then
if is_dpkg; then
adduser --quiet --system --no-create-home --ingroup "elasticsearch" --disabled-password --shell /bin/false "elasticsearch"
else
useradd --system -M --gid "elasticsearch" --shell /sbin/nologin --comment "elasticsearch user" "elasticsearch"
fi
fi
chown -R elasticsearch:elasticsearch "$eshome/elasticsearch"
}
# Checks that all directories & files are correctly installed
# after a archive (tar.gz/zip) install
verify_archive_installation() {
local eshome="/tmp/elasticsearch"
if [ "x$1" != "x" ]; then
eshome="$1"
fi
assert_file "$eshome" d
assert_file "$eshome/bin" d
assert_file "$eshome/bin/elasticsearch" f
assert_file "$eshome/bin/elasticsearch.in.sh" f
assert_file "$eshome/bin/plugin" f
assert_file "$eshome/config" d
assert_file "$eshome/config/elasticsearch.yml" f
assert_file "$eshome/config/logging.yml" f
assert_file "$eshome/config" d
assert_file "$eshome/lib" d
assert_file "$eshome/NOTICE.txt" f
assert_file "$eshome/LICENSE.txt" f
assert_file "$eshome/README.textile" f
assert_file "$ESHOME" d
assert_file "$ESHOME/bin" d
assert_file "$ESHOME/bin/elasticsearch" f
assert_file "$ESHOME/bin/elasticsearch.in.sh" f
assert_file "$ESHOME/bin/plugin" f
assert_file "$ESCONFIG" d
assert_file "$ESCONFIG/elasticsearch.yml" f
assert_file "$ESCONFIG/logging.yml" f
assert_file "$ESHOME/lib" d
assert_file "$ESHOME/NOTICE.txt" f
assert_file "$ESHOME/LICENSE.txt" f
assert_file "$ESHOME/README.textile" f
}
# Deletes everything before running a test file
@ -478,3 +449,15 @@ run_elasticsearch_tests() {
curl -s -XDELETE 'http://localhost:9200/_all'
}
# Move the config directory to another directory and properly chown it.
move_config() {
local oldConfig="$ESCONFIG"
export ESCONFIG="${1:-$(mktemp -d -t 'config.XXXX')}"
echo "Moving configuration directory from $oldConfig to $ESCONFIG"
# Move configuration files to the new configuration directory
mv "$oldConfig"/* "$ESCONFIG"
chown -R elasticsearch:elasticsearch "$ESCONFIG"
assert_file_exist "$ESCONFIG/elasticsearch.yml"
}

View File

@ -0,0 +1,185 @@
#!/usr/bin/env bats
# This file is used to test the installation and removal
# of plugins after Elasticsearch has been installed with tar.gz,
# 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.
# The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats
# Thanks to Sam Stephenson!
# 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.
##################################
# Common test cases for both tar and rpm/deb based plugin tests
##################################
# This file is symlinked to both 25_tar_plugins.bats and 50_plugins.bats so its
# executed twice - once to test plugins using the tar distribution and once to
# test files using the rpm distribution or the deb distribution, whichever the
# system uses.
# Load test utilities
load packaging_test_utils
load plugins
setup() {
# The rules on when we should clean an reinstall are complex - all the
# jvm-example tests need cleaning because they are rough on the filesystem.
# The first and any tests that find themselves without an ESHOME need to
# clean as well.... this is going to mostly only happen on the first
# non-jvm-example-plugin-test _and_ any first test if you comment out the
# other tests. Commenting out lots of test cases seems like a reasonably
# common workflow.
if [ $BATS_TEST_NUMBER == 1 ] ||
[[ $BATS_TEST_NAME =~ install_jvm.*example ]] ||
[ ! -d "$ESHOME" ]; then
echo "cleaning" >> /tmp/ss
clean_before_test
install
fi
}
if [[ "$BATS_TEST_FILENAME" =~ 25_tar_plugins.bats$ ]]; then
load tar
GROUP='TAR PLUGINS'
install() {
install_archive
verify_archive_installation
}
export ESHOME=/tmp/elasticsearch
export_elasticsearch_paths
else
if is_rpm; then
GROUP='RPM PLUGINS'
elif is_dpkg; then
GROUP='DEB PLUGINS'
fi
export ESHOME="/usr/share/elasticsearch"
export ESPLUGINS="$ESHOME/plugins"
export ESCONFIG="/etc/elasticsearch"
install() {
install_package
verify_package_installation
}
fi
@test "[$GROUP] install jvm-example plugin" {
install_jvm_example
remove_jvm_example
}
@test "[$GROUP] install jvm-example plugin with a custom path.plugins" {
# Clean up after the last time this test was run
rm -rf /tmp/plugins.*
local oldPlugins="$ESPLUGINS"
export ESPLUGINS=$(mktemp -d -t 'plugins.XXXX')
# Modify the path.plugins setting in configuration file
echo "path.plugins: $ESPLUGINS" >> "$ESCONFIG/elasticsearch.yml"
chown -R elasticsearch:elasticsearch "$ESPLUGINS"
install_jvm_example
remove_jvm_example
}
@test "[$GROUP] install jvm-example plugin with a custom CONFIG_DIR" {
# Clean up after the last time we ran this test
rm -rf /tmp/config.*
move_config
CONF_DIR="$ESCONFIG" install_jvm_example
CONF_DIR="$ESCONFIG" remove_jvm_example
}
@test "[$GROUP] install jvm-example plugin from a directory with a space" {
rm -rf "/tmp/plugins with space"
mkdir -p "/tmp/plugins with space"
local zip=$(ls jvm-example-*.zip)
cp $zip "/tmp/plugins with space"
install_jvm_example "/tmp/plugins with space/$zip"
remove_jvm_example
}
@test "[$GROUP] install jvm-example plugin to elasticsearch directory with a space" {
[ "$GROUP" == "TAR PLUGINS" ] || skip "Test case only supported by TAR PLUGINS"
move_elasticsearch "/tmp/elastic search"
install_jvm_example
remove_jvm_example
}
@test "[$GROUP] install icu plugin" {
install_and_remove_special_plugin analysis icu icu4j-*.jar
}
@test "[$GROUP] install kuromoji plugin" {
install_and_remove_special_plugin analysis kuromoji
}
@test "[$GROUP] install phonetic plugin" {
install_and_remove_special_plugin analysis phonetic commons-codec-*.jar
}
@test "[$GROUP] install smartcn plugin" {
install_and_remove_special_plugin analysis smartcn
}
@test "[$GROUP] install stempel plugin" {
install_and_remove_special_plugin analysis stempel
}
@test "[$GROUP] install aws plugin" {
install_and_remove_special_plugin cloud aws aws-java-sdk-core-*.jar
}
@test "[$GROUP] install azure plugin" {
install_and_remove_special_plugin cloud azure azure-core-*.jar
}
@test "[$GROUP] install gce plugin" {
install_and_remove_special_plugin cloud gce google-api-client-*.jar
}
@test "[$GROUP] install delete by query" {
install_and_remove_special_plugin - delete-by-query
}
@test "[$GROUP] install javascript plugin" {
install_and_remove_special_plugin lang javascript rhino-*.jar
}
@test "[$GROUP] install python plugin" {
install_and_remove_special_plugin lang python jython-standalone-*.jar
}
@test "[$GROUP] install murmur3 mapper" {
install_and_remove_special_plugin mapper murmur3
}
@test "[$GROUP] install size mapper" {
install_and_remove_special_plugin mapper size
}

View File

@ -0,0 +1,104 @@
#!/bin/sh
# This file contains some utilities to test the elasticsearch scripts,
# 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.
# 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.
# Install a plugin an run all the common post installation tests.
install_plugin() {
local name=$1
local path="$2"
assert_file_exist "$path"
"$ESHOME/bin/plugin" install "file://$path"
assert_file_exist "$ESPLUGINS/$name"
assert_file_exist "$ESPLUGINS/$name/plugin-descriptor.properties"
assert_file_exist "$ESPLUGINS/$name/$name"*".jar"
}
# Remove a plugin and make sure its plugin directory is removed.
remove_plugin() {
local name=$1
echo "Removing $name...."
"$ESHOME/bin/plugin" remove $name
assert_file_not_exist "$ESPLUGINS/$name"
}
# Install the jvm-example plugin which fully excercises the special case file
# placements for non-site plugins.
install_jvm_example() {
local relativePath=${1:-$(readlink -m jvm-example-*.zip)}
install_plugin jvm-example "$relativePath"
assert_file_exist "$ESHOME/bin/jvm-example"
assert_file_exist "$ESHOME/bin/jvm-example/test"
assert_file_exist "$ESCONFIG/jvm-example"
assert_file_exist "$ESCONFIG/jvm-example/example.yaml"
echo "Running jvm-example's bin script...."
"$ESHOME/bin/jvm-example/test" | grep test
}
# Remove the jvm-example plugin which fully excercises the special cases of
# removing bin and not removing config.
remove_jvm_example() {
remove_plugin jvm-example
assert_file_not_exist "$ESHOME/bin/jvm-example"
assert_file_exist "$ESCONFIG/jvm-example"
assert_file_exist "$ESCONFIG/jvm-example/example.yaml"
}
# Install and remove a plugin with a special prefix. For the most part prefixes
# are just useful for grouping but the "analysis" prefix is special because all
# 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
install_and_remove_special_plugin() {
local prefix=$1
shift
local name=$1
shift
if [ "$prefix" == "-" ]; then
local fullName="$name"
else
local fullName="$prefix-$name"
fi
install_plugin $fullName "$(readlink -m $fullName-*.zip)"
if [ $prefix == 'analysis' ]; then
assert_file_exist "$(readlink -m $ESPLUGINS/$fullName/lucene-analyzers-$name-*.jar)"
fi
for file in "$@"; do
assert_file_exist "$(readlink -m $ESPLUGINS/$fullName/$file)"
done
remove_plugin $fullName
}

View File

@ -0,0 +1,73 @@
#!/bin/sh
# This file contains some utilities to test the elasticsearch scripts,
# 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.
# 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.
# Install the tar.gz archive
install_archive() {
export ESHOME=${1:-/tmp/elasticsearch}
echo "Unpacking tarball to $ESHOME"
rm -rf /tmp/untar
mkdir -p /tmp/untar
tar -xzf elasticsearch*.tar.gz -C /tmp/untar
find /tmp/untar -depth -type d -name 'elasticsearch*' -exec mv {} "$ESHOME" \; > /dev/null
# ES cannot run as root so create elasticsearch user & group if needed
if ! getent group "elasticsearch" > /dev/null 2>&1 ; then
if is_dpkg; then
addgroup --system "elasticsearch"
else
groupadd -r "elasticsearch"
fi
fi
if ! id "elasticsearch" > /dev/null 2>&1 ; then
if is_dpkg; then
adduser --quiet --system --no-create-home --ingroup "elasticsearch" --disabled-password --shell /bin/false "elasticsearch"
else
useradd --system -M --gid "elasticsearch" --shell /sbin/nologin --comment "elasticsearch user" "elasticsearch"
fi
fi
chown -R elasticsearch:elasticsearch "$ESHOME"
export_elasticsearch_paths
}
# Move the unzipped tarball to another location.
move_elasticsearch() {
local oldhome="$ESHOME"
export ESHOME="$1"
rm -rf "$ESHOME"
mv "$oldhome" "$ESHOME"
export_elasticsearch_paths
}
# Export some useful paths.
export_elasticsearch_paths() {
export ESPLUGINS="$ESHOME/plugins"
export ESCONFIG="$ESHOME/config"
}