Skip to content

Commit d7697b4

Browse files
committed
Run elasticsearch-node as the right user in package tests (#64858)
Closes #64735. When running the `elasticsearch-node` tool in the archive packaging tests with a non-standard data directory, make sure we run the tool as the same user as Elasticsearch. Some systems place extra restrictions on `/tmp` that prevent a different user getting a lock on `/tmp/node.lock`.
1 parent 8f45694 commit d7697b4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import static java.nio.file.StandardOpenOption.APPEND;
3636
import static java.nio.file.StandardOpenOption.CREATE;
37+
import static org.elasticsearch.packaging.util.Archives.ARCHIVE_OWNER;
3738
import static org.elasticsearch.packaging.util.Archives.installArchive;
3839
import static org.elasticsearch.packaging.util.Archives.verifyArchiveInstallation;
3940
import static org.elasticsearch.packaging.util.FileExistenceMatchers.fileDoesNotExist;
@@ -394,7 +395,12 @@ public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws Ex
394395
startElasticsearch();
395396
stopElasticsearch();
396397

397-
Result result = sh.run("echo y | " + installation.executables().nodeTool + " unsafe-bootstrap");
398+
String nodeTool = installation.executables().nodeTool.toString();
399+
if (Platforms.WINDOWS == false) {
400+
nodeTool = "sudo -E -u " + ARCHIVE_OWNER + " " + nodeTool;
401+
}
402+
403+
Result result = sh.run("echo y | " + nodeTool + " unsafe-bootstrap");
398404
assertThat(result.stdout, containsString("Master node was successfully bootstrapped"));
399405
}
400406

qa/os/src/test/java/org/elasticsearch/packaging/util/Archives.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public static void stopElasticsearch(Installation installation) throws Exception
399399
assertThat(pid, is(not(emptyOrNullString())));
400400

401401
final Shell sh = new Shell();
402-
Platforms.onLinux(() -> sh.run("kill -SIGTERM " + pid + "; tail --pid=" + pid + " -f /dev/null"));
402+
Platforms.onLinux(() -> sh.run("kill -SIGTERM " + pid + " && tail --pid=" + pid + " -f /dev/null"));
403403
Platforms.onWindows(() -> {
404404
sh.run("Get-Process -Id " + pid + " | Stop-Process -Force; Wait-Process -Id " + pid);
405405

0 commit comments

Comments
 (0)