Skip to content

Commit

Permalink
Convert x-pack rolling upgrade tests to new test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Oct 6, 2023
1 parent 7ff9c9f commit 99ea966
Show file tree
Hide file tree
Showing 54 changed files with 646 additions and 478 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public static Iterable<Object[]> createParameters(NamedXContentRegistry executea
/**
* Create parameters for this parameterized test.
*/
public static Iterable<Object[]> createParameters(String[] testPaths) throws Exception {
public static Iterable<Object[]> createParameters(String... testPaths) throws Exception {
return createParameters(ExecutableSection.XCONTENT_REGISTRY, testPaths);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public LicenseClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCa

@ParametersFactory
public static Iterable<Object[]> parameters() throws Exception {
return ESClientYamlSuiteTestCase.createParameters(new String[] { "license" });
return ESClientYamlSuiteTestCase.createParameters("license");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RRFRankClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCa

@ParametersFactory
public static Iterable<Object[]> parameters() throws Exception {
return ESClientYamlSuiteTestCase.createParameters(new String[] { "rrf" });
return ESClientYamlSuiteTestCase.createParameters("rrf");
}

@Override
Expand Down
206 changes: 24 additions & 182 deletions x-pack/qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
@@ -1,209 +1,51 @@
import org.elasticsearch.gradle.internal.BwcVersions
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
import org.elasticsearch.gradle.util.GradleUtils

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.bwc-test'
apply plugin: 'elasticsearch.rest-resources'

dependencies {
testImplementation testArtifact(project(xpackModule('core')))
testImplementation project(':x-pack:qa')
testImplementation project(':client:rest-high-level')
implementation project(':test:framework')
implementation project(':test:test-clusters')
implementation project(':x-pack:qa')
javaRestTestImplementation testArtifact(project(xpackModule('core')))
yamlRestTestImplementation testArtifact(project(xpackModule('core')))
javaRestTestImplementation project(':client:rest-high-level')
}

GradleUtils.extendSourceSet(project, "main", "yamlRestTest", tasks.named("yamlRestTest"))
GradleUtils.extendSourceSet(project, "main", "javaRestTest", tasks.named("javaRestTest"))

restResources {
restApi {
include '*'
}
}

tasks.named("forbiddenPatterns").configure {
exclude '**/system_key'
}

String outputDir = "${buildDir}/generated-resources/${project.name}"

tasks.register("copyTestNodeKeyMaterial", Copy) {
from project(':x-pack:plugin:core').files('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem',
'src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt')
into outputDir
}
tasks.named("yamlRestTest") { enabled = false}

BuildParams.bwcVersions.withWireCompatible { bwcVersion, baseName ->
String oldVersion = bwcVersion.toString()

// SearchableSnapshotsRollingUpgradeIT uses a specific repository to not interfere with other tests
String searchableSnapshotRepository = "${buildDir}/cluster/shared/searchable-snapshots-repo/${baseName}"

def baseCluster = testClusters.register(baseName) {
testDistribution = "DEFAULT"
versions = [oldVersion, project.version]
numberOfNodes = 3

systemProperty 'ingest.geoip.downloader.enabled.default', 'true'
//we don't want to hit real service from each test
systemProperty 'ingest.geoip.downloader.endpoint.default', 'http://invalid.endpoint'
if (bwcVersion.onOrAfter('7.14.0')) {
setting 'ingest.geoip.downloader.endpoint', 'http://invalid.endpoint'
}

setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
setting 'path.repo', "['${buildDir}/cluster/shared/repo/${baseName}', '${searchableSnapshotRepository}']"
setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
setting 'xpack.security.transport.ssl.enabled', 'true'
setting 'xpack.security.authc.token.enabled', 'true'
setting 'xpack.security.authc.token.timeout', '60m'
setting 'xpack.security.authc.api_key.enabled', 'true'
setting 'xpack.security.audit.enabled', 'true'
setting 'xpack.security.transport.ssl.key', 'testnode.pem'
setting 'xpack.security.transport.ssl.certificate', 'testnode.crt'
keystore 'xpack.security.transport.ssl.secure_key_passphrase', 'testnode'

if (bwcVersion.onOrAfter('7.0.0')) {
setting 'xpack.security.authc.realms.file.file1.order', '0'
setting 'xpack.security.authc.realms.native.native1.order', '1'
} else {
setting 'xpack.security.authc.realms.file1.type', 'file'
setting 'xpack.security.authc.realms.file1.order', '0'
setting 'xpack.security.authc.realms.native1.type', 'native'
setting 'xpack.security.authc.realms.native1.order', '1'
}
if (bwcVersion.onOrAfter('6.6.0')) {
setting 'ccr.auto_follow.wait_for_metadata_timeout', '1s'
}
if (bwcVersion.onOrAfter('7.11.0')) {
extraConfigFile 'operator_users.yml', file("${project.projectDir}/src/test/resources/operator_users.yml")
setting 'xpack.security.operator_privileges.enabled', "true"
user username: "non_operator", password: 'x-pack-test-password', role: "superuser"
}

user username: "test_user", password: "x-pack-test-password"

extraConfigFile 'testnode.pem', file("$outputDir/testnode.pem")
extraConfigFile 'testnode.crt', file("$outputDir/testnode.crt")

keystore 'xpack.watcher.encryption_key', file("${project.projectDir}/src/test/resources/system_key")
setting 'xpack.watcher.encrypt_sensitive_data', 'true'

// Old versions of the code contain an invalid assertion that trips
// during tests. Versions 5.6.9 and 6.2.4 have been fixed by removing
// the assertion, but this is impossible for released versions.
// However, released versions run without assertions, so end users won't
// be suffering the effects. This argument effectively removes the
// incorrect assertion from the older versions used in the BWC tests.
if (bwcVersion.before('5.6.9') || (bwcVersion.onOrAfter('6.0.0') && bwcVersion.before('6.2.4'))) {
jvmArgs '-da:org.elasticsearch.xpack.monitoring.exporter.http.HttpExportBulk'
}
setting 'logger.org.elasticsearch.xpack.watcher', 'DEBUG'

if (bwcVersion.onOrAfter('7.12.0')) {
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
}
def javaRestTest = tasks.register("v${bwcVersion}#javaRestTest", StandaloneRestIntegTestTask) {
usesBwcDistribution(bwcVersion)
systemProperty('tests.upgrade_from_version', bwcVersion)
systemProperty('tests.ml.skip', Boolean.toString(BwcVersions.isMlCompatible(bwcVersion) == false))
}

tasks.register("${baseName}#oldClusterTest", StandaloneRestIntegTestTask) {
useCluster baseCluster
mustRunAfter("precommit")
dependsOn "copyTestNodeKeyMaterial"
doFirst {
delete("${buildDir}/cluster/shared/repo/${baseName}")
delete("${searchableSnapshotRepository}")
}

systemProperty 'tests.rest.suite', 'old_cluster'
systemProperty 'tests.upgrade_from_version', oldVersion
systemProperty 'tests.path.searchable.snapshots.repo', searchableSnapshotRepository
nonInputProperties.systemProperty('tests.rest.cluster', baseCluster.map(c->c.allHttpSocketURI.join(",")))
nonInputProperties.systemProperty('tests.clustername', baseName)

// Disable ML tests for incompatible systems
if (BwcVersions.isMlCompatible(bwcVersion) == false) {
systemProperty 'tests.ml.skip', 'true'
systemProperty 'tests.rest.blacklist', ['old_cluster/30_ml_jobs_crud/*', 'old_cluster/40_ml_datafeed_crud/*', 'old_cluster/90_ml_data_frame_analytics_crud'].join(',')
}
}

tasks.register("${baseName}#oneThirdUpgradedTest", StandaloneRestIntegTestTask) {
dependsOn "${baseName}#oldClusterTest"
useCluster baseCluster
doFirst {
baseCluster.get().nextNodeToNextVersion()
}
nonInputProperties.systemProperty('tests.rest.cluster', baseCluster.map(c->c.allHttpSocketURI.join(",")))
nonInputProperties.systemProperty('tests.clustername', baseName)
systemProperty 'tests.rest.suite', 'mixed_cluster'
systemProperty 'tests.first_round', 'true'
systemProperty 'tests.upgrade_from_version', oldVersion
systemProperty 'tests.path.searchable.snapshots.repo', searchableSnapshotRepository
// We only need to run these tests once so we may as well do it when we're two thirds upgraded
def excludeList = [
'mixed_cluster/10_basic/Start scroll in mixed cluster on upgraded node that we will continue after upgrade',
'mixed_cluster/30_ml_jobs_crud/Create a job in the mixed cluster and write some data',
'mixed_cluster/40_ml_datafeed_crud/Put job and datafeed in mixed cluster',
'mixed_cluster/40_ml_datafeed_crud/Put job and datafeed without aggs in mixed cluster',
'mixed_cluster/40_ml_datafeed_crud/Put job and datafeed with aggs in mixed cluster',
'mixed_cluster/40_ml_datafeed_crud/Put job and datafeed with composite aggs in mixed cluster',
'mixed_cluster/80_transform_jobs_crud/Test put batch transform on mixed cluster',
'mixed_cluster/80_transform_jobs_crud/Test put continuous transform on mixed cluster',
'mixed_cluster/90_ml_data_frame_analytics_crud/Put an outlier_detection job on the mixed cluster',
'mixed_cluster/110_enrich/Enrich stats query smoke test for mixed cluster',
'mixed_cluster/120_api_key/Test API key authentication will work in a mixed cluster',
'mixed_cluster/120_api_key/Create API key with metadata in a mixed cluster',
'mixed_cluster/130_operator_privileges/Test operator privileges will work in the mixed cluster'
]

// Disable ML tests for incompatible systems
if (BwcVersions.isMlCompatible(bwcVersion) == false) {
systemProperty 'tests.ml.skip', 'true'
excludeList.addAll(['mixed_cluster/30_ml_jobs_crud/*', 'mixed_cluster/40_ml_datafeed_crud/*', 'mixed_cluster/90_ml_data_frame_analytics_crud'])
}
systemProperty 'tests.rest.blacklist', excludeList.join(',')
}

tasks.register("${baseName}#twoThirdsUpgradedTest", StandaloneRestIntegTestTask) {
dependsOn "${baseName}#oneThirdUpgradedTest"
useCluster baseCluster
doFirst {
baseCluster.get().nextNodeToNextVersion()
}
nonInputProperties.systemProperty('tests.rest.cluster', "${-> baseCluster.get().allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', baseName)
systemProperty 'tests.rest.suite', 'mixed_cluster'
systemProperty 'tests.first_round', 'false'
systemProperty 'tests.upgrade_from_version', oldVersion
systemProperty 'tests.path.searchable.snapshots.repo', searchableSnapshotRepository

// Disable ML tests for incompatible systems
if (BwcVersions.isMlCompatible(bwcVersion) == false) {
systemProperty 'tests.ml.skip', 'true'
systemProperty 'tests.rest.blacklist', ['mixed_cluster/30_ml_jobs_crud/*', 'mixed_cluster/40_ml_datafeed_crud/*', 'mixed_cluster/90_ml_data_frame_analytics_crud'].join(',')
}
}

tasks.register("${baseName}#upgradedClusterTest", StandaloneRestIntegTestTask) {
dependsOn "${baseName}#twoThirdsUpgradedTest"
useCluster baseCluster
doFirst {
baseCluster.get().nextNodeToNextVersion()
}
nonInputProperties.systemProperty('tests.rest.cluster', "${-> baseCluster.get().allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', baseName)
systemProperty 'tests.rest.suite', 'upgraded_cluster'
systemProperty 'tests.upgrade_from_version', oldVersion
systemProperty 'tests.path.searchable.snapshots.repo', searchableSnapshotRepository

def yamlRestTest = tasks.register("v${bwcVersion}#yamlRestTest", StandaloneRestIntegTestTask) {
testClassesDirs = sourceSets.yamlRestTest.output.classesDirs
classpath = sourceSets.yamlRestTest.runtimeClasspath
usesBwcDistribution(bwcVersion)
systemProperty('tests.upgrade_from_version', bwcVersion)
// Disable ML tests for incompatible systems
if (BwcVersions.isMlCompatible(bwcVersion) == false) {
systemProperty 'tests.ml.skip', 'true'
systemProperty 'tests.rest.blacklist', ['upgraded_cluster/30_ml_jobs_crud/*', 'upgraded_cluster/40_ml_datafeed_crud/*', 'upgraded_cluster/90_ml_data_frame_analytics_crud'].join(',')
systemProperty 'tests.rest.blacklist', ['*/30_ml_jobs_crud/*', '*/40_ml_datafeed_crud/*', '*/90_ml_data_frame_analytics_crud'].join(',')
}
}

tasks.register(bwcTaskName(bwcVersion)) {
dependsOn "${baseName}#upgradedClusterTest"
dependsOn(javaRestTest, yamlRestTest)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package org.elasticsearch.upgrades;

import com.carrotsearch.randomizedtesting.annotations.Name;

import org.apache.http.HttpHost;
import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.Build;
Expand All @@ -25,6 +27,7 @@
import org.elasticsearch.xpack.core.security.authz.RoleDescriptorTests;
import org.elasticsearch.xpack.core.security.user.User;
import org.elasticsearch.xpack.test.SecuritySettingsSourceField;
import org.junit.BeforeClass;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -51,11 +54,19 @@ public class ApiKeyBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
private RestClient oldVersionClient = null;
private RestClient newVersionClient = null;

public void testCreatingAndUpdatingApiKeys() throws Exception {
public ApiKeyBackwardsCompatibilityIT(@Name("upgradedNodes") int upgradedNodes) {
super(upgradedNodes);
}

@BeforeClass
public static void testVersionCompatibility() {
assumeTrue(
"The remote_indices for API Keys are not supported before version " + API_KEY_SUPPORT_REMOTE_INDICES_VERSION,
UPGRADE_FROM_VERSION.before(API_KEY_SUPPORT_REMOTE_INDICES_VERSION)
);
}

public void testCreatingAndUpdatingApiKeys() throws Exception {
switch (CLUSTER_TYPE) {
case OLD -> {
// succeed when remote_indices are not provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.elasticsearch.upgrades;

import com.carrotsearch.randomizedtesting.annotations.Name;

import org.apache.http.util.EntityUtils;
import org.elasticsearch.Version;
import org.elasticsearch.client.Request;
Expand All @@ -15,6 +17,7 @@
import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.Strings;
import org.hamcrest.Matchers;
import org.junit.BeforeClass;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -24,8 +27,16 @@

public class DataStreamsUpgradeIT extends AbstractUpgradeTestCase {

public void testDataStreams() throws IOException {
public DataStreamsUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
super(upgradedNodes);
}

@BeforeClass
public static void testVersionCompatibility() {
assumeTrue("no data streams in versions before " + Version.V_7_9_0, UPGRADE_FROM_VERSION.onOrAfter(Version.V_7_9_0));
}

public void testDataStreams() throws IOException {
if (CLUSTER_TYPE == ClusterType.OLD) {
String requestBody = """
{
Expand Down Expand Up @@ -67,7 +78,7 @@ public void testDataStreams() throws IOException {
Request index = new Request("POST", "/logs-foobar/_doc");
index.addParameter("refresh", "true");
index.addParameter("filter_path", "_index");
if (Booleans.parseBoolean(System.getProperty("tests.first_round"))) {
if (isFirstRound()) {
// include legacy name and date-named indices with today +/-1 in case of clock skew
var expectedIndices = List.of(
"{\"_index\":\"" + DataStreamTestHelper.getLegacyDefaultBackingIndexName("logs-foobar", 2) + "\"}",
Expand Down Expand Up @@ -96,7 +107,7 @@ public void testDataStreams() throws IOException {
if (CLUSTER_TYPE.equals(ClusterType.OLD)) {
expectedCount = 1000;
} else if (CLUSTER_TYPE.equals(ClusterType.MIXED)) {
if (Booleans.parseBoolean(System.getProperty("tests.first_round"))) {
if (isFirstRound()) {
expectedCount = 1001;
} else {
expectedCount = 1002;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package org.elasticsearch.upgrades;

import com.carrotsearch.randomizedtesting.annotations.Name;

import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
Expand All @@ -16,6 +18,10 @@

public class GeoIpUpgradeIT extends AbstractUpgradeTestCase {

public GeoIpUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
super(upgradedNodes);
}

public void testGeoIpDownloader() throws Exception {
if (CLUSTER_TYPE == ClusterType.UPGRADED) {
assertBusy(() -> {
Expand Down
Loading

0 comments on commit 99ea966

Please sign in to comment.