mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 02:14:54 +00:00
[test] package pre-install java check (#32259)
This recreates a test that was added to the bats packaging tests in #31343 but didn't make it over to the java project during when the linux package tests were ported in #31943 When packages are installed but can not locate the java executable, they should fail with a descriptive message
This commit is contained in:
parent
1091ec115e
commit
ac04ba42df
@ -129,7 +129,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
|
||||
});
|
||||
|
||||
Platforms.onLinux(() -> {
|
||||
final String javaPath = sh.run("which java").stdout.trim();
|
||||
final String javaPath = sh.run("command -v java").stdout.trim();
|
||||
|
||||
try {
|
||||
sh.run("chmod -x '" + javaPath + "'");
|
||||
|
@ -30,16 +30,20 @@ import org.junit.BeforeClass;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.elasticsearch.packaging.util.Cleanup.cleanEverything;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.assertPathsDontExist;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.mv;
|
||||
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.runInstallCommand;
|
||||
import static org.elasticsearch.packaging.util.Packages.startElasticsearch;
|
||||
import static org.elasticsearch.packaging.util.Packages.verifyPackageInstallation;
|
||||
import static org.elasticsearch.packaging.util.Platforms.getOsRelease;
|
||||
@ -75,6 +79,21 @@ public abstract class PackageTestCase extends PackagingTestCase {
|
||||
assumeTrue("only compatible distributions", distribution().packaging.compatible);
|
||||
}
|
||||
|
||||
public void test05InstallFailsWhenJavaMissing() {
|
||||
final Shell sh = new Shell();
|
||||
final Result java = sh.run("command -v java");
|
||||
|
||||
final Path originalJavaPath = Paths.get(java.stdout.trim());
|
||||
final Path relocatedJavaPath = originalJavaPath.getParent().resolve("java.relocated");
|
||||
try {
|
||||
mv(originalJavaPath, relocatedJavaPath);
|
||||
final Result installResult = runInstallCommand(distribution());
|
||||
assertThat(installResult.exitCode, is(1));
|
||||
} finally {
|
||||
mv(relocatedJavaPath, originalJavaPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void test10InstallPackage() {
|
||||
assertRemoved(distribution());
|
||||
installation = install(distribution());
|
||||
|
@ -67,7 +67,10 @@ public class Packages {
|
||||
Platforms.onDPKG(() -> {
|
||||
assertThat(status.exitCode, anyOf(is(0), is(1)));
|
||||
if (status.exitCode == 0) {
|
||||
assertTrue(Pattern.compile("(?m)^Status:.+deinstall ok").matcher(status.stdout).find());
|
||||
assertTrue("an uninstalled status should be indicated: " + status.stdout,
|
||||
Pattern.compile("(?m)^Status:.+deinstall ok").matcher(status.stdout).find() ||
|
||||
Pattern.compile("(?m)^Status:.+ok not-installed").matcher(status.stdout).find()
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -90,13 +93,27 @@ public class Packages {
|
||||
}
|
||||
|
||||
public static Installation install(Distribution distribution, String version) {
|
||||
final Result result = runInstallCommand(distribution, version);
|
||||
if (result.exitCode != 0) {
|
||||
throw new RuntimeException("Installing distribution " + distribution + " version " + version + " failed: " + result);
|
||||
}
|
||||
|
||||
return Installation.ofPackage(distribution.packaging);
|
||||
}
|
||||
|
||||
public static Result runInstallCommand(Distribution distribution) {
|
||||
return runInstallCommand(distribution, getCurrentVersion());
|
||||
}
|
||||
|
||||
public static Result runInstallCommand(Distribution distribution, String version) {
|
||||
final Shell sh = new Shell();
|
||||
final Path distributionFile = getDistributionFile(distribution, version);
|
||||
|
||||
Platforms.onRPM(() -> sh.run("rpm -i " + distributionFile));
|
||||
Platforms.onDPKG(() -> sh.run("dpkg -i " + distributionFile));
|
||||
|
||||
return Installation.ofPackage(distribution.packaging);
|
||||
if (Platforms.isRPM()) {
|
||||
return sh.runIgnoreExitCode("rpm -i " + distributionFile);
|
||||
} else {
|
||||
return sh.runIgnoreExitCode("dpkg -i " + distributionFile);
|
||||
}
|
||||
}
|
||||
|
||||
public static void remove(Distribution distribution) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user