Migrate plugin packaging tests to java (#58518)
This commit converts the bats tests for the plugin cli into the java packaging test framework. The new tests only use the example plugin to test the plugin cli. The tests for each individual plugin's contents after being installed are handled by a new unit test for the plugin installer added in #58287.
This commit is contained in:
parent
d22a242613
commit
a524800b3e
|
@ -42,6 +42,7 @@ import org.gradle.api.Plugin;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.Task;
|
import org.gradle.api.Task;
|
||||||
import org.gradle.api.artifacts.Configuration;
|
import org.gradle.api.artifacts.Configuration;
|
||||||
|
import org.gradle.api.artifacts.dsl.DependencyHandler;
|
||||||
import org.gradle.api.file.Directory;
|
import org.gradle.api.file.Directory;
|
||||||
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
||||||
import org.gradle.api.plugins.JavaBasePlugin;
|
import org.gradle.api.plugins.JavaBasePlugin;
|
||||||
|
@ -76,12 +77,12 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
// all distributions used by distro tests. this is temporary until tests are per distribution
|
// all distributions used by distro tests. this is temporary until tests are per distribution
|
||||||
private static final String DISTRIBUTIONS_CONFIGURATION = "distributions";
|
private static final String DISTRIBUTIONS_CONFIGURATION = "distributions";
|
||||||
private static final String UPGRADE_CONFIGURATION = "upgradeDistributions";
|
private static final String UPGRADE_CONFIGURATION = "upgradeDistributions";
|
||||||
private static final String PLUGINS_CONFIGURATION = "packagingPlugins";
|
private static final String EXAMPLE_PLUGIN_CONFIGURATION = "examplePlugin";
|
||||||
private static final String COPY_DISTRIBUTIONS_TASK = "copyDistributions";
|
private static final String COPY_DISTRIBUTIONS_TASK = "copyDistributions";
|
||||||
private static final String COPY_UPGRADE_TASK = "copyUpgradePackages";
|
private static final String COPY_UPGRADE_TASK = "copyUpgradePackages";
|
||||||
private static final String COPY_PLUGINS_TASK = "copyPlugins";
|
|
||||||
private static final String IN_VM_SYSPROP = "tests.inVM";
|
private static final String IN_VM_SYSPROP = "tests.inVM";
|
||||||
private static final String DISTRIBUTION_SYSPROP = "tests.distribution";
|
private static final String DISTRIBUTION_SYSPROP = "tests.distribution";
|
||||||
|
private static final String EXAMPLE_PLUGIN_SYSPROP = "tests.example-plugin";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(Project project) {
|
public void apply(Project project) {
|
||||||
|
@ -100,30 +101,22 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
Version upgradeVersion = getUpgradeVersion(project);
|
Version upgradeVersion = getUpgradeVersion(project);
|
||||||
Provider<Directory> distributionsDir = project.getLayout().getBuildDirectory().dir("packaging/distributions");
|
Provider<Directory> distributionsDir = project.getLayout().getBuildDirectory().dir("packaging/distributions");
|
||||||
Provider<Directory> upgradeDir = project.getLayout().getBuildDirectory().dir("packaging/upgrade");
|
Provider<Directory> upgradeDir = project.getLayout().getBuildDirectory().dir("packaging/upgrade");
|
||||||
Provider<Directory> pluginsDir = project.getLayout().getBuildDirectory().dir("packaging/plugins");
|
|
||||||
|
|
||||||
List<ElasticsearchDistribution> distributions = configureDistributions(project, upgradeVersion);
|
List<ElasticsearchDistribution> distributions = configureDistributions(project, upgradeVersion);
|
||||||
TaskProvider<Copy> copyDistributionsTask = configureCopyDistributionsTask(project, distributionsDir);
|
TaskProvider<Copy> copyDistributionsTask = configureCopyDistributionsTask(project, distributionsDir);
|
||||||
TaskProvider<Copy> copyUpgradeTask = configureCopyUpgradeTask(project, upgradeVersion, upgradeDir);
|
TaskProvider<Copy> copyUpgradeTask = configureCopyUpgradeTask(project, upgradeVersion, upgradeDir);
|
||||||
TaskProvider<Copy> copyPluginsTask = configureCopyPluginsTask(project, pluginsDir);
|
|
||||||
|
|
||||||
Map<ElasticsearchDistribution.Type, TaskProvider<?>> lifecyleTasks = lifecyleTasks(project, "destructiveDistroTest");
|
Map<ElasticsearchDistribution.Type, TaskProvider<?>> lifecyleTasks = lifecyleTasks(project, "destructiveDistroTest");
|
||||||
TaskProvider<Task> destructiveDistroTest = project.getTasks().register("destructiveDistroTest");
|
TaskProvider<Task> destructiveDistroTest = project.getTasks().register("destructiveDistroTest");
|
||||||
|
|
||||||
|
Configuration examplePlugin = configureExamplePlugin(project);
|
||||||
|
|
||||||
for (ElasticsearchDistribution distribution : distributions) {
|
for (ElasticsearchDistribution distribution : distributions) {
|
||||||
TaskProvider<?> destructiveTask = configureDistroTest(project, distribution, dockerSupport);
|
TaskProvider<?> destructiveTask = configureDistroTest(project, distribution, dockerSupport, examplePlugin);
|
||||||
destructiveDistroTest.configure(t -> t.dependsOn(destructiveTask));
|
destructiveDistroTest.configure(t -> t.dependsOn(destructiveTask));
|
||||||
lifecyleTasks.get(distribution.getType()).configure(t -> t.dependsOn(destructiveTask));
|
lifecyleTasks.get(distribution.getType()).configure(t -> t.dependsOn(destructiveTask));
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskProvider<BatsTestTask> batsPluginsTest = configureBatsTest(
|
|
||||||
project,
|
|
||||||
"plugins",
|
|
||||||
distributionsDir,
|
|
||||||
copyDistributionsTask,
|
|
||||||
copyPluginsTask
|
|
||||||
);
|
|
||||||
batsPluginsTest.configure(t -> t.setPluginsDir(pluginsDir));
|
|
||||||
TaskProvider<BatsTestTask> batsUpgradeTest = configureBatsTest(
|
TaskProvider<BatsTestTask> batsUpgradeTest = configureBatsTest(
|
||||||
project,
|
project,
|
||||||
"upgrade",
|
"upgrade",
|
||||||
|
@ -152,7 +145,7 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
destructiveTaskName,
|
destructiveTaskName,
|
||||||
vmDependencies
|
vmDependencies
|
||||||
);
|
);
|
||||||
vmTask.configure(t -> t.dependsOn(distribution));
|
vmTask.configure(t -> t.dependsOn(distribution, examplePlugin));
|
||||||
|
|
||||||
vmLifecyleTasks.get(distribution.getType()).configure(t -> t.dependsOn(vmTask));
|
vmLifecyleTasks.get(distribution.getType()).configure(t -> t.dependsOn(vmTask));
|
||||||
distroTest.configure(t -> {
|
distroTest.configure(t -> {
|
||||||
|
@ -175,11 +168,6 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configureVMWrapperTask(vmProject, "bats plugins", batsPluginsTest.getName(), vmDependencies).configure(t -> {
|
|
||||||
t.setProgressHandler(new BatsProgressLogger(project.getLogger()));
|
|
||||||
t.onlyIf(spec -> isWindows(vmProject) == false); // bats doesn't run on windows
|
|
||||||
t.dependsOn(copyDistributionsTask, copyPluginsTask);
|
|
||||||
});
|
|
||||||
configureVMWrapperTask(vmProject, "bats upgrade", batsUpgradeTest.getName(), vmDependencies).configure(t -> {
|
configureVMWrapperTask(vmProject, "bats upgrade", batsUpgradeTest.getName(), vmDependencies).configure(t -> {
|
||||||
t.setProgressHandler(new BatsProgressLogger(project.getLogger()));
|
t.setProgressHandler(new BatsProgressLogger(project.getLogger()));
|
||||||
t.onlyIf(spec -> isWindows(vmProject) == false); // bats doesn't run on windows
|
t.onlyIf(spec -> isWindows(vmProject) == false); // bats doesn't run on windows
|
||||||
|
@ -327,14 +315,12 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TaskProvider<Copy> configureCopyPluginsTask(Project project, Provider<Directory> pluginsDir) {
|
private static Configuration configureExamplePlugin(Project project) {
|
||||||
Configuration pluginsConfiguration = project.getConfigurations().create(PLUGINS_CONFIGURATION);
|
Configuration examplePlugin = project.getConfigurations().create(EXAMPLE_PLUGIN_CONFIGURATION);
|
||||||
|
DependencyHandler deps = project.getDependencies();
|
||||||
// temporary, until we have tasks per distribution
|
Map<String, String> examplePluginProject = Map.of("path", ":example-plugins:custom-settings", "configuration", "zip");
|
||||||
return project.getTasks().register(COPY_PLUGINS_TASK, Copy.class, t -> {
|
deps.add(EXAMPLE_PLUGIN_CONFIGURATION, deps.project(examplePluginProject));
|
||||||
t.into(pluginsDir);
|
return examplePlugin;
|
||||||
t.from(pluginsConfiguration);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TaskProvider<GradleDistroTestTask> configureVMWrapperTask(
|
private static TaskProvider<GradleDistroTestTask> configureVMWrapperTask(
|
||||||
|
@ -358,7 +344,8 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
private static TaskProvider<?> configureDistroTest(
|
private static TaskProvider<?> configureDistroTest(
|
||||||
Project project,
|
Project project,
|
||||||
ElasticsearchDistribution distribution,
|
ElasticsearchDistribution distribution,
|
||||||
Provider<DockerSupportService> dockerSupport
|
Provider<DockerSupportService> dockerSupport,
|
||||||
|
Configuration examplePlugin
|
||||||
) {
|
) {
|
||||||
return project.getTasks().register(destructiveDistroTestTaskName(distribution), Test.class, t -> {
|
return project.getTasks().register(destructiveDistroTestTaskName(distribution), Test.class, t -> {
|
||||||
// Disable Docker distribution tests unless a Docker installation is available
|
// Disable Docker distribution tests unless a Docker installation is available
|
||||||
|
@ -369,8 +356,10 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
t.setMaxParallelForks(1);
|
t.setMaxParallelForks(1);
|
||||||
t.setWorkingDir(project.getProjectDir());
|
t.setWorkingDir(project.getProjectDir());
|
||||||
t.systemProperty(DISTRIBUTION_SYSPROP, distribution.toString());
|
t.systemProperty(DISTRIBUTION_SYSPROP, distribution.toString());
|
||||||
|
t.systemProperty(EXAMPLE_PLUGIN_SYSPROP, examplePlugin.getSingleFile().toString());
|
||||||
if (System.getProperty(IN_VM_SYSPROP) == null) {
|
if (System.getProperty(IN_VM_SYSPROP) == null) {
|
||||||
t.dependsOn(distribution);
|
t.dependsOn(distribution);
|
||||||
|
t.dependsOn(examplePlugin);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
module_and_plugin_test_cases.bash
|
|
|
@ -1 +0,0 @@
|
||||||
module_and_plugin_test_cases.bash
|
|
|
@ -1,476 +0,0 @@
|
||||||
#!/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 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
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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_modules_and_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 $BATS_UTILS/utils.bash
|
|
||||||
load $BATS_UTILS/modules.bash
|
|
||||||
load $BATS_UTILS/plugins.bash
|
|
||||||
|
|
||||||
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_a_sample_plugin ]] ||
|
|
||||||
[ ! -d "$ESHOME" ]; then
|
|
||||||
clean_before_test
|
|
||||||
install
|
|
||||||
set_debug_logging
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$BATS_TEST_FILENAME" =~ 25_tar_plugins.bats$ ]]; then
|
|
||||||
load $BATS_UTILS/tar.bash
|
|
||||||
GROUP='TAR PLUGINS'
|
|
||||||
install() {
|
|
||||||
install_archive
|
|
||||||
verify_archive_installation
|
|
||||||
}
|
|
||||||
export ESHOME=/tmp/elasticsearch
|
|
||||||
export_elasticsearch_paths
|
|
||||||
export ESPLUGIN_COMMAND_USER=elasticsearch
|
|
||||||
else
|
|
||||||
load $BATS_UTILS/packages.bash
|
|
||||||
if is_rpm; then
|
|
||||||
GROUP='RPM PLUGINS'
|
|
||||||
elif is_dpkg; then
|
|
||||||
GROUP='DEB PLUGINS'
|
|
||||||
fi
|
|
||||||
export_elasticsearch_paths
|
|
||||||
export ESPLUGIN_COMMAND_USER=root
|
|
||||||
install() {
|
|
||||||
install_package
|
|
||||||
verify_package_installation
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
@test "[$GROUP] install a sample plugin with a symlinked plugins path" {
|
|
||||||
# Clean up after the last time this test was run
|
|
||||||
rm -rf /var/plugins.*
|
|
||||||
rm -rf /var/old_plugins.*
|
|
||||||
|
|
||||||
rm -rf "$ESPLUGINS"
|
|
||||||
# The custom plugins directory is not under /tmp or /var/tmp because
|
|
||||||
# systemd's private temp directory functionally means different
|
|
||||||
# processes can have different views of what's in these directories
|
|
||||||
local es_plugins=$(mktemp -p /var -d -t 'plugins.XXXX')
|
|
||||||
chown -R elasticsearch:elasticsearch "$es_plugins"
|
|
||||||
ln -s "$es_plugins" "$ESPLUGINS"
|
|
||||||
|
|
||||||
install_plugin_example
|
|
||||||
start_elasticsearch_service
|
|
||||||
|
|
||||||
# check that symlinked plugin was actually picked up
|
|
||||||
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/plugins?h=component' | sed 's/ *$//' > /tmp/installed
|
|
||||||
echo "custom-settings" > /tmp/expected
|
|
||||||
diff /tmp/installed /tmp/expected
|
|
||||||
|
|
||||||
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cluster/settings?include_defaults&filter_path=defaults.custom.simple' > /tmp/installed
|
|
||||||
echo -n '{"defaults":{"custom":{"simple":"foo"}}}' > /tmp/expected
|
|
||||||
diff /tmp/installed /tmp/expected
|
|
||||||
|
|
||||||
stop_elasticsearch_service
|
|
||||||
remove_plugin_example
|
|
||||||
|
|
||||||
unlink "$ESPLUGINS"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install a sample plugin with a custom CONFIG_DIR" {
|
|
||||||
# Clean up after the last time we ran this test
|
|
||||||
rm -rf /tmp/config.*
|
|
||||||
|
|
||||||
move_config
|
|
||||||
|
|
||||||
ES_PATH_CONF="$ESCONFIG" install_plugin_example
|
|
||||||
ES_PATH_CONF="$ESCONFIG" start_elasticsearch_service
|
|
||||||
|
|
||||||
# check that symlinked plugin was actually picked up
|
|
||||||
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/plugins?h=component' | sed 's/ *$//' > /tmp/installed
|
|
||||||
echo "custom-settings" > /tmp/expected
|
|
||||||
diff /tmp/installed /tmp/expected
|
|
||||||
|
|
||||||
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cluster/settings?include_defaults&filter_path=defaults.custom.simple' > /tmp/installed
|
|
||||||
echo -n '{"defaults":{"custom":{"simple":"foo"}}}' > /tmp/expected
|
|
||||||
diff /tmp/installed /tmp/expected
|
|
||||||
|
|
||||||
stop_elasticsearch_service
|
|
||||||
ES_PATH_CONF="$ESCONFIG" remove_plugin_example
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install a sample plugin from a directory with a space" {
|
|
||||||
rm -rf "/tmp/plugins with space"
|
|
||||||
mkdir -p "/tmp/plugins with space"
|
|
||||||
local zip=$(ls $BATS_PLUGINS/custom-settings-*.zip)
|
|
||||||
local zipname=$(basename $zip)
|
|
||||||
cp $zip "/tmp/plugins with space"
|
|
||||||
|
|
||||||
install_plugin_example "/tmp/plugins with space/$zipname"
|
|
||||||
remove_plugin_example
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install a sample plugin to elasticsearch directory with a space" {
|
|
||||||
[ "$GROUP" == "TAR PLUGINS" ] || skip "Test case only supported by TAR PLUGINS"
|
|
||||||
|
|
||||||
move_elasticsearch "/tmp/elastic search"
|
|
||||||
|
|
||||||
install_plugin_example
|
|
||||||
remove_plugin_example
|
|
||||||
}
|
|
||||||
|
|
||||||
# Note that all of the tests from here to the end of the file expect to be run
|
|
||||||
# in sequence and don't take well to being run one at a time.
|
|
||||||
@test "[$GROUP] install a sample plugin" {
|
|
||||||
install_plugin_example
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install icu plugin" {
|
|
||||||
install_and_check_plugin analysis icu icu4j-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install kuromoji plugin" {
|
|
||||||
install_and_check_plugin analysis kuromoji
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install nori plugin" {
|
|
||||||
install_and_check_plugin analysis nori
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install phonetic plugin" {
|
|
||||||
install_and_check_plugin analysis phonetic commons-codec-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install smartcn plugin" {
|
|
||||||
install_and_check_plugin analysis smartcn
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install stempel plugin" {
|
|
||||||
install_and_check_plugin analysis stempel
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install ukrainian plugin" {
|
|
||||||
install_and_check_plugin analysis ukrainian morfologik-fsa-*.jar morfologik-stemming-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install gce plugin" {
|
|
||||||
install_and_check_plugin discovery gce google-api-client-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install discovery-azure-classic plugin" {
|
|
||||||
install_and_check_plugin discovery azure-classic azure-core-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install discovery-ec2 plugin" {
|
|
||||||
install_and_check_plugin discovery ec2 aws-java-sdk-core-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install ingest-attachment plugin" {
|
|
||||||
# we specify the version on the poi-4.0.1.jar so that the test does
|
|
||||||
# not spuriously pass if the jar is missing but the other poi jars
|
|
||||||
# are present
|
|
||||||
install_and_check_plugin ingest attachment bcprov-jdk15on-*.jar tika-core-*.jar pdfbox-*.jar poi-4.0.1.jar poi-ooxml-4.0.1.jar poi-ooxml-schemas-*.jar poi-scratchpad-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check ingest-common module" {
|
|
||||||
check_module ingest-common jcodings-*.jar joni-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check ingest-geoip module" {
|
|
||||||
check_module ingest-geoip geoip2-*.jar jackson-annotations-*.jar jackson-databind-*.jar maxmind-db-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check ingest-user-agent module" {
|
|
||||||
check_module ingest-user-agent
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check lang-expression module" {
|
|
||||||
# we specify the version on the asm-5.0.4.jar so that the test does
|
|
||||||
# not spuriously pass if the jar is missing but the other asm jars
|
|
||||||
# are present
|
|
||||||
check_secure_module lang-expression antlr4-runtime-*.jar asm-5.0.4.jar asm-commons-*.jar asm-tree-*.jar lucene-expressions-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check lang-mustache module" {
|
|
||||||
check_secure_module lang-mustache compiler-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check lang-painless module" {
|
|
||||||
check_secure_module lang-painless antlr4-runtime-*.jar asm-util-*.jar asm-tree-*.jar asm-commons-*.jar asm-analysis-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install murmur3 mapper plugin" {
|
|
||||||
install_and_check_plugin mapper murmur3
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install annotated-text mapper plugin" {
|
|
||||||
install_and_check_plugin mapper annotated-text
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check reindex module" {
|
|
||||||
check_module reindex
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install repository-hdfs plugin" {
|
|
||||||
install_and_check_plugin repository hdfs hadoop-client-*.jar hadoop-common-*.jar hadoop-annotations-*.jar hadoop-auth-*.jar hadoop-hdfs-client-*.jar htrace-core4-*.jar guava-*.jar protobuf-java-*.jar commons-logging-*.jar commons-cli-*.jar commons-collections-*.jar commons-configuration-*.jar commons-io-*.jar commons-lang-*.jar servlet-api-*.jar slf4j-api-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install size mapper plugin" {
|
|
||||||
install_and_check_plugin mapper size
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install repository-azure plugin" {
|
|
||||||
install_and_check_plugin repository azure azure-storage-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install repository-gcs plugin" {
|
|
||||||
install_and_check_plugin repository gcs google-api-services-storage-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install repository-s3 plugin" {
|
|
||||||
install_and_check_plugin repository s3 aws-java-sdk-core-*.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install store-smb plugin" {
|
|
||||||
install_and_check_plugin store smb
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install transport-nio plugin" {
|
|
||||||
install_and_check_plugin transport nio
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check the installed plugins can be listed with 'plugins list' and result matches the list of plugins in plugins pom" {
|
|
||||||
"$ESHOME/bin/elasticsearch-plugin" list | cut -d'@' -f1 > /tmp/installed
|
|
||||||
compare_plugins_list "/tmp/installed" "'plugins list'"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] start elasticsearch with all plugins installed" {
|
|
||||||
start_elasticsearch_service
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check the installed plugins matches the list of build plugins" {
|
|
||||||
curl -s localhost:9200/_cat/plugins?h=c | sed 's/ *$//' > /tmp/installed
|
|
||||||
compare_plugins_list "/tmp/installed" "_cat/plugins"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] stop elasticsearch" {
|
|
||||||
stop_elasticsearch_service
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove a sample plugin" {
|
|
||||||
remove_plugin_example
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove icu plugin" {
|
|
||||||
remove_plugin analysis-icu
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove kuromoji plugin" {
|
|
||||||
remove_plugin analysis-kuromoji
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove nori plugin" {
|
|
||||||
remove_plugin analysis-nori
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove phonetic plugin" {
|
|
||||||
remove_plugin analysis-phonetic
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove smartcn plugin" {
|
|
||||||
remove_plugin analysis-smartcn
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove stempel plugin" {
|
|
||||||
remove_plugin analysis-stempel
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove ukrainian plugin" {
|
|
||||||
remove_plugin analysis-ukrainian
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove gce plugin" {
|
|
||||||
remove_plugin discovery-gce
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove discovery-azure-classic plugin" {
|
|
||||||
remove_plugin discovery-azure-classic
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove discovery-ec2 plugin" {
|
|
||||||
remove_plugin discovery-ec2
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove ingest-attachment plugin" {
|
|
||||||
remove_plugin ingest-attachment
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove murmur3 mapper plugin" {
|
|
||||||
remove_plugin mapper-murmur3
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove annotated-text mapper plugin" {
|
|
||||||
remove_plugin mapper-annotated-text
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove size mapper plugin" {
|
|
||||||
remove_plugin mapper-size
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove repository-azure plugin" {
|
|
||||||
remove_plugin repository-azure
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove repository-gcs plugin" {
|
|
||||||
remove_plugin repository-gcs
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove repository-hdfs plugin" {
|
|
||||||
remove_plugin repository-hdfs
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove repository-s3 plugin" {
|
|
||||||
remove_plugin repository-s3
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove store-smb plugin" {
|
|
||||||
remove_plugin store-smb
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] remove transport-nio plugin" {
|
|
||||||
remove_plugin transport-nio
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] start elasticsearch with all plugins removed" {
|
|
||||||
start_elasticsearch_service
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] check that there are now no plugins installed" {
|
|
||||||
curl -s localhost:9200/_cat/plugins > /tmp/installed
|
|
||||||
local installedCount=$(cat /tmp/installed | wc -l)
|
|
||||||
[ "$installedCount" == "0" ] || {
|
|
||||||
echo "Expected all plugins to be removed but found $installedCount:"
|
|
||||||
cat /tmp/installed
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] stop elasticsearch" {
|
|
||||||
stop_elasticsearch_service
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] install a sample plugin with different logging modes and check output" {
|
|
||||||
local relativePath=${1:-$(readlink -m $BATS_PLUGINS/custom-settings-*.zip)}
|
|
||||||
sudo -E -u $ESPLUGIN_COMMAND_USER "$ESHOME/bin/elasticsearch-plugin" install --batch "file://$relativePath" > /tmp/plugin-cli-output
|
|
||||||
# exclude progress line
|
|
||||||
local loglines=$(cat /tmp/plugin-cli-output | grep -v "^[[:cntrl:]]" | wc -l)
|
|
||||||
[ "$loglines" -eq "3" ] || {
|
|
||||||
echo "Expected 3 lines excluding progress bar but the output had $loglines lines and was:"
|
|
||||||
cat /tmp/plugin-cli-output
|
|
||||||
false
|
|
||||||
}
|
|
||||||
remove_plugin_example
|
|
||||||
|
|
||||||
local relativePath=${1:-$(readlink -m $BATS_PLUGINS/custom-settings-*.zip)}
|
|
||||||
sudo -E -u $ESPLUGIN_COMMAND_USER ES_JAVA_OPTS="-Des.logger.level=DEBUG" "$ESHOME/bin/elasticsearch-plugin" install --batch "file://$relativePath" > /tmp/plugin-cli-output
|
|
||||||
local loglines=$(cat /tmp/plugin-cli-output | grep -v "^[[:cntrl:]]" | wc -l)
|
|
||||||
[ "$loglines" -gt "2" ] || {
|
|
||||||
echo "Expected more than 2 lines excluding progress bar but the output had $loglines lines and was:"
|
|
||||||
cat /tmp/plugin-cli-output
|
|
||||||
false
|
|
||||||
}
|
|
||||||
remove_plugin_example
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] test java home with space" {
|
|
||||||
# preserve JAVA_HOME
|
|
||||||
local java_home=$JAVA_HOME
|
|
||||||
|
|
||||||
# create a JAVA_HOME with a space
|
|
||||||
local java=$(which java)
|
|
||||||
local temp=`mktemp -d --suffix="java home"`
|
|
||||||
mkdir -p "$temp/bin"
|
|
||||||
ln -s "$java" "$temp/bin/java"
|
|
||||||
export JAVA_HOME="$temp"
|
|
||||||
|
|
||||||
# this will fail if the elasticsearch-plugin script does not
|
|
||||||
# properly handle JAVA_HOME with spaces
|
|
||||||
"$ESHOME/bin/elasticsearch-plugin" list
|
|
||||||
|
|
||||||
rm -rf "$temp"
|
|
||||||
|
|
||||||
# restore JAVA_HOME
|
|
||||||
export JAVA_HOME=$java_home
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] test ES_JAVA_OPTS" {
|
|
||||||
# preserve ES_JAVA_OPTS
|
|
||||||
local es_java_opts=$ES_JAVA_OPTS
|
|
||||||
|
|
||||||
export ES_JAVA_OPTS="-XX:+PrintFlagsFinal"
|
|
||||||
# this will fail if ES_JAVA_OPTS is not passed through
|
|
||||||
"$ESHOME/bin/elasticsearch-plugin" list | grep MaxHeapSize
|
|
||||||
|
|
||||||
# restore ES_JAVA_OPTS
|
|
||||||
export ES_JAVA_OPTS=$es_java_opts
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] test umask" {
|
|
||||||
install_plugin_example $(readlink -m $BATS_PLUGINS/custom-settings-*.zip) 0077
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[$GROUP] hostname" {
|
|
||||||
local temp=`mktemp -d`
|
|
||||||
cp "$ESCONFIG"/elasticsearch.yml "$temp"
|
|
||||||
echo 'node.name: ${HOSTNAME}' >> "$ESCONFIG"/elasticsearch.yml
|
|
||||||
start_elasticsearch_service
|
|
||||||
wait_for_elasticsearch_status
|
|
||||||
[ "$(curl -XGET localhost:9200/_cat/nodes?h=name)" == "$HOSTNAME" ]
|
|
||||||
stop_elasticsearch_service
|
|
||||||
cp "$temp"/elasticsearch.yml "$ESCONFIG"/elasticsearch.yml
|
|
||||||
rm -rf "$temp"
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# 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 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
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
check_module() {
|
|
||||||
local name=$1
|
|
||||||
shift
|
|
||||||
|
|
||||||
assert_module_or_plugin_directory "$ESMODULES/$name"
|
|
||||||
|
|
||||||
for file in "$@"; do
|
|
||||||
assert_module_or_plugin_file "$ESMODULES/$name/$file"
|
|
||||||
done
|
|
||||||
|
|
||||||
assert_module_or_plugin_file "$ESMODULES/$name/$name-*.jar"
|
|
||||||
assert_module_or_plugin_file "$ESMODULES/$name/plugin-descriptor.properties"
|
|
||||||
}
|
|
||||||
|
|
||||||
check_secure_module() {
|
|
||||||
check_module "$@" plugin-security.policy
|
|
||||||
}
|
|
|
@ -1,191 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# This file contains some utilities to test the elasticsearch
|
|
||||||
# plugin installation and uninstallation process.
|
|
||||||
|
|
||||||
# WARNING: This testing file must be executed as root and can
|
|
||||||
# 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
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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
|
|
||||||
install_plugin() {
|
|
||||||
local name=$1
|
|
||||||
local path="$2"
|
|
||||||
local umask="$3"
|
|
||||||
|
|
||||||
assert_file_exist "$path"
|
|
||||||
|
|
||||||
if [ ! -z "$ES_PATH_CONF" ] ; then
|
|
||||||
if is_dpkg; then
|
|
||||||
echo "ES_PATH_CONF=$ES_PATH_CONF" >> /etc/default/elasticsearch;
|
|
||||||
elif is_rpm; then
|
|
||||||
echo "ES_PATH_CONF=$ES_PATH_CONF" >> /etc/sysconfig/elasticsearch;
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$umask" ]; then
|
|
||||||
sudo -E -u $ESPLUGIN_COMMAND_USER "$ESHOME/bin/elasticsearch-plugin" install --batch "file://$path"
|
|
||||||
else
|
|
||||||
sudo -E -u $ESPLUGIN_COMMAND_USER bash -c "umask $umask && \"$ESHOME/bin/elasticsearch-plugin\" install --batch \"file://$path\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
#check we did not accidentially create a log file as root as /usr/share/elasticsearch
|
|
||||||
assert_file_not_exist "/usr/share/elasticsearch/logs"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove a plugin and make sure its plugin directory is removed.
|
|
||||||
remove_plugin() {
|
|
||||||
local name=$1
|
|
||||||
|
|
||||||
echo "Removing $name...."
|
|
||||||
sudo -E -u $ESPLUGIN_COMMAND_USER "$ESHOME/bin/elasticsearch-plugin" remove $name
|
|
||||||
|
|
||||||
assert_file_not_exist "$ESPLUGINS/$name"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install a sample plugin which fully exercises the special case file placements.
|
|
||||||
install_plugin_example() {
|
|
||||||
local relativePath=${1:-$(readlink -m $BATS_PLUGINS/custom-settings-*.zip)}
|
|
||||||
install_plugin custom-settings "$relativePath" $2
|
|
||||||
|
|
||||||
bin_user=$(find "$ESHOME/bin" -maxdepth 0 -printf "%u")
|
|
||||||
bin_owner=$(find "$ESHOME/bin" -maxdepth 0 -printf "%g")
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
#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
|
|
||||||
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
|
|
||||||
|
|
||||||
#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")
|
|
||||||
# directories should user the user file-creation mask
|
|
||||||
assert_file "$ESCONFIG/custom-settings" d $config_user $config_owner 750
|
|
||||||
assert_file "$ESCONFIG/custom-settings/custom.yml" f $config_user $config_owner 660
|
|
||||||
|
|
||||||
run sudo -E -u vagrant LANG="en_US.UTF-8" cat "$ESCONFIG/custom-settings/custom.yml"
|
|
||||||
[ $status = 1 ]
|
|
||||||
[[ "$output" == *"Permission denied"* ]] || {
|
|
||||||
echo "Expected permission denied but found $output:"
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "Running sample plugin bin script...."
|
|
||||||
"$ESHOME/bin/custom-settings/test" | grep test
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove the sample plugin which fully exercises the special cases of
|
|
||||||
# removing bin and not removing config.
|
|
||||||
remove_plugin_example() {
|
|
||||||
remove_plugin custom-settings
|
|
||||||
|
|
||||||
assert_file_not_exist "$ESHOME/bin/custom-settings"
|
|
||||||
assert_file_exist "$ESCONFIG/custom-settings"
|
|
||||||
assert_file_exist "$ESCONFIG/custom-settings/custom.yml"
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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
|
|
||||||
# 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_check_plugin() {
|
|
||||||
local prefix=$1
|
|
||||||
shift
|
|
||||||
local name=$1
|
|
||||||
shift
|
|
||||||
|
|
||||||
if [ "$prefix" == "-" ]; then
|
|
||||||
local full_name="$name"
|
|
||||||
else
|
|
||||||
local full_name="$prefix-$name"
|
|
||||||
fi
|
|
||||||
|
|
||||||
install_plugin $full_name "$(readlink -m $BATS_PLUGINS/$full_name-*.zip)"
|
|
||||||
|
|
||||||
assert_module_or_plugin_directory "$ESPLUGINS/$full_name"
|
|
||||||
assert_file_exist "$ESPLUGINS/$full_name/plugin-descriptor.properties"
|
|
||||||
assert_file_exist "$ESPLUGINS/$full_name/$full_name"*".jar"
|
|
||||||
|
|
||||||
# analysis plugins have a corresponding analyzers jar
|
|
||||||
if [ $prefix == 'analysis' ]; then
|
|
||||||
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"
|
|
||||||
fi
|
|
||||||
for file in "$@"; do
|
|
||||||
assert_module_or_plugin_file "$ESPLUGINS/$full_name/$file"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
install_plugin $name "$(readlink -m $BATS_PLUGINS/$name-*.zip)"
|
|
||||||
assert_module_or_plugin_directory "$ESPLUGINS/$name"
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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 (>):"
|
|
||||||
# bats tests are run under build/packaging/distributions, and expected file is in build/plugins/expected
|
|
||||||
# this can't be an absolute path since it differs whether running in vagrant or GCP
|
|
||||||
diff -w ../../plugins/expected /tmp/plugins
|
|
||||||
}
|
|
|
@ -58,7 +58,7 @@ tasks.dependenciesInfo.enabled = false
|
||||||
tasks.thirdPartyAudit.ignoreMissingClasses()
|
tasks.thirdPartyAudit.ignoreMissingClasses()
|
||||||
|
|
||||||
tasks.register('destructivePackagingTest') {
|
tasks.register('destructivePackagingTest') {
|
||||||
dependsOn 'destructiveDistroTest', 'destructiveBatsTest.plugins', 'destructiveBatsTest.upgrade'
|
dependsOn 'destructiveDistroTest', 'destructiveBatsTest.upgrade'
|
||||||
}
|
}
|
||||||
|
|
||||||
processTestResources {
|
processTestResources {
|
||||||
|
@ -67,33 +67,10 @@ processTestResources {
|
||||||
|
|
||||||
subprojects { Project platformProject ->
|
subprojects { Project platformProject ->
|
||||||
tasks.register('packagingTest') {
|
tasks.register('packagingTest') {
|
||||||
dependsOn 'distroTest', 'batsTest.plugins', 'batsTest.upgrade'
|
dependsOn 'distroTest', 'batsTest.upgrade'
|
||||||
}
|
}
|
||||||
|
|
||||||
vagrant {
|
vagrant {
|
||||||
hostEnv 'VAGRANT_PROJECT_DIR', platformProject.projectDir.absolutePath
|
hostEnv 'VAGRANT_PROJECT_DIR', platformProject.projectDir.absolutePath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> pluginNames = []
|
|
||||||
for (Project subproj : project.rootProject.subprojects) {
|
|
||||||
if (subproj.parent.path == ':plugins' || subproj.path.equals(':example-plugins:custom-settings')) {
|
|
||||||
// add plugin as a dep
|
|
||||||
dependencies {
|
|
||||||
packagingPlugins project(path: "${subproj.path}", configuration: 'zip')
|
|
||||||
}
|
|
||||||
pluginNames.add(subproj.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pluginNames = pluginNames.toSorted()
|
|
||||||
|
|
||||||
tasks.named('copyPlugins') {
|
|
||||||
doLast {
|
|
||||||
// TODO: this was copied from the old way bats tests get the plugins list. we should pass
|
|
||||||
// this in differently when converting to java tests
|
|
||||||
File expectedPlugins = file('build/plugins/expected')
|
|
||||||
expectedPlugins.parentFile.mkdirs()
|
|
||||||
expectedPlugins.setText(pluginNames.join('\n'), 'UTF-8')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.packaging.test;
|
||||||
|
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.elasticsearch.packaging.util.Distribution;
|
||||||
|
import org.elasticsearch.packaging.util.FileUtils;
|
||||||
|
import org.elasticsearch.packaging.util.Platforms;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
import static org.elasticsearch.packaging.util.FileUtils.append;
|
||||||
|
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
public class ConfigurationTests extends PackagingTestCase {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void filterDistros() {
|
||||||
|
assumeTrue("no docker", distribution.packaging != Distribution.Packaging.DOCKER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test10Install() throws Exception {
|
||||||
|
install();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test60HostnameSubstitution() throws Exception {
|
||||||
|
String hostnameKey = Platforms.WINDOWS ? "COMPUTERNAME" : "HOSTNAME";
|
||||||
|
sh.getEnv().put(hostnameKey, "mytesthost");
|
||||||
|
withCustomConfig(confPath -> {
|
||||||
|
FileUtils.append(confPath.resolve("elasticsearch.yml"), "node.name: ${HOSTNAME}");
|
||||||
|
if (distribution.isPackage()) {
|
||||||
|
append(installation.envFile, "HOSTNAME=mytesthost");
|
||||||
|
}
|
||||||
|
assertWhileRunning(() -> {
|
||||||
|
final String nameResponse = makeRequest(Request.Get("http://localhost:9200/_cat/nodes?h=name")).trim();
|
||||||
|
assertThat(nameResponse, equalTo("mytesthost"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -403,7 +403,7 @@ public abstract class PackagingTestCase extends Assert {
|
||||||
* use the temporary directory.
|
* use the temporary directory.
|
||||||
*/
|
*/
|
||||||
public void withCustomConfig(CheckedConsumer<Path, Exception> action) throws Exception {
|
public void withCustomConfig(CheckedConsumer<Path, Exception> action) throws Exception {
|
||||||
Path tempDir = Files.createTempDirectory(getRootTempDir(), "custom-config");
|
Path tempDir = createTempDir("custom-config");
|
||||||
Path tempConf = tempDir.resolve("elasticsearch");
|
Path tempConf = tempDir.resolve("elasticsearch");
|
||||||
FileUtils.copyDirectory(installation.config, tempConf);
|
FileUtils.copyDirectory(installation.config, tempConf);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.packaging.test;
|
||||||
|
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.elasticsearch.packaging.util.Distribution;
|
||||||
|
import org.elasticsearch.packaging.util.Installation;
|
||||||
|
import org.elasticsearch.packaging.util.Platforms;
|
||||||
|
import org.elasticsearch.packaging.util.Shell;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
public class PluginCliTests extends PackagingTestCase {
|
||||||
|
|
||||||
|
private static final String EXAMPLE_PLUGIN_NAME = "custom-settings";
|
||||||
|
private static final Path EXAMPLE_PLUGIN_ZIP;
|
||||||
|
static {
|
||||||
|
// re-read before each test so the plugin path can be manipulated within tests
|
||||||
|
EXAMPLE_PLUGIN_ZIP = Paths.get(System.getProperty("tests.example-plugin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void filterDistros() {
|
||||||
|
assumeTrue("no docker", distribution.packaging != Distribution.Packaging.DOCKER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface PluginAction {
|
||||||
|
void run(Shell.Result installResult) throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Shell.Result assertWithPlugin(Installation.Executable pluginTool, Path pluginZip, String pluginName, PluginAction action)
|
||||||
|
throws Exception {
|
||||||
|
Shell.Result installResult = pluginTool.run("install --batch \"" + pluginZip.toUri().toString() + "\"");
|
||||||
|
action.run(installResult);
|
||||||
|
return pluginTool.run("remove " + pluginName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertWithExamplePlugin(PluginAction action) throws Exception {
|
||||||
|
assertWithPlugin(installation.executables().pluginTool, EXAMPLE_PLUGIN_ZIP, EXAMPLE_PLUGIN_NAME, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test10Install() throws Exception {
|
||||||
|
install();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test20SymlinkPluginsDir() throws Exception {
|
||||||
|
Path pluginsDir = installation.plugins;
|
||||||
|
Path stashedPluginsDir = createTempDir("stashed-plugins");
|
||||||
|
|
||||||
|
Files.delete(stashedPluginsDir); // delete so we can replace it
|
||||||
|
Files.move(pluginsDir, stashedPluginsDir);
|
||||||
|
Path linkedPlugins = createTempDir("symlinked-plugins");
|
||||||
|
Platforms.onLinux(() -> sh.run("chown elasticsearch:elasticsearch " + linkedPlugins.toString()));
|
||||||
|
Files.createSymbolicLink(pluginsDir, linkedPlugins);
|
||||||
|
assertWithExamplePlugin(installResult -> {
|
||||||
|
assertWhileRunning(() -> {
|
||||||
|
final String pluginsResponse = makeRequest(Request.Get("http://localhost:9200/_cat/plugins?h=component")).trim();
|
||||||
|
assertThat(pluginsResponse, equalTo(EXAMPLE_PLUGIN_NAME));
|
||||||
|
|
||||||
|
String settingsPath = "_cluster/settings?include_defaults&filter_path=defaults.custom.simple";
|
||||||
|
final String settingsResponse = makeRequest(Request.Get("http://localhost:9200/" + settingsPath)).trim();
|
||||||
|
assertThat(settingsResponse, equalTo("{\"defaults\":{\"custom\":{\"simple\":\"foo\"}}}"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Files.delete(pluginsDir);
|
||||||
|
Files.move(stashedPluginsDir, pluginsDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test21CustomConfDir() throws Exception {
|
||||||
|
withCustomConfig(confPath -> assertWithExamplePlugin(installResult -> {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test22PluginZipWithSpace() throws Exception {
|
||||||
|
Path spacedDir = createTempDir("spaced dir");
|
||||||
|
Path plugin = Files.copy(EXAMPLE_PLUGIN_ZIP, spacedDir.resolve(EXAMPLE_PLUGIN_ZIP.getFileName()));
|
||||||
|
assertWithPlugin(installation.executables().pluginTool, plugin, EXAMPLE_PLUGIN_NAME, installResult -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test23ElasticsearchWithSpace() throws Exception {
|
||||||
|
assumeTrue(distribution.isArchive());
|
||||||
|
|
||||||
|
Path spacedDir = createTempDir("spaced dir");
|
||||||
|
Path elasticsearch = spacedDir.resolve("elasticsearch");
|
||||||
|
Files.move(installation.home, elasticsearch);
|
||||||
|
Installation spacedInstallation = Installation.ofArchive(sh, distribution, elasticsearch);
|
||||||
|
|
||||||
|
assertWithPlugin(spacedInstallation.executables().pluginTool, EXAMPLE_PLUGIN_ZIP, EXAMPLE_PLUGIN_NAME, installResult -> {});
|
||||||
|
|
||||||
|
Files.move(elasticsearch, installation.home);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test24JavaOpts() throws Exception {
|
||||||
|
sh.getEnv().put("ES_JAVA_OPTS", "-XX:+PrintFlagsFinal");
|
||||||
|
assertWithExamplePlugin(installResult -> assertThat(installResult.stdout, containsString("MaxHeapSize")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test25Umask() throws Exception {
|
||||||
|
sh.setUmask("0077");
|
||||||
|
assertWithExamplePlugin(installResult -> {});
|
||||||
|
}
|
||||||
|
}
|
|
@ -169,14 +169,20 @@ public class Installation {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shell.Result run(String args, String input) {
|
public Shell.Result run(String args, String input) {
|
||||||
String command = path + " " + args;
|
String command = path.toString();
|
||||||
if (distribution.isArchive() && Platforms.WINDOWS == false) {
|
if (Platforms.WINDOWS) {
|
||||||
|
command = "& '" + command + "'";
|
||||||
|
} else {
|
||||||
|
command = "\"" + command + "\"";
|
||||||
|
if (distribution.isArchive()) {
|
||||||
command = "sudo -E -u " + ARCHIVE_OWNER + " " + command;
|
command = "sudo -E -u " + ARCHIVE_OWNER + " " + command;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
command = "echo \"" + input + "\" | " + command;
|
command = "echo \"" + input + "\" | " + command;
|
||||||
}
|
}
|
||||||
return sh.run(command);
|
return sh.run(command + " " + args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,10 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -46,6 +48,7 @@ public class Shell {
|
||||||
protected final Logger logger = LogManager.getLogger(getClass());
|
protected final Logger logger = LogManager.getLogger(getClass());
|
||||||
|
|
||||||
final Map<String, String> env = new HashMap<>();
|
final Map<String, String> env = new HashMap<>();
|
||||||
|
String umask;
|
||||||
Path workingDirectory;
|
Path workingDirectory;
|
||||||
|
|
||||||
public Shell() {
|
public Shell() {
|
||||||
|
@ -58,6 +61,7 @@ public class Shell {
|
||||||
public void reset() {
|
public void reset() {
|
||||||
env.clear();
|
env.clear();
|
||||||
workingDirectory = null;
|
workingDirectory = null;
|
||||||
|
umask = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getEnv() {
|
public Map<String, String> getEnv() {
|
||||||
|
@ -68,6 +72,10 @@ public class Shell {
|
||||||
this.workingDirectory = workingDirectory;
|
this.workingDirectory = workingDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUmask(String umask) {
|
||||||
|
this.umask = umask;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the provided string as a shell script. On Linux the {@code bash -c [script]} syntax will be used, and on Windows
|
* Run the provided string as a shell script. On Linux the {@code bash -c [script]} syntax will be used, and on Windows
|
||||||
* the {@code powershell.exe -Command [script]} syntax will be used. Throws an exception if the exit code of the script is nonzero
|
* the {@code powershell.exe -Command [script]} syntax will be used. Throws an exception if the exit code of the script is nonzero
|
||||||
|
@ -127,8 +135,16 @@ public class Shell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] bashCommand(String script) {
|
private String[] bashCommand(String script) {
|
||||||
return new String[] { "bash", "-c", script };
|
List<String> command = new ArrayList<>();
|
||||||
|
command.add("bash");
|
||||||
|
command.add("-c");
|
||||||
|
if (umask == null) {
|
||||||
|
command.add(script);
|
||||||
|
} else {
|
||||||
|
command.add(String.format(Locale.ROOT, "umask %s && %s", umask, script));
|
||||||
|
}
|
||||||
|
return command.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] powershellCommand(String script) {
|
private static String[] powershellCommand(String script) {
|
||||||
|
|
Loading…
Reference in New Issue