Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a basic sanity test to run against a remote cluster #1958

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6cc81af
Initial commit with a base test, gradle change and execution script
DarshitChanpura Jul 14, 2022
efd02f9
Disable JarHell with classpsloading override
peternied Jul 14, 2022
7a33b42
Sample certficates for sanity tests
DarshitChanpura Jul 20, 2022
c8dd025
Updates test and adds a base class that extends OpenSearchRestTestCas…
DarshitChanpura Jul 20, 2022
72be44a
Adds common-utils dependency and modifies integTestRemote task
DarshitChanpura Jul 20, 2022
7717120
Updates integtest script
DarshitChanpura Jul 20, 2022
c810715
Makes integtest script executable
DarshitChanpura Jul 20, 2022
3d7977e
Updates code hygiene
DarshitChanpura Jul 21, 2022
560f638
Disabling integTest task that was auto-triggered
DarshitChanpura Jul 21, 2022
35c905e
Fix broken github action for build-artifacts
DarshitChanpura Jul 21, 2022
8666c2d
Updates bwc gradle to skip sanity tests
DarshitChanpura Jul 21, 2022
8b80b61
Updates test task to skip sanity test
DarshitChanpura Jul 21, 2022
791b3aa
Code cleanup
DarshitChanpura Jul 21, 2022
02471b3
Documenting the changes
DarshitChanpura Jul 21, 2022
f2a0d97
Updates exclusion filter for build gradle test task
DarshitChanpura Jul 21, 2022
9666423
Addresses requested PR changes
DarshitChanpura Jul 22, 2022
e48f942
Fixes incorrect license headers
DarshitChanpura Jul 25, 2022
df85516
Adds sanity tests CI check
DarshitChanpura Jul 25, 2022
5b21749
Hard codes common-utils version to stop CI from failing
DarshitChanpura Jul 26, 2022
094d54d
Updates TODO comment with tracking issue
DarshitChanpura Jul 26, 2022
39cb673
Makes common-utils version dynamic and acceptable as input parameter …
DarshitChanpura Jul 28, 2022
ea01765
Update bwc build gradle to exclude sanity tests
DarshitChanpura Aug 2, 2022
cf02ac2
Hardcodes default common utils version
DarshitChanpura Aug 2, 2022
10491fb
Uses assertThat
DarshitChanpura Aug 2, 2022
6c3f82a
Removes incorrect license headers
DarshitChanpura Aug 2, 2022
6d6fd75
Fixes CI errors
DarshitChanpura Aug 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
DarshitChanpura marked this conversation as resolved.
Show resolved Hide resolved
// 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 @@
/*
peternied marked this conversation as resolved.
Show resolved Hide resolved
* 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