From d93975b3f22c7bc664d97bb762913b59119464db Mon Sep 17 00:00:00 2001 From: suzhou Date: Wed, 18 Jan 2023 09:13:10 +0800 Subject: [PATCH 1/3] feat: remove snapshot spec and update commands Signed-off-by: suzhou --- .../snapshots_spec.js | 146 ------------------ .../commands.js | 63 -------- 2 files changed, 209 deletions(-) delete mode 100644 cypress/integration/plugins/index-management-dashboards-plugin/snapshots_spec.js diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/snapshots_spec.js b/cypress/integration/plugins/index-management-dashboards-plugin/snapshots_spec.js deleted file mode 100644 index e94de5be1..000000000 --- a/cypress/integration/plugins/index-management-dashboards-plugin/snapshots_spec.js +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { BASE_PATH, IM_PLUGIN_NAME } from '../../../utils/constants'; - -describe('Snapshots', () => { - before(() => { - // Set welcome screen tracking to false - localStorage.setItem('home:welcome:show', 'false'); - - // Visit ISM Snapshots Dashboard - cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/snapshots`); - - // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load - cy.contains('Restore', { timeout: 60000 }); - }); - - describe('Repository can be created', () => { - it('successfully creates a new repository', () => { - // Create repository to store snapshots - cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/repositories`); - - // Route to create repository page - cy.contains('Create repository').click({ force: true }); - - // Type in repository name - cy.get(`input[data-test-subj="repoNameInput"]`).focus().type('test_repo'); - - // Type in repository location - cy.get(`input[placeholder="e.g., /mnt/snapshots"]`) - .focus() - .type('~/Desktop'); - - // Click Add button - cy.get('button').contains('Add').click({ force: true }); - - // Confirm repository created - cy.contains('test_repo'); - }); - }); - - describe('Snapshot can be created', () => { - it('successfully creates a new snapshot', () => { - cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/snapshots`); - - // delete any existing indices - cy.deleteAllIndices(); - - // create test indices - cy.createIndex('test_index_1'); - cy.createIndex('test_index_2'); - cy.createIndex('test_index_3'); - - // wait needed here to enable cypress to find "Take snapshot" button. Timeout - // cannot be used with cy.createIndex - cy.wait(5000); - - // Click Take snapshot button - cy.get('button').contains('Take snapshot').click({ force: true }); - - // Confirm test_repo exists and is in the Select repo field - cy.contains('test_repo'); - - // Type in Snapshot name - cy.get(`input[data-test-subj="snapshotNameInput"]`).type( - 'test_snapshot{enter}' - ); - - // Select all indexes to be included - cy.get(`[data-test-subj="indicesComboBoxInput"]`).type( - 'test_index_1{enter}' - ); - cy.get(`[data-test-subj="indicesComboBoxInput"]`).type( - 'test_index_2{enter}' - ); - cy.get(`[data-test-subj="indicesComboBoxInput"]`).type( - 'test_index_3{enter}' - ); - - // Click 'Add' button to create snapshot - cy.get('button') - .contains('Add', { timeout: 3000 }) - .click({ force: true }); - - // check for success status and snapshot name - cy.get('button').contains('Refresh').click({ force: true }); - - cy.contains('Success'); - - // remove all indices - cy.deleteAllIndices(); - }); - }); - - describe('Snapshot can be restored', () => { - it('Successfully restores indices from snapshot', () => { - // Must wait here before refreshing so snapshot status becomes 'success' - cy.wait(5000); - - // Wait for snapshot to be created successfully - cy.get('button').contains('Refresh').click({ force: true }); - - // Select test snapshot - cy.get( - `[data-test-subj="checkboxSelectRow-test_repo:test_snapshot"]` - ).check({ force: true }); - - // click "Restore" button - cy.get(`[data-test-subj="restoreButton"]`).click({ force: true }); - - // Check for restore flyout - cy.contains('Restore snapshot'); - - // enter a prefix - cy.get(`input[data-test-subj="prefixInput"]`).type('restored_'); - - // Click restore snapshot button - cy.get('button').contains('Restore snapshot').click({ force: true }); - - // Check for success toast - cy.contains(`Restore from snapshot "test_snapshot" is in progress.`); - }); - }); - - describe('Snapshot can be deleted', () => { - it('deletes snapshot successfully', () => { - // Select test snapshot - cy.get( - `[data-test-subj="checkboxSelectRow-test_repo:test_snapshot"]` - ).check({ force: true }); - - // click "Delete" button - cy.get('button') - .contains('Delete', { timeout: 3000 }) - .click({ force: true }); - - // click "Delete snapshot" button on modal - cy.get('button').contains('Delete snapshot').click({ force: true }); - - cy.contains('Deleted snapshot'); - cy.contains('No items found'); - }); - }); -}); diff --git a/cypress/utils/plugins/index-management-dashboards-plugin/commands.js b/cypress/utils/plugins/index-management-dashboards-plugin/commands.js index c112ab89b..d2ce5c882 100644 --- a/cypress/utils/plugins/index-management-dashboards-plugin/commands.js +++ b/cypress/utils/plugins/index-management-dashboards-plugin/commands.js @@ -48,18 +48,6 @@ Cypress.Commands.add('createPolicy', (policyId, policyJSON) => { ); }); -Cypress.Commands.add('getIndexSettings', (index) => { - cy.request('GET', `${Cypress.env('openSearchUrl')}/${index}/_settings`); -}); - -Cypress.Commands.add('updateIndexSettings', (index, settings) => { - cy.request( - 'PUT', - `${Cypress.env('openSearchUrl')}/${index}/_settings`, - settings - ); -}); - Cypress.Commands.add('updateManagedIndexConfigStartTime', (index) => { // TODO directly changing system index will not be supported, need to introduce new way // Creating closure over startTime so it's not calculated until actual update_by_query call @@ -86,18 +74,6 @@ Cypress.Commands.add('updateManagedIndexConfigStartTime', (index) => { }); }); -Cypress.Commands.add('createIndex', (index, policyID = null, settings = {}) => { - cy.request('PUT', `${Cypress.env('openSearchUrl')}/${index}`, settings); - if (policyID != null) { - const body = { policy_id: policyID }; - cy.request( - 'POST', - `${Cypress.env('openSearchUrl')}${IM_API.ADD_POLICY_BASE}/${index}`, - body - ); - } -}); - Cypress.Commands.add('createRollup', (rollupId, rollupJSON) => { cy.request( 'PUT', @@ -106,14 +82,6 @@ Cypress.Commands.add('createRollup', (rollupId, rollupJSON) => { ); }); -Cypress.Commands.add('createIndexTemplate', (name, template) => { - cy.request( - 'PUT', - `${Cypress.env('openSearchUrl')}${IM_API.INDEX_TEMPLATE_BASE}/${name}`, - template - ); -}); - Cypress.Commands.add('deleteTemplate', (name) => { cy.request({ url: `${Cypress.env('openSearchUrl')}${IM_API.INDEX_TEMPLATE_BASE}/${name}`, @@ -122,24 +90,6 @@ Cypress.Commands.add('deleteTemplate', (name) => { }); }); -Cypress.Commands.add('createDataStream', (name) => { - cy.request( - 'PUT', - `${Cypress.env('openSearchUrl')}${IM_API.DATA_STREAM_BASE}/${name}` - ); -}); - -Cypress.Commands.add('deleteDataStreams', (names) => { - cy.request( - 'DELETE', - `${Cypress.env('openSearchUrl')}${IM_API.DATA_STREAM_BASE}/${names}` - ); -}); - -Cypress.Commands.add('rollover', (target) => { - cy.request('POST', `${Cypress.env('openSearchUrl')}/${target}/_rollover`); -}); - Cypress.Commands.add('createTransform', (transformId, transformJSON) => { cy.request( 'PUT', @@ -176,19 +126,6 @@ Cypress.Commands.add('disableJitter', () => { ); }); -Cypress.Commands.add('deleteAllIndices', () => { - cy.request( - 'DELETE', - `${Cypress.env( - 'openSearchUrl' - )}/index*,sample*,opensearch_dashboards*,test*` - ); - cy.request( - 'DELETE', - `${Cypress.env('openSearchUrl')}/.opendistro-ism*?expand_wildcards=all` - ); -}); - Cypress.Commands.add('addAlias', (alias, index) => { cy.request({ url: `${Cypress.env('openSearchUrl')}/_aliases`, From aeabde2a1f2edd2e8e439de04a3e298859fa26c2 Mon Sep 17 00:00:00 2001 From: suzhou Date: Wed, 18 Jan 2023 11:35:32 +0800 Subject: [PATCH 2/3] feat: make actions to run again Signed-off-by: suzhou --- .../utils/plugins/index-management-dashboards-plugin/commands.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cypress/utils/plugins/index-management-dashboards-plugin/commands.js b/cypress/utils/plugins/index-management-dashboards-plugin/commands.js index d2ce5c882..3443bcc46 100644 --- a/cypress/utils/plugins/index-management-dashboards-plugin/commands.js +++ b/cypress/utils/plugins/index-management-dashboards-plugin/commands.js @@ -144,6 +144,7 @@ Cypress.Commands.add('addAlias', (alias, index) => { }); }); + Cypress.Commands.add('removeAlias', (alias) => { cy.request({ url: `${Cypress.env('openSearchUrl')}/_aliases`, From 74626d97a2d5029e5280b67a0b0348aa385c2021 Mon Sep 17 00:00:00 2001 From: suzhou Date: Wed, 18 Jan 2023 13:58:00 +0800 Subject: [PATCH 3/3] feat: change to addIndexAlias & removeIndexAlias Signed-off-by: suzhou --- .../index-management-dashboards-plugin/aliases.js | 10 +++++----- .../index-management-dashboards-plugin/commands.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js index 91b6c6165..73124ecb8 100644 --- a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js +++ b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js @@ -19,13 +19,13 @@ describe('Aliases', () => { } cy.createIndex(EDIT_INDEX, null); for (let i = 0; i < 30; i++) { - cy.addAlias( + cy.addIndexAlias( `${SAMPLE_ALIAS_PREFIX}-${i}`, `${SAMPLE_INDEX_PREFIX}-${i % 11}` ); } - cy.removeAlias(`${SAMPLE_ALIAS_PREFIX}-0`); - cy.addAlias(`${SAMPLE_ALIAS_PREFIX}-0`, `${SAMPLE_INDEX_PREFIX}-*`); + cy.removeIndexAlias(`${SAMPLE_ALIAS_PREFIX}-0`); + cy.addIndexAlias(`${SAMPLE_ALIAS_PREFIX}-0`, `${SAMPLE_INDEX_PREFIX}-*`); }); beforeEach(() => { @@ -131,8 +131,8 @@ describe('Aliases', () => { after(() => { cy.deleteAllIndices(); for (let i = 0; i < 30; i++) { - cy.removeAlias(`${SAMPLE_ALIAS_PREFIX}-${i}`); + cy.removeIndexAlias(`${SAMPLE_ALIAS_PREFIX}-${i}`); } - cy.removeAlias(CREATE_ALIAS); + cy.removeIndexAlias(CREATE_ALIAS); }); }); diff --git a/cypress/utils/plugins/index-management-dashboards-plugin/commands.js b/cypress/utils/plugins/index-management-dashboards-plugin/commands.js index 3443bcc46..388e71f9c 100644 --- a/cypress/utils/plugins/index-management-dashboards-plugin/commands.js +++ b/cypress/utils/plugins/index-management-dashboards-plugin/commands.js @@ -126,7 +126,7 @@ Cypress.Commands.add('disableJitter', () => { ); }); -Cypress.Commands.add('addAlias', (alias, index) => { +Cypress.Commands.add('addIndexAlias', (alias, index) => { cy.request({ url: `${Cypress.env('openSearchUrl')}/_aliases`, method: 'POST', @@ -145,7 +145,7 @@ Cypress.Commands.add('addAlias', (alias, index) => { }); -Cypress.Commands.add('removeAlias', (alias) => { +Cypress.Commands.add('removeIndexAlias', (alias) => { cy.request({ url: `${Cypress.env('openSearchUrl')}/_aliases`, method: 'POST',