forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ILM] Fixed snapshot repositories and policies routes (elastic#129200)
* [ILM] Fixed snapshot repositories and policies routes * [ILM] Updated console.log to error Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
294fe2b
commit d7c6bfb
Showing
8 changed files
with
220 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...t/api_integration/apis/management/index_lifecycle_management/snapshot_policies.helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { API_BASE_PATH, SNAPSHOT_REPOSITORY_NAME } from './constants'; | ||
|
||
export const registerSnapshotPoliciesHelpers = (getService: FtrProviderContext['getService']) => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
let policiesCreated: string[] = []; | ||
|
||
const loadSnapshotPolicies = () => supertest.get(`${API_BASE_PATH}/snapshot_policies`); | ||
|
||
const createSnapshotPolicy = (policyName: string, repositoryName?: string) => { | ||
return es.slm | ||
.putLifecycle({ | ||
policy_id: policyName, | ||
config: { | ||
indices: 'test_index', | ||
}, | ||
name: policyName, | ||
repository: repositoryName ?? SNAPSHOT_REPOSITORY_NAME, | ||
schedule: '0 30 1 * * ?', | ||
}) | ||
.then(() => policiesCreated.push(policyName)); | ||
}; | ||
|
||
const deletePolicy = (policyName: string) => es.slm.deleteLifecycle({ policy_id: policyName }); | ||
|
||
const cleanupPolicies = () => | ||
Promise.all(policiesCreated.map(deletePolicy)) | ||
.then(() => { | ||
policiesCreated = []; | ||
}) | ||
.catch((err) => { | ||
// eslint-disable-next-line no-console | ||
console.error(`[Cleanup error] Error deleting ES resources: ${err.message}`); | ||
}); | ||
|
||
return { | ||
loadSnapshotPolicies, | ||
createSnapshotPolicy, | ||
cleanupPolicies, | ||
}; | ||
}; |
45 changes: 45 additions & 0 deletions
45
x-pack/test/api_integration/apis/management/index_lifecycle_management/snapshot_policies.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { registerSnapshotPoliciesHelpers } from './snapshot_policies.helpers'; | ||
import { registerSnapshotRepositoriesHelpers } from './snapshot_repositories.helpers'; | ||
import { SNAPSHOT_REPOSITORY_NAME } from './constants'; | ||
|
||
const snapshotPolicyName = 'test_snapshot_policy'; | ||
export default function ({ getService }: FtrProviderContext) { | ||
const deployment = getService('deployment'); | ||
|
||
const { loadSnapshotPolicies, createSnapshotPolicy, cleanupPolicies } = | ||
registerSnapshotPoliciesHelpers(getService); | ||
|
||
const { createSnapshotRepository, cleanupRepositories } = | ||
registerSnapshotRepositoriesHelpers(getService); | ||
|
||
describe('snapshot policies', () => { | ||
before(async () => Promise.all([cleanupPolicies(), cleanupRepositories()])); | ||
after(async () => Promise.all([cleanupPolicies(), cleanupRepositories()])); | ||
|
||
it('returns empty array if no policies', async () => { | ||
const { body } = await loadSnapshotPolicies().expect(200); | ||
expect(body).to.eql([]); | ||
}); | ||
|
||
it('returns policies', async () => { | ||
const isCloud = await deployment.isCloud(); | ||
if (!isCloud) { | ||
await createSnapshotRepository(SNAPSHOT_REPOSITORY_NAME); | ||
} | ||
await createSnapshotPolicy(snapshotPolicyName); | ||
const { body } = await loadSnapshotPolicies().expect(200); | ||
|
||
expect(body).to.have.length(1); | ||
expect(body[0]).to.eql(snapshotPolicyName); | ||
}); | ||
}); | ||
} |
55 changes: 55 additions & 0 deletions
55
...i_integration/apis/management/index_lifecycle_management/snapshot_repositories.helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { API_BASE_PATH } from './constants'; | ||
|
||
export const registerSnapshotRepositoriesHelpers = ( | ||
getService: FtrProviderContext['getService'] | ||
) => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
let repositoriesCreated: string[] = []; | ||
|
||
const loadSnapshotRepositories = () => supertest.get(`${API_BASE_PATH}/snapshot_repositories`); | ||
|
||
const createSnapshotRepository = (repositoryName: string) => { | ||
return es.snapshot | ||
.createRepository({ | ||
name: repositoryName, | ||
body: { | ||
type: 'fs', | ||
settings: { | ||
location: '/tmp/repo', | ||
}, | ||
}, | ||
verify: false, | ||
}) | ||
.then(() => repositoriesCreated.push(repositoryName)); | ||
}; | ||
|
||
const deleteRepository = (repositoryName: string) => { | ||
return es.snapshot.deleteRepository({ name: repositoryName }); | ||
}; | ||
|
||
const cleanupRepositories = () => | ||
Promise.all(repositoriesCreated.map(deleteRepository)) | ||
.then(() => { | ||
repositoriesCreated = []; | ||
}) | ||
.catch((err) => { | ||
// eslint-disable-next-line no-console | ||
console.error(`[Cleanup error] Error deleting ES resources: ${err.message}`); | ||
}); | ||
|
||
return { | ||
loadSnapshotRepositories, | ||
createSnapshotRepository, | ||
cleanupRepositories, | ||
}; | ||
}; |
63 changes: 63 additions & 0 deletions
63
.../test/api_integration/apis/management/index_lifecycle_management/snapshot_repositories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { registerSnapshotRepositoriesHelpers } from './snapshot_repositories.helpers'; | ||
import { CLOUD_REPOSITORY_NAME } from './constants'; | ||
|
||
const repositoryName = 'test_repository'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const deployment = getService('deployment'); | ||
let isCloud: boolean; | ||
|
||
const { loadSnapshotRepositories, createSnapshotRepository, cleanupRepositories } = | ||
registerSnapshotRepositoriesHelpers(getService); | ||
|
||
describe('snapshot repositories', () => { | ||
before(async () => { | ||
isCloud = await deployment.isCloud(); | ||
await Promise.all([cleanupRepositories()]); | ||
}); | ||
after(async () => Promise.all([cleanupRepositories()])); | ||
|
||
it('returns empty array if no repositories ', async () => { | ||
const { | ||
body: { repositories }, | ||
} = await loadSnapshotRepositories().expect(200); | ||
if (!isCloud) { | ||
expect(repositories).to.eql([]); | ||
} | ||
}); | ||
|
||
it('returns cloud default repository if on Cloud', async () => { | ||
const { | ||
body: { repositories }, | ||
} = await loadSnapshotRepositories().expect(200); | ||
if (isCloud) { | ||
expect(repositories).to.have.length(1); | ||
expect(repositories).to.eql([CLOUD_REPOSITORY_NAME]); | ||
} | ||
}); | ||
|
||
it('returns repositories', async () => { | ||
await createSnapshotRepository(repositoryName); | ||
const { | ||
body: { repositories }, | ||
} = await loadSnapshotRepositories().expect(200); | ||
|
||
if (isCloud) { | ||
expect(repositories).to.have.length(2); | ||
expect(repositories[0]).to.contain(repositoryName); | ||
} else { | ||
expect(repositories).to.have.length(1); | ||
expect(repositories[0]).to.eql(repositoryName); | ||
} | ||
}); | ||
}); | ||
} |