Split off upgrade and plugins bats tests (#45360) (#45508)

The bats tests currently require many additional artifacts to be built.
In addition to the current distributions, they need all the plugins to
be installed, as well as a randomly chosen bwc distribution. This commit
splits these two cases into their own bats task, so the dependencies do
not slow down other tasks like distroTests which do not need them.
This commit is contained in:
Ryan Ernst 2019-08-13 12:45:29 -07:00 committed by GitHub
parent 884f26a1dc
commit 80a3aeaef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 136 additions and 52 deletions

View File

@ -67,8 +67,12 @@ public class DistroTestPlugin implements Plugin<Project> {
private static final String GRADLE_JDK_VERSION = "12.0.1+12@69cfe15208a647278a19ef0990eea691";
// all distributions used by distro tests. this is temporary until tests are per distribution
private static final String PACKAGING_DISTRIBUTION = "packaging";
private static final String DISTRIBUTIONS_CONFIGURATION = "distributions";
private static final String UPGRADE_CONFIGURATION = "upgradeDistributions";
private static final String PLUGINS_CONFIGURATION = "packagingPlugins";
private static final String COPY_DISTRIBUTIONS_TASK = "copyDistributions";
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";
@Override
@ -81,15 +85,24 @@ public class DistroTestPlugin implements Plugin<Project> {
Version upgradeVersion = getUpgradeVersion(project);
Provider<Directory> distributionsDir = project.getLayout().getBuildDirectory().dir("packaging/distributions");
Provider<Directory> upgradeDir = project.getLayout().getBuildDirectory().dir("packaging/upgrade");
Provider<Directory> pluginsDir = project.getLayout().getBuildDirectory().dir("packaging/plugins");
configureDistributions(project, upgradeVersion);
TaskProvider<Copy> copyDistributionsTask = configureCopyDistributionsTask(project, upgradeVersion, distributionsDir);
TaskProvider<Copy> copyDistributionsTask = configureCopyDistributionsTask(project, distributionsDir);
TaskProvider<Copy> copyUpgradeTask = configureCopyUpgradeTask(project, upgradeVersion, upgradeDir);
TaskProvider<Copy> copyPluginsTask = configureCopyPluginsTask(project, pluginsDir);
Map<String, TaskProvider<?>> distroTests = new HashMap<>();
Map<String, TaskProvider<?>> batsTests = new HashMap<>();
distroTests.put("distribution", configureDistroTest(project, distributionsDir, copyDistributionsTask));
batsTests.put("bats oss", configureBatsTest(project, "oss", distributionsDir, copyDistributionsTask));
batsTests.put("bats default", configureBatsTest(project, "default", distributionsDir, copyDistributionsTask));
configureBatsTest(project, "plugins",distributionsDir, copyDistributionsTask, copyPluginsTask).configure(t ->
t.setPluginsDir(pluginsDir)
);
configureBatsTest(project, "upgrade", distributionsDir, copyDistributionsTask, copyUpgradeTask).configure(t ->
t.setUpgradeDir(upgradeDir));
project.subprojects(vmProject -> {
vmProject.getPluginManager().apply(VagrantBasePlugin.class);
@ -171,16 +184,36 @@ public class DistroTestPlugin implements Plugin<Project> {
};
}
private static TaskProvider<Copy> configureCopyDistributionsTask(Project project, Version upgradeVersion,
Provider<Directory> archivesDir) {
private static TaskProvider<Copy> configureCopyDistributionsTask(Project project, Provider<Directory> distributionsDir) {
// temporary, until we have tasks per distribution
return project.getTasks().register(COPY_DISTRIBUTIONS_TASK, Copy.class,
t -> {
t.into(archivesDir);
t.from(project.getConfigurations().getByName(PACKAGING_DISTRIBUTION));
t.into(distributionsDir);
t.from(project.getConfigurations().getByName(DISTRIBUTIONS_CONFIGURATION));
Path archivesPath = archivesDir.get().getAsFile().toPath();
Path distributionsPath = distributionsDir.get().getAsFile().toPath();
TaskInputs inputs = t.getInputs();
inputs.property("version", VersionProperties.getElasticsearch());
t.doLast(action -> {
try {
Files.writeString(distributionsPath.resolve("version"), VersionProperties.getElasticsearch());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
});
}
private static TaskProvider<Copy> configureCopyUpgradeTask(Project project, Version upgradeVersion,
Provider<Directory> upgradeDir) {
// temporary, until we have tasks per distribution
return project.getTasks().register(COPY_UPGRADE_TASK, Copy.class,
t -> {
t.into(upgradeDir);
t.from(project.getConfigurations().getByName(UPGRADE_CONFIGURATION));
Path upgradePath = upgradeDir.get().getAsFile().toPath();
// write bwc version, and append -SNAPSHOT if it is an unreleased version
ExtraPropertiesExtension extraProperties = project.getExtensions().getByType(ExtraPropertiesExtension.class);
@ -192,15 +225,14 @@ public class DistroTestPlugin implements Plugin<Project> {
upgradeFromVersion = upgradeVersion.toString();
}
TaskInputs inputs = t.getInputs();
inputs.property("version", VersionProperties.getElasticsearch());
inputs.property("upgrade_from_version", upgradeFromVersion);
// TODO: this is serializable, need to think how to represent this as an input
//inputs.property("bwc_versions", bwcVersions);
t.doLast(action -> {
try {
Files.writeString(archivesPath.resolve("version"), VersionProperties.getElasticsearch());
Files.writeString(archivesPath.resolve("upgrade_from_version"), upgradeFromVersion);
Path upgradeMarkerPath = archivesPath.resolve("upgrade_is_oss");
Files.writeString(upgradePath.resolve("version"), VersionProperties.getElasticsearch());
Files.writeString(upgradePath.resolve("upgrade_from_version"), upgradeFromVersion);
Path upgradeMarkerPath = upgradePath.resolve("upgrade_is_oss");
project.delete(upgradeMarkerPath);
// this is always true, but bats tests rely on it. It is just temporary until bats is removed.
if (upgradeVersion.onOrAfter("6.3.0")) {
@ -210,11 +242,22 @@ public class DistroTestPlugin implements Plugin<Project> {
throw new UncheckedIOException(e);
}
});
});
});
}
private TaskProvider<GradleDistroTestTask> configureVMWrapperTask(Project project, String type, String destructiveTaskPath,
List<Object> dependsOn) {
private static TaskProvider<Copy> configureCopyPluginsTask(Project project, Provider<Directory> pluginsDir) {
Configuration pluginsConfiguration = project.getConfigurations().create(PLUGINS_CONFIGURATION);
// temporary, until we have tasks per distribution
return project.getTasks().register(COPY_PLUGINS_TASK, Copy.class,
t -> {
t.into(pluginsDir);
t.from(pluginsConfiguration);
});
}
private static TaskProvider<GradleDistroTestTask> configureVMWrapperTask(Project project, String type, String destructiveTaskPath,
List<Object> dependsOn) {
int taskNameStart = destructiveTaskPath.lastIndexOf(':') + "destructive".length() + 1;
String taskname = destructiveTaskPath.substring(taskNameStart);
taskname = taskname.substring(0, 1).toLowerCase(Locale.ROOT) + taskname.substring(1);
@ -228,8 +271,8 @@ public class DistroTestPlugin implements Plugin<Project> {
});
}
private TaskProvider<?> configureDistroTest(Project project, Provider<Directory> distributionsDir,
TaskProvider<Copy> copyPackagingArchives) {
private static TaskProvider<?> configureDistroTest(Project project, Provider<Directory> distributionsDir,
TaskProvider<Copy> copyPackagingArchives) {
// TODO: don't run with security manager...
return project.getTasks().register("destructiveDistroTest", Test.class,
t -> {
@ -241,8 +284,8 @@ public class DistroTestPlugin implements Plugin<Project> {
});
}
private TaskProvider<?> configureBatsTest(Project project, String type, Provider<Directory> distributionsDir,
TaskProvider<Copy> copyPackagingArchives) {
private static TaskProvider<BatsTestTask> configureBatsTest(Project project, String type, Provider<Directory> distributionsDir,
TaskProvider<Copy> copyPackagingArchives, Object... deps) {
return project.getTasks().register("destructiveBatsTest." + type, BatsTestTask.class,
t -> {
Directory batsDir = project.getLayout().getProjectDirectory().dir("bats");
@ -251,51 +294,60 @@ public class DistroTestPlugin implements Plugin<Project> {
t.setDistributionsDir(distributionsDir);
t.setPackageName("elasticsearch" + (type.equals("oss") ? "-oss" : ""));
if (System.getProperty(IN_VM_SYSPROP) == null) {
t.dependsOn(copyPackagingArchives);
t.dependsOn(deps);
}
});
}
private void configureDistributions(Project project, Version upgradeVersion) {
NamedDomainObjectContainer<ElasticsearchDistribution> distributions = DistributionDownloadPlugin.getContainer(project);
List<ElasticsearchDistribution> currentDistros = new ArrayList<>();
List<ElasticsearchDistribution> upgradeDistros = new ArrayList<>();
for (Type type : Arrays.asList(Type.DEB, Type.RPM)) {
for (Flavor flavor : Flavor.values()) {
for (boolean bundledJdk : Arrays.asList(true, false)) {
addDistro(distributions, type, null, flavor, bundledJdk, VersionProperties.getElasticsearch());
addDistro(distributions, type, null, flavor, bundledJdk, VersionProperties.getElasticsearch(), currentDistros);
}
}
// upgrade version is always bundled jdk
// NOTE: this is mimicking the old VagrantTestPlugin upgrade behavior. It will eventually be replaced
// witha dedicated upgrade test from every bwc version like other bwc tests
addDistro(distributions, type, null, Flavor.DEFAULT, true, upgradeVersion.toString());
addDistro(distributions, type, null, Flavor.DEFAULT, true, upgradeVersion.toString(), upgradeDistros);
if (upgradeVersion.onOrAfter("6.3.0")) {
addDistro(distributions, type, null, Flavor.OSS, true, upgradeVersion.toString());
addDistro(distributions, type, null, Flavor.OSS, true, upgradeVersion.toString(), upgradeDistros);
}
}
for (Platform platform : Arrays.asList(Platform.LINUX, Platform.WINDOWS)) {
for (Flavor flavor : Flavor.values()) {
for (boolean bundledJdk : Arrays.asList(true, false)) {
addDistro(distributions, Type.ARCHIVE, platform, flavor, bundledJdk, VersionProperties.getElasticsearch());
addDistro(distributions, Type.ARCHIVE, platform, flavor, bundledJdk,
VersionProperties.getElasticsearch(), currentDistros);
}
}
}
// temporary until distro tests have one test per distro
Configuration packagingConfig = project.getConfigurations().create(PACKAGING_DISTRIBUTION);
List<Configuration> distroConfigs = distributions.stream().map(ElasticsearchDistribution::getConfiguration)
Configuration packagingConfig = project.getConfigurations().create(DISTRIBUTIONS_CONFIGURATION);
List<Configuration> distroConfigs = currentDistros.stream().map(ElasticsearchDistribution::getConfiguration)
.collect(Collectors.toList());
packagingConfig.setExtendsFrom(distroConfigs);
Configuration packagingUpgradeConfig = project.getConfigurations().create(UPGRADE_CONFIGURATION);
List<Configuration> distroUpgradeConfigs = upgradeDistros.stream().map(ElasticsearchDistribution::getConfiguration)
.collect(Collectors.toList());
packagingUpgradeConfig.setExtendsFrom(distroUpgradeConfigs);
}
private static void addDistro(NamedDomainObjectContainer<ElasticsearchDistribution> distributions,
Type type, Platform platform, Flavor flavor, boolean bundledJdk, String version) {
Type type, Platform platform, Flavor flavor, boolean bundledJdk, String version,
List<ElasticsearchDistribution> container) {
String name = flavor + "-" + (type == Type.ARCHIVE ? platform + "-" : "") + type + (bundledJdk ? "" : "-no-jdk") + "-" + version;
if (distributions.findByName(name) != null) {
return;
}
distributions.create(name, d -> {
ElasticsearchDistribution distro = distributions.create(name, d -> {
d.setFlavor(flavor);
d.setType(type);
if (type == Type.ARCHIVE) {
@ -304,5 +356,6 @@ public class DistroTestPlugin implements Plugin<Project> {
d.setBundledJdk(bundledJdk);
d.setVersion(version);
});
container.add(distro);
}
}

View File

@ -25,6 +25,7 @@ import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
import java.util.ArrayList;
@ -36,12 +37,16 @@ public class BatsTestTask extends DefaultTask {
private final DirectoryProperty testsDir;
private final DirectoryProperty utilsDir;
private final DirectoryProperty distributionsDir;
private final DirectoryProperty pluginsDir;
private final DirectoryProperty upgradeDir;
private String packageName;
public BatsTestTask() {
this.testsDir = getProject().getObjects().directoryProperty();
this.utilsDir = getProject().getObjects().directoryProperty();
this.distributionsDir = getProject().getObjects().directoryProperty();
this.pluginsDir = getProject().getObjects().directoryProperty();
this.upgradeDir = getProject().getObjects().directoryProperty();
}
@InputDirectory
@ -71,6 +76,26 @@ public class BatsTestTask extends DefaultTask {
this.distributionsDir.set(distributionsDir);
}
@InputDirectory
@Optional
public Provider<Directory> getPluginsDir() {
return pluginsDir;
}
public void setPluginsDir(Provider<Directory> pluginsDir) {
this.pluginsDir.set(pluginsDir);
}
@InputDirectory
@Optional
public Provider<Directory> getUpgradeDir() {
return upgradeDir;
}
public void setUpgradeDir(Provider<Directory> upgradeDir) {
this.upgradeDir.set(upgradeDir);
}
@Input
public String getPackageName() {
return packageName;
@ -93,6 +118,12 @@ public class BatsTestTask extends DefaultTask {
spec.environment(System.getenv());
spec.environment("BATS_TESTS", testsDir.getAsFile().get().toString());
spec.environment("BATS_UTILS", utilsDir.getAsFile().get().toString());
if (pluginsDir.isPresent()) {
spec.environment("BATS_PLUGINS", pluginsDir.getAsFile().get().toString());
}
if (upgradeDir.isPresent()) {
spec.environment("BATS_UPGRADE", upgradeDir.getAsFile().get().toString());
}
spec.environment("PACKAGE_NAME", packageName);
spec.setCommandLine(command);
});

View File

@ -146,10 +146,11 @@ fi
@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 custom-settings-*.zip)
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/$zip"
install_plugin_example "/tmp/plugins with space/$zipname"
remove_plugin_example
}
@ -403,7 +404,7 @@ fi
}
@test "[$GROUP] install a sample plugin with different logging modes and check output" {
local relativePath=${1:-$(readlink -m custom-settings-*.zip)}
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)
@ -414,7 +415,7 @@ fi
}
remove_plugin_example
local relativePath=${1:-$(readlink -m custom-settings-*.zip)}
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" ] || {
@ -459,7 +460,7 @@ fi
}
@test "[$GROUP] test umask" {
install_plugin_example $(readlink -m custom-settings-*.zip) 0077
install_plugin_example $(readlink -m $BATS_PLUGINS/custom-settings-*.zip) 0077
}
@test "[$GROUP] hostname" {

View File

@ -44,11 +44,11 @@ setup() {
skip_not_dpkg_or_rpm
sameVersion="false"
if [ "$(cat upgrade_from_version)" == "$(cat version)" ]; then
if [ "$(cat $BATS_UPGRADE/upgrade_from_version)" == "$(cat version)" ]; then
sameVersion="true"
fi
# TODO: this needs to conditionally change based on version > 6.3.0
if [ -f upgrade_is_oss ]; then
if [ -f $BATS_UPGRADE/upgrade_is_oss ]; then
export PACKAGE_NAME="elasticsearch-oss"
else
skip "upgrade cannot happen from pre 6.3.0 to elasticsearch-oss"
@ -57,7 +57,7 @@ setup() {
@test "[UPGRADE] install old version" {
clean_before_test
install_package -v $(cat upgrade_from_version)
install_package -v $(cat $BATS_UPGRADE/upgrade_from_version) -d $BATS_UPGRADE
}
@test "[UPGRADE] modify keystore" {
@ -74,7 +74,7 @@ setup() {
}
@test "[UPGRADE] check elasticsearch version is old version" {
check_elasticsearch_version "$(cat upgrade_from_version)"
check_elasticsearch_version "$(cat $BATS_UPGRADE/upgrade_from_version)"
}
@test "[UPGRADE] index some documents into a few indexes" {

View File

@ -58,6 +58,7 @@ export_elasticsearch_paths() {
install_package() {
local version=$(cat version)
local rpmCommand='-i'
local dir='./'
while getopts ":fuv:" opt; do
case $opt in
u)
@ -68,6 +69,9 @@ install_package() {
rpmCommand='-U --force'
dpkgCommand='--force-conflicts'
;;
d)
dir=$OPTARG
;;
v)
version=$OPTARG
;;
@ -83,9 +87,9 @@ install_package() {
deb_classifier=""
fi
if is_rpm; then
rpm $rpmCommand $PACKAGE_NAME-$version$rpm_classifier.rpm
rpm $rpmCommand $dir/$PACKAGE_NAME-$version$rpm_classifier.rpm
elif is_dpkg; then
run dpkg $dpkgCommand -i $PACKAGE_NAME-$version$deb_classifier.deb
run dpkg $dpkgCommand -i $dir/$PACKAGE_NAME-$version$deb_classifier.deb
[[ "$status" -eq 0 ]] || {
echo "dpkg failed:"
echo "$output"

View File

@ -84,7 +84,7 @@ remove_plugin() {
# Install a sample plugin which fully exercises the special case file placements.
install_plugin_example() {
local relativePath=${1:-$(readlink -m custom-settings-*.zip)}
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")
@ -146,7 +146,7 @@ install_and_check_plugin() {
local full_name="$prefix-$name"
fi
install_plugin $full_name "$(readlink -m $full_name-*.zip)"
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"
@ -175,7 +175,7 @@ install_and_check_plugin() {
install_meta_plugin() {
local name=$1
install_plugin $name "$(readlink -m $name-*.zip)"
install_plugin $name "$(readlink -m $BATS_PLUGINS/$name-*.zip)"
assert_module_or_plugin_directory "$ESPLUGINS/$name"
}

View File

@ -81,30 +81,25 @@ subprojects { Project platformProject ->
}
}
configurations {
allPlugins
}
List<String> plugins = []
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 {
allPlugins project(path: "${subproj.path}", configuration: 'zip')
packagingPlugins project(path: "${subproj.path}", configuration: 'zip')
}
plugins.add(subproj.name)
pluginNames.add(subproj.name)
}
}
plugins = plugins.toSorted()
pluginNames = pluginNames.toSorted()
tasks.named('copyDistributions') {
from configurations.allPlugins
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(plugins.join('\n'), 'UTF-8')
expectedPlugins.setText(pluginNames.join('\n'), 'UTF-8')
}
}