chore(xen-api): rewrite inject-event test CLI
This commit is contained in:
parent
924aef84f1
commit
49fc86e4b1
@ -4,31 +4,33 @@ import { pDelay } from 'promise-toolbox'
|
|||||||
|
|
||||||
import { createClient } from './'
|
import { createClient } from './'
|
||||||
|
|
||||||
const xapi = (() => {
|
async function main([url]) {
|
||||||
const [, , url, user, password] = process.argv
|
const xapi = createClient({
|
||||||
|
allowUnauthorized: true,
|
||||||
return createClient({
|
|
||||||
auth: { user, password },
|
|
||||||
url,
|
url,
|
||||||
watchEvents: false,
|
watchEvents: false,
|
||||||
})
|
})
|
||||||
})()
|
await xapi.connect()
|
||||||
|
|
||||||
xapi
|
let loop = true
|
||||||
.connect()
|
process.on('SIGINT', () => {
|
||||||
|
loop = false
|
||||||
// Get the pool record's ref.
|
|
||||||
.then(() => xapi.call('pool.get_all'))
|
|
||||||
|
|
||||||
// Injects lots of events.
|
|
||||||
.then(([poolRef]) => {
|
|
||||||
const loop = () =>
|
|
||||||
pDelay
|
|
||||||
.call(
|
|
||||||
xapi.call('event.inject', 'pool', poolRef),
|
|
||||||
10 // A small delay is required to avoid overloading the Xen API.
|
|
||||||
)
|
|
||||||
.then(loop)
|
|
||||||
|
|
||||||
return loop()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { pool } = xapi
|
||||||
|
// eslint-disable-next-line no-unmodified-loop-condition
|
||||||
|
while (loop) {
|
||||||
|
await pool.update_other_config(
|
||||||
|
'xo:injectEvents',
|
||||||
|
Math.random()
|
||||||
|
.toString(36)
|
||||||
|
.slice(2)
|
||||||
|
)
|
||||||
|
await pDelay(1e2)
|
||||||
|
}
|
||||||
|
|
||||||
|
await pool.update_other_config('xo:injectEvents', null)
|
||||||
|
await xapi.disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
main(process.argv.slice(2)).catch(console.error)
|
||||||
|
Loading…
Reference in New Issue
Block a user