Skip to content

Commit cdedcf0

Browse files
committed
Merge branch 'main' into securityworkflow
2 parents de1c773 + d91df69 commit cdedcf0

File tree

4 files changed

+101
-96
lines changed

4 files changed

+101
-96
lines changed

build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ afterEvaluate {
303303
node.setting("plugins.security.check_snapshot_restore_write_privileges", "true")
304304
node.setting("plugins.security.restapi.roles_enabled", "[\"all_access\", \"security_rest_api_access\"]")
305305
node.setting("plugins.security.system_indices.enabled", "true")
306-
// node.setting("plugins.security.system_indices.indices", "[\".opendistro-ism-config\"]")
306+
node.setting("plugins.security.system_indices.indices", "[\".opendistro-alerting-config\"]")
307307
}
308308
}
309309
}
@@ -431,6 +431,7 @@ def configureCluster(OpenSearchCluster cluster, Boolean securityEnabled) {
431431
//
432432
// cluster.@waitConditions.put("cluster health yellow", pred)
433433
// cluster.waitForAllConditions()
434+
Thread.sleep(5_000)
434435
}
435436

436437
integTest {
@@ -477,6 +478,8 @@ integTest {
477478
filter {
478479
excludeTestsMatching "org.opensearch.indexmanagement.indexstatemanagement.action.NotificationActionIT"
479480
}
481+
// Don't execute IntegTest under https
482+
exclude 'org/opensearch/indexmanagement/indexstatemanagement/MetadataRegressionIT.class'
480483
}
481484

482485
// TODO: raise issue in Core, this is because of the test framework
@@ -705,8 +708,9 @@ run {
705708
getClusters().forEach { cluster ->
706709
if (securityEnabled) {
707710
// TODO: This is a bit of a hack
708-
LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>()
709-
cluster.waitForConditions(waitConditions, System.currentTimeMillis(), 40, TimeUnit.SECONDS, cluster)
711+
// LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>()
712+
// cluster.waitForConditions(waitConditions, System.currentTimeMillis(), 40, TimeUnit.SECONDS, cluster)
713+
configureCluster(cluster, securityEnabled)
710714
} else {
711715
cluster.waitForAllConditions()
712716
}

src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.apache.http.entity.StringEntity
1010
import org.junit.AfterClass
1111
import org.junit.Before
1212
import org.junit.rules.DisableOnDebug
13+
import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksAction
1314
import org.opensearch.client.Request
1415
import org.opensearch.client.Response
1516
import org.opensearch.client.RestClient
@@ -25,11 +26,15 @@ import org.opensearch.common.xcontent.NamedXContentRegistry
2526
import org.opensearch.common.xcontent.XContentType
2627
import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN
2728
import org.opensearch.rest.RestStatus
29+
import java.io.IOException
2830
import java.nio.file.Files
31+
import java.util.*
2932
import javax.management.MBeanServerInvocationHandler
3033
import javax.management.ObjectName
3134
import javax.management.remote.JMXConnectorFactory
3235
import javax.management.remote.JMXServiceURL
36+
import kotlin.collections.ArrayList
37+
import kotlin.collections.HashSet
3338

3439
abstract class IndexManagementRestTestCase : ODFERestTestCase() {
3540

@@ -63,7 +68,6 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() {
6368

6469
protected val isDebuggingTest = DisableOnDebug(null).isDebugging
6570
protected val isDebuggingRemoteCluster = System.getProperty("cluster.debug", "false")!!.toBoolean()
66-
protected val isMultiNode = System.getProperty("cluster.number_of_nodes", "1").toInt() > 1
6771

6872
protected val isLocalTest = clusterName() == "integTest"
6973
private fun clusterName(): String {
@@ -160,21 +164,15 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() {
160164
}
161165

162166
override fun preserveIndicesUponCompletion(): Boolean = true
163-
164167
companion object {
165-
168+
@JvmStatic
169+
protected val isMultiNode = System.getProperty("cluster.number_of_nodes", "1").toInt() > 1
166170
protected val defaultKeepIndexSet = setOf(".opendistro_security")
167171
/**
168-
* This clean up function can be use in @After or @AfterClass in the base test file
169-
* of your feature test suite
172+
* We override preserveIndicesUponCompletion to true and use this function to clean up indices
173+
* Meant to be used in @After or @AfterClass of your feature test suite
170174
*/
171175
fun wipeAllIndices(client: RestClient = adminClient(), keepIndex: kotlin.collections.Set<String> = defaultKeepIndexSet) {
172-
waitFor {
173-
waitForRunningTasks(client)
174-
waitForPendingTasks(client)
175-
waitForThreadPools(client)
176-
}
177-
// Delete all data stream indices
178176
try {
179177
client.performRequest(Request("DELETE", "_data_stream/*"))
180178
} catch (e: ResponseException) {
@@ -186,9 +184,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() {
186184
}
187185
}
188186

189-
// Delete all indices
190187
val response = client.performRequest(Request("GET", "/_cat/indices?format=json&expand_wildcards=all"))
191-
192188
val xContentType = XContentType.fromMediaType(response.entity.contentType.value)
193189
xContentType.xContent().createParser(
194190
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
@@ -208,6 +204,72 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() {
208204
}
209205
}
210206
}
207+
208+
waitFor {
209+
if (!isMultiNode) {
210+
waitForRunningTasks(client)
211+
waitForPendingTasks(client)
212+
waitForThreadPools(client)
213+
} else {
214+
// Multi node test is not suitable to waitFor
215+
// We have seen long-running write task that fails the waitFor
216+
// probably because of cluster manager - data node task not in sync
217+
// So instead we just sleep 1s after wiping indices
218+
Thread.sleep(1_000)
219+
}
220+
}
221+
}
222+
223+
@JvmStatic
224+
@Throws(IOException::class)
225+
protected fun waitForRunningTasks(client: RestClient) {
226+
val runningTasks: MutableSet<String> = runningTasks(client.performRequest(Request("GET", "/_tasks?detailed")))
227+
if (runningTasks.isEmpty()) {
228+
return
229+
}
230+
val stillRunning = ArrayList<String>(runningTasks)
231+
fail("${Date()}: There are still tasks running after this test that might break subsequent tests: \n${stillRunning.joinToString("\n")}.")
232+
}
233+
234+
@Suppress("UNCHECKED_CAST")
235+
@Throws(IOException::class)
236+
private fun runningTasks(response: Response): MutableSet<String> {
237+
val runningTasks: MutableSet<String> = HashSet()
238+
val nodes = entityAsMap(response)["nodes"] as Map<String, Any>?
239+
for ((_, value) in nodes!!) {
240+
val nodeInfo = value as Map<String, Any>
241+
val nodeTasks = nodeInfo["tasks"] as Map<String, Any>?
242+
for ((_, value1) in nodeTasks!!) {
243+
val task = value1 as Map<String, Any>
244+
// Ignore the task list API - it doesn't count against us
245+
if (task["action"] == ListTasksAction.NAME || task["action"] == ListTasksAction.NAME + "[n]") continue
246+
// runningTasks.add(task["action"].toString() + " | " + task["description"].toString())
247+
runningTasks.add(task.toString())
248+
}
249+
}
250+
return runningTasks
251+
}
252+
253+
@JvmStatic
254+
protected fun waitForThreadPools(client: RestClient) {
255+
val response = client.performRequest(Request("GET", "/_cat/thread_pool?format=json"))
256+
257+
val xContentType = XContentType.fromMediaType(response.entity.contentType.value)
258+
xContentType.xContent().createParser(
259+
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
260+
response.entity.content
261+
).use { parser ->
262+
for (index in parser.list()) {
263+
val jsonObject: Map<*, *> = index as java.util.HashMap<*, *>
264+
val active = (jsonObject["active"] as String).toInt()
265+
val queue = (jsonObject["queue"] as String).toInt()
266+
val name = jsonObject["name"]
267+
val trueActive = if (name == "management") active - 1 else active
268+
if (trueActive > 0 || queue > 0) {
269+
fail("Still active threadpools in cluster: $jsonObject")
270+
}
271+
}
272+
}
211273
}
212274

213275
internal interface IProxy {

src/test/kotlin/org/opensearch/indexmanagement/ODFERestTestCase.kt

Lines changed: 7 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
package org.opensearch.indexmanagement
77

88
import org.apache.http.HttpHost
9-
import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksAction
10-
import org.opensearch.client.Request
11-
import org.opensearch.client.Response
129
import org.opensearch.client.RestClient
10+
import org.opensearch.common.io.PathUtils
1311
import org.opensearch.common.settings.Settings
14-
import org.opensearch.common.xcontent.DeprecationHandler
15-
import org.opensearch.common.xcontent.NamedXContentRegistry
16-
import org.opensearch.common.xcontent.XContentType
1712
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_ENABLED
1813
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH
1914
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD
@@ -22,7 +17,6 @@ import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_PEMCE
2217
import org.opensearch.commons.rest.SecureRestClientBuilder
2318
import org.opensearch.test.rest.OpenSearchRestTestCase
2419
import java.io.IOException
25-
import java.util.*
2620

2721
abstract class ODFERestTestCase : OpenSearchRestTestCase() {
2822

@@ -32,60 +26,6 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {
3226

3327
override fun getProtocol(): String = if (isHttps()) "https" else "http"
3428

35-
companion object {
36-
@JvmStatic
37-
@Throws(IOException::class)
38-
protected fun waitForRunningTasks(client: RestClient) {
39-
val runningTasks: MutableSet<String> = runningTasks(client.performRequest(Request("GET", "/_tasks?detailed")))
40-
if (runningTasks.isEmpty()) {
41-
return
42-
}
43-
val stillRunning = ArrayList<String>(runningTasks)
44-
fail("${Date()}: There are still tasks running after this test that might break subsequent tests: \n${stillRunning.joinToString("\n")}.")
45-
}
46-
47-
@Suppress("UNCHECKED_CAST")
48-
@Throws(IOException::class)
49-
private fun runningTasks(response: Response): MutableSet<String> {
50-
val runningTasks: MutableSet<String> = HashSet()
51-
val nodes = entityAsMap(response)["nodes"] as Map<String, Any>?
52-
for ((_, value) in nodes!!) {
53-
val nodeInfo = value as Map<String, Any>
54-
val nodeTasks = nodeInfo["tasks"] as Map<String, Any>?
55-
for ((_, value1) in nodeTasks!!) {
56-
val task = value1 as Map<String, Any>
57-
// Ignore the task list API - it doesn't count against us
58-
if (task["action"] == ListTasksAction.NAME || task["action"] == ListTasksAction.NAME + "[n]") continue
59-
// runningTasks.add(task["action"].toString() + " | " + task["description"].toString())
60-
runningTasks.add(task.toString())
61-
}
62-
}
63-
return runningTasks
64-
}
65-
66-
@JvmStatic
67-
protected fun waitForThreadPools(client: RestClient) {
68-
val response = client.performRequest(Request("GET", "/_cat/thread_pool?format=json"))
69-
70-
val xContentType = XContentType.fromMediaType(response.entity.contentType.value)
71-
xContentType.xContent().createParser(
72-
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
73-
response.entity.content
74-
).use { parser ->
75-
for (index in parser.list()) {
76-
val jsonObject: Map<*, *> = index as java.util.HashMap<*, *>
77-
val active = (jsonObject["active"] as String).toInt()
78-
val queue = (jsonObject["queue"] as String).toInt()
79-
val name = jsonObject["name"]
80-
val trueActive = if (name == "management") active - 1 else active
81-
if (trueActive > 0 || queue > 0) {
82-
fail("Still active threadpools in cluster: $jsonObject")
83-
}
84-
}
85-
}
86-
}
87-
}
88-
8929
/**
9030
* Returns the REST client settings used for super-admin actions like cleaning up after the test has completed.
9131
*/
@@ -107,31 +47,18 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {
10747
val keystore = settings.get(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH)
10848
return when (keystore != null) {
10949
true -> {
110-
println("Build super admin client")
50+
logger.info("set up super admin")
11151
// create adminDN (super-admin) client
112-
// val uri = javaClass.classLoader.getResource("security/sample.pem")?.toURI()
113-
// val configPath = PathUtils.get(uri).parent.toAbsolutePath()
114-
// SecureRestClientBuilder(settings, configPath).setSocketTimeout(60000).build()
115-
116-
val userName = System.getProperty("user")
117-
val password = System.getProperty("password")
118-
println("Build client with user:password $userName:$password")
119-
hosts.map {
120-
println("Host uri ${it.toURI()}")
121-
}
122-
SecureRestClientBuilder(hosts, isHttps(), userName, password)
123-
.setSocketTimeout(60000).build()
52+
val uri = javaClass.classLoader.getResource("security/sample.pem")?.toURI()
53+
val configPath = PathUtils.get(uri).parent.toAbsolutePath()
54+
SecureRestClientBuilder(settings, configPath, hosts).setSocketTimeout(5000).build()
12455
}
12556
false -> {
57+
logger.info("set up admin")
12658
// create client with passed user
127-
println("Build admin client")
12859
val userName = System.getProperty("user")
12960
val password = System.getProperty("password")
130-
println("Build client with user:password $userName:$password")
131-
hosts.map {
132-
println("Host uri ${it.toURI()}")
133-
}
134-
SecureRestClientBuilder(hosts, isHttps(), userName, password).setSocketTimeout(60000).build()
61+
SecureRestClientBuilder(hosts, isHttps(), userName, password).setSocketTimeout(5000).build()
13562
}
13663
}
13764
} else {

src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionRetryIT.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
package org.opensearch.indexmanagement.indexstatemanagement.action
77

8+
import org.apache.http.entity.ContentType
9+
import org.apache.http.entity.StringEntity
10+
import org.junit.Before
811
import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase
912
import org.opensearch.indexmanagement.indexstatemanagement.step.rollover.AttemptRolloverStep
13+
import org.opensearch.indexmanagement.makeRequest
1014
import org.opensearch.indexmanagement.spi.indexstatemanagement.Step
1115
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData
1216
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData
@@ -20,6 +24,14 @@ import java.util.Locale
2024
class ActionRetryIT : IndexStateManagementRestTestCase() {
2125
private val testIndexName = javaClass.simpleName.lowercase(Locale.ROOT)
2226

27+
@Before
28+
fun setDebugLogLevel() {
29+
client().makeRequest(
30+
"PUT", "_cluster/settings",
31+
StringEntity("""{"transient":{"logger.org.opensearch.security":"DEBUG"}}""", ContentType.APPLICATION_JSON)
32+
)
33+
}
34+
2335
/**
2436
* We are forcing RollOver to fail in this Integ test.
2537
*/

0 commit comments

Comments
 (0)