Update integration test runner (#1085)
* Improved user and roles handling * Avoid deleting internal indices * Updated skip version handling * Fix leftover * Improved indices and aliases cleanup * Clean also internal indices * Restore previous index/alias cleanup * Ignore 404
This commit is contained in:
committed by
GitHub
parent
0c4875aa6d
commit
b2c85f7797
@ -4,49 +4,6 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
const esDefaultRoles = [
|
||||
'apm_system',
|
||||
'apm_user',
|
||||
'beats_admin',
|
||||
'beats_system',
|
||||
'code_admin',
|
||||
'code_user',
|
||||
'data_frame_transforms_admin',
|
||||
'data_frame_transforms_user',
|
||||
'enrich_user',
|
||||
'ingest_admin',
|
||||
'kibana_admin',
|
||||
'kibana_dashboard_only_user',
|
||||
'kibana_system',
|
||||
'kibana_user',
|
||||
'logstash_admin',
|
||||
'logstash_system',
|
||||
'machine_learning_admin',
|
||||
'machine_learning_user',
|
||||
'monitoring_user',
|
||||
'remote_monitoring_agent',
|
||||
'remote_monitoring_collector',
|
||||
'reporting_user',
|
||||
'rollup_admin',
|
||||
'rollup_user',
|
||||
'snapshot_user',
|
||||
'superuser',
|
||||
'transform_admin',
|
||||
'transform_user',
|
||||
'transport_client',
|
||||
'watcher_admin',
|
||||
'watcher_user'
|
||||
]
|
||||
|
||||
const esDefaultUsers = [
|
||||
'apm_system',
|
||||
'beats_system',
|
||||
'elastic',
|
||||
'logstash_system',
|
||||
'kibana',
|
||||
'remote_monitoring_user'
|
||||
]
|
||||
|
||||
function runInParallel (client, operation, options, clientOptions) {
|
||||
if (options.length === 0) return Promise.resolve()
|
||||
const operations = options.map(opts => {
|
||||
@ -77,4 +34,4 @@ function to (promise) {
|
||||
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
module.exports = { runInParallel, esDefaultRoles, esDefaultUsers, delve, to, sleep }
|
||||
module.exports = { runInParallel, delve, to, sleep }
|
||||
|
||||
@ -38,23 +38,21 @@ function build (opts = {}) {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async function cleanup () {
|
||||
// // tap.comment('Cleanup')
|
||||
|
||||
response = null
|
||||
stash.clear()
|
||||
|
||||
try {
|
||||
await client.indices.delete({ index: '_all' }, { ignore: 404 })
|
||||
} catch (err) {
|
||||
assert.ifError(err, 'should not error: indices.delete')
|
||||
}
|
||||
|
||||
try {
|
||||
await client.indices.deleteAlias({ index: '_all', name: '_all' }, { ignore: 404 })
|
||||
} catch (err) {
|
||||
assert.ifError(err, 'should not error: indices.deleteAlias')
|
||||
}
|
||||
|
||||
try {
|
||||
await client.indices.delete({ index: '_all' }, { ignore: 404 })
|
||||
} catch (err) {
|
||||
assert.ifError(err, 'should not error: indices.delete')
|
||||
}
|
||||
|
||||
try {
|
||||
const { body: templates } = await client.indices.getTemplate()
|
||||
await helper.runInParallel(
|
||||
@ -91,7 +89,7 @@ function build (opts = {}) {
|
||||
|
||||
try {
|
||||
const { body } = await client.security.getRole()
|
||||
const roles = Object.keys(body).filter(n => helper.esDefaultRoles.indexOf(n) === -1)
|
||||
const roles = Object.keys(body).filter(n => !body[n].metadata._reserved)
|
||||
await helper.runInParallel(
|
||||
client, 'security.deleteRole',
|
||||
roles.map(r => ({ name: r }))
|
||||
@ -102,7 +100,7 @@ function build (opts = {}) {
|
||||
|
||||
try {
|
||||
const { body } = await client.security.getUser()
|
||||
const users = Object.keys(body).filter(n => helper.esDefaultUsers.indexOf(n) === -1)
|
||||
const users = Object.keys(body).filter(n => !body[n].metadata._reserved)
|
||||
await helper.runInParallel(
|
||||
client, 'security.deleteUser',
|
||||
users.map(r => ({ username: r }))
|
||||
@ -836,19 +834,22 @@ function shouldSkip (esVersion, action) {
|
||||
// skip based on the version
|
||||
if (action.version) {
|
||||
if (action.version.trim() === 'all') return true
|
||||
const [min, max] = action.version.split('-').map(v => v.trim())
|
||||
// if both `min` and `max` are specified
|
||||
if (min && max) {
|
||||
shouldSkip = semver.satisfies(esVersion, action.version)
|
||||
// if only `min` is specified
|
||||
} else if (min) {
|
||||
shouldSkip = semver.gte(esVersion, min)
|
||||
// if only `max` is specified
|
||||
} else if (max) {
|
||||
shouldSkip = semver.lte(esVersion, max)
|
||||
// something went wrong!
|
||||
} else {
|
||||
throw new Error(`skip: Bad version range: ${action.version}`)
|
||||
const versions = action.version.split(',').filter(Boolean)
|
||||
for (const version of versions) {
|
||||
const [min, max] = version.split('-').map(v => v.trim())
|
||||
// if both `min` and `max` are specified
|
||||
if (min && max) {
|
||||
shouldSkip = semver.satisfies(esVersion, action.version)
|
||||
// if only `min` is specified
|
||||
} else if (min) {
|
||||
shouldSkip = semver.gte(esVersion, min)
|
||||
// if only `max` is specified
|
||||
} else if (max) {
|
||||
shouldSkip = semver.lte(esVersion, max)
|
||||
// something went wrong!
|
||||
} else {
|
||||
throw new Error(`skip: Bad version range: ${action.version}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user