-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Snapshot Restore] Fix initial policy form state (#83928)
- Loading branch information
1 parent
fb48e90
commit 23dccb7
Showing
9 changed files
with
395 additions
and
25 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
12 changes: 12 additions & 0 deletions
12
x-pack/test/api_integration/apis/management/snapshot_restore/index.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,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: FtrProviderContext) { | ||
describe('Snapshot and Restore', () => { | ||
loadTestFile(require.resolve('./snapshot_restore')); | ||
}); | ||
} |
89 changes: 89 additions & 0 deletions
89
x-pack/test/api_integration/apis/management/snapshot_restore/lib/elasticsearch.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,89 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
interface SlmPolicy { | ||
name: string; | ||
snapshotName: string; | ||
schedule: string; | ||
repository: string; | ||
isManagedPolicy: boolean; | ||
config?: { | ||
indices?: string | string[]; | ||
ignoreUnavailable?: boolean; | ||
includeGlobalState?: boolean; | ||
partial?: boolean; | ||
metadata?: Record<string, string>; | ||
}; | ||
retention?: { | ||
expireAfterValue?: number | ''; | ||
expireAfterUnit?: string; | ||
maxCount?: number | ''; | ||
minCount?: number | ''; | ||
}; | ||
} | ||
|
||
/** | ||
* Helpers to create and delete SLM policies on the Elasticsearch instance | ||
* during our tests. | ||
* @param {ElasticsearchClient} es The Elasticsearch client instance | ||
*/ | ||
export const registerEsHelpers = (getService: FtrProviderContext['getService']) => { | ||
let policiesCreated: string[] = []; | ||
|
||
const es = getService('legacyEs'); | ||
|
||
const createRepository = (repoName: string) => { | ||
return es.snapshot.createRepository({ | ||
repository: repoName, | ||
body: { | ||
type: 'fs', | ||
settings: { | ||
location: '/tmp/', | ||
}, | ||
}, | ||
verify: false, | ||
}); | ||
}; | ||
|
||
const createPolicy = (policy: SlmPolicy, cachePolicy?: boolean) => { | ||
if (cachePolicy) { | ||
policiesCreated.push(policy.name); | ||
} | ||
|
||
return es.sr.updatePolicy({ | ||
name: policy.name, | ||
body: policy, | ||
}); | ||
}; | ||
|
||
const getPolicy = (policyName: string) => { | ||
return es.sr.policy({ | ||
name: policyName, | ||
human: true, | ||
}); | ||
}; | ||
|
||
const deletePolicy = (policyName: string) => es.sr.deletePolicy({ name: policyName }); | ||
|
||
const cleanupPolicies = () => | ||
Promise.all(policiesCreated.map(deletePolicy)) | ||
.then(() => { | ||
policiesCreated = []; | ||
}) | ||
.catch((err) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`[Cleanup error] Error deleting ES resources: ${err.message}`); | ||
}); | ||
|
||
return { | ||
createRepository, | ||
createPolicy, | ||
deletePolicy, | ||
cleanupPolicies, | ||
getPolicy, | ||
}; | ||
}; |
7 changes: 7 additions & 0 deletions
7
x-pack/test/api_integration/apis/management/snapshot_restore/lib/index.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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { registerEsHelpers } from './elasticsearch'; |
Oops, something went wrong.