test: smoke-test-plugins-ssl no longer relies on logging to start
This change adds a HTTPS check for smoke-test-plugins-ssl so it no longer has to wait for a debug level log message. Closes elastic/elasticsearch#2303 Original commit: elastic/x-pack-elasticsearch@f3eaaad5d4
This commit is contained in:
parent
82649355a0
commit
942a70328c
|
@ -1,5 +1,14 @@
|
||||||
import org.elasticsearch.gradle.LoggedExec
|
import org.elasticsearch.gradle.LoggedExec
|
||||||
import org.elasticsearch.gradle.MavenFilteringHack
|
import org.elasticsearch.gradle.MavenFilteringHack
|
||||||
|
import org.elasticsearch.gradle.test.NodeInfo
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
import javax.net.ssl.KeyManagerFactory
|
||||||
|
import javax.net.ssl.SSLContext
|
||||||
|
import javax.net.ssl.TrustManagerFactory
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
|
import java.security.KeyStore
|
||||||
|
import java.security.SecureRandom
|
||||||
|
|
||||||
apply plugin: 'elasticsearch.rest-test'
|
apply plugin: 'elasticsearch.rest-test'
|
||||||
|
|
||||||
|
@ -177,25 +186,47 @@ integTest {
|
||||||
setupCommand 'setupMonitoringUser',
|
setupCommand 'setupMonitoringUser',
|
||||||
'bin/x-pack/users', 'useradd', 'monitoring_agent', '-p', 'changeme', '-r', 'remote_monitoring_agent'
|
'bin/x-pack/users', 'useradd', 'monitoring_agent', '-p', 'changeme', '-r', 'remote_monitoring_agent'
|
||||||
|
|
||||||
// Required to detect that the monitoring agent service has started
|
waitCondition = { NodeInfo node, AntBuilder ant ->
|
||||||
setting 'logger.level', 'DEBUG'
|
File tmpFile = new File(node.cwd, 'wait.success')
|
||||||
|
KeyStore keyStore = KeyStore.getInstance("JKS");
|
||||||
waitCondition = { node, ant ->
|
keyStore.load(clientKeyStore.newInputStream(), 'keypass'.toCharArray());
|
||||||
// HTTPS check is tricky to do, so we wait for the log file to indicate that the node is started
|
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||||
String waitForNodeStartProp = "waitForNodeStart${name}"
|
kmf.init(keyStore, 'keypass'.toCharArray());
|
||||||
ant.waitfor(maxwait: '30', maxwaitunit: 'second', checkevery: '100', checkeveryunit: 'millisecond',
|
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||||
timeoutproperty: waitForNodeStartProp) {
|
tmf.init(keyStore);
|
||||||
and {
|
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
|
||||||
resourcecontains(resource: "${node.startLog.toString()}", substring: 'started')
|
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());
|
||||||
resourcecontains(resource: "${node.startLog.toString()}", substring: 'monitoring service started')
|
for (int i = 0; i < 10; i++) {
|
||||||
|
// we use custom wait logic here for HTTPS
|
||||||
|
HttpsURLConnection httpURLConnection = null;
|
||||||
|
try {
|
||||||
|
httpURLConnection = (HttpsURLConnection) new URL("https://${node.httpUri()}/_cluster/health?wait_for_nodes=${numNodes}").openConnection();
|
||||||
|
httpURLConnection.setSSLSocketFactory(sslContext.getSocketFactory());
|
||||||
|
httpURLConnection.setRequestProperty("Authorization", "Basic " +
|
||||||
|
Base64.getEncoder().encodeToString("test_user:changeme".getBytes(StandardCharsets.UTF_8)));
|
||||||
|
httpURLConnection.setRequestMethod("GET");
|
||||||
|
httpURLConnection.connect();
|
||||||
|
if (httpURLConnection.getResponseCode() == 200) {
|
||||||
|
tmpFile.withWriter StandardCharsets.UTF_8.name(), {
|
||||||
|
it.write(httpURLConnection.getInputStream().getText(StandardCharsets.UTF_8.name()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (i == 9) {
|
||||||
|
logger.error("final attempt of calling cluster health failed", e)
|
||||||
|
} else {
|
||||||
|
logger.debug("failed to call cluster health", e)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (httpURLConnection != null) {
|
||||||
|
httpURLConnection.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ant.project.getProperty(waitForNodeStartProp)) {
|
// did not start, so wait a bit before trying again
|
||||||
println "Timed out when looking for node startup in log file ${node.startLog.toString()}"
|
Thread.sleep(500L);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return tmpFile.exists()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ integTest {
|
||||||
// we use custom wait logic here as the elastic user is not available immediately and ant.get will fail when a 401 is returned
|
// we use custom wait logic here as the elastic user is not available immediately and ant.get will fail when a 401 is returned
|
||||||
HttpURLConnection httpURLConnection = null;
|
HttpURLConnection httpURLConnection = null;
|
||||||
try {
|
try {
|
||||||
httpURLConnection = (HttpURLConnection) new URL("http://${node.httpUri()}").openConnection();
|
httpURLConnection = (HttpURLConnection) new URL("http://${node.httpUri()}/_cluster/health?wait_for_nodes=${numNodes}").openConnection();
|
||||||
httpURLConnection.setRequestProperty("Authorization", "Basic " +
|
httpURLConnection.setRequestProperty("Authorization", "Basic " +
|
||||||
Base64.getEncoder().encodeToString("elastic:changeme".getBytes(StandardCharsets.UTF_8)));
|
Base64.getEncoder().encodeToString("elastic:changeme".getBytes(StandardCharsets.UTF_8)));
|
||||||
httpURLConnection.setRequestMethod("GET");
|
httpURLConnection.setRequestMethod("GET");
|
||||||
|
@ -187,7 +187,11 @@ integTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace()
|
if (i == 9) {
|
||||||
|
logger.error("final attempt of calling cluster health failed", e)
|
||||||
|
} else {
|
||||||
|
logger.debug("failed to call cluster health", e)
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (httpURLConnection != null) {
|
if (httpURLConnection != null) {
|
||||||
httpURLConnection.disconnect();
|
httpURLConnection.disconnect();
|
||||||
|
|
|
@ -119,7 +119,6 @@ public class AgentService extends AbstractLifecycleComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() {
|
protected void doStart() {
|
||||||
// Please don't remove this log message since it can be used in integration tests
|
|
||||||
logger.debug("monitoring service started");
|
logger.debug("monitoring service started");
|
||||||
|
|
||||||
for (Collector collector : collectors) {
|
for (Collector collector : collectors) {
|
||||||
|
|
Loading…
Reference in New Issue