Skip to content

Commit

Permalink
Add option to functional test server to run elasticsearch from instal… (
Browse files Browse the repository at this point in the history
#22608) (#23447)

* Add option to functional test server to run elasticsearch from install dir

* Fix variable

* Fix server CLI test

* Updates to include install path in esFrom command line option

* Fix snapshot

* Update args/cli tests

* Keep default snapshot in args/help
  • Loading branch information
liza-mae authored Sep 24, 2018
1 parent a5950b7 commit 0d66bcd
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 40 deletions.
16 changes: 12 additions & 4 deletions packages/kbn-test/src/es/es_test_cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { esTestConfig } from './es_test_config';
import { rmrfSync } from './rmrf_sync';
import { KIBANA_ROOT } from '../';
import elasticsearch from 'elasticsearch';
const path = require('path');

export function createEsTestCluster(options = {}) {
const {
Expand Down Expand Up @@ -61,10 +62,17 @@ export function createEsTestCluster(options = {}) {
}

async start(esArgs = []) {
const { installPath } =
esFrom === 'source'
? await cluster.installSource(config)
: await cluster.installSnapshot(config);
let installPath;

if (esFrom === 'source') {
installPath = (await cluster.installSource(config)).installPath;
} else if (esFrom === 'snapshot') {
installPath = (await cluster.installSnapshot(config)).installPath;
} else if (path.isAbsolute(esFrom)) {
installPath = esFrom;
} else {
throw new Error(`unknown option esFrom "${esFrom}"`);
}

await cluster.start(installPath, {
esArgs: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Usage:
node scripts/functional_tests_server [options] [-- --<other args>]
Options:
--help Display this menu and exit.
--config <file> Pass in a config
--esFrom <snapshot|source> Build Elasticsearch from source or run from snapshot. Default: snapshot
--kibana-install-dir <dir> Run Kibana from existing install directory instead of from source.
--verbose Log everything.
--debug Run in debug mode.
--quiet Only log errors.
--silent Log nothing."
--help Display this menu and exit.
--config <file> Pass in a config
--esFrom <snapshot|source|path> Build Elasticsearch from source, snapshot or path to existing install dir. Default: snapshot
--kibana-install-dir <dir> Run Kibana from existing install directory instead of from source.
--verbose Log everything.
--debug Run in debug mode.
--quiet Only log errors.
--silent Log nothing."
`;
exports[`process options for start servers CLI accepts debug option 1`] = `
Expand All @@ -26,6 +26,7 @@ Object {
],
"createLogger": [Function],
"debug": true,
"esFrom": "snapshot",
"extraKbnOpts": undefined,
}
`;
Expand All @@ -36,6 +37,7 @@ Object {
"foo",
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
}
`;
Expand All @@ -49,6 +51,7 @@ Object {
"foo",
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": Object {
"server.foo": "bar",
},
Expand All @@ -61,6 +64,7 @@ Object {
"foo",
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"quiet": true,
}
Expand All @@ -72,6 +76,7 @@ Object {
"foo",
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"silent": true,
}
Expand All @@ -94,6 +99,7 @@ Object {
"foo",
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"installDir": "foo",
}
Expand All @@ -105,6 +111,7 @@ Object {
"foo",
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"verbose": true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,4 @@ exports[`start servers CLI options rejects invalid options even if valid options
functional_tests_server: invalid option [grep]
...stack trace...
"
`;

exports[`start servers CLI options rejects non-enum value for esFrom 1`] = `
"
functional_tests_server: invalid argument [butter] to option [esFrom]
...stack trace...
"
`;
`;
11 changes: 7 additions & 4 deletions packages/kbn-test/src/functional_tests/cli/start_servers/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ const options = {
desc: 'Pass in a config',
},
esFrom: {
arg: '<snapshot|source>',
choices: ['snapshot', 'source'],
desc: 'Build Elasticsearch from source or run from snapshot.',
arg: '<snapshot|source|path>',
desc: 'Build Elasticsearch from source, snapshot or path to existing install dir.',
default: 'snapshot',
},
'kibana-install-dir': {
Expand All @@ -54,7 +53,7 @@ export function displayHelp() {
};
})
.map(option => {
return `--${option.usage.padEnd(28)} ${option.desc} ${option.default}`;
return `--${option.usage.padEnd(30)} ${option.desc} ${option.default}`;
})
.join(`\n `);

Expand All @@ -80,6 +79,10 @@ export function processOptions(userOptions, defaultConfigPath) {
throw new Error(`functional_tests_server: config is required`);
}

if (!userOptions.esFrom) {
userOptions.esFrom = 'snapshot';
}

if (userOptions['kibana-install-dir']) {
userOptions.installDir = userOptions['kibana-install-dir'];
delete userOptions['kibana-install-dir'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ describe('process options for start servers CLI', () => {
expect(options).toMatchSnapshot();
});

it('rejects non-enum value for esFrom', () => {
expect(() => {
processOptions({ esFrom: 'butter' }, ['foo']);
}).toThrow('functional_tests_server: invalid argument [butter] to option [esFrom]');
});

it('accepts debug option', () => {
const options = processOptions({ debug: true }, ['foo']);
expect(options).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,6 @@ describe('start servers CLI', () => {
expect(exitMock).not.toHaveBeenCalled();
});

it('rejects non-enum value for esFrom', async () => {
global.process.argv.push('--esFrom', 'butter');

await startServersCli('foo');

expect(exitMock).toHaveBeenCalledWith(1);
checkMockConsoleLogSnapshot(logMock);
});

it('accepts debug option', async () => {
global.process.argv.push('--debug');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { createEsTestCluster } from '../../es';
import { setupUsers, DEFAULT_SUPERUSER_PASS } from './auth';

export async function runElasticsearch({ config, options }) {
const { log, esFrom } = options;
const { log, esFrom, esInstallDir } = options;
const isOss = config.get('esTestCluster.license') === 'oss';

const cluster = createEsTestCluster({
Expand All @@ -34,6 +34,7 @@ export async function runElasticsearch({ config, options }) {
log,
basePath: resolve(KIBANA_ROOT, '.es'),
esFrom: esFrom || config.get('esTestCluster.from'),
esInstallDir,
});

const esArgs = config.get('esTestCluster.serverArgs');
Expand Down

0 comments on commit 0d66bcd

Please sign in to comment.