From 1ec67d64f4323f1c4d5a69fdae5f9869b830d92a Mon Sep 17 00:00:00 2001 From: pawel-gudel-eliatra <136344230+pawel-gudel-eliatra@users.noreply.github.com> Date: Mon, 10 Jul 2023 23:39:39 +0200 Subject: [PATCH] [Backport] Parallel test jobs for CI (#2861) (#2936) * [Enhancement] Parallel test jobs for CI (#2861) * Split multiple tests into separate gradle tasks. * Tasks are configured in "splitTestConfig" map in build.gradle file. Map allows to use all patterns from TestFilter like: includeTestsMatching, excludeTestsMatching, includeTest etc. * Tasks are automatically generated from "splitTestConfig" map. * Two new Gradle tasks: listTasksAsJSON and listTasksAsParam to output task names to console. First one outputs them as a JSON and second - in gradlew "-x " format to use in CLI. * Patterns included in tasks are automatically excluded from main "test" task but at the same time generated tasks are dependencies for "test". Running "gradlew test" will run whole suite at once. * CI pipeline has been configured to accomodate all changes. * New 'master' task to generate list of jobs to run in parallel. * Updated matrix strategy to include task name to start. Signed-off-by: Pawel Gudel (cherry picked from commit e4f4817e0d2d9caf80da0d0cb1da73e4913f62e3) Signed-off-by: Pawel Gudel * Generalize Backwards Compatibility tests so we can test from any version to any version With an issue reported indicating that there are serialization issue between 1.3 and 2.X, making sure that we can reproduce the errors. This new workflow(s) will make sure that we aren't breaking BWC with changes we are adding to 2.X and will give us the flexibility to test certain migration workflows. Fixing an issue where the BWC tests were not actually building or executing causing the clusters to spin up and then immediately spin down. We will need to invest more energy into running multiple kinds of security plugin specific scenarios through the test system. Signed-off-by: Peter Nied * Remove seperate integration test workflow Signed-off-by: Peter Nied * Adjust BWC setting to point to correct BWC versions Signed-off-by: Peter Nied * Fix spotless issues Signed-off-by: Peter Nied --------- Signed-off-by: Pawel Gudel Signed-off-by: Peter Nied Co-authored-by: Peter Nied --- .github/actions/create-bwc-build/action.yaml | 43 +++++ .github/actions/run-bwc-suite/action.yaml | 46 +++++ .github/workflows/bwc-tests.yml | 42 +++++ .github/workflows/ci.yml | 68 +++++--- build.gradle | 162 ++++++++++++++++-- bwc-test/build.gradle | 82 +++------ .../SecurityBackwardsCompatibilityIT.java | 52 +++--- 7 files changed, 378 insertions(+), 117 deletions(-) create mode 100644 .github/actions/create-bwc-build/action.yaml create mode 100644 .github/actions/run-bwc-suite/action.yaml create mode 100644 .github/workflows/bwc-tests.yml diff --git a/.github/actions/create-bwc-build/action.yaml b/.github/actions/create-bwc-build/action.yaml new file mode 100644 index 0000000000..43ba5ea82e --- /dev/null +++ b/.github/actions/create-bwc-build/action.yaml @@ -0,0 +1,43 @@ +name: 'Create a backwards compatible ready build' +description: 'Checkouts the official version of a the Security plugin and builds it so it can be used for BWC tests' + +inputs: + plugin-branch: + description: 'The branch of the plugin that should be built, e.g "2.2", "1.x"' + required: true + +outputs: + built-version: + description: 'The version of OpenSearch that was associated with this branch' + value: ${{ steps.get-opensearch-version.outputs.version }} + +runs: + using: "composite" + steps: + - name: Enable Longpaths if on Windows + if: ${{ runner.os == 'Windows' }} + run: git config --system core.longpaths true + shell: pwsh + + - uses: actions/checkout@v3 + with: + repository: opensearch-project/security + ref: ${{ inputs.plugin-branch }} + path: ${{ inputs.plugin-branch }} + + - name: Build + uses: gradle/gradle-build-action@v2 + with: + arguments: assemble -Dbuild.snapshot=false + build-root-directory: ${{ inputs.plugin-branch }} + + - id: get-opensearch-version + uses: peternied/get-opensearch-version@v1 + with: + working-directory: ${{ inputs.plugin-branch }} + + - name: Copy current distro into the expected folder + run: | + mkdir -p ./bwc-test/src/test/resources/${{ steps.get-opensearch-version.outputs.version }} + cp ${{ inputs.plugin-branch }}/build/distributions/opensearch-security-${{ steps.get-opensearch-version.outputs.version }}.zip ./bwc-test/src/test/resources/${{ steps.get-opensearch-version.outputs.version }} + shell: bash diff --git a/.github/actions/run-bwc-suite/action.yaml b/.github/actions/run-bwc-suite/action.yaml new file mode 100644 index 0000000000..4614872858 --- /dev/null +++ b/.github/actions/run-bwc-suite/action.yaml @@ -0,0 +1,46 @@ +name: 'Runs the backward bompatiblity test suite' +description: 'Tests backwards compability between a previous and next version of this plugin' + +inputs: + plugin-previous-branch: + description: 'The branch of the plugin that should be built for the previous version, e.g "2.2", "1.x"' + required: true + + plugin-next-branch: + description: 'The branch of the plugin that should be built for the next version, e.g "2.3", "main"' + required: true + + report-artifact-name: + description: 'The name of the artifacts for this run, e.g. "BWC-2.1-to-2.4-results"' + required: true + +runs: + using: "composite" + steps: + + - id: build-previous + uses: ./.github/actions/create-bwc-build + with: + plugin-branch: ${{ inputs.plugin-previous-branch }} + + - id: build-next + uses: ./.github/actions/create-bwc-build + with: + plugin-branch: ${{ inputs.plugin-next-branch }} + + - name: Run BWC tests + uses: gradle/gradle-build-action@v2 + with: + arguments: | + bwcTestSuite + -Dtests.security.manager=false + -Dbwc.version.previous=${{ steps.build-previous.outputs.built-version }} + -Dbwc.version.next=${{ steps.build-next.outputs.built-version }} -i + build-root-directory: bwc-test + + - uses: actions/upload-artifact@v3 + if: always() + with: + name: ${{ inputs.report-artifact-name }} + path: | + ./bwc-test/build/reports/ diff --git a/.github/workflows/bwc-tests.yml b/.github/workflows/bwc-tests.yml new file mode 100644 index 0000000000..ed65970a30 --- /dev/null +++ b/.github/workflows/bwc-tests.yml @@ -0,0 +1,42 @@ +name: Backwards Compability Suite + +on: [workflow_dispatch] + +jobs: + last-supported-major-to-current: + name: Make sure that the last supported major version can move to the most current version + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Checkout Security Repo + uses: actions/checkout@v2 + + - id: build-previous + uses: ./.github/actions/run-bwc-suite + with: + plugin-previous-branch: "1.3" + plugin-next-branch: "2.x" + report-artifact-name: BWC-Last-Supported-Major + + current-to-next-unreleased-major: + name: Make sure that the current version is compatible with the next major version + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Checkout Security Repo + uses: actions/checkout@v2 + + - id: build-previous + uses: ./.github/actions/run-bwc-suite + with: + plugin-previous-branch: "2.x" + plugin-next-branch: "main" + report-artifact-name: BWC-Next-Major diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 889854ee3a..6b4ae5a76a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,13 +6,34 @@ env: GRADLE_OPTS: -Dhttp.keepAlive=false jobs: - build: - name: build + generate-test-list: + runs-on: ubuntu-latest + outputs: + separateTestsNames: ${{ steps.set-matrix.outputs.separateTestsNames }} + steps: + - name: Set up JDK for build and test + uses: actions/setup-java@v2 + with: + distribution: temurin # Temurin is a distribution of adoptium + java-version: 17 + + - name: Checkout security + uses: actions/checkout@v2 + + - name: Generate list of tasks + id: set-matrix + run: | + echo "separateTestsNames=$(./gradlew listTasksAsJSON -q --console=plain | tail -n 1)" >> $GITHUB_OUTPUT + + test: + name: test + needs: generate-test-list strategy: fail-fast: false matrix: + gradle_task: ${{ fromJson(needs.generate-test-list.outputs.separateTestsNames) }} + platform: [windows-latest, ubuntu-latest] jdk: [11, 17] - platform: ["ubuntu-latest", "windows-latest", "macos-latest"] runs-on: ${{ matrix.platform }} steps: @@ -29,11 +50,8 @@ jobs: uses: gradle/gradle-build-action@v2 with: arguments: | - build test -Dbuild.snapshot=false - -x spotlessCheck - -x checkstyleMain - -x checkstyleTest - -x spotbugsMain + ${{ matrix.gradle_task }} -Dbuild.snapshot=false + -x test - name: Coverage uses: codecov/codecov-action@v1 @@ -53,25 +71,27 @@ jobs: run: echo "Check the artifact ${{ matrix.platform }}-JDK${{ matrix.jdk }}-reports for detailed test results" backward-compatibility: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + jdk: [11, 17] + platform: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: - - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: - java-version: 11 - - run: ./gradlew clean build -Dbuild.snapshot=false -x test - - run: | - echo "Running backwards compatibility tests ..." - security_plugin_version_no_snapshot=$(./gradlew properties -q | grep -E '^version:' | awk '{print $2}' | sed 's/-SNAPSHOT//g') - bwc_version=2.8.0 - cp -r build/ ./bwc-test/ - mkdir ./bwc-test/src/test/resources/security_plugin_version_no_snapshot - cp build/distributions/opensearch-security-${security_plugin_version_no_snapshot}.zip ./bwc-test/src/test/resources/${security_plugin_version_no_snapshot} - mkdir bwc-test/src/test/resources/${bwc_version}.0 - wget https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${bwc_version}/latest/linux/x64/tar/builds/opensearch/plugins/opensearch-security-${bwc_version}.0.zip - mv opensearch-security-${bwc_version}.0.zip bwc-test/src/test/resources/${bwc_version}.0/ - cd bwc-test/ - ./gradlew bwcTestSuite -Dtests.security.manager=false + java-version: ${{ matrix.jdk }} + + - name: Checkout Security Repo + uses: actions/checkout@v2 + + - id: build-previous + uses: ./.github/actions/run-bwc-suite + with: + plugin-previous-branch: "2.8" + plugin-next-branch: "2.x" + report-artifact-name: bwc-${{ matrix.platform }}-jdk${{ matrix.jdk }} code-ql: runs-on: ubuntu-latest diff --git a/build.gradle b/build.gradle index d89da23090..fd70351cd5 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,7 @@ */ import org.opensearch.gradle.test.RestIntegTestTask +import groovy.json.JsonBuilder buildscript { ext { @@ -97,12 +98,91 @@ forbiddenPatterns.enabled = false testingConventions.enabled = false // Conflicts between runtime kafka-clients:x.y.z & testRuntime kafka-clients:x.y.z:test jarHell.enabled = false +tasks.whenTaskAdded {task -> + if(task.name.contains("forbiddenApisIntegrationTest")) { + task.enabled = false + } +} + +def splitTestConfig = [ + ciSecurityIntegrationTest: [ + description: "Runs integration tests from all classes.", + filters: [ + includeTestsMatching: [ + "org.opensearch.security.*Integ*" + ], + excludeTestsMatching: [ + "org.opensearch.security.sanity.tests.*" + ] + ] + ], + crossClusterTest: [ + description: "Runs cross-cluster tests.", + filters: [ + includeTestsMatching: [ + "org.opensearch.security.ccstest.*" + ] + ] + ], + dlicDlsflsTest: [ + description: "Runs Document- and Field-Level Security tests.", + filters: [ + includeTestsMatching: [ + "org.opensearch.security.dlic.dlsfls.*" + ] + ] + ], + dlicRestApiTest: [ + description: "Runs REST Management API tests.", + filters: [ + includeTestsMatching: [ + "org.opensearch.security.dlic.rest.*" + ] + ] + ], + indicesTest: [ + description: "Runs indices tests from all classes.", + filters: [ + includeTestsMatching: [ + "org.opensearch.security.*indices*" + ], + excludeTestsMatching: [ + "org.opensearch.security.sanity.tests.*" + ] + ] + ], + opensslCITest: [ + description: "Runs portion of SSL tests related to OpenSSL. Explained in https://github.com/opensearch-project/security/pull/2301", + include: '**/OpenSSL*.class' + ], + sslTest: [ + description: "Runs most of the SSL tests.", + filters: [ + includeTestsMatching: [ + "org.opensearch.security.ssl.*" + ], + excludeTestsMatching: [ + "org.opensearch.security.ssl.OpenSSL*" + ] + ] + ] +] as ConfigObject + +List taskNames = splitTestConfig.keySet() as List + +task listTasksAsJSON { + // We are using `doLast` to explicitly specify when we + // want this action to be started. Without it the output + // is not shown at all or can be mixed with other outputs. + doLast { + System.out.println(new JsonBuilder(["citest"] + taskNames)) + } +} test { include '**/*.class' filter { excludeTestsMatching "org.opensearch.security.sanity.tests.*" - excludeTestsMatching "org.opensearch.security.ssl.OpenSSL*" } maxParallelForks = 8 jvmArgs += "-Xmx3072m" @@ -130,14 +210,37 @@ test { } } -//add new task that runs OpenSSL tests -task opensslTest(type: Test) { - include '**/OpenSSL*.class' - retry { +task copyExtraTestResources(dependsOn: testClasses) { + + copy { + from 'src/test/resources' + into 'build/testrun/test/src/test/resources' + } + + taskNames.each { testName -> + copy { + from 'src/test/resources' + into "build/testrun/${testName}/src/test/resources" + } + } + + copy { + from 'src/test/resources' + into 'build/testrun/citest/src/test/resources' + } +} + +def setCommonTestConfig(Test task) { + task.maxParallelForks = 8 + task.jvmArgs += "-Xmx3072m" + if (JavaVersion.current() > JavaVersion.VERSION_1_8) { + task.jvmArgs += "--add-opens=java.base/java.io=ALL-UNNAMED" + } + task.retry { failOnPassedAfterRetry = false maxRetries = 5 } - jacoco { + task.jacoco { excludes = [ "com.sun.jndi.dns.*", "com.sun.security.sasl.gsskerb.*", @@ -152,21 +255,58 @@ task opensslTest(type: Test) { "sun.util.resources.provider.*" ] } + task.dependsOn copyExtraTestResources + task.finalizedBy jacocoTestReport } -task copyExtraTestResources(dependsOn: testClasses) { - copy { - from 'src/test/resources' - into 'build/testrun/test/src/test/resources' +task citest(type: Test) { + group = "Github Actions tests" + description = "Runs the test suite on classes not covered by rest of the task in this group." + include '**/*.class' + filter { + excludeTestsMatching "org.opensearch.security.sanity.tests.*" + excludeTestsMatching "org.opensearch.security.ssl.OpenSSL*" + splitTestConfig.each { entry -> + entry.value.filters.each{ test -> + if (test.key == "includeTestsMatching") { + test.value.each{ + excludeTestsMatching "${it}" + } + } else if (test.key == "includeTest") { + test.value.each{ + excludeTest "${it}" + } + } + } + } + } + setCommonTestConfig(it) +} + +splitTestConfig.each{ testName, testCfg -> + task "${testName}"(type: Test) { + group = testCfg.group ?: "Github Actions tests" + description = testCfg.description + include testCfg.include ?: '**/*.class' + filter { + testCfg.filters.each{ filter, values -> + values.each{ value -> + "${filter}" "${value}" + } + } + } + setCommonTestConfig(it) } } -tasks.test.dependsOn(copyExtraTestResources, opensslTest) + +tasks.test.dependsOn(copyExtraTestResources) jacoco { reportsDirectory = file("$buildDir/reports/jacoco") } jacocoTestReport { + getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec")) reports { xml.required = true } diff --git a/bwc-test/build.gradle b/bwc-test/build.gradle index 81732df698..01594b31ad 100644 --- a/bwc-test/build.gradle +++ b/bwc-test/build.gradle @@ -37,10 +37,7 @@ apply plugin: 'java' apply plugin: 'opensearch.testclusters' -compileTestJava.enabled = false - ext { - projectSubstitutions = [:] licenseFile = rootProject.file('LICENSE.TXT') noticeFile = rootProject.file('NOTICE') } @@ -70,19 +67,38 @@ repositories { } dependencies { + testImplementation 'com.google.guava:guava:30.0-jre' testImplementation "org.opensearch.test:framework:${opensearch_version}" + testImplementation 'org.apache.logging.log4j:log4j-core:2.17.1' } -String bwcVersion = "2.8.0.0"; +loggerUsageCheck.enabled = false +testingConventions.enabled = false +validateNebulaPom.enabled = false + +String previousVersion = System.getProperty("bwc.version.previous", "2.8.0.0") +String nextVersion = System.getProperty("bwc.version.next", "2.9.0.0") + +String bwcVersion = previousVersion String baseName = "securityBwcCluster" String bwcFilePath = "src/test/resources/" -String projectVersion = "2.9.0.0" +String projectVersion = nextVersion + +String previousOpenSearch = extractVersion(previousVersion); +String nextOpenSearch = extractVersion(nextVersion); + +// Extracts the OpenSearch version from a plugin version string, 2.4.0.0 -> 2.4.0. +def String extractVersion(versionStr) { + def versionMatcher = versionStr =~ /(.+?)(\.\d+)$/ + versionMatcher.find() + return versionMatcher.group(1) +} 2.times {i -> testClusters { "${baseName}$i" { testDistribution = "ARCHIVE" - versions = ["2.8.0","2.9.0"] + versions = [previousOpenSearch, nextOpenSearch] numberOfNodes = 3 plugin(provider(new Callable() { @Override @@ -148,24 +164,7 @@ List> plugins = [ // Creates a test cluster with 3 nodes of the old version. 2.times {i -> task "${baseName}#oldVersionClusterTask$i"(type: StandaloneRestIntegTestTask) { - exclude '**/*Test*' - exclude '**/*Sanity*' useCluster testClusters."${baseName}$i" - if (System.getProperty("mixedCluster") != null) { - filter { - includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInAMixedCluster") - } - } - if (System.getProperty("rollingUpgradeCluster") != null) { - filter { - includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInARollingUpgradedCluster") - } - } - if (System.getProperty("fullRestartCluster") != null) { - filter { - includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInAnUpgradedCluster") - } - } systemProperty 'tests.rest.bwcsuite', 'old_cluster' systemProperty 'tests.rest.bwcsuite_round', 'old' systemProperty 'tests.plugin_bwc_version', bwcVersion @@ -178,23 +177,11 @@ List> plugins = [ // This results in a mixed cluster with 2 nodes on the old version and 1 upgraded node. // This is also used as a one third upgraded cluster for a rolling upgrade. task "${baseName}#mixedClusterTask"(type: StandaloneRestIntegTestTask) { - exclude '**/*Test*' - exclude '**/*Sanity*' dependsOn "${baseName}#oldVersionClusterTask0" useCluster testClusters."${baseName}0" doFirst { testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins) } - if (System.getProperty("mixedCluster") != null) { - filter { - includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInAMixedCluster") - } - } - if (System.getProperty("rollingUpgradeCluster") != null) { - filter { - includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInARollingUpgradedCluster") - } - } systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' systemProperty 'tests.rest.bwcsuite_round', 'first' systemProperty 'tests.plugin_bwc_version', bwcVersion @@ -206,18 +193,11 @@ task "${baseName}#mixedClusterTask"(type: StandaloneRestIntegTestTask) { // This results in a mixed cluster with 1 node on the old version and 2 upgraded nodes. // This is used for rolling upgrade. task "${baseName}#twoThirdsUpgradedClusterTask"(type: StandaloneRestIntegTestTask) { - exclude '**/*Test*' - exclude '**/*Sanity*' dependsOn "${baseName}#mixedClusterTask" useCluster testClusters."${baseName}0" doFirst { testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins) } - if (System.getProperty("rollingUpgradeCluster") != null) { - filter { - includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInARollingUpgradedCluster") - } - } systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' systemProperty 'tests.rest.bwcsuite_round', 'second' systemProperty 'tests.plugin_bwc_version', bwcVersion @@ -229,18 +209,11 @@ task "${baseName}#twoThirdsUpgradedClusterTask"(type: StandaloneRestIntegTestTas // This results in a fully upgraded cluster. // This is used for rolling upgrade. task "${baseName}#rollingUpgradeClusterTask"(type: StandaloneRestIntegTestTask) { - exclude '**/*Test*' - exclude '**/*Sanity*' dependsOn "${baseName}#twoThirdsUpgradedClusterTask" useCluster testClusters."${baseName}0" doFirst { testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins) } - if (System.getProperty("rollingUpgradeCluster") != null) { - filter { - includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInARollingUpgradedCluster") - } - } systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' systemProperty 'tests.rest.bwcsuite_round', 'third' systemProperty 'tests.plugin_bwc_version', bwcVersion @@ -251,28 +224,21 @@ task "${baseName}#rollingUpgradeClusterTask"(type: StandaloneRestIntegTestTask) // Upgrades all the nodes of the old cluster to new OpenSearch version with upgraded plugin version // at the same time resulting in a fully upgraded cluster. tasks.register("${baseName}#fullRestartClusterTask", StandaloneRestIntegTestTask) { - exclude '**/*Test*' - exclude '**/*Sanity*' dependsOn "${baseName}#oldVersionClusterTask1" useCluster testClusters."${baseName}1" doFirst { testClusters."${baseName}1".upgradeAllNodesAndPluginsToNextVersion(plugins) } - if (System.getProperty("fullRestartCluster") != null) { - filter { - includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInAnUpgradedCluster") - } - } systemProperty 'tests.rest.bwcsuite', 'upgraded_cluster' systemProperty 'tests.plugin_bwc_version', bwcVersion + systemProperty 'tests.rest.bwcsuite_round', 'first' nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}1".allHttpSocketURI.join(",")}") nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}1".getName()}") } // A bwc test suite which runs all the bwc tasks combined. task bwcTestSuite(type: StandaloneRestIntegTestTask) { - exclude '**/*Test*' - exclude '**/*Sanity*' + exclude '**/**' // Do not run any tests as part of this aggregate task dependsOn tasks.named("${baseName}#mixedClusterTask") dependsOn tasks.named("${baseName}#rollingUpgradeClusterTask") dependsOn tasks.named("${baseName}#fullRestartClusterTask") diff --git a/bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java b/bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java index 1336798e94..6415a23bea 100644 --- a/bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java +++ b/bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java @@ -12,14 +12,28 @@ import java.util.Set; import java.util.stream.Collectors; -import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; import org.opensearch.common.settings.Settings; import org.opensearch.test.rest.OpenSearchRestTestCase; +import org.opensearch.Version; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; + public class SecurityBackwardsCompatibilityIT extends OpenSearchRestTestCase { - private static final ClusterType CLUSTER_TYPE = ClusterType.parse(System.getProperty("tests.rest.bwcsuite")); - private static final String CLUSTER_NAME = System.getProperty("tests.clustername"); + private ClusterType CLUSTER_TYPE; + private String CLUSTER_NAME; + + @Before + private void testSetup() { + final String bwcsuiteString = System.getProperty("tests.rest.bwcsuite"); + Assume.assumeTrue("Test cannot be run outside the BWC gradle task 'bwcTestSuite' or its dependent tasks", bwcsuiteString != null); + CLUSTER_TYPE = ClusterType.parse(bwcsuiteString); + CLUSTER_NAME = System.getProperty("tests.clustername"); + } @Override protected final boolean preserveIndicesUponCompletion() { @@ -47,16 +61,9 @@ protected final Settings restClientSettings() { .build(); } - public void testPluginUpgradeInAMixedCluster() throws Exception { - assertPluginUpgrade("_nodes/" + CLUSTER_NAME + "-0/plugins"); - } - - public void testPluginUpgradeInAnUpgradedCluster() throws Exception { - assertPluginUpgrade("_nodes/plugins"); - } - - public void testPluginUpgradeInARollingUpgradedCluster() throws Exception { + public void testBasicBackwardsCompatibility() throws Exception { String round = System.getProperty("tests.rest.bwcsuite_round"); + if (round.equals("first") || round.equals("old")) { assertPluginUpgrade("_nodes/" + CLUSTER_NAME + "-0/plugins"); } else if (round.equals("second")) { @@ -90,19 +97,16 @@ private void assertPluginUpgrade(String uri) throws Exception { Map> responseMap = (Map>) getAsMap(uri).get("nodes"); for (Map response : responseMap.values()) { List> plugins = (List>) response.get("plugins"); - Set pluginNames = plugins.stream().map(map -> map.get("name")).collect(Collectors.toSet()); - switch (CLUSTER_TYPE) { - case OLD: - Assert.assertTrue(pluginNames.contains("opendistro_security")); - break; - case MIXED: - Assert.assertTrue(pluginNames.contains("opensearch-security")); - break; - case UPGRADED: - Assert.assertTrue(pluginNames.contains("opendistro_security")); - break; + Set pluginNames = plugins.stream().map(map -> (String) map.get("name")).collect(Collectors.toSet()); + + final Version minNodeVersion = this.minimumNodeVersion(); + + if (minNodeVersion.major <= 1) { + assertThat(pluginNames, hasItem("opensearch_security")); + } else { + assertThat(pluginNames, hasItem("opensearch-security")); } - break; + } } }