From 91366f02219b333f78f408add128657072e1fd5b Mon Sep 17 00:00:00 2001 From: Rashmi Kulkarni Date: Mon, 9 Aug 2021 12:50:13 -0700 Subject: [PATCH] Rollup - Conversion of functional test files to use custom roles and permissions and also convert esArchiver to kbnArchiver (#107818) * updated the test to use kbnArchiver to load the data and also the test uses minimal set of roles-permissions for the test-user lint errors lint errors * hybrid index pattern - conversion to kbnArchiver and the test user to use specific roles n permissions --- .../apps/rollup_job/hybrid_index_pattern.js | 22 +++++++++-- .../test/functional/apps/rollup_job/tsvb.js | 18 +++++++-- x-pack/test/functional/config.js | 11 ++++++ .../fixtures/kbn_archiver/rollup/rollup.json | 39 +++++++++++++++++++ .../kbn_archiver/rollup/rollup_hybrid.json | 1 + 5 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup.json create mode 100644 x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup_hybrid.json diff --git a/x-pack/test/functional/apps/rollup_job/hybrid_index_pattern.js b/x-pack/test/functional/apps/rollup_job/hybrid_index_pattern.js index e479c6729d8c..4fe957dac7b6 100644 --- a/x-pack/test/functional/apps/rollup_job/hybrid_index_pattern.js +++ b/x-pack/test/functional/apps/rollup_job/hybrid_index_pattern.js @@ -11,8 +11,9 @@ import mockRolledUpData, { mockIndices } from './hybrid_index_helper'; export default function ({ getService, getPageObjects }) { const es = getService('es'); - const esArchiver = getService('esArchiver'); const retry = getService('retry'); + const security = getService('security'); + const kibanaServer = getService('kibanaServer'); const PageObjects = getPageObjects(['common', 'settings']); const esDeleteAllIndices = getService('esDeleteAllIndices'); @@ -31,6 +32,20 @@ export default function ({ getService, getPageObjects }) { datemath.parse('now-3d', { forceNow: now }), ]; + before(async () => { + // load visualize to have an index pattern ready, otherwise visualize will redirect + await security.testUser.setRoles([ + 'global_index_pattern_management_all', + 'test_rollup_reader', + ]); + await kibanaServer.importExport.load( + 'x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup_hybrid' + ); + await kibanaServer.uiSettings.replace({ + defaultIndex: 'rollup', + }); + }); + it('create hybrid index pattern', async () => { //Create data for rollup job to recognize. //Index past data to be used in the test. @@ -105,8 +120,9 @@ export default function ({ getService, getPageObjects }) { `${regularIndexPrefix}*`, `${rollupSourceIndexPrefix}*`, ]); - - await esArchiver.load('x-pack/test/functional/es_archives/empty_kibana'); + await kibanaServer.importExport.unload( + 'x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup_hybrid' + ); }); }); } diff --git a/x-pack/test/functional/apps/rollup_job/tsvb.js b/x-pack/test/functional/apps/rollup_job/tsvb.js index ba39a8aaa436..3b216bfb34b9 100644 --- a/x-pack/test/functional/apps/rollup_job/tsvb.js +++ b/x-pack/test/functional/apps/rollup_job/tsvb.js @@ -10,8 +10,9 @@ import mockRolledUpData from './hybrid_index_helper'; export default function ({ getService, getPageObjects }) { const es = getService('es'); - const esArchiver = getService('esArchiver'); const retry = getService('retry'); + const security = getService('security'); + const kibanaServer = getService('kibanaServer'); const esDeleteAllIndices = getService('esDeleteAllIndices'); const PageObjects = getPageObjects([ 'common', @@ -26,7 +27,7 @@ export default function ({ getService, getPageObjects }) { //we add the Date.now() to avoid name collision if you run the tests locally back to back. const rollupJobName = `tsvb-test-rollup-job-${Date.now()}`; const rollupSourceIndexName = 'rollup-source-data'; - const rollupTargetIndexName = `rollup-target-data`; + const rollupTargetIndexName = 'rollup-target-data'; const pastDates = [ new Date('October 15, 2019 05:35:32'), new Date('October 15, 2019 05:34:32'), @@ -35,7 +36,13 @@ export default function ({ getService, getPageObjects }) { before(async () => { // load visualize to have an index pattern ready, otherwise visualize will redirect - await esArchiver.load('x-pack/test/functional/es_archives/visualize/default'); + await security.testUser.setRoles(['global_visualize_all', 'test_rollup_reader']); + await kibanaServer.importExport.load( + 'x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup.json' + ); + await kibanaServer.uiSettings.replace({ + defaultIndex: 'rollup', + }); }); it('create rollup tsvb', async () => { @@ -100,7 +107,10 @@ export default function ({ getService, getPageObjects }) { }); await esDeleteAllIndices([rollupTargetIndexName, rollupSourceIndexName]); - await esArchiver.load('x-pack/test/functional/es_archives/empty_kibana'); + await kibanaServer.importExport.unload( + 'x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup.json' + ); + await security.testUser.restoreDefaults(); }); }); } diff --git a/x-pack/test/functional/config.js b/x-pack/test/functional/config.js index a79e51057c90..06e58638922d 100644 --- a/x-pack/test/functional/config.js +++ b/x-pack/test/functional/config.js @@ -465,6 +465,17 @@ export default async function ({ readConfigFile }) { ], }, + test_rollup_reader: { + elasticsearch: { + indices: [ + { + names: ['rollup-*'], + privileges: ['read', 'view_index_metadata'], + }, + ], + }, + }, + //Kibana feature privilege isn't specific to advancedSetting. It can be anything. https://github.com/elastic/kibana/issues/35965 test_api_keys: { elasticsearch: { diff --git a/x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup.json b/x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup.json new file mode 100644 index 000000000000..00596d865f03 --- /dev/null +++ b/x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup.json @@ -0,0 +1,39 @@ +{ + "attributes": { + "accessibility:disableAnimations": true, + "buildNum": 9007199254740991, + "dateFormat:tz": "UTC", + "defaultIndex": "rollup", + "visualization:visualize:legacyChartsLibrary": true, + "visualization:visualize:legacyPieChartsLibrary": true + }, + "coreMigrationVersion": "7.15.0", + "id": "7.15.0", + "migrationVersion": { + "config": "7.13.0" + }, + "references": [], + "type": "config", + "updated_at": "2021-08-04T23:35:47.992Z", + "version": "WzQwLDFd" +} + +{ + "attributes": { + "fieldAttrs": "{}", + "fields": "[]", + "runtimeFieldMap": "{}", + "timeFieldName": "@timestamp.date_histogram.timestamp", + "title": "rollup*", + "typeMeta": "{}" + }, + "coreMigrationVersion": "7.15.0", + "id": "rollup", + "migrationVersion": { + "index-pattern": "7.11.0" + }, + "references": [], + "type": "index-pattern", + "updated_at": "2021-08-04T23:22:14.902Z", + "version": "WzIyLDFd" +} \ No newline at end of file diff --git a/x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup_hybrid.json b/x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup_hybrid.json new file mode 100644 index 000000000000..a148ac8612d2 --- /dev/null +++ b/x-pack/test/functional/fixtures/kbn_archiver/rollup/rollup_hybrid.json @@ -0,0 +1 @@ +{"attributes":{"fieldAttrs":"{}","fields":"[]","runtimeFieldMap":"{}","timeFieldName":"@timestamp","title":"regular-index*,rollup-target-data","type":"rollup","typeMeta":"{\"params\":{\"rollup_index\":\"rollup-target-data\"},\"aggs\":{\"date_histogram\":{\"@timestamp\":{\"agg\":\"date_histogram\",\"fixed_interval\":\"1000ms\",\"time_zone\":\"UTC\"}}}}"},"coreMigrationVersion":"8.0.0","id":"b8f05720-f5b0-11eb-a2ec-8d77790684d1","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-08-05T05:48:13.077Z","version":"WzksMl0="}