Skip to content

Commit

Permalink
add more settings
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Nov 17, 2022
1 parent 8e0c016 commit c5a44f6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/
out/
.idea/*
!.idea/copyright
.vscode
*.ipr
*.iws
.DS_Store
Expand Down
51 changes: 49 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/


import org.opensearch.gradle.testclusters.OpenSearchCluster
import org.opensearch.gradle.testclusters.TestClusterConfiguration
import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask

import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.concurrent.Callable
import java.util.concurrent.TimeUnit
import java.util.function.Predicate
Expand Down Expand Up @@ -395,11 +399,42 @@ testClusters.integTest {
setting 'path.repo', repo.absolutePath
}

def configureCluster(OpenSearchCluster cluster, Boolean securityEnabled) {
// clear existing health checks as we will need custom handling based on
// security plugin installation
cluster.@waitConditions.clear()
String unicastUris = cluster.nodes.stream().flatMap { node ->
node.getAllTransportPortURI().stream()
}.collect(Collectors.joining("\n"))
cluster.nodes.forEach {node ->
try {
// Manually write the unicast hosts as we are not depending on the internal method
Files.write(node.getConfigDir().resolve("unicast_hosts.txt"), unicastUris.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new java.io.UncheckedIOException("Failed to write configuation files for " + this, e);
}
}

// Health check based on security plugin installation
// Predicate pred = { OpenSearchCluster c ->
// String protocol = "http"
// if(securityEnabled && !c.name.equalsIgnoreCase("integTest")) {
// protocol = "https"
// }
// CrossClusterWaitForHttpResource wait = new CrossClusterWaitForHttpResource(protocol, cluster.getFirstNode().getHttpSocketURI(), cluster.nodes.size())
// wait.setUsername("admin")
// wait.setPassword("admin")
// return wait.wait(500)
// }
//
// [email protected]("cluster health yellow", pred)
// cluster.waitForAllConditions()
}

integTest {
systemProperty 'tests.security.manager', 'false'
systemProperty 'java.io.tmpdir', opensearch_tmp_dir.absolutePath
systemProperty 'buildDir', buildDir.path
systemProperty "java.security.policy", "file://${projectDir}/src/test/resources/test-security.policy"
systemProperty "https", System.getProperty("https")
systemProperty "security", System.getProperty("security")
systemProperty "user", System.getProperty("user", "admin")
Expand All @@ -413,7 +448,17 @@ integTest {
// There seems to be an issue when running multi node run or integ tasks with unicast_hosts
// not being written, the waitForAllConditions ensures it's written
getClusters().forEach { cluster ->
cluster.waitForAllConditions()
String alltransportSocketURI = cluster.nodes.stream().flatMap { node ->
node.getAllTransportPortURI().stream()
}.collect(Collectors.joining(","))
String allHttpSocketURI = cluster.nodes.stream().flatMap { node ->
node.getAllHttpSocketURI().stream()
}.collect(Collectors.joining(","))

println("transport socket uri: ${alltransportSocketURI}")
println("http socket uri: ${allHttpSocketURI}")
// cluster.waitForAllConditions()
configureCluster(cluster, securityEnabled)
}
}

Expand Down Expand Up @@ -692,6 +737,8 @@ apply from: 'build-tools/pkgbuild.gradle'
// and new version mixed in one cluster
import org.opensearch.gradle.test.RestIntegTestTask

import java.util.stream.Collectors

def mixedClusterTest = project.tasks.create('mixedCluster', RestIntegTestTask.class)
def mixedClusterFlag = findProperty('mixed') as Boolean ?: false
println("mixed cluster flag: $mixedClusterFlag")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,20 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {
return when (keystore != null) {
true -> {
// create adminDN (super-admin) client
val uri = javaClass.classLoader.getResource("security/sample.pem").toURI()
val uri = javaClass.classLoader.getResource("security/sample.pem")?.toURI()
val configPath = PathUtils.get(uri).parent.toAbsolutePath()
SecureRestClientBuilder(settings, configPath).setSocketTimeout(60000).build()
}
false -> {
// create client with passed user
val userName = System.getProperty("user")
val password = System.getProperty("password")
SecureRestClientBuilder(hosts, isHttps(), userName, password).setSocketTimeout(60000).build()
println("Build client with user:password $userName:$password")
val httpsHosts = hosts.map {
println("Host uri ${it.toURI()}")
HttpHost.create("https://${it.toURI()}")
}
SecureRestClientBuilder(httpsHosts.toTypedArray(), isHttps(), userName, password).setSocketTimeout(60000).build()
}
}
} else {
Expand Down
3 changes: 0 additions & 3 deletions src/test/resources/test-security.policy

This file was deleted.

0 comments on commit c5a44f6

Please sign in to comment.