Skip to content
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

Migrate SysV init tests from bats to java packaging #51077

Merged
merged 5 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -115,7 +115,6 @@ public void apply(Project project) {
}
}
Map<String, TaskProvider<?>> batsTests = new HashMap<>();
batsTests.put("bats oss", configureBatsTest(project, "oss", distributionsDir, copyDistributionsTask));
configureBatsTest(project, "plugins", distributionsDir, copyDistributionsTask, copyPluginsTask).configure(
t -> t.setPluginsDir(pluginsDir)
);
Expand Down
192 changes: 0 additions & 192 deletions qa/os/bats/oss/70_sysv_initd.bats

This file was deleted.

2 changes: 1 addition & 1 deletion qa/os/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tasks.dependenciesInfo.enabled = false
tasks.thirdPartyAudit.ignoreMissingClasses()

tasks.register('destructivePackagingTest') {
dependsOn 'destructiveDistroTest', 'destructiveBatsTest.oss'
dependsOn 'destructiveDistroTest'
}

processTestResources {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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 java.nio.file.Files;

import static org.elasticsearch.packaging.util.FileUtils.assertPathsExist;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
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());
assumeTrue(Platforms.isSystemd());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually should be assumeFalse. This is necessary because some systems have both sysv init and systemd, where sysv commands are a thin layer over systemd. This assume is meant to ensure we only test on systems with true sysv init support. Without it the tests will fail as we are testing behavior specifically in our init.d script, which would not be run in the hybrid systems.

}

@Override
public void startElasticsearch() throws Exception {
// since some systems have both sysv and systemd, we need to be explicit here to use sysv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looks like we skip this when systemd is around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed this comment is out of date. I do like being more epxlicit here and using the service calls directly , rather than relying on the parent class to decide to use sysv.

sh.run("service elasticsearch start");
ServerUtils.waitForElasticsearch(installation);
sh.run("service elasticsearch status");
}

@Override
public void stopElasticsearch() {
sh.run("service elasticsearch stop");
}

public void assertStatus(int code, String msg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover from a previous iteration. Removed.

Shell.Result result = sh.runIgnoreExitCode("service elasticsearch status");
assertThat(result.exitCode, equalTo(code));
if (msg != null) {
assertThat(result.stdout, containsString(msg));
}
}

public void test10Install() throws Exception {
install();
}

public void test20Start() throws Exception {
startElasticsearch();
assertTrue("gc logs exist", Files.exists(installation.logs.resolve("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.strip();
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.strip();
sh.run("service elasticsearch stop");
assertThat(maxMapCount, equalTo("262145"));
}

}