Browse Source

Add failure logging in package tests (#49486)

Part of #49406. Sometimes restarting systemd-journald fails, so detect
this and attempt to log more information.
Rory Hunter 5 years ago
parent
commit
644d77c242
1 changed files with 17 additions and 2 deletions
  1. 17 2
      qa/os/src/test/java/org/elasticsearch/packaging/util/Packages.java

+ 17 - 2
qa/os/src/test/java/org/elasticsearch/packaging/util/Packages.java

@@ -49,6 +49,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 public class Packages {
 
@@ -301,8 +302,22 @@ public class Packages {
      */
     public static void clearJournal(Shell sh) {
         if (isSystemd()) {
-            sh.run("rm -rf /run/log/journal/");
-            sh.run("systemctl restart systemd-journald");
+            sh.run("rm -rf /run/log/journal/*");
+            final Result result = sh.runIgnoreExitCode("systemctl restart systemd-journald");
+
+            // Sometimes the restart fails on Debian 10 with:
+            //    Job for systemd-journald.service failed because the control process exited with error code.
+            //    See "systemctl status systemd-journald.service" and "journalctl -xe" for details.]
+            //
+            // ...so run these commands in an attempt to figure out what's going on.
+            if (result.isSuccess() == false) {
+                logger.error("Failed to restart systemd-journald: " + result);
+
+                logger.error(sh.runIgnoreExitCode("systemctl status systemd-journald.service"));
+                logger.error(sh.runIgnoreExitCode("journalctl -xe"));
+
+                fail("Couldn't clear the systemd journal as restarting systemd-journald failed");
+            }
         }
     }