Skip to content

Commit

Permalink
Logsdb snapshot functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SoniaSanzV committed Jan 10, 2025
1 parent 3d82bb5 commit 7a49b7d
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export const CollapsibleIndicesList: React.FunctionComponent<Props> = ({ indices
values={{ count: hiddenItemsCount }}
/>
)}{' '}
<EuiIcon type={isShowingFullList ? 'arrowUp' : 'arrowDown'} />
<EuiIcon
type={isShowingFullList ? 'arrowUp' : 'arrowDown'}
data-test-subj="collapsibleIndicesArrow"
/>
</EuiLink>
</>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export const IndicesAndDataStreamsField: FunctionComponent<Props> = ({
setSelectIndicesMode('custom');
onUpdate({ indices: indexPatterns.join(',') });
}}
data-test-subj="useIndexPatternsButton"
>
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepSettings.indicesToggleCustomLink"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent<StepProps> =
});
}
}}
data-test-subj="allDsAndIndicesToggle"
/>
{isAllIndicesAndDataStreams ? null : (
<Fragment>
Expand All @@ -281,6 +282,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent<StepProps> =
setSelectIndicesMode('custom');
updateRestoreSettings({ indices: restoreIndexPatterns.join(',') });
}}
data-test-subj="restoreIndexPatternsButton"
>
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.stepLogistics.indicesToggleCustomLink"
Expand Down Expand Up @@ -476,6 +478,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent<StepProps> =
});
}
}}
data-test-subj="restoreRenameToggle"
/>
{!isRenamingIndices ? null : (
<Fragment>
Expand Down Expand Up @@ -510,6 +513,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent<StepProps> =
renamePattern: e.target.value,
});
}}
data-test-subj="capturePattern"
/>
</EuiFormRow>
</EuiFlexItem>
Expand All @@ -536,6 +540,7 @@ export const RestoreSnapshotStepLogistics: React.FunctionComponent<StepProps> =
renameReplacement: e.target.value,
});
}}
data-test-subj="replacementPattern"
/>
</EuiFormRow>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export const RestoreSnapshotStepReview: React.FunctionComponent<StepProps> = ({

return (
<Fragment>
<EuiTitle>
<EuiTitle data-test-subj="reviewSnapshotTitle">
<h2>
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.stepReviewTitle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const RestoreSnapshotStepSettings: React.FunctionComponent<StepProps> = (
{/* Step title and doc link */}
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiTitle>
<EuiTitle data-test-subj="indexSettingsTitle">
<h2>
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.stepSettingsTitle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export const PolicyDetails: React.FunctionComponent<Props> = ({
);
},
disabled: Boolean(policyDetails.policy.inProgress),
'data-test-subj': 'policyActionMenuRunPolicy',
},
{
name: i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export const SnapshotDetails: React.FunctionComponent<Props> = ({
snapshotDetails.state !== SNAPSHOT_STATE.SUCCESS &&
snapshotDetails.state !== SNAPSHOT_STATE.PARTIAL
}
data-test-subj="restoreSnapshotButton"
>
<FormattedMessage
id="xpack.snapshotRestore.snapshotDetails.restoreButtonLabel"
Expand Down
172 changes: 142 additions & 30 deletions x-pack/test/functional/apps/snapshot_restore/snapshot_restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const security = getService('security');

describe('Snapshot restore', function () {
const REPOSITORY = 'my-repository';
before(async () => {
await security.testUser.setRoles(['snapshot_restore_user'], { skipBrowserRefresh: true });
await pageObjects.common.navigateToApp('snapshotRestore');

// Create a repository
await es.snapshot.createRepository({
name: 'my-repository',
name: REPOSITORY,
verify: true,
repository: {
type: 'fs',
Expand All @@ -32,50 +33,161 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
},
},
});
});

describe('Snapshot', () => {
before(async () => {
// Create a snapshot
await es.snapshot.create({
snapshot: 'my-snapshot',
repository: REPOSITORY,
});

// Create a snapshot
await es.snapshot.create({
snapshot: 'my-snapshot',
repository: 'my-repository',
// Wait for snapshot to be ready
await pageObjects.common.sleep(2000);

// Refresh page so that the snapshot shows up in the snapshots table
await browser.refresh();
});

// Wait for snapshot to be ready
await pageObjects.common.sleep(2000);
after(async () => {
await es.snapshot.delete({
snapshot: 'my-snapshot',
repository: REPOSITORY,
});
});

it('Renders the Snapshot restore form', async () => {
const snapshots = await pageObjects.snapshotRestore.getSnapshotList();
const snapshotRestoreButton = await snapshots[0].snapshotRestore;
// Open the Snapshot restore form
await snapshotRestoreButton.click();

// Go to second step (Index settings)
await testSubjects.click('nextButton');

// Verify that the Index Settings editor is rendered (uses CodeEditor)
await testSubjects.click('modifyIndexSettingsSwitch');
expect(await testSubjects.exists('indexSettingsEditor')).to.be(true);

// Refresh page so that the snapshot shows up in the snapshots table
await browser.refresh();
// Close Index Settings editor
await testSubjects.click('modifyIndexSettingsSwitch');

// Go to final step (Review)
await testSubjects.click('nextButton');

// Verify that Restore button exists
expect(await testSubjects.exists('restoreButton')).to.be(true);
});
});

it('Renders the Snapshot restore form', async () => {
const snapshots = await pageObjects.snapshotRestore.getSnapshotList();
const snapshotRestoreButton = await snapshots[0].snapshotRestore;
// Open the Snapshot restore form
await snapshotRestoreButton.click();
describe('Allows to create and restore a snapshot from a Logsdb index', () => {
const logsDbIndex = 'logsdb-index';
const policyId = 'testPolicy';
const snapshotPrefx = 'logsdb-snap';

before(async () => {
await es.indices.create({
index: logsDbIndex,
settings: {
mode: 'logsdb',
},
});
await pageObjects.common.navigateToApp('snapshotRestore');
// Create a policy
await pageObjects.snapshotRestore.navToPolicies();
await pageObjects.snapshotRestore.fillCreateNewPolicyPageOne(
policyId,
`<${snapshotPrefx}-{now/d}>`
);
await pageObjects.snapshotRestore.fillCreateNewPolicyPageTwo();
await pageObjects.snapshotRestore.fillCreateNewPolicyPageThree();
await pageObjects.snapshotRestore.submitNewPolicy();
await pageObjects.snapshotRestore.closeFlyout();
});

after(async () => {
// Delete the logdb index
await es.indices.delete({
index: logsDbIndex,
});
// Delete policy
await es.slm.deleteLifecycle({
policy_id: policyId,
});
await es.snapshot.delete({
snapshot: `${snapshotPrefx}-*`,
repository: REPOSITORY,
});
await es.indices.delete({
index: `restored_${logsDbIndex}`,
});
});

it('create snapshot', async () => {
// Verify there are no snapshots
await pageObjects.snapshotRestore.navToSnapshots();
expect(await testSubjects.exists('snapshotListEmpty')).to.be(true);

// Run policy snapshot
await pageObjects.snapshotRestore.navToPolicies();

await pageObjects.snapshotRestore.clickPolicyNameLink(policyId);
await pageObjects.snapshotRestore.clickPolicyActionButton();
await pageObjects.snapshotRestore.clickRunPolicy();
await pageObjects.snapshotRestore.clickConfirmationModal();
await pageObjects.snapshotRestore.closeFlyout();

// Wait for snapshot to be ready
await pageObjects.common.sleep(2000);

// Go to second step (Index settings)
await testSubjects.click('nextButton');
// Open snapshot info flyout
await pageObjects.snapshotRestore.navToSnapshots();
expect(await testSubjects.exists('snapshotList')).to.be(true);

// Verify that the Index Settings editor is rendered (uses CodeEditor)
await testSubjects.click('modifyIndexSettingsSwitch');
expect(await testSubjects.exists('indexSettingsEditor')).to.be(true);
// Reload page to make sure snapshot is complete
await testSubjects.click('reloadButton');
await pageObjects.header.waitUntilLoadingHasFinished();

// Close Index Settings editor
await testSubjects.click('modifyIndexSettingsSwitch');
// Verify that one snapshot has been created
const snapshots = await pageObjects.snapshotRestore.getSnapshotList();
expect(snapshots.length).to.be(1);

// Go to final step (Review)
await testSubjects.click('nextButton');
// Verify that snaphot has been created
const snapshotLink = snapshots[0].snapshotLink;
await snapshotLink.click();

// Verify that Restore button exists
expect(await testSubjects.exists('restoreButton')).to.be(true);
// Verify snapshot exists and contains the logsdb index
expect(await testSubjects.exists('detailTitle')).to.be(true);
expect(await testSubjects.getVisibleText('detailTitle')).to.contain(snapshotPrefx);
await pageObjects.snapshotRestore.clickShowCollapsedIndicesIfPresent();
expect(await testSubjects.getVisibleText('indices')).to.contain(logsDbIndex);
await pageObjects.snapshotRestore.closeSnaphsotFlyout();
});

it('restore snapshot', async () => {
// Verify there are not restore snapshots
await pageObjects.snapshotRestore.navToRestoreStatus();
expect(await testSubjects.exists('noRestoredSnapshotsHeader')).to.be(true);

// restore snapshot
await pageObjects.snapshotRestore.navToSnapshots();
const snapshots = await pageObjects.snapshotRestore.getSnapshotList();
const snapshotLink = snapshots[0].snapshotLink;
await snapshotLink.click();
await pageObjects.snapshotRestore.restoreSnapshot(logsDbIndex, true);

// Verify snapshot has been restored
await pageObjects.snapshotRestore.navToRestoreStatus(false);
expect(await testSubjects.getVisibleText('restoreList')).to.contain(
`restored_${logsDbIndex}`
);
});
});

after(async () => {
await es.snapshot.delete({
snapshot: 'my-snapshot',
repository: 'my-repository',
});
await es.snapshot.deleteRepository({
name: 'my-repository',
name: REPOSITORY,
});
await security.testUser.restoreDefaults();
});
Expand Down
7 changes: 7 additions & 0 deletions x-pack/test/functional/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,13 @@ export default async function ({ readConfigFile }) {
'manage_slm',
'cluster:admin/snapshot',
'cluster:admin/repository',
'manage_index_templates',
],
indices: [
{
names: ['*'],
privileges: ['all'],
},
],
},
kibana: [
Expand Down
Loading

0 comments on commit 7a49b7d

Please sign in to comment.