From 1e5e7f603eab09ae7de5bcf5482e03e3108e00e9 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 8 Jul 2021 14:51:25 +0200 Subject: [PATCH] [ML] test for aliases --- .../apis/ml/trained_models/get_model_pipelines.ts | 2 +- .../apis/ml/trained_models/get_models.ts | 14 ++++++++++---- x-pack/test/functional/services/ml/api.ts | 8 ++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/x-pack/test/api_integration/apis/ml/trained_models/get_model_pipelines.ts b/x-pack/test/api_integration/apis/ml/trained_models/get_model_pipelines.ts index 495637f7b41e9..1e8c919e24e92 100644 --- a/x-pack/test/api_integration/apis/ml/trained_models/get_model_pipelines.ts +++ b/x-pack/test/api_integration/apis/ml/trained_models/get_model_pipelines.ts @@ -23,9 +23,9 @@ export default ({ getService }: FtrProviderContext) => { }); after(async () => { - await ml.api.cleanMlIndices(); // delete all created ingest pipelines await Promise.all(testModelIds.map((modelId) => ml.api.deleteIngestPipeline(modelId))); + await ml.api.cleanMlIndices(); }); it('returns trained model pipelines by id', async () => { diff --git a/x-pack/test/api_integration/apis/ml/trained_models/get_models.ts b/x-pack/test/api_integration/apis/ml/trained_models/get_models.ts index a6063b102613d..0210b60bf503c 100644 --- a/x-pack/test/api_integration/apis/ml/trained_models/get_models.ts +++ b/x-pack/test/api_integration/apis/ml/trained_models/get_models.ts @@ -20,15 +20,21 @@ export default ({ getService }: FtrProviderContext) => { before(async () => { await ml.testResources.setKibanaTimeZoneToUTC(); testModelIds = await ml.api.createdTestTrainedModels('regression', 5, true); + await ml.api.createModelAlias('dfa_regression_model_n_0', 'dfa_regression_model_alias'); + await ml.api.createIngestPipeline('dfa_regression_model_alias'); }); after(async () => { - await ml.api.cleanMlIndices(); // delete created ingest pipelines - await Promise.all(testModelIds.map((modelId) => ml.api.deleteIngestPipeline(modelId))); + await Promise.all( + ['dfa_regression_model_alias', ...testModelIds].map((modelId) => + ml.api.deleteIngestPipeline(modelId) + ) + ); + await ml.api.cleanMlIndices(); }); - it('returns all trained models with associated pipelines', async () => { + it('returns all trained models with associated pipelines including aliases', async () => { const { body } = await supertest .get(`/api/ml/trained_models?with_pipelines=true`) .auth(USER.ML_POWERUSER, ml.securityCommon.getPasswordForUser(USER.ML_POWERUSER)) @@ -38,7 +44,7 @@ export default ({ getService }: FtrProviderContext) => { expect(body.length).to.eql(6); const sampleModel = body.find((v: any) => v.model_id === 'dfa_regression_model_n_0'); - expect(Object.keys(sampleModel.pipelines).length).to.eql(1); + expect(Object.keys(sampleModel.pipelines).length).to.eql(2); }); it('returns models without pipeline in case user does not have required permission', async () => { diff --git a/x-pack/test/functional/services/ml/api.ts b/x-pack/test/functional/services/ml/api.ts index d61e33c19204b..ec5ca4c661157 100644 --- a/x-pack/test/functional/services/ml/api.ts +++ b/x-pack/test/functional/services/ml/api.ts @@ -998,6 +998,14 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) { ); }, + async createModelAlias(modelId: string, modelAlias: string) { + log.debug(`Creating alias for model "${modelId}"`); + await esSupertest + .put(`/_ml/trained_models/${modelId}/model_aliases/${modelAlias}`) + .expect(200); + log.debug('> Model alias created'); + }, + /** * Creates ingest pipelines for trained model * @param modelId