Skip to content

Commit

Permalink
Adds a basic sanity test to run against a remote cluster (opensearch-…
Browse files Browse the repository at this point in the history
…project#1958)

* Initial commit with a base test, gradle change and execution script

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Disable JarHell with classpsloading override

Signed-off-by: Peter Nied <petern@amazon.com>

* Sample certficates for sanity tests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates test and adds a base class that extends OpenSearchRestTestCase and modifies client builder methods

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds common-utils dependency and modifies integTestRemote task

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates integtest script

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Makes integtest script executable

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates code hygiene

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Disabling integTest task that was auto-triggered

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fix broken github action for build-artifacts

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates bwc gradle to skip sanity tests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates test task to skip sanity test

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Code cleanup

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Documenting the changes

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates exclusion filter for build gradle test task

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Addresses requested PR changes

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes incorrect license headers

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds sanity tests CI check

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Hard codes common-utils version to stop CI from failing

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates TODO comment with tracking issue

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Makes common-utils version dynamic and acceptable as input parameter to gradle command

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Update bwc build gradle to exclude sanity tests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Hardcodes default common utils version

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Uses assertThat

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes incorrect license headers

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes CI errors

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

Co-authored-by: Peter Nied <petern@amazon.com>
  • Loading branch information
DarshitChanpura and peternied authored Aug 3, 2022
1 parent 437eb02 commit f7b6fe5
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/plugin_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ jobs:
- name: Get Docker Logs
if: always()
run: docker logs ops

- name: Run sanity tests
run: ./gradlew integTestRemote -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="opensearch" -Dhttps=true -Duser=admin -Dpassword=admin
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ Run all tests:
./gradlew clean test
```

Run tests against local cluster:
```bash
./gradlew integTestRemote -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername=docker-cluster -Dsecurity=true -Dhttps=true -Duser=admin -Dpassword=admin -Dcommon_utils.version="2.2.0.0"
```
OR
```bash
./scripts/integtest.sh
```
Note: To run against a remote cluster replace cluster-name and `localhost:9200` with the IPAddress:Port of that cluster.

Build artifacts (zip, deb, rpm):
```bash
./gradlew clean assemble
Expand Down
31 changes: 30 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* GitHub history for details.
*/

import org.opensearch.gradle.test.RestIntegTestTask

buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "2.2.0-SNAPSHOT")
Expand All @@ -18,6 +20,10 @@ buildscript {
// 2.0.0-rc1-SNAPSHOT -> 2.0.0.0-rc1-SNAPSHOT
version_tokens = opensearch_version.tokenize('-')
opensearch_build = version_tokens[0] + '.0'

common_utils_version = System.getProperty("common_utils.version", '2.1.0.0')


if (buildVersionQualifier) {
opensearch_build += "-${buildVersionQualifier}"
}
Expand Down Expand Up @@ -57,6 +63,8 @@ allprojects {

apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.pluginzip'
apply plugin: 'opensearch.rest-test'
apply plugin: 'opensearch.testclusters'

licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
Expand Down Expand Up @@ -87,6 +95,9 @@ jarHell.enabled = false

test {
include '**/*.class'
filter {
excludeTestsMatching "org.opensearch.security.sanity.tests.*"
}
maxParallelForks = 8
jvmArgs += "-Xmx3072m"
if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
Expand Down Expand Up @@ -330,6 +341,7 @@ dependencies {
testImplementation 'org.springframework:spring-beans:5.3.20'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation "org.opensearch:common-utils:${common_utils_version}"
// JUnit build requirement
testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
// Kafka test execution
Expand Down Expand Up @@ -425,6 +437,23 @@ publishing {
}
}

task integTestRemote(type: RestIntegTestTask) {

systemProperty "tests.security.manager", "false"
systemProperty "user", System.getProperty("user")
systemProperty "password", System.getProperty("password")
systemProperty "https", System.getProperty("https")
systemProperty "security.enabled", "true"

filter {
setIncludePatterns("org.opensearch.security.sanity.tests.*IT")
}
}

integTestRemote.enabled = System.getProperty("tests.rest.cluster") != null
// should be updated appropriately, when we add integTests in future
integTest.enabled = false

// This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name
afterEvaluate {
ospackage {
Expand Down Expand Up @@ -503,4 +532,4 @@ task updateVersion {
}
ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true)
}
}
}
9 changes: 7 additions & 2 deletions bwc-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ String projectVersion = "2.2.0.0"
testClusters {
"${baseName}$i" {
testDistribution = "ARCHIVE"
versions = ["2.1.0","2.2.0"]
versions = ["2.1.0","2.2.0"]
numberOfNodes = 3
plugin(provider(new Callable<RegularFile>() {
@Override
Expand Down Expand Up @@ -149,8 +149,8 @@ List<Provider<RegularFile>> plugins = [
2.times {i ->
task "${baseName}#oldVersionClusterTask$i"(type: StandaloneRestIntegTestTask) {
exclude '**/*Test*'
exclude '**/*Sanity*'
useCluster testClusters."${baseName}$i"
exclude '**/*Test*'
if (System.getProperty("mixedCluster") != null) {
filter {
includeTest("org.opensearch.security.bwc.SecurityBackwardsCompatibilityIT", "testPluginUpgradeInAMixedCluster")
Expand Down Expand Up @@ -179,6 +179,7 @@ List<Provider<RegularFile>> plugins = [
// 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 {
Expand Down Expand Up @@ -206,6 +207,7 @@ task "${baseName}#mixedClusterTask"(type: StandaloneRestIntegTestTask) {
// This is used for rolling upgrade.
task "${baseName}#twoThirdsUpgradedClusterTask"(type: StandaloneRestIntegTestTask) {
exclude '**/*Test*'
exclude '**/*Sanity*'
dependsOn "${baseName}#mixedClusterTask"
useCluster testClusters."${baseName}0"
doFirst {
Expand All @@ -228,6 +230,7 @@ task "${baseName}#twoThirdsUpgradedClusterTask"(type: StandaloneRestIntegTestTas
// This is used for rolling upgrade.
task "${baseName}#rollingUpgradeClusterTask"(type: StandaloneRestIntegTestTask) {
exclude '**/*Test*'
exclude '**/*Sanity*'
dependsOn "${baseName}#twoThirdsUpgradedClusterTask"
useCluster testClusters."${baseName}0"
doFirst {
Expand All @@ -249,6 +252,7 @@ task "${baseName}#rollingUpgradeClusterTask"(type: StandaloneRestIntegTestTask)
// 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 {
Expand All @@ -268,6 +272,7 @@ tasks.register("${baseName}#fullRestartClusterTask", StandaloneRestIntegTestTask
// A bwc test suite which runs all the bwc tasks combined.
task bwcTestSuite(type: StandaloneRestIntegTestTask) {
exclude '**/*Test*'
exclude '**/*Sanity*'
dependsOn tasks.named("${baseName}#mixedClusterTask")
dependsOn tasks.named("${baseName}#rollingUpgradeClusterTask")
dependsOn tasks.named("${baseName}#fullRestartClusterTask")
Expand Down
110 changes: 110 additions & 0 deletions scripts/integtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

set -e

function usage() {
echo ""
echo "This script is used to run integration tests for plugin installed on a remote OpenSearch/Dashboards cluster."
echo "--------------------------------------------------------------------------"
echo "Usage: $0 [args]"
echo ""
echo "Required arguments:"
echo "None"
echo ""
echo "Optional arguments:"
echo -e "-b BIND_ADDRESS\t, defaults to localhost | 127.0.0.1, can be changed to any IP or domain name for the cluster location."
echo -e "-p BIND_PORT\t, defaults to 9200, can be changed to any port for the cluster location."
echo -e "-s SECURITY_ENABLED\t(true | false), defaults to true. Specify the OpenSearch/Dashboards have security enabled or not."
echo -e "-c CREDENTIAL\t(usename:password), no defaults, effective when SECURITY_ENABLED=true."
echo -e "-h\tPrint this message."
echo -e "-v OPENSEARCH_VERSION\t, no defaults"
echo -e "-n SNAPSHOT\t, defaults to false"
echo -e "-m CLUSTER_NAME\t, defaults to docker-cluster"
echo -e "-u COMMON_UTILS_VERSION\t, defaults to 2.2.0.0"
echo "--------------------------------------------------------------------------"
}

while getopts ":h:b:p:s:c:v:n:t:m:u:" arg; do
case $arg in
h)
usage
exit 1
;;
b)
BIND_ADDRESS=$OPTARG
;;
p)
BIND_PORT=$OPTARG
;;
t)
TRANSPORT_PORT=$OPTARG
;;
s)
SECURITY_ENABLED=$OPTARG
;;
c)
CREDENTIAL=$OPTARG
;;
m)
CLUSTER_NAME=$OPTARG
;;
v)
# Do nothing as we're not consuming this param.
;;
n)
# Do nothing as we're not consuming this param.
;;
u)
COMMON_UTILS_VERSION=$OPTARG
;;
:)
echo "-${OPTARG} requires an argument"
usage
exit 1
;;
?)
echo "Invalid option: -${OPTARG}"
exit 1
;;
esac
done


if [ -z "$BIND_ADDRESS" ]
then
BIND_ADDRESS="localhost"
fi

if [ -z "$BIND_PORT" ]
then
BIND_PORT="9200"
fi

if [ -z "$SECURITY_ENABLED" ]
then
SECURITY_ENABLED="true"
fi

if [ -z "$CREDENTIAL" ]
then
CREDENTIAL="admin:admin"
fi

if [ -z "$CREDENTIAL" ]
then
CREDENTIAL="admin:admin"
fi

if [ -z "$CLUSTER_NAME" ]
then
CLUSTER_NAME="docker-cluster"
fi
if [ -z "$COMMON_UTILS_VERSION" ]
then
COMMON_UTILS_VERSION="2.2.0.0"
fi

USERNAME=`echo $CREDENTIAL | awk -F ':' '{print $1}'`
PASSWORD=`echo $CREDENTIAL | awk -F ':' '{print $2}'`

./gradlew integTestRemote -Dtests.rest.cluster="$BIND_ADDRESS:$BIND_PORT" -Dtests.cluster="$BIND_ADDRESS:$BIND_PORT" -Dsecurity_enabled=$SECURITY_ENABLED -Dtests.clustername=$CLUSTER_NAME -Dhttps=true -Duser=$USERNAME -Dpassword=$PASSWORD -Dcommon_utils.version=$COMMON_UTILS_VERSION
32 changes: 32 additions & 0 deletions src/test/java/org/opensearch/bootstrap/JarHell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.bootstrap;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;

/**
* Disable JarHell to unblock test development
* https://github.com/opensearch-project/security/issues/1938
*/
public class JarHell {
private JarHell() {}
public static void checkJarHell(Consumer<String> output) throws IOException, Exception {}
public static void checkJarHell(Set<URL> urls, Consumer<String> output) throws URISyntaxException, IOException {}
public static void checkVersionFormat(String targetVersion) {}
public static void checkJavaVersion(String resource, String targetVersion) {}
public static Set<URL> parseClassPath() {return new HashSet<URL>();}
}
Loading

0 comments on commit f7b6fe5

Please sign in to comment.