From 49fc86e4b18c62e33090459ebcfce6a40bec17f0 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 2 Apr 2019 15:24:25 +0200 Subject: [PATCH] chore(xen-api): rewrite inject-event test CLI --- packages/xen-api/src/inject-events.js | 48 ++++++++++++++------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/packages/xen-api/src/inject-events.js b/packages/xen-api/src/inject-events.js index 7f09e18e1..1fc4a5d5a 100755 --- a/packages/xen-api/src/inject-events.js +++ b/packages/xen-api/src/inject-events.js @@ -4,31 +4,33 @@ import { pDelay } from 'promise-toolbox' import { createClient } from './' -const xapi = (() => { - const [, , url, user, password] = process.argv - - return createClient({ - auth: { user, password }, +async function main([url]) { + const xapi = createClient({ + allowUnauthorized: true, url, watchEvents: false, }) -})() + await xapi.connect() -xapi - .connect() - - // 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() + let loop = true + process.on('SIGINT', () => { + loop = false }) + + 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)