15
15
import org .opensearch .action .search .SearchResponse ;
16
16
import org .opensearch .client .Response ;
17
17
import org .opensearch .client .ResponseException ;
18
+ import org .opensearch .core .rest .RestStatus ;
18
19
import org .opensearch .rest .RestRequest ;
19
20
20
21
public class RestMLModelTenantAwareIT extends MLCommonsTenantAwareRestTestCase {
@@ -32,7 +33,14 @@ public void testModelCRUD() throws Exception {
32
33
Map <String , Object > map = responseToMap (response );
33
34
assertTrue (map .containsKey (CONNECTOR_ID ));
34
35
String connectorId = map .get (CONNECTOR_ID ).toString ();
35
- // Create a second connector from other tenant
36
+ // Create a second connector with same tenant for deletion tests later
37
+ response = makeRequest (createConnectorRequest , POST , CONNECTORS_PATH + "_create" );
38
+ assertOK (response );
39
+ map = responseToMap (response );
40
+ assertTrue (map .containsKey (CONNECTOR_ID ));
41
+ String secondConnectorId = map .get (CONNECTOR_ID ).toString ();
42
+
43
+ // Create a third connector from other tenant
36
44
createConnectorRequest = getRestRequestWithHeadersAndContent (otherTenantId , COHERE_CONNECTOR_BLUEPRINT );
37
45
response = makeRequest (createConnectorRequest , POST , CONNECTORS_PATH + "_create" );
38
46
assertOK (response );
@@ -308,6 +316,17 @@ public void testModelCRUD() throws Exception {
308
316
assertEquals (MISSING_TENANT_REASON , getErrorReasonFromResponseMap (map ));
309
317
}
310
318
319
+ // Try to delete connector while model exists
320
+ ResponseException ex = assertThrows (
321
+ ResponseException .class ,
322
+ () -> makeRequest (tenantRequest , DELETE , CONNECTORS_PATH + connectorId )
323
+ );
324
+ response = ex .getResponse ();
325
+ assertEquals (RestStatus .CONFLICT .getStatus (), response .getStatusLine ().getStatusCode ());
326
+ // but it should work with the connector not in a model
327
+ response = makeRequest (tenantRequest , DELETE , CONNECTORS_PATH + secondConnectorId );
328
+ assertOK (response );
329
+
311
330
// Now actually do the deletions. Same result whether multi-tenancy is enabled.
312
331
// Verify still exists
313
332
response = makeRequest (tenantRequest , GET , MODELS_PATH + modelId );
@@ -320,7 +339,7 @@ public void testModelCRUD() throws Exception {
320
339
assertEquals (modelId , map .get (DOC_ID ).toString ());
321
340
322
341
// Verify the deletion
323
- ResponseException ex = assertThrows (ResponseException .class , () -> makeRequest (tenantRequest , GET , MODELS_PATH + modelId ));
342
+ ex = assertThrows (ResponseException .class , () -> makeRequest (tenantRequest , GET , MODELS_PATH + modelId ));
324
343
response = ex .getResponse ();
325
344
assertNotFound (response );
326
345
map = responseToMap (response );
0 commit comments