Skip to content

[WIP] Refactor utility code in qa:os: tests #49945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void test50StartAndStop() throws Exception {
rm(installation.config("elasticsearch.keystore"));

try {
Archives.runElasticsearch(installation, sh);
startElasticsearch();
} catch (Exception e ){
if (Files.exists(installation.home.resolve("elasticsearch.pid"))) {
String pid = FileUtils.slurp(installation.home.resolve("elasticsearch.pid")).trim();
Expand All @@ -151,7 +151,7 @@ public void test50StartAndStop() throws Exception {
assertTrue("gc logs exist", Files.exists(installation.logs.resolve("gc.log")));
ServerUtils.runElasticsearchTests();

Archives.stopElasticsearch(installation);
stopElasticsearch();
}

public void test51JavaHomeOverride() throws Exception {
Expand All @@ -164,9 +164,9 @@ public void test51JavaHomeOverride() throws Exception {
sh.getEnv().put("JAVA_HOME", systemJavaHome1);
});

Archives.runElasticsearch(installation, sh);
startElasticsearch();
ServerUtils.runElasticsearchTests();
Archives.stopElasticsearch(installation);
stopElasticsearch();

String systemJavaHome1 = sh.getEnv().get("JAVA_HOME");
assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"),
Expand All @@ -188,9 +188,9 @@ public void test52BundledJdkRemoved() throws Exception {
sh.getEnv().put("JAVA_HOME", systemJavaHome1);
});

Archives.runElasticsearch(installation, sh);
startElasticsearch();
ServerUtils.runElasticsearchTests();
Archives.stopElasticsearch(installation);
stopElasticsearch();

String systemJavaHome1 = sh.getEnv().get("JAVA_HOME");
assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"),
Expand All @@ -211,9 +211,9 @@ public void test53JavaHomeWithSpecialCharacters() throws Exception {
sh.getEnv().put("JAVA_HOME", "C:\\Program Files (x86)\\java");

//verify ES can start, stop and run plugin list
Archives.runElasticsearch(installation, sh);
startElasticsearch();

Archives.stopElasticsearch(installation);
stopElasticsearch();

String pluginListCommand = installation.bin + "/elasticsearch-plugin list";
Result result = sh.run(pluginListCommand);
Expand All @@ -237,9 +237,9 @@ public void test53JavaHomeWithSpecialCharacters() throws Exception {
sh.getEnv().put("JAVA_HOME", testJavaHome);

//verify ES can start, stop and run plugin list
Archives.runElasticsearch(installation, sh);
startElasticsearch();

Archives.stopElasticsearch(installation);
stopElasticsearch();

String pluginListCommand = installation.bin + "/elasticsearch-plugin list";
Result result = sh.run(pluginListCommand);
Expand Down Expand Up @@ -284,13 +284,12 @@ public void test70CustomPathConfAndJvmOptions() throws Exception {
"-Dlog4j2.disable.jmx=true\n";
append(tempConf.resolve("jvm.options"), jvmOptions);

final Shell sh = newShell();
sh.chown(tempConf);

sh.getEnv().put("ES_PATH_CONF", tempConf.toString());
sh.getEnv().put("ES_JAVA_OPTS", "-XX:-UseCompressedOops");

Archives.runElasticsearch(installation, sh);
startElasticsearch();

final String nodesResponse = makeRequest(Request.Get("http://localhost:9200/_nodes"));
assertThat(nodesResponse, containsString("\"heap_init_in_bytes\":536870912"));
Expand Down Expand Up @@ -318,17 +317,16 @@ public void test80RelativePathConf() throws Exception {

append(tempConf.resolve("elasticsearch.yml"), "node.name: relative");

final Shell sh = newShell();
sh.chown(temp);

sh.setWorkingDirectory(temp);
sh.getEnv().put("ES_PATH_CONF", "config");
Archives.runElasticsearch(installation, sh);
startElasticsearch();

final String nodesResponse = makeRequest(Request.Get("http://localhost:9200/_nodes"));
assertThat(nodesResponse, containsString("\"name\":\"relative\""));

Archives.stopElasticsearch(installation);
stopElasticsearch();

} finally {
rm(tempConf);
Expand Down Expand Up @@ -393,7 +391,7 @@ public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws Ex

sh.setWorkingDirectory(getTempDir());

Archives.runElasticsearch(installation, sh);
startElasticsearch();
Archives.stopElasticsearch(installation);

Result result = sh.run("echo y | " + installation.executables().elasticsearchNode + " unsafe-bootstrap");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
import static org.elasticsearch.packaging.util.Packages.installPackage;
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.startElasticsearchIgnoringFailure;
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;
Expand Down Expand Up @@ -101,9 +98,9 @@ private void assertRunsWithJavaHome() throws Exception {
try {
Files.write(installation.envFile, ("JAVA_HOME=" + systemJavaHome + "\n").getBytes(StandardCharsets.UTF_8),
StandardOpenOption.APPEND);
startElasticsearch(sh, installation);
startElasticsearch();
runElasticsearchTests();
stopElasticsearch(sh);
stopElasticsearch();
} finally {
Files.write(installation.envFile, originalEnvFile);
}
Expand All @@ -129,9 +126,9 @@ public void test33RunsIfJavaNotOnPath() throws Exception {
}

try {
startElasticsearch(sh, installation);
startElasticsearch();
runElasticsearchTests();
stopElasticsearch(sh);
stopElasticsearch();
} finally {
if (Files.exists(Paths.get(backupPath))) {
sh.run("sudo mv " + backupPath + " /usr/bin/java");
Expand All @@ -153,7 +150,7 @@ public void test42BundledJdkRemoved() throws Exception {

public void test40StartServer() throws Exception {
String start = sh.runIgnoreExitCode("date ").stdout.trim();
startElasticsearch(sh, installation);
startElasticsearch();

String journalEntries = sh.runIgnoreExitCode("journalctl _SYSTEMD_UNIT=elasticsearch.service " +
"--since \"" + start + "\" --output cat | wc -l").stdout.trim();
Expand Down Expand Up @@ -218,7 +215,7 @@ public void test50Remove() throws Exception {
}

public void test60Reinstall() throws Exception {
installation = installPackage(distribution());
install();
assertInstalled(distribution());
verifyPackageInstallation(installation, distribution(), sh);

Expand All @@ -228,13 +225,13 @@ public void test60Reinstall() throws Exception {

public void test70RestartServer() throws Exception {
try {
installation = installPackage(distribution());
install();
assertInstalled(distribution());

startElasticsearch(sh, installation);
startElasticsearch();
restartElasticsearch(sh, installation);
runElasticsearchTests();
stopElasticsearch(sh);
stopElasticsearch();
} finally {
cleanup();
}
Expand All @@ -243,22 +240,22 @@ public void test70RestartServer() throws Exception {

public void test72TestRuntimeDirectory() throws Exception {
try {
installation = installPackage(distribution());
install();
FileUtils.rm(installation.pidDir);
startElasticsearch(sh, installation);
startElasticsearch();
assertPathsExist(installation.pidDir);
stopElasticsearch(sh);
stopElasticsearch();
} finally {
cleanup();
}
}

public void test73gcLogsExist() throws Exception {
installation = installPackage(distribution());
startElasticsearch(sh, installation);
install();
startElasticsearch();
// it can be gc.log or gc.log.0.current
assertThat(installation.logs, fileWithGlobExist("gc.log*"));
stopElasticsearch(sh);
stopElasticsearch();
}

// TEST CASES FOR SYSTEMD ONLY
Expand All @@ -277,26 +274,26 @@ public void test80DeletePID_DIRandRestart() throws Exception {

sh.run("systemd-tmpfiles --create");

startElasticsearch(sh, installation);
startElasticsearch();

final Path pidFile = installation.pidDir.resolve("elasticsearch.pid");

assertTrue(Files.exists(pidFile));

stopElasticsearch(sh);
stopElasticsearch();
}

public void test81CustomPathConfAndJvmOptions() throws Exception {
withCustomConfig(tempConf -> {
append(installation.envFile, "ES_JAVA_OPTS=-XX:-UseCompressedOops");

startElasticsearch(sh, installation);
startElasticsearch();

final String nodesResponse = makeRequest(Request.Get("http://localhost:9200/_nodes"));
assertThat(nodesResponse, containsString("\"heap_init_in_bytes\":536870912"));
assertThat(nodesResponse, containsString("\"using_compressed_ordinary_object_pointers\":\"false\""));

stopElasticsearch(sh);
stopElasticsearch();
});
}

Expand All @@ -306,7 +303,7 @@ public void test82SystemdMask() throws Exception {

sh.run("systemctl mask systemd-sysctl.service");

installation = installPackage(distribution());
install();

sh.run("systemctl unmask systemd-sysctl.service");
} finally {
Expand All @@ -318,9 +315,9 @@ public void test83serviceFileSetsLimits() throws Exception {
// Limits are changed on systemd platforms only
assumeTrue(isSystemd());

installation = installPackage(distribution());
install();

startElasticsearch(sh, installation);
startElasticsearch();

final Path pidFile = installation.pidDir.resolve("elasticsearch.pid");
assertTrue(Files.exists(pidFile));
Expand All @@ -337,7 +334,7 @@ public void test83serviceFileSetsLimits() throws Exception {
String maxAddressSpace = sh.run("cat /proc/%s/limits | grep \"Max address space\" | awk '{ print $4 }'", pid).stdout.trim();
assertThat(maxAddressSpace, equalTo("unlimited"));

stopElasticsearch(sh);
stopElasticsearch();
}

public void test90DoNotCloseStderrWhenQuiet() throws Exception {
Expand All @@ -347,7 +344,7 @@ public void test90DoNotCloseStderrWhenQuiet() throws Exception {

// Make sure we don't pick up the journal entries for previous ES instances.
clearJournal(sh);
startElasticsearchIgnoringFailure(sh);
runElasticsearchStartCommand();

final Result logs = sh.run("journalctl -u elasticsearch.service");

Expand All @@ -365,7 +362,7 @@ private void withCustomConfig(CustomConfigConsumer pathConsumer) throws Exceptio

assertPathsExist(installation.envFile);

stopElasticsearch(sh);
stopElasticsearch();

// The custom config directory is not under /tmp or /var/tmp because
// systemd's private temp directory functionally means different
Expand Down
Loading