Skip to content

Commit 3dda52b

Browse files
authored
Use mock ML model server in yaml tests (#138108)
* refactor setting ML model server in tests * Use test ML model server in xpack rest tests * unmute tests * use adminClient to set ML model server URL * spotless
1 parent 2c76cbb commit 3dda52b

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

muted-tests.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ tests:
8686
issue: https://github.com/elastic/elasticsearch/issues/120339
8787
- class: org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeToCharProcessorTests
8888
issue: https://github.com/elastic/elasticsearch/issues/120575
89-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
90-
method: test {p0=ml/3rd_party_deployment/Test start deployment fails while model download in progress}
91-
issue: https://github.com/elastic/elasticsearch/issues/120810
9289
- class: org.elasticsearch.xpack.security.authc.service.ServiceAccountIT
9390
method: testAuthenticateShouldNotFallThroughInCaseOfFailure
9491
issue: https://github.com/elastic/elasticsearch/issues/120902
@@ -113,12 +110,6 @@ tests:
113110
- class: org.elasticsearch.indices.recovery.IndexRecoveryIT
114111
method: testSourceThrottling
115112
issue: https://github.com/elastic/elasticsearch/issues/123680
116-
- class: org.elasticsearch.smoketest.MlWithSecurityIT
117-
method: test {yaml=ml/3rd_party_deployment/Test start deployment fails while model download in progress}
118-
issue: https://github.com/elastic/elasticsearch/issues/120814
119-
- class: org.elasticsearch.smoketest.MlWithSecurityIT
120-
method: test {yaml=ml/3rd_party_deployment/Test start and stop multiple deployments}
121-
issue: https://github.com/elastic/elasticsearch/issues/124315
122113
- class: org.elasticsearch.xpack.restart.MLModelDeploymentFullClusterRestartIT
123114
method: testDeploymentSurvivesRestart {cluster=OLD}
124115
issue: https://github.com/elastic/elasticsearch/issues/124160

x-pack/plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies {
2121
testImplementation project(xpackModule('core'))
2222
testImplementation(testArtifact(project(xpackModule('core'))))
2323
testImplementation(testArtifact(project(":x-pack:plugin:security:qa:service-account"), "javaRestTest"))
24+
testImplementation(testArtifact(project(':x-pack:plugin:inference:qa:inference-service-tests'), "javaRestTest"))
2425
testImplementation project(':test:yaml-rest-runner')
2526
}
2627

x-pack/plugin/inference/qa/inference-service-tests/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apply plugin: 'elasticsearch.internal-java-rest-test'
2+
apply plugin: 'elasticsearch.internal-test-artifact'
23

34
dependencies {
45
javaRestTestImplementation project(path: xpackModule('core'))

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceBaseRestTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,7 @@ public class InferenceBaseRestTest extends ESRestTestCase {
6060

6161
@Before
6262
public void setMlModelRepository() throws IOException {
63-
logger.info("setting ML model repository to: {}", mlModelServer.getUrl());
64-
var request = new Request("PUT", "/_cluster/settings");
65-
request.setJsonEntity(Strings.format("""
66-
{
67-
"persistent": {
68-
"xpack.ml.model_repository": "%s"
69-
}
70-
}""", mlModelServer.getUrl()));
71-
assertOK(client().performRequest(request));
63+
assertOK(mlModelServer.setMlModelRepository(adminClient()));
7264
}
7365

7466
@Override

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/MlModelServer.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import org.apache.http.HttpHeaders;
1414
import org.apache.http.HttpStatus;
1515
import org.apache.http.client.utils.URIBuilder;
16+
import org.elasticsearch.client.Request;
17+
import org.elasticsearch.client.Response;
18+
import org.elasticsearch.client.RestClient;
19+
import org.elasticsearch.common.Strings;
1620
import org.elasticsearch.logging.LogManager;
1721
import org.elasticsearch.logging.Logger;
1822
import org.elasticsearch.test.fixture.HttpHeaderParser;
@@ -48,7 +52,19 @@ public class MlModelServer implements TestRule {
4852

4953
private int port;
5054

51-
public String getUrl() {
55+
public Response setMlModelRepository(RestClient restClient) throws IOException {
56+
logger.info("setting ML model repository to: {}", getUrl());
57+
var request = new Request("PUT", "/_cluster/settings");
58+
request.setJsonEntity(Strings.format("""
59+
{
60+
"persistent": {
61+
"xpack.ml.model_repository": "%s"
62+
}
63+
}""", getUrl()));
64+
return restClient.performRequest(request);
65+
}
66+
67+
private String getUrl() {
5268
return new URIBuilder().setScheme("http").setHost(HOST).setPort(port).toString();
5369
}
5470

x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/AbstractXPackRestTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields;
2626
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
2727
import org.elasticsearch.xpack.core.rollup.job.RollupJob;
28+
import org.elasticsearch.xpack.inference.MlModelServer;
2829
import org.junit.After;
2930
import org.junit.Before;
31+
import org.junit.ClassRule;
3032

3133
import java.io.IOException;
3234
import java.util.Arrays;
@@ -50,6 +52,14 @@ public abstract class AbstractXPackRestTest extends ESClientYamlSuiteTestCase {
5052
SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING
5153
);
5254

55+
@ClassRule
56+
public static MlModelServer mlModelServer = new MlModelServer();
57+
58+
@Before
59+
public void setMlModelRepository() throws IOException {
60+
assertOK(mlModelServer.setMlModelRepository(adminClient()));
61+
}
62+
5363
public AbstractXPackRestTest(ClientYamlTestCandidate testCandidate) {
5464
super(testCandidate);
5565
}

0 commit comments

Comments
 (0)