Refactor ES-related environment variables (#33036)

* [ci/es] base default es version on pkg.branch value

* [ci/env] initialize $TEST_ES_FROM in checkout_sibling_es.sh

* [UA] remove TEST_ES_SNAPSHOT_VERSION override

* [ci/es] call checkout_sibling_es.sh from one location

* [ci] remove unused `--from` param

* [ci/env] always default to snapshots, switch to source when necessary

* [kbn/test] default esFrom to $TEST_ES_FROM

* [ci/setup] fix define order

* [ci/grunt] don't pass --esFrom let env pass through

* [ci/env] use branch, not version

* [ci] use same indent style as following lines

* [kbn/test] apply default values when processing args

* [kbn/test] simplify defaults, read default on each process
This commit is contained in:
Spencer 2019-03-13 11:51:06 -07:00 committed by GitHub
parent 0b7715bc76
commit 06195e9d8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 154 additions and 51 deletions

View file

@ -7,6 +7,7 @@ cd "$(dirname "$0")/.."
source src/dev/ci_setup/extract_bootstrap_cache.sh
source src/dev/ci_setup/setup.sh
source src/dev/ci_setup/checkout_sibling_es.sh
case "$JOB" in
kibana-intake)

View file

@ -11,7 +11,7 @@ Usage:
Options:
--help Display this menu and exit.
--config <file> Pass in a config. Can pass in multiple configs.
--esFrom <snapshot|source> Build Elasticsearch from source or run from snapshot. Default: snapshot
--esFrom <snapshot|source> Build Elasticsearch from source or run from snapshot. Default: $TEST_ES_FROM or snapshot
--kibana-install-dir <dir> Run Kibana from existing install directory instead of from source.
--bail Stop the test run at the first failure.
--grep <pattern> Pattern to select which tests to run.
@ -32,6 +32,7 @@ Object {
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"suiteTags": Object {
"exclude": Array [],
@ -49,6 +50,7 @@ Object {
],
"createLogger": [Function],
"debug": true,
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"suiteTags": Object {
"exclude": Array [],
@ -65,6 +67,7 @@ Object {
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"suiteTags": Object {
"exclude": Array [],
@ -83,6 +86,7 @@ Object {
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": Object {
"server.foo": "bar",
},
@ -100,6 +104,7 @@ Object {
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"quiet": true,
"suiteTags": Object {
@ -116,6 +121,7 @@ Object {
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"silent": true,
"suiteTags": Object {
@ -125,6 +131,22 @@ Object {
}
`;
exports[`process options for run tests CLI accepts source value for $TEST_ES_FROM 1`] = `
Object {
"assertNoneExcluded": false,
"configs": Array [
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "source",
"extraKbnOpts": undefined,
"suiteTags": Object {
"exclude": Array [],
"include": Array [],
},
}
`;
exports[`process options for run tests CLI accepts source value for esFrom 1`] = `
Object {
"assertNoneExcluded": false,
@ -148,6 +170,7 @@ Object {
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"installDir": "foo",
"suiteTags": Object {
@ -164,6 +187,7 @@ Object {
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"grep": "management",
"suiteTags": Object {
@ -180,6 +204,7 @@ Object {
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"suiteTags": Object {
"exclude": Array [],
@ -188,3 +213,19 @@ Object {
"verbose": true,
}
`;
exports[`process options for run tests CLI prioritizes source flag over $TEST_ES_FROM 1`] = `
Object {
"assertNoneExcluded": false,
"configs": Array [
<absolute path>/foo,
],
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
"suiteTags": Object {
"exclude": Array [],
"include": Array [],
},
}
`;

View file

@ -11,7 +11,7 @@ Usage:
Options:
--help Display this menu and exit.
--config <file> Pass in a config. Can pass in multiple configs.
--esFrom <snapshot|source> Build Elasticsearch from source or run from snapshot. Default: snapshot
--esFrom <snapshot|source> Build Elasticsearch from source or run from snapshot. Default: $TEST_ES_FROM or snapshot
--kibana-install-dir <dir> Run Kibana from existing install directory instead of from source.
--bail Stop the test run at the first failure.
--grep <pattern> Pattern to select which tests to run.

View file

@ -32,7 +32,7 @@ const options = {
arg: '<snapshot|source>',
choices: ['snapshot', 'source'],
desc: 'Build Elasticsearch from source or run from snapshot.',
default: 'snapshot',
defaultHelp: 'Default: $TEST_ES_FROM or snapshot',
},
'kibana-install-dir': {
arg: '<dir>',
@ -71,7 +71,7 @@ export function displayHelp() {
return {
...option,
usage: `${name} ${option.arg || ''}`,
default: option.default ? `Default: ${option.default}` : '',
default: option.defaultHelp || '',
};
})
.map(option => {
@ -106,6 +106,10 @@ export function processOptions(userOptions, defaultConfigPaths) {
}
}
if (!userOptions.esFrom) {
userOptions.esFrom = process.env.TEST_ES_FROM || 'snapshot';
}
if (userOptions['kibana-install-dir']) {
userOptions.installDir = userOptions['kibana-install-dir'];
delete userOptions['kibana-install-dir'];

View file

@ -22,6 +22,14 @@ import { createAbsolutePathSerializer } from '@kbn/dev-utils';
expect.addSnapshotSerializer(createAbsolutePathSerializer(process.cwd()));
const INITIAL_TEST_ES_FROM = process.env.TEST_ES_FROM;
beforeEach(() => {
process.env.TEST_ES_FROM = 'snapshot';
});
afterEach(() => {
process.env.TEST_ES_FROM = INITIAL_TEST_ES_FROM;
});
describe('display help for run tests CLI', () => {
it('displays as expected', () => {
expect(displayHelp()).toMatchSnapshot();
@ -73,6 +81,18 @@ describe('process options for run tests CLI', () => {
expect(options).toMatchSnapshot();
});
it('accepts source value for $TEST_ES_FROM', () => {
process.env.TEST_ES_FROM = 'source';
const options = processOptions({}, ['foo']);
expect(options).toMatchSnapshot();
});
it('prioritizes source flag over $TEST_ES_FROM', () => {
process.env.TEST_ES_FROM = 'source';
const options = processOptions({ esFrom: 'snapshot' }, ['foo']);
expect(options).toMatchSnapshot();
});
it('rejects non-enum value for esFrom', () => {
expect(() => {
processOptions({ esFrom: 'butter' }, ['foo']);

View file

@ -30,7 +30,7 @@ jest.mock('../../tasks', () => ({
describe('run tests CLI', () => {
describe('options', () => {
const originalObjects = {};
const originalObjects = { process, console };
const exitMock = jest.fn();
const logMock = jest.fn(); // mock logging so we don't send output to the test results
const argvMock = ['foo', 'foo'];
@ -40,11 +40,13 @@ describe('run tests CLI', () => {
argv: argvMock,
stdout: new Writable(),
cwd: jest.fn(),
env: {
...originalObjects.process.env,
TEST_ES_FROM: 'snapshot',
},
};
beforeAll(() => {
originalObjects.process = process;
originalObjects.console = console;
global.process = processMock;
global.console = { log: logMock };
});
@ -56,6 +58,10 @@ describe('run tests CLI', () => {
beforeEach(() => {
global.process.argv = [...argvMock];
global.process.env = {
...originalObjects.process.env,
TEST_ES_FROM: 'snapshot',
};
jest.resetAllMocks();
});

View file

@ -11,7 +11,7 @@ Usage:
Options:
--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
--esFrom <snapshot|source|path> Build Elasticsearch from source, snapshot or path to existing install dir. Default: $TEST_ES_FROM or snapshot
--kibana-install-dir <dir> Run Kibana from existing install directory instead of from source.
--verbose Log everything.
--debug Run in debug mode.
@ -72,6 +72,15 @@ Object {
}
`;
exports[`process options for start servers CLI accepts source value for $TEST_ES_FROM 1`] = `
Object {
"config": <absolute path>/foo,
"createLogger": [Function],
"esFrom": "source",
"extraKbnOpts": undefined,
}
`;
exports[`process options for start servers CLI accepts source value for esFrom 1`] = `
Object {
"config": <absolute path>/foo,
@ -100,3 +109,12 @@ Object {
"verbose": true,
}
`;
exports[`process options for start servers CLI prioritizes source flag over $TEST_ES_FROM 1`] = `
Object {
"config": <absolute path>/foo,
"createLogger": [Function],
"esFrom": "snapshot",
"extraKbnOpts": undefined,
}
`;

View file

@ -31,7 +31,7 @@ const options = {
esFrom: {
arg: '<snapshot|source|path>',
desc: 'Build Elasticsearch from source, snapshot or path to existing install dir.',
default: 'snapshot',
defaultHelp: 'Default: $TEST_ES_FROM or snapshot',
},
'kibana-install-dir': {
arg: '<dir>',
@ -51,7 +51,7 @@ export function displayHelp() {
return {
...option,
usage: `${name} ${option.arg || ''}`,
default: option.default ? `Default: ${option.default}` : '',
default: option.defaultHelp || '',
};
})
.map(option => {
@ -82,7 +82,7 @@ export function processOptions(userOptions, defaultConfigPath) {
}
if (!userOptions.esFrom) {
userOptions.esFrom = 'snapshot';
userOptions.esFrom = process.env.TEST_ES_FROM || 'snapshot';
}
if (userOptions['kibana-install-dir']) {

View file

@ -22,6 +22,14 @@ import { createAbsolutePathSerializer } from '@kbn/dev-utils';
expect.addSnapshotSerializer(createAbsolutePathSerializer(process.cwd()));
const INITIAL_TEST_ES_FROM = process.env.TEST_ES_FROM;
beforeEach(() => {
process.env.TEST_ES_FROM = 'snapshot';
});
afterEach(() => {
process.env.TEST_ES_FROM = INITIAL_TEST_ES_FROM;
});
describe('display help for start servers CLI', () => {
it('displays as expected', () => {
expect(displayHelp()).toMatchSnapshot();
@ -68,6 +76,18 @@ describe('process options for start servers CLI', () => {
expect(options).toMatchSnapshot();
});
it('accepts source value for $TEST_ES_FROM', () => {
process.env.TEST_ES_FROM = 'source';
const options = processOptions({}, 'foo');
expect(options).toMatchSnapshot();
});
it('prioritizes source flag over $TEST_ES_FROM', () => {
process.env.TEST_ES_FROM = 'source';
const options = processOptions({ esFrom: 'snapshot' }, 'foo');
expect(options).toMatchSnapshot();
});
it('accepts debug option', () => {
const options = processOptions({ debug: true }, 'foo');
expect(options).toMatchSnapshot();

View file

@ -30,7 +30,7 @@ jest.mock('../../tasks', () => ({
describe('start servers CLI', () => {
describe('options', () => {
const originalObjects = {};
const originalObjects = { process, console };
const exitMock = jest.fn();
const logMock = jest.fn(); // mock logging so we don't send output to the test results
const argvMock = ['foo', 'foo'];
@ -40,11 +40,13 @@ describe('start servers CLI', () => {
argv: argvMock,
stdout: new Writable(),
cwd: jest.fn(),
env: {
...originalObjects.process.env,
TEST_ES_FROM: 'snapshot',
},
};
beforeAll(() => {
originalObjects.process = process;
originalObjects.console = console;
global.process = processMock;
global.console = { log: logMock };
});
@ -56,6 +58,10 @@ describe('start servers CLI', () => {
beforeEach(() => {
global.process.argv = [...argvMock];
global.process.env = {
...originalObjects.process.env,
TEST_ES_FROM: 'snapshot',
};
jest.resetAllMocks();
});

View file

@ -48,12 +48,12 @@ function checkout_sibling {
return 0
fi
cloneBranch="${PR_TARGET_BRANCH:-master}"
cloneBranch="${PR_TARGET_BRANCH:-$KIBANA_PKG_BRANCH}"
if clone_target_is_valid ; then
return 0
fi
cloneBranch="master"
cloneBranch="$KIBANA_PKG_BRANCH"
if clone_target_is_valid; then
return 0
fi
@ -64,13 +64,15 @@ function checkout_sibling {
function checkout_clone_target {
pick_clone_target
if [[ $cloneBranch = "master" && $cloneAuthor = "elastic" ]]; then
export TEST_ES_FROM=snapshot
if [[ "$cloneAuthor/$cloneBranch" != "elastic/$KIBANA_PKG_BRANCH" ]]; then
echo " -> Setting TEST_ES_FROM=source so that ES in tests will be built from $cloneAuthor/$cloneBranch"
export TEST_ES_FROM=source
fi
echo " -> checking out '${cloneBranch}' branch from ${cloneAuthor}/${project}..."
git clone -b "$cloneBranch" "git@github.com:${cloneAuthor}/${project}.git" "$targetDir" --depth=1
echo " -> checked out ${project} revision: $(git -C ${targetDir} rev-parse HEAD)"
echo " -> checked out ${project} revision: $(git -C "${targetDir}" rev-parse HEAD)"
echo
}
@ -86,6 +88,7 @@ function checkout_sibling {
}
checkout_sibling "elasticsearch" "${PARENT_DIR}/elasticsearch" "USE_EXISTING_ES"
export TEST_ES_FROM=${TEST_ES_FROM:-snapshot}
# Set the JAVA_HOME based on the Java property file in the ES repo
# This assumes the naming convention used on CI (ex: ~/.java/java10)

View file

@ -26,14 +26,21 @@ else
exit 1
fi
export KIBANA_DIR="$dir"
export XPACK_DIR="$KIBANA_DIR/x-pack"
export PARENT_DIR="$(cd "$KIBANA_DIR/.."; pwd)"
echo "-> KIBANA_DIR $KIBANA_DIR"
echo "-> XPACK_DIR $XPACK_DIR"
echo "-> PARENT_DIR $PARENT_DIR"
echo "-> TEST_ES_SNAPSHOT_VERSION $TEST_ES_SNAPSHOT_VERSION"
parentDir="$(cd "$KIBANA_DIR/.."; pwd)"
export PARENT_DIR="$parentDir"
kbnBranch="$(jq -r .branch "$KIBANA_DIR/package.json")"
export KIBANA_PKG_BRANCH="$kbnBranch"
echo " -- KIBANA_DIR='$KIBANA_DIR'"
echo " -- XPACK_DIR='$XPACK_DIR'"
echo " -- PARENT_DIR='$PARENT_DIR'"
echo " -- KIBANA_PKG_BRANCH='$KIBANA_PKG_BRANCH'"
echo " -- TEST_ES_SNAPSHOT_VERSION='$TEST_ES_SNAPSHOT_VERSION'"
###
### download node
@ -77,7 +84,6 @@ else
else
curl --silent "$nodeUrl" | tar -xz -C "$nodeDir" --strip-components=1
fi
fi
###

View file

@ -62,7 +62,6 @@ module.exports = function (grunt) {
'--server.port=5610',
];
const esFrom = process.env.TEST_ES_FROM || 'source';
return {
// used by the test and jenkins:unit tasks
// runs the eslint script to check for linting errors
@ -192,7 +191,6 @@ module.exports = function (grunt) {
args: [
'scripts/functional_tests',
'--config', 'test/api_integration/config.js',
'--esFrom', esFrom,
'--bail',
'--debug',
],
@ -204,7 +202,6 @@ module.exports = function (grunt) {
'scripts/functional_tests',
'--config', 'test/server_integration/http/ssl/config.js',
'--config', 'test/server_integration/http/ssl_redirect/config.js',
'--esFrom', esFrom,
'--bail',
'--debug',
'--kibana-install-dir', KIBANA_INSTALL_DIR,
@ -216,7 +213,6 @@ module.exports = function (grunt) {
args: [
'scripts/functional_tests',
'--config', 'test/plugin_functional/config.js',
'--esFrom', esFrom,
'--bail',
'--debug',
'--kibana-install-dir', KIBANA_INSTALL_DIR,
@ -228,14 +224,12 @@ module.exports = function (grunt) {
args: [
'scripts/functional_tests',
'--config', 'test/functional/config.js',
'--esFrom', esFrom,
'--bail',
'--debug',
],
},
...getFunctionalTestGroupRunConfigs({
esFrom,
kibanaInstallDir: KIBANA_INSTALL_DIR
})
};

View file

@ -30,7 +30,7 @@ const TEST_TAGS = safeLoad(JOBS_YAML)
.filter(id => id.startsWith('kibana-ciGroup'))
.map(id => id.replace(/^kibana-/, ''));
export function getFunctionalTestGroupRunConfigs({ esFrom, kibanaInstallDir } = {}) {
export function getFunctionalTestGroupRunConfigs({ kibanaInstallDir } = {}) {
return {
// include a run task for each test group
...TEST_TAGS.reduce((acc, tag) => ({
@ -41,7 +41,6 @@ export function getFunctionalTestGroupRunConfigs({ esFrom, kibanaInstallDir } =
'scripts/functional_tests',
'--include-tag', tag,
'--config', 'test/functional/config.js',
'--esFrom', esFrom,
'--bail',
'--debug',
'--kibana-install-dir', kibanaInstallDir,

View file

@ -13,17 +13,14 @@ function report {
trap report EXIT
source src/dev/ci_setup/checkout_sibling_es.sh
"$(FORCE_COLOR=0 yarn bin)/grunt" functionalTests:ensureAllTestsInCiGroup;
node scripts/build --debug --oss;
export TEST_BROWSER_HEADLESS=1
export TEST_ES_FROM=${TEST_ES_FROM:-source}
"$(FORCE_COLOR=0 yarn bin)/grunt" "run:functionalTests_ciGroup${CI_GROUP}" --from=source;
"$(FORCE_COLOR=0 yarn bin)/grunt" "run:functionalTests_ciGroup${CI_GROUP}";
if [ "$CI_GROUP" == "1" ]; then
"$(FORCE_COLOR=0 yarn bin)/grunt" run:pluginFunctionalTestsRelease --from=source;
"$(FORCE_COLOR=0 yarn bin)/grunt" run:pluginFunctionalTestsRelease;
fi

View file

@ -12,9 +12,6 @@ function report {
trap report EXIT
source src/dev/ci_setup/checkout_sibling_es.sh
export TEST_BROWSER_HEADLESS=1
export TEST_ES_FROM=${TEST_ES_FROM:-source}
"$(FORCE_COLOR=0 yarn bin)/grunt" jenkins:unit --from=source --dev;
"$(FORCE_COLOR=0 yarn bin)/grunt" jenkins:unit --dev;

View file

@ -13,8 +13,6 @@ function report {
trap report EXIT
source src/dev/ci_setup/checkout_sibling_es.sh
export TEST_BROWSER_HEADLESS=1
echo " -> Running mocha tests"
@ -23,7 +21,6 @@ yarn test
echo ""
echo ""
echo " -> Running jest tests"
cd "$XPACK_DIR"
node scripts/jest --ci --no-cache --verbose

View file

@ -13,8 +13,6 @@ function report {
trap report EXIT
source src/dev/ci_setup/checkout_sibling_es.sh
export TEST_BROWSER_HEADLESS=1
echo " -> Ensuring all functional tests are in a ciGroup"
@ -36,7 +34,6 @@ installDir="$PARENT_DIR/install/kibana"
mkdir -p "$installDir"
tar -xzf "$linuxBuild" -C "$installDir" --strip=1
export TEST_ES_FROM=${TEST_ES_FROM:-source}
echo " -> Running functional and api tests"
cd "$XPACK_DIR"
node scripts/functional_tests --debug --bail --kibana-install-dir "$installDir" --include-tag "ciGroup$CI_GROUP"

View file

@ -9,9 +9,6 @@ import {
EsProvider,
} from './services';
// Temporary until https://github.com/elastic/kibana/pull/29184 is merged
delete process.env.TEST_ES_SNAPSHOT_VERSION;
export default async function ({ readConfigFile }) {
// Read the Kibana API integration tests config file so that we can utilize its services.