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'
|
'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) {
|
function runInParallel (client, operation, options, clientOptions) {
|
||||||
if (options.length === 0) return Promise.resolve()
|
if (options.length === 0) return Promise.resolve()
|
||||||
const operations = options.map(opts => {
|
const operations = options.map(opts => {
|
||||||
@ -77,4 +34,4 @@ function to (promise) {
|
|||||||
|
|
||||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
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}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
async function cleanup () {
|
async function cleanup () {
|
||||||
// // tap.comment('Cleanup')
|
|
||||||
|
|
||||||
response = null
|
response = null
|
||||||
stash.clear()
|
stash.clear()
|
||||||
|
|
||||||
try {
|
|
||||||
await client.indices.delete({ index: '_all' }, { ignore: 404 })
|
|
||||||
} catch (err) {
|
|
||||||
assert.ifError(err, 'should not error: indices.delete')
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.indices.deleteAlias({ index: '_all', name: '_all' }, { ignore: 404 })
|
await client.indices.deleteAlias({ index: '_all', name: '_all' }, { ignore: 404 })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert.ifError(err, 'should not error: indices.deleteAlias')
|
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 {
|
try {
|
||||||
const { body: templates } = await client.indices.getTemplate()
|
const { body: templates } = await client.indices.getTemplate()
|
||||||
await helper.runInParallel(
|
await helper.runInParallel(
|
||||||
@ -91,7 +89,7 @@ function build (opts = {}) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { body } = await client.security.getRole()
|
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(
|
await helper.runInParallel(
|
||||||
client, 'security.deleteRole',
|
client, 'security.deleteRole',
|
||||||
roles.map(r => ({ name: r }))
|
roles.map(r => ({ name: r }))
|
||||||
@ -102,7 +100,7 @@ function build (opts = {}) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { body } = await client.security.getUser()
|
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(
|
await helper.runInParallel(
|
||||||
client, 'security.deleteUser',
|
client, 'security.deleteUser',
|
||||||
users.map(r => ({ username: r }))
|
users.map(r => ({ username: r }))
|
||||||
@ -836,19 +834,22 @@ function shouldSkip (esVersion, action) {
|
|||||||
// skip based on the version
|
// skip based on the version
|
||||||
if (action.version) {
|
if (action.version) {
|
||||||
if (action.version.trim() === 'all') return true
|
if (action.version.trim() === 'all') return true
|
||||||
const [min, max] = action.version.split('-').map(v => v.trim())
|
const versions = action.version.split(',').filter(Boolean)
|
||||||
// if both `min` and `max` are specified
|
for (const version of versions) {
|
||||||
if (min && max) {
|
const [min, max] = version.split('-').map(v => v.trim())
|
||||||
shouldSkip = semver.satisfies(esVersion, action.version)
|
// if both `min` and `max` are specified
|
||||||
// if only `min` is specified
|
if (min && max) {
|
||||||
} else if (min) {
|
shouldSkip = semver.satisfies(esVersion, action.version)
|
||||||
shouldSkip = semver.gte(esVersion, min)
|
// if only `min` is specified
|
||||||
// if only `max` is specified
|
} else if (min) {
|
||||||
} else if (max) {
|
shouldSkip = semver.gte(esVersion, min)
|
||||||
shouldSkip = semver.lte(esVersion, max)
|
// if only `max` is specified
|
||||||
// something went wrong!
|
} else if (max) {
|
||||||
} else {
|
shouldSkip = semver.lte(esVersion, max)
|
||||||
throw new Error(`skip: Bad version range: ${action.version}`)
|
// something went wrong!
|
||||||
|
} else {
|
||||||
|
throw new Error(`skip: Bad version range: ${action.version}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user