Skip to content

Commit bc99908

Browse files
authored
[8.18] [CI] Fix packaging tests by patching system java home (#135504) (#135539)
Older version of openjdk17 are incompatible with newer ubuntu versions. Packaging tests swap out bundled jdk for the minimum jdk for a few tests. On ubuntu24 we now replace openjdk17 with adoptopenjdk17 in these cases. * Fix package upgrade tests for older versions on ubuntu24 * Rework patching JDK in PackageUpgradetests * Only parse base version * Fix ubuntu lookup and remove explicit java for upgraded versions
1 parent 81803d3 commit bc99908

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

.ci/scripts/packaging-test.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,30 @@ sudo mkdir -p /elasticsearch/qa/ && sudo chown jenkins /elasticsearch/qa/ && ln
6969
# See: https://git-scm.com/docs/git-config/2.35.2#Documentation/git-config.txt-safedirectory
7070
git config --global --add safe.directory $WORKSPACE
7171

72+
# Older versions of openjdk are incompatible to newer kernel of ubuntu. Use adoptopenjdk17 instead
73+
resolve_system_java_home() {
74+
if [[ "$BUILD_JAVA_HOME" == *"openjdk17"* ]]; then
75+
if [ -f "/etc/os-release" ]; then
76+
. /etc/os-release
77+
if [[ "$ID" == "ubuntu" && "$VERSION_ID" == "24.04" ]]; then
78+
echo "$HOME/.java/adoptopenjdk17"
79+
return
80+
fi
81+
fi
82+
fi
83+
84+
echo "$(readlink -f -n $BUILD_JAVA_HOME)"
85+
}
86+
87+
7288
# sudo sets it's own PATH thus we use env to override that and call sudo annother time so we keep the secure root PATH
7389
# run with --continue to run both bats and java tests even if one fails
7490
# be explicit about Gradle home dir so we use the same even with sudo
7591
sudo -E env \
7692
PATH=$BUILD_JAVA_HOME/bin:`sudo bash -c 'echo -n $PATH'` \
7793
--unset=ES_JAVA_HOME \
7894
--unset=JAVA_HOME \
79-
SYSTEM_JAVA_HOME=`readlink -f -n $BUILD_JAVA_HOME` \
95+
SYSTEM_JAVA_HOME=$(resolve_system_java_home) \
8096
DOCKER_CONFIG="${HOME}/.docker" \
8197
./gradlew -g $HOME/.gradle --console=plain --scan --parallel --build-cache -Dorg.elasticsearch.build.cache.url=https://gradle-enterprise.elastic.co/cache/ --continue $@
8298

qa/packaging/src/test/java/org/elasticsearch/packaging/test/PackageUpgradeTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public void test12SetupBwcVersion() throws Exception {
8787
);
8888

8989
assertDocsExist();
90-
9190
stopElasticsearch();
9291
}
9392

qa/packaging/src/test/java/org/elasticsearch/packaging/util/Packages.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static Installation installPackage(Shell sh, Distribution distribution) t
8686
public static Installation installPackage(Shell sh, Distribution distribution, @Nullable Predicate<String> outputPredicate)
8787
throws IOException {
8888
String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout().trim();
89-
if (distribution.hasJdk == false) {
89+
if (requiresExplicitJavaHome(distribution)) {
9090
sh.getEnv().put("ES_JAVA_HOME", systemJavaHome);
9191
}
9292
final Result result = runPackageManager(distribution, sh, PackageManagerCommand.INSTALL);
@@ -98,7 +98,7 @@ public static Installation installPackage(Shell sh, Distribution distribution, @
9898
}
9999
Installation installation = Installation.ofPackage(sh, distribution);
100100
installation.setElasticPassword(captureElasticPasswordFromOutput(result));
101-
if (distribution.hasJdk == false) {
101+
if (requiresExplicitJavaHome(distribution)) {
102102
Files.write(installation.envFile, List.of("ES_JAVA_HOME=" + systemJavaHome), StandardOpenOption.APPEND);
103103
}
104104

@@ -109,6 +109,15 @@ public static Installation installPackage(Shell sh, Distribution distribution, @
109109
return installation;
110110
}
111111

112+
private static boolean requiresExplicitJavaHome(Distribution distribution) {
113+
if (distribution.hasJdk == false) {
114+
return true;
115+
}
116+
Version version = Version.fromString(distribution.baseVersion);
117+
boolean requiresPatch = Platforms.isUbuntu24() && (version.onOrAfter(Version.V_8_0_0) && version.onOrBefore(Version.V_8_4_3));
118+
return requiresPatch;
119+
}
120+
112121
private static String captureElasticPasswordFromOutput(Result result) {
113122
return Arrays.stream(result.stdout().split(System.lineSeparator()))
114123
.filter(l -> l.contains("The generated password for the elastic built-in superuser is : "))
@@ -123,7 +132,20 @@ public static Installation upgradePackage(Shell sh, Distribution distribution) t
123132
throw new RuntimeException("Upgrading distribution " + distribution + " failed: " + result);
124133
}
125134

126-
return Installation.ofPackage(sh, distribution);
135+
Installation installation = Installation.ofPackage(sh, distribution);
136+
if (requiresExplicitJavaHome(distribution)) {
137+
String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout().trim();
138+
Files.write(installation.envFile, List.of("ES_JAVA_HOME=" + systemJavaHome), StandardOpenOption.APPEND);
139+
} else {
140+
// Explicitly remove the line if added for previous installation
141+
Files.write(
142+
installation.envFile,
143+
Files.readAllLines(installation.envFile).stream().filter(line -> line.startsWith("ES_JAVA_HOME") == false).toList(),
144+
StandardOpenOption.WRITE,
145+
StandardOpenOption.TRUNCATE_EXISTING
146+
);
147+
}
148+
return installation;
127149
}
128150

129151
public static Installation forceUpgradePackage(Shell sh, Distribution distribution) throws IOException {

qa/packaging/src/test/java/org/elasticsearch/packaging/util/Platforms.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public static String getOsRelease() {
2828
}
2929
}
3030

31+
public static boolean isUbuntu24() {
32+
if (LINUX) {
33+
String osRelease = getOsRelease();
34+
return osRelease.contains("ID=ubuntu") && osRelease.contains("VERSION_ID=\"24.04\"");
35+
} else {
36+
return false;
37+
}
38+
}
39+
3140
public static boolean isDPKG() {
3241
if (WINDOWS) {
3342
return false;

0 commit comments

Comments
 (0)