From d4947c26aea5fdbee2b8b0ed4c2e9d6f837f8a1f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 13 Apr 2017 12:00:10 -0400 Subject: [PATCH] Use jvm.options where needed in packaging tests We have some packaging tests where we use a custom jvm.options file. The flags we use here are barebones, just enough to exercise that using a custom jvm.options files actually works. Due to this, we are missing a Log4j flag that prevents Log4j from trying to use JMX. If Log4j tries to use JMX, it hits a security manager exception and tries to log this. This attempt to log happens before we've configured logging. Previously, Elasticsearch was lenient here so this was treated as harmless and the test could march on. Now, we fail startup if we detect an attempt to log before logging is configured so this prevents Elasticsearch from starting if we do not have jvm.options files in place that prevent these log messages from being written before logging is being configured. This commit adds jvm.options files in the places need to prevent this. --- .../src/test/resources/packaging/tests/20_tar_package.bats | 4 ++++ .../src/test/resources/packaging/tests/70_sysv_initd.bats | 4 ++++ .../packaging/tests/module_and_plugin_test_cases.bash | 2 +- qa/vagrant/src/test/resources/packaging/utils/utils.bash | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats b/qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats index dde2147ea45..2d502084a4a 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats +++ b/qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats @@ -116,6 +116,10 @@ setup() { chown -R elasticsearch:elasticsearch "$temp" echo "-Xms512m" >> "$temp/jvm.options" echo "-Xmx512m" >> "$temp/jvm.options" + # we have to disable Log4j from using JMX lest it will hit a security + # manager exception before we have configured logging; this will fail + # startup since we detect usages of logging before it is configured + echo "-Dlog4j2.disable.jmx=true" >> "$temp/jvm.options" export ES_JVM_OPTIONS="$temp/jvm.options" export ES_JAVA_OPTS="-XX:-UseCompressedOops" start_elasticsearch_service diff --git a/qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats b/qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats index 64f0e977c7d..70db8744456 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats +++ b/qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats @@ -147,6 +147,10 @@ setup() { chown -R elasticsearch:elasticsearch "$temp" echo "-Xms512m" >> "$temp/jvm.options" echo "-Xmx512m" >> "$temp/jvm.options" + # we have to disable Log4j from using JMX lest it will hit a security + # manager exception before we have configured logging; this will fail + # startup since we detect usages of logging before it is configured + echo "-Dlog4j2.disable.jmx=true" >> "$temp/jvm.options" cp $ESENVFILE "$temp/elasticsearch" echo "ES_JVM_OPTIONS=\"$temp/jvm.options\"" >> $ESENVFILE echo "ES_JAVA_OPTS=\"-XX:-UseCompressedOops\"" >> $ESENVFILE diff --git a/qa/vagrant/src/test/resources/packaging/tests/module_and_plugin_test_cases.bash b/qa/vagrant/src/test/resources/packaging/tests/module_and_plugin_test_cases.bash index 705daad6279..64797a33f57 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/module_and_plugin_test_cases.bash +++ b/qa/vagrant/src/test/resources/packaging/tests/module_and_plugin_test_cases.bash @@ -142,7 +142,7 @@ fi move_config CONF_DIR="$ESCONFIG" install_jvm_example - CONF_DIR="$ESCONFIG" start_elasticsearch_service + CONF_DIR="$ESCONFIG" ES_JVM_OPTIONS="$ESCONFIG/jvm.options" start_elasticsearch_service diff <(curl -s localhost:9200/_cat/configured_example | sed 's/ //g') <(echo "foo") stop_elasticsearch_service CONF_DIR="$ESCONFIG" remove_jvm_example diff --git a/qa/vagrant/src/test/resources/packaging/utils/utils.bash b/qa/vagrant/src/test/resources/packaging/utils/utils.bash index f8abe1b5266..0272dc8fafe 100644 --- a/qa/vagrant/src/test/resources/packaging/utils/utils.bash +++ b/qa/vagrant/src/test/resources/packaging/utils/utils.bash @@ -330,8 +330,10 @@ run_elasticsearch_service() { if [ ! -z "$CONF_DIR" ] ; then if is_dpkg ; then echo "CONF_DIR=$CONF_DIR" >> /etc/default/elasticsearch; + echo "ES_JVM_OPTIONS=$ES_JVM_OPTIONS" >> /etc/default/elasticsearch; elif is_rpm; then echo "CONF_DIR=$CONF_DIR" >> /etc/sysconfig/elasticsearch; + echo "ES_JVM_OPTIONS=$ES_JVM_OPTIONS" >> /etc/sysconfig/elasticsearch fi fi @@ -525,6 +527,7 @@ move_config() { mv "$oldConfig"/* "$ESCONFIG" chown -R elasticsearch:elasticsearch "$ESCONFIG" assert_file_exist "$ESCONFIG/elasticsearch.yml" + assert_file_exist "$ESCONFIG/jvm.options" assert_file_exist "$ESCONFIG/log4j2.properties" }