mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 02:14:54 +00:00
Migrating systemd bats tests from bats to java dsl. This also covers partially the sysv, but more must be added relates #32143 backport #39954
This commit is contained in:
parent
e5cec87697
commit
a6faf85f26
@ -20,31 +20,45 @@
|
||||
package org.elasticsearch.packaging.test;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering;
|
||||
import org.apache.http.client.fluent.Request;
|
||||
import org.elasticsearch.packaging.util.FileUtils;
|
||||
import org.elasticsearch.packaging.util.Shell;
|
||||
import org.elasticsearch.packaging.util.Shell.Result;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.elasticsearch.packaging.util.FileUtils.append;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.assertPathsDontExist;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.assertPathsExist;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.cp;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.fileWithGlobExist;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.mkdir;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.mv;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.rm;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.slurp;
|
||||
import static org.elasticsearch.packaging.util.Packages.SYSTEMD_SERVICE;
|
||||
import static org.elasticsearch.packaging.util.Packages.assertInstalled;
|
||||
import static org.elasticsearch.packaging.util.Packages.assertRemoved;
|
||||
import static org.elasticsearch.packaging.util.Packages.install;
|
||||
import static org.elasticsearch.packaging.util.Packages.remove;
|
||||
import static org.elasticsearch.packaging.util.Packages.restartElasticsearch;
|
||||
import static org.elasticsearch.packaging.util.Packages.startElasticsearch;
|
||||
import static org.elasticsearch.packaging.util.Packages.stopElasticsearch;
|
||||
import static org.elasticsearch.packaging.util.Packages.verifyPackageInstallation;
|
||||
import static org.elasticsearch.packaging.util.Platforms.getOsRelease;
|
||||
import static org.elasticsearch.packaging.util.Platforms.isSystemd;
|
||||
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest;
|
||||
import static org.elasticsearch.packaging.util.ServerUtils.runElasticsearchTests;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@ -55,42 +69,50 @@ import static org.junit.Assume.assumeTrue;
|
||||
|
||||
@TestCaseOrdering(TestCaseOrdering.AlphabeticOrder.class)
|
||||
public abstract class PackageTestCase extends PackagingTestCase {
|
||||
private Shell sh;
|
||||
|
||||
@Before
|
||||
public void onlyCompatibleDistributions() {
|
||||
assumeTrue("only compatible distributions", distribution().packaging.compatible);
|
||||
sh = newShell();
|
||||
}
|
||||
|
||||
public void test10InstallPackage() throws IOException {
|
||||
assertRemoved(distribution());
|
||||
installation = install(distribution());
|
||||
assertInstalled(distribution());
|
||||
verifyPackageInstallation(installation, distribution(), newShell());
|
||||
verifyPackageInstallation(installation, distribution(), sh);
|
||||
}
|
||||
|
||||
public void test20PluginsCommandWhenNoPlugins() {
|
||||
assumeThat(installation, is(notNullValue()));
|
||||
|
||||
assertThat(newShell().run(installation.bin("elasticsearch-plugin") + " list").stdout, isEmptyString());
|
||||
assertThat(sh.run(installation.bin("elasticsearch-plugin") + " list").stdout, isEmptyString());
|
||||
}
|
||||
|
||||
public void test30InstallDoesNotStartServer() {
|
||||
public void test30DaemonIsNotEnabledOnRestart() {
|
||||
if (isSystemd()) {
|
||||
sh.run("systemctl daemon-reload");
|
||||
String isEnabledOutput = sh.runIgnoreExitCode("systemctl is-enabled elasticsearch.service").stdout.trim();
|
||||
assertThat(isEnabledOutput, equalTo("disabled"));
|
||||
}
|
||||
}
|
||||
|
||||
public void test31InstallDoesNotStartServer() {
|
||||
assumeThat(installation, is(notNullValue()));
|
||||
|
||||
assertThat(newShell().run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch")));
|
||||
assertThat(sh.run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch")));
|
||||
}
|
||||
|
||||
public void assertRunsWithJavaHome() throws IOException {
|
||||
Shell sh = newShell();
|
||||
|
||||
String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
|
||||
byte[] originalEnvFile = Files.readAllBytes(installation.envFile);
|
||||
try {
|
||||
Files.write(installation.envFile, ("JAVA_HOME=" + systemJavaHome + "\n").getBytes(StandardCharsets.UTF_8),
|
||||
StandardOpenOption.APPEND);
|
||||
startElasticsearch();
|
||||
startElasticsearch(sh);
|
||||
runElasticsearchTests();
|
||||
stopElasticsearch();
|
||||
stopElasticsearch(sh);
|
||||
} finally {
|
||||
Files.write(installation.envFile, originalEnvFile);
|
||||
}
|
||||
@ -99,7 +121,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
|
||||
assertThat(new String(Files.readAllBytes(log), StandardCharsets.UTF_8), containsString(systemJavaHome));
|
||||
}
|
||||
|
||||
public void test31JavaHomeOverride() throws IOException {
|
||||
public void test32JavaHomeOverride() throws IOException {
|
||||
assumeThat(installation, is(notNullValue()));
|
||||
// we always run with java home when no bundled jdk is included, so this test would be repetitive
|
||||
assumeThat(distribution().hasJdk, is(true));
|
||||
@ -121,11 +143,21 @@ public abstract class PackageTestCase extends PackagingTestCase {
|
||||
}
|
||||
|
||||
public void test40StartServer() throws IOException {
|
||||
String start = sh.runIgnoreExitCode("date ").stdout.trim();
|
||||
assumeThat(installation, is(notNullValue()));
|
||||
|
||||
startElasticsearch();
|
||||
startElasticsearch(sh);
|
||||
|
||||
String journalEntries = sh.runIgnoreExitCode("journalctl _SYSTEMD_UNIT=elasticsearch.service " +
|
||||
"--since \"" + start + "\" --output cat | grep -v \"future versions of Elasticsearch will require Java 11\" | wc -l")
|
||||
.stdout.trim();
|
||||
assertThat(journalEntries, equalTo("0"));
|
||||
|
||||
assertPathsExist(installation.pidDir.resolve("elasticsearch.pid"));
|
||||
assertPathsExist(installation.logs.resolve("elasticsearch_server.json"));
|
||||
|
||||
runElasticsearchTests();
|
||||
verifyPackageInstallation(installation, distribution(), newShell()); // check startup script didn't change permissions
|
||||
verifyPackageInstallation(installation, distribution(), sh); // check startup script didn't change permissions
|
||||
}
|
||||
|
||||
public void test50Remove() {
|
||||
@ -134,7 +166,6 @@ public abstract class PackageTestCase extends PackagingTestCase {
|
||||
remove(distribution());
|
||||
|
||||
// removing must stop the service
|
||||
final Shell sh = newShell();
|
||||
assertThat(sh.run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch")));
|
||||
|
||||
if (isSystemd()) {
|
||||
@ -184,9 +215,160 @@ public abstract class PackageTestCase extends PackagingTestCase {
|
||||
|
||||
installation = install(distribution());
|
||||
assertInstalled(distribution());
|
||||
verifyPackageInstallation(installation, distribution(), newShell());
|
||||
verifyPackageInstallation(installation, distribution(), sh);
|
||||
|
||||
remove(distribution());
|
||||
assertRemoved(distribution());
|
||||
}
|
||||
|
||||
public void test70RestartServer() throws IOException {
|
||||
try {
|
||||
installation = install(distribution());
|
||||
assertInstalled(distribution());
|
||||
|
||||
startElasticsearch(sh);
|
||||
restartElasticsearch(sh);
|
||||
runElasticsearchTests();
|
||||
stopElasticsearch(sh);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test72TestRuntimeDirectory() throws IOException {
|
||||
try {
|
||||
installation = install(distribution());
|
||||
FileUtils.rm(installation.pidDir);
|
||||
startElasticsearch(sh);
|
||||
assertPathsExist(installation.pidDir);
|
||||
stopElasticsearch(sh);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
public void test73gcLogsExist() throws IOException {
|
||||
installation = install(distribution());
|
||||
startElasticsearch(sh);
|
||||
// it can be gc.log or gc.log.0.current
|
||||
assertThat(installation.logs, fileWithGlobExist("gc.log*"));
|
||||
stopElasticsearch(sh);
|
||||
}
|
||||
|
||||
// TEST CASES FOR SYSTEMD ONLY
|
||||
|
||||
|
||||
/**
|
||||
* # 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
|
||||
*/
|
||||
public void test80DeletePID_DIRandRestart() throws IOException {
|
||||
assumeTrue(isSystemd());
|
||||
|
||||
rm(installation.pidDir);
|
||||
|
||||
sh.run("systemd-tmpfiles --create");
|
||||
|
||||
startElasticsearch(sh);
|
||||
|
||||
final Path pidFile = installation.pidDir.resolve("elasticsearch.pid");
|
||||
|
||||
assertTrue(Files.exists(pidFile));
|
||||
|
||||
stopElasticsearch(sh);
|
||||
}
|
||||
|
||||
public void test81CustomPathConfAndJvmOptions() throws IOException {
|
||||
assumeTrue(isSystemd());
|
||||
|
||||
assumeThat(installation, is(notNullValue()));
|
||||
assertPathsExist(installation.envFile);
|
||||
|
||||
stopElasticsearch(sh);
|
||||
|
||||
// The custom config directory is not under /tmp or /var/tmp because
|
||||
// systemd's private temp directory functionally means different
|
||||
// processes can have different views of what's in these directories
|
||||
String temp = sh.runIgnoreExitCode("mktemp -p /etc -d").stdout.trim();
|
||||
final Path tempConf = Paths.get(temp);
|
||||
|
||||
try {
|
||||
mkdir(tempConf);
|
||||
cp(installation.config("elasticsearch.yml"), tempConf.resolve("elasticsearch.yml"));
|
||||
cp(installation.config("log4j2.properties"), tempConf.resolve("log4j2.properties"));
|
||||
|
||||
// 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
|
||||
final String jvmOptions =
|
||||
"-Xms512m\n" +
|
||||
"-Xmx512m\n" +
|
||||
"-Dlog4j2.disable.jmx=true\n";
|
||||
append(tempConf.resolve("jvm.options"), jvmOptions);
|
||||
|
||||
sh.runIgnoreExitCode("chown -R elasticsearch:elasticsearch " + tempConf);
|
||||
|
||||
final Shell serverShell = newShell();
|
||||
cp(installation.envFile, tempConf.resolve("elasticsearch.bk"));//backup
|
||||
append(installation.envFile, "ES_PATH_CONF=" + tempConf + "\n");
|
||||
append(installation.envFile, "ES_JAVA_OPTS=-XX:-UseCompressedOops");
|
||||
|
||||
startElasticsearch(serverShell);
|
||||
|
||||
final String nodesResponse = makeRequest(Request.Get("http://localhost:9200/_nodes"));
|
||||
assertThat(nodesResponse, CoreMatchers.containsString("\"heap_init_in_bytes\":536870912"));
|
||||
assertThat(nodesResponse, CoreMatchers.containsString("\"using_compressed_ordinary_object_pointers\":\"false\""));
|
||||
|
||||
stopElasticsearch(serverShell);
|
||||
|
||||
} finally {
|
||||
rm(installation.envFile);
|
||||
cp(tempConf.resolve("elasticsearch.bk"), installation.envFile);
|
||||
rm(tempConf);
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
public void test82SystemdMask() throws IOException {
|
||||
try {
|
||||
assumeTrue(isSystemd());
|
||||
|
||||
sh.run("systemctl mask systemd-sysctl.service");
|
||||
|
||||
installation = install(distribution());
|
||||
|
||||
sh.run("systemctl unmask systemd-sysctl.service");
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
public void test83serviceFileSetsLimits() throws IOException {
|
||||
// Limits are changed on systemd platforms only
|
||||
assumeTrue(isSystemd());
|
||||
|
||||
installation = install(distribution());
|
||||
|
||||
startElasticsearch(sh);
|
||||
|
||||
final Path pidFile = installation.pidDir.resolve("elasticsearch.pid");
|
||||
assertTrue(Files.exists(pidFile));
|
||||
String pid = slurp(pidFile).trim();
|
||||
String maxFileSize = sh.run("cat /proc/%s/limits | grep \"Max file size\" | awk '{ print $4 }'", pid).stdout.trim();
|
||||
assertThat(maxFileSize, equalTo("unlimited"));
|
||||
|
||||
String maxProcesses = sh.run("cat /proc/%s/limits | grep \"Max processes\" | awk '{ print $3 }'", pid).stdout.trim();
|
||||
assertThat(maxProcesses, equalTo("4096"));
|
||||
|
||||
String maxOpenFiles = sh.run("cat /proc/%s/limits | grep \"Max open files\" | awk '{ print $4 }'", pid).stdout.trim();
|
||||
assertThat(maxOpenFiles, equalTo("65535"));
|
||||
|
||||
String maxAddressSpace = sh.run("cat /proc/%s/limits | grep \"Max address space\" | awk '{ print $4 }'", pid).stdout.trim();
|
||||
assertThat(maxAddressSpace, equalTo("unlimited"));
|
||||
|
||||
stopElasticsearch(sh);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
package org.elasticsearch.packaging.util;
|
||||
|
||||
import org.elasticsearch.core.internal.io.IOUtils;
|
||||
import org.hamcrest.FeatureMatcher;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
@ -34,9 +36,11 @@ import java.nio.file.attribute.FileOwnerAttributeView;
|
||||
import java.nio.file.attribute.PosixFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.emptyIterable;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.hamcrest.text.IsEmptyString.isEmptyOrNullString;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@ -69,6 +73,15 @@ public class FileUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Path mktempDir(Path path) {
|
||||
try {
|
||||
return Files.createTempDirectory(path,"tmp");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Path mkdir(Path path) {
|
||||
try {
|
||||
return Files.createDirectories(path);
|
||||
@ -176,6 +189,20 @@ public class FileUtils {
|
||||
Arrays.stream(paths).forEach(path -> assertTrue(path + " should exist", Files.exists(path)));
|
||||
}
|
||||
|
||||
public static Matcher<Path> fileWithGlobExist(String glob) throws IOException {
|
||||
return new FeatureMatcher<Path,Iterable<Path>>(not(emptyIterable()),"File with pattern exist", "file with pattern"){
|
||||
|
||||
@Override
|
||||
protected Iterable<Path> featureValueOf(Path actual) {
|
||||
try {
|
||||
return Files.newDirectoryStream(actual,glob);
|
||||
} catch (IOException e) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void assertPathsDontExist(Path... paths) {
|
||||
Arrays.stream(paths).forEach(path -> assertFalse(path + " should not exist", Files.exists(path)));
|
||||
}
|
||||
|
@ -270,8 +270,7 @@ public class Packages {
|
||||
).forEach(configFile -> assertThat(es.config(configFile), file(File, "root", "elasticsearch", p660)));
|
||||
}
|
||||
|
||||
public static void startElasticsearch() throws IOException {
|
||||
final Shell sh = new Shell();
|
||||
public static void startElasticsearch(Shell sh) throws IOException {
|
||||
if (isSystemd()) {
|
||||
sh.run("systemctl daemon-reload");
|
||||
sh.run("systemctl enable elasticsearch.service");
|
||||
@ -281,6 +280,10 @@ public class Packages {
|
||||
sh.run("service elasticsearch start");
|
||||
}
|
||||
|
||||
assertElasticsearchStarted(sh);
|
||||
}
|
||||
|
||||
public static void assertElasticsearchStarted(Shell sh) throws IOException {
|
||||
waitForElasticsearch();
|
||||
|
||||
if (isSystemd()) {
|
||||
@ -291,12 +294,21 @@ public class Packages {
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopElasticsearch() throws IOException {
|
||||
final Shell sh = new Shell();
|
||||
public static void stopElasticsearch(Shell sh) throws IOException {
|
||||
if (isSystemd()) {
|
||||
sh.run("systemctl stop elasticsearch.service");
|
||||
} else {
|
||||
sh.run("service elasticsearch stop");
|
||||
}
|
||||
}
|
||||
|
||||
public static void restartElasticsearch(Shell sh) throws IOException {
|
||||
if (isSystemd()) {
|
||||
sh.run("systemctl restart elasticsearch.service");
|
||||
} else {
|
||||
sh.run("service elasticsearch restart");
|
||||
}
|
||||
|
||||
waitForElasticsearch();
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
@ -67,6 +68,10 @@ public class Shell {
|
||||
return runScriptIgnoreExitCode(getScriptCommand(script));
|
||||
}
|
||||
|
||||
public Result run( String command, Object... args) {
|
||||
String formattedCommand = String.format(Locale.ROOT, command, args);
|
||||
return run(formattedCommand);
|
||||
}
|
||||
private String[] getScriptCommand(String script) {
|
||||
if (Platforms.WINDOWS) {
|
||||
return powershellCommand(script);
|
||||
|
@ -1,257 +0,0 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
# This file is used to test the elasticsearch Systemd setup.
|
||||
|
||||
# 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_systemd
|
||||
skip_not_dpkg_or_rpm
|
||||
export_elasticsearch_paths
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] install elasticsearch" {
|
||||
clean_before_test
|
||||
install_package
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] daemon reload after install" {
|
||||
systemctl daemon-reload
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] daemon isn't enabled on restart" {
|
||||
# Rather than restart the VM we just ask systemd if it plans on starting
|
||||
# elasticsearch on restart. Not as strong as a restart but much much
|
||||
# faster.
|
||||
run systemctl is-enabled elasticsearch.service
|
||||
[ "$output" = "disabled" ]
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] enable" {
|
||||
systemctl enable elasticsearch.service
|
||||
|
||||
systemctl is-enabled elasticsearch.service
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] start" {
|
||||
# Capture the current epoch in millis
|
||||
run date +%s
|
||||
epoch="$output"
|
||||
|
||||
# The OpenJDK packaged for CentOS and OEL both override the default value (false) for the JVM option "AssumeMP".
|
||||
#
|
||||
# Because it is forced to "true" by default for these packages, the following warning message is printed to the
|
||||
# standard output when the Vagrant box has only 1 CPU:
|
||||
# OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure
|
||||
# the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
|
||||
#
|
||||
# This message will then fail the next test where we check if no entries have been added to the journal.
|
||||
#
|
||||
# This message appears since with java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64 because of the commit:
|
||||
# 2016-10-10 - Andrew Hughes <gnu.andrew@redhat.com> - 1:1.8.0.111-1.b15 - Turn debug builds on for all JIT architectures.
|
||||
# Always AssumeMP on RHEL.
|
||||
# - Resolves: rhbz#1381990
|
||||
#
|
||||
if [ -x "$(command -v lsb_release)" ]; then
|
||||
# Here we set the "-XX:-AssumeMP" option to false again:
|
||||
lsb_release=$(lsb_release -i)
|
||||
if [[ "$lsb_release" =~ "CentOS" ]] || [[ "$lsb_release" =~ "OracleServer" ]]; then
|
||||
echo "-XX:-AssumeMP" >> $ESCONFIG/jvm.options
|
||||
fi
|
||||
fi
|
||||
|
||||
systemctl start elasticsearch.service
|
||||
wait_for_elasticsearch_status
|
||||
assert_file_exist "/var/run/elasticsearch/elasticsearch.pid"
|
||||
assert_file_exist "/var/log/elasticsearch/elasticsearch_server.json"
|
||||
|
||||
# Converts the epoch back in a human readable format
|
||||
run date --date=@$epoch "+%Y-%m-%d %H:%M:%S"
|
||||
since="$output"
|
||||
|
||||
# Verifies that no new entries in journald have been added
|
||||
# since the last start
|
||||
result="$(journalctl _SYSTEMD_UNIT=elasticsearch.service --since "$since" --output cat | grep -v "future versions of Elasticsearch will require Java 11" | wc -l)"
|
||||
[ "$result" -eq "0" ] || {
|
||||
echo "Expected no entries in journalctl for the Elasticsearch service but found:"
|
||||
journalctl _SYSTEMD_UNIT=elasticsearch.service --since "$since"
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] start (running)" {
|
||||
systemctl start elasticsearch.service
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] is active (running)" {
|
||||
run systemctl is-active elasticsearch.service
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "active" ]
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] status (running)" {
|
||||
systemctl status elasticsearch.service
|
||||
}
|
||||
|
||||
##################################
|
||||
# Check that Elasticsearch is working
|
||||
##################################
|
||||
@test "[SYSTEMD] test elasticsearch" {
|
||||
run_elasticsearch_tests
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] restart" {
|
||||
systemctl restart elasticsearch.service
|
||||
|
||||
wait_for_elasticsearch_status
|
||||
|
||||
service elasticsearch status
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] stop (running)" {
|
||||
systemctl stop elasticsearch.service
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] status (stopping)" {
|
||||
run systemctl status elasticsearch.service
|
||||
# I'm not sure why suse exits 0 here, but it does
|
||||
if [ ! -e /etc/SuSE-release ]; then
|
||||
[ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped but got $status"
|
||||
fi
|
||||
echo "$output" | grep "Active:" | grep "inactive"
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] stop (stopped)" {
|
||||
systemctl stop elasticsearch.service
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] status (stopped)" {
|
||||
run systemctl status elasticsearch.service
|
||||
# I'm not sure why suse exits 0 here, but it does
|
||||
if [ ! -e /etc/SuSE-release ]; then
|
||||
[ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped but got $status"
|
||||
fi
|
||||
echo "$output" | grep "Active:" | grep "inactive"
|
||||
}
|
||||
|
||||
# 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 "[SYSTEMD] delete PID_DIR and restart" {
|
||||
rm -rf /var/run/elasticsearch
|
||||
|
||||
systemd-tmpfiles --create
|
||||
|
||||
systemctl start elasticsearch.service
|
||||
|
||||
wait_for_elasticsearch_status
|
||||
|
||||
assert_file_exist "/var/run/elasticsearch/elasticsearch.pid"
|
||||
|
||||
systemctl stop elasticsearch.service
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] start Elasticsearch with custom JVM options" {
|
||||
assert_file_exist $ESENVFILE
|
||||
# The custom config directory is not under /tmp or /var/tmp because
|
||||
# systemd's private temp directory functionally means different
|
||||
# processes can have different views of what's in these directories
|
||||
local temp=`mktemp -p /etc -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
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] masking systemd-sysctl" {
|
||||
clean_before_test
|
||||
|
||||
systemctl mask systemd-sysctl.service
|
||||
install_package
|
||||
|
||||
systemctl unmask systemd-sysctl.service
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] service file sets limits" {
|
||||
clean_before_test
|
||||
install_package
|
||||
systemctl start elasticsearch.service
|
||||
wait_for_elasticsearch_status
|
||||
local pid=$(cat /var/run/elasticsearch/elasticsearch.pid)
|
||||
local max_file_size=$(cat /proc/$pid/limits | grep "Max file size" | awk '{ print $4 }')
|
||||
[ "$max_file_size" == "unlimited" ]
|
||||
local max_processes=$(cat /proc/$pid/limits | grep "Max processes" | awk '{ print $3 }')
|
||||
[ "$max_processes" == "4096" ]
|
||||
local max_open_files=$(cat /proc/$pid/limits | grep "Max open files" | awk '{ print $4 }')
|
||||
[ "$max_open_files" == "65535" ]
|
||||
local max_address_space=$(cat /proc/$pid/limits | grep "Max address space" | awk '{ print $4 }')
|
||||
[ "$max_address_space" == "unlimited" ]
|
||||
systemctl stop elasticsearch.service
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] test runtime directory" {
|
||||
clean_before_test
|
||||
install_package
|
||||
sudo rm -rf /var/run/elasticsearch
|
||||
systemctl start elasticsearch.service
|
||||
wait_for_elasticsearch_status
|
||||
[ -d /var/run/elasticsearch ]
|
||||
systemctl stop elasticsearch.service
|
||||
}
|
||||
|
||||
@test "[SYSTEMD] GC logs exist" {
|
||||
start_elasticsearch_service
|
||||
assert_file_exist /var/log/elasticsearch/gc.log.0.current
|
||||
stop_elasticsearch_service
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user