This commit converts the sysv init tests from bats tests into the java packaging tests. Since it is the last oss specific test, the bats oss test task is also removed. relates #46005
This commit is contained in:
parent
42610c6d74
commit
5a72b23716
|
@ -114,7 +114,6 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, TaskProvider<?>> batsTests = new HashMap<>();
|
Map<String, TaskProvider<?>> batsTests = new HashMap<>();
|
||||||
batsTests.put("bats oss", configureBatsTest(project, "oss", distributionsDir, copyDistributionsTask));
|
|
||||||
configureBatsTest(project, "plugins", distributionsDir, copyDistributionsTask, copyPluginsTask).configure(
|
configureBatsTest(project, "plugins", distributionsDir, copyDistributionsTask, copyPluginsTask).configure(
|
||||||
t -> t.setPluginsDir(pluginsDir)
|
t -> t.setPluginsDir(pluginsDir)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,192 +0,0 @@
|
||||||
#!/usr/bin/env bats
|
|
||||||
|
|
||||||
# This file is used to test the elasticsearch init.d scripts.
|
|
||||||
|
|
||||||
# WARNING: This testing file must be executed as root and can
|
|
||||||
# dramatically change your system. It should only be executed
|
|
||||||
# in a throw-away VM like those made by the Vagrantfile at
|
|
||||||
# the root of the Elasticsearch source code. This should
|
|
||||||
# cause the script to fail if it is executed any other way:
|
|
||||||
[ -f /etc/is_vagrant_vm ] || {
|
|
||||||
>&2 echo "must be run on a vagrant VM"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# The test case can be executed with the Bash Automated
|
|
||||||
# Testing System tool available at https://github.com/sstephenson/bats
|
|
||||||
# Thanks to Sam Stephenson!
|
|
||||||
|
|
||||||
# Licensed to Elasticsearch under one or more contributor
|
|
||||||
# license agreements. See the NOTICE file distributed with
|
|
||||||
# this work for additional information regarding copyright
|
|
||||||
# ownership. Elasticsearch licenses this file to you under
|
|
||||||
# the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
# Load test utilities
|
|
||||||
load $BATS_UTILS/utils.bash
|
|
||||||
load $BATS_UTILS/packages.bash
|
|
||||||
load $BATS_UTILS/plugins.bash
|
|
||||||
|
|
||||||
# Cleans everything for the 1st execution
|
|
||||||
setup() {
|
|
||||||
skip_not_sysvinit
|
|
||||||
skip_not_dpkg_or_rpm
|
|
||||||
export_elasticsearch_paths
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] remove any leftover configuration to start elasticsearch on restart" {
|
|
||||||
# This configuration can be added with a command like:
|
|
||||||
# $ sudo update-rc.d elasticsearch defaults 95 10
|
|
||||||
# but we want to test that the RPM and deb _don't_ add it on its own.
|
|
||||||
# Note that it'd be incorrect to use:
|
|
||||||
# $ sudo update-rc.d elasticsearch disable
|
|
||||||
# here because that'd prevent elasticsearch from installing the symlinks
|
|
||||||
# that cause it to be started on restart.
|
|
||||||
sudo update-rc.d -f elasticsearch remove || true
|
|
||||||
sudo chkconfig elasticsearch off || true
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] install elasticsearch" {
|
|
||||||
clean_before_test
|
|
||||||
install_package
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] elasticsearch fails if startup script is not executable" {
|
|
||||||
local INIT="/etc/init.d/elasticsearch"
|
|
||||||
local DAEMON="$ESHOME/bin/elasticsearch"
|
|
||||||
|
|
||||||
sudo chmod -x "$DAEMON"
|
|
||||||
run "$INIT"
|
|
||||||
sudo chmod +x "$DAEMON"
|
|
||||||
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" == *"The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON"* ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] daemon isn't enabled on restart" {
|
|
||||||
# Rather than restart the VM which would be slow we check for the symlinks
|
|
||||||
# that init.d uses to restart the application on startup.
|
|
||||||
! find /etc/rc[0123456].d | grep elasticsearch
|
|
||||||
# Note that we don't use -iname above because that'd have to look like:
|
|
||||||
# [ $(find /etc/rc[0123456].d -iname "elasticsearch*" | wc -l) -eq 0 ]
|
|
||||||
# Which isn't really clearer than what we do use.
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] start" {
|
|
||||||
service elasticsearch start
|
|
||||||
wait_for_elasticsearch_status
|
|
||||||
assert_file_exist "/var/run/elasticsearch/elasticsearch.pid"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] status (running)" {
|
|
||||||
service elasticsearch status
|
|
||||||
}
|
|
||||||
|
|
||||||
##################################
|
|
||||||
# Check that Elasticsearch is working
|
|
||||||
##################################
|
|
||||||
@test "[INIT.D] test elasticsearch" {
|
|
||||||
run_elasticsearch_tests
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] restart" {
|
|
||||||
service elasticsearch restart
|
|
||||||
|
|
||||||
wait_for_elasticsearch_status
|
|
||||||
|
|
||||||
service elasticsearch status
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] stop (running)" {
|
|
||||||
service elasticsearch stop
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] status (stopped)" {
|
|
||||||
run service elasticsearch status
|
|
||||||
# precise returns 4, trusty 3
|
|
||||||
[ "$status" -eq 3 ] || [ "$status" -eq 4 ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] start Elasticsearch with custom JVM options" {
|
|
||||||
assert_file_exist $ESENVFILE
|
|
||||||
local temp=`mktemp -d`
|
|
||||||
cp "$ESCONFIG"/elasticsearch.yml "$temp"
|
|
||||||
cp "$ESCONFIG"/log4j2.properties "$temp"
|
|
||||||
touch "$temp/jvm.options"
|
|
||||||
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_PATH_CONF=\"$temp\"" >> $ESENVFILE
|
|
||||||
echo "ES_JAVA_OPTS=\"-XX:-UseCompressedOops\"" >> $ESENVFILE
|
|
||||||
service elasticsearch start
|
|
||||||
wait_for_elasticsearch_status
|
|
||||||
curl -s -XGET localhost:9200/_nodes | fgrep '"heap_init_in_bytes":536870912'
|
|
||||||
curl -s -XGET localhost:9200/_nodes | fgrep '"using_compressed_ordinary_object_pointers":"false"'
|
|
||||||
service elasticsearch stop
|
|
||||||
cp "$temp/elasticsearch" $ESENVFILE
|
|
||||||
}
|
|
||||||
|
|
||||||
# Simulates the behavior of a system restart:
|
|
||||||
# the PID directory is deleted by the operating system
|
|
||||||
# but it should not block ES from starting
|
|
||||||
# see https://github.com/elastic/elasticsearch/issues/11594
|
|
||||||
@test "[INIT.D] delete PID_DIR and restart" {
|
|
||||||
rm -rf /var/run/elasticsearch
|
|
||||||
|
|
||||||
service elasticsearch start
|
|
||||||
|
|
||||||
wait_for_elasticsearch_status
|
|
||||||
|
|
||||||
assert_file_exist "/var/run/elasticsearch/elasticsearch.pid"
|
|
||||||
|
|
||||||
service elasticsearch stop
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "[INIT.D] GC logs exist" {
|
|
||||||
start_elasticsearch_service
|
|
||||||
assert_file_exist /var/log/elasticsearch/gc.log.0.current
|
|
||||||
stop_elasticsearch_service
|
|
||||||
}
|
|
||||||
|
|
||||||
# Ensures that if $MAX_MAP_COUNT is less than the set value on the OS
|
|
||||||
# it will be updated
|
|
||||||
@test "[INIT.D] sysctl is run when the value set is too small" {
|
|
||||||
# intentionally a ridiculously low number
|
|
||||||
sysctl -q -w vm.max_map_count=100
|
|
||||||
start_elasticsearch_service
|
|
||||||
max_map_count=$(sysctl -n vm.max_map_count)
|
|
||||||
stop_elasticsearch_service
|
|
||||||
|
|
||||||
[ $max_map_count = 262144 ]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# Ensures that if $MAX_MAP_COUNT is greater than the set vaule on the OS
|
|
||||||
# we do not attempt to update it.
|
|
||||||
@test "[INIT.D] sysctl is not run when it already has a larger or equal value set" {
|
|
||||||
# intentionally set to the default +1
|
|
||||||
sysctl -q -w vm.max_map_count=262145
|
|
||||||
start_elasticsearch_service
|
|
||||||
max_map_count=$(sysctl -n vm.max_map_count)
|
|
||||||
stop_elasticsearch_service
|
|
||||||
|
|
||||||
# default value +1
|
|
||||||
[ $max_map_count = 262145 ]
|
|
||||||
|
|
||||||
}
|
|
|
@ -58,7 +58,7 @@ tasks.dependenciesInfo.enabled = false
|
||||||
tasks.thirdPartyAudit.ignoreMissingClasses()
|
tasks.thirdPartyAudit.ignoreMissingClasses()
|
||||||
|
|
||||||
tasks.register('destructivePackagingTest') {
|
tasks.register('destructivePackagingTest') {
|
||||||
dependsOn 'destructiveDistroTest', 'destructiveBatsTest.oss'
|
dependsOn 'destructiveDistroTest'
|
||||||
}
|
}
|
||||||
|
|
||||||
processTestResources {
|
processTestResources {
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.packaging.test;
|
||||||
|
|
||||||
|
import org.elasticsearch.packaging.util.Platforms;
|
||||||
|
import org.elasticsearch.packaging.util.ServerUtils;
|
||||||
|
import org.elasticsearch.packaging.util.Shell;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
import static org.elasticsearch.packaging.util.FileUtils.assertPathsExist;
|
||||||
|
import static org.elasticsearch.packaging.util.FileUtils.fileWithGlobExist;
|
||||||
|
import static org.hamcrest.CoreMatchers.anyOf;
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.junit.Assume.assumeFalse;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
public class SysVInitTests extends PackagingTestCase {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void filterDistros() {
|
||||||
|
assumeTrue("rpm or deb", distribution.isPackage());
|
||||||
|
assumeTrue(Platforms.isSysVInit());
|
||||||
|
assumeFalse(Platforms.isSystemd());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElasticsearch() throws Exception {
|
||||||
|
sh.run("service elasticsearch start");
|
||||||
|
ServerUtils.waitForElasticsearch(installation);
|
||||||
|
sh.run("service elasticsearch status");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopElasticsearch() {
|
||||||
|
sh.run("service elasticsearch stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test10Install() throws Exception {
|
||||||
|
install();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test20Start() throws Exception {
|
||||||
|
startElasticsearch();
|
||||||
|
assertThat(installation.logs, fileWithGlobExist("gc.log*"));
|
||||||
|
ServerUtils.runElasticsearchTests();
|
||||||
|
sh.run("service elasticsearch status"); // returns 0 exit status when ok
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test21Restart() throws Exception {
|
||||||
|
sh.run("service elasticsearch restart");
|
||||||
|
sh.run("service elasticsearch status"); // returns 0 exit status when ok
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test22Stop() throws Exception {
|
||||||
|
stopElasticsearch();
|
||||||
|
Shell.Result status = sh.runIgnoreExitCode("service elasticsearch status");
|
||||||
|
assertThat(status.exitCode, anyOf(equalTo(3), equalTo(4)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test30PidDirCreation() throws Exception {
|
||||||
|
// Simulates the behavior of a system restart:
|
||||||
|
// the PID directory is deleted by the operating system
|
||||||
|
// but it should not block ES from starting
|
||||||
|
// see https://github.com/elastic/elasticsearch/issues/11594
|
||||||
|
|
||||||
|
sh.run("rm -rf " + installation.pidDir);
|
||||||
|
startElasticsearch();
|
||||||
|
assertPathsExist(installation.pidDir.resolve("elasticsearch.pid"));
|
||||||
|
stopElasticsearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test31MaxMapTooSmall() throws Exception {
|
||||||
|
sh.run("sysctl -q -w vm.max_map_count=262140");
|
||||||
|
startElasticsearch();
|
||||||
|
Shell.Result result = sh.run("sysctl -n vm.max_map_count");
|
||||||
|
String maxMapCount = result.stdout.trim();
|
||||||
|
sh.run("service elasticsearch stop");
|
||||||
|
assertThat(maxMapCount, equalTo("262144"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test32MaxMapBigEnough() throws Exception {
|
||||||
|
// Ensures that if $MAX_MAP_COUNT is greater than the set
|
||||||
|
// value on the OS we do not attempt to update it.
|
||||||
|
sh.run("sysctl -q -w vm.max_map_count=262145");
|
||||||
|
startElasticsearch();
|
||||||
|
Shell.Result result = sh.run("sysctl -n vm.max_map_count");
|
||||||
|
String maxMapCount = result.stdout.trim();
|
||||||
|
sh.run("service elasticsearch stop");
|
||||||
|
assertThat(maxMapCount, equalTo("262145"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue