diff options
author | Håkon Hallingstad <hakon@oath.com> | 2018-01-31 00:44:12 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@oath.com> | 2018-01-31 00:44:12 +0100 |
commit | 8cb0db31b98e02e0d3f89b36b1f68b112ffba8f7 (patch) | |
tree | d0676a404c90c5abaf742bd0cf09c9b57cae0bd2 /node-admin | |
parent | 7923c31a91388782f6f6b169358a6cecdf63d2fc (diff) |
Fix regex for no-op yum commands
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java | 14 | ||||
-rw-r--r-- | node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java | 6 |
2 files changed, 9 insertions, 11 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java index 35729b5a428..dbb4c909a4b 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java @@ -16,12 +16,10 @@ import java.util.regex.Pattern; * @author hakonhall */ public class Yum { - private static final Pattern INSTALL_NOOP_PATTERN = - Pattern.compile("\nNothing to do\n$"); - private static final Pattern UPGRADE_NOOP_PATTERN = - Pattern.compile("\nNo packages marked for update\n$"); - private static final Pattern REMOVE_NOOP_PATTERN = - Pattern.compile("\nNo Packages marked for removal\n$"); + // Note: "(?dm)" makes newline be \n (only), and enables multiline mode where ^$ match lines with find() + private static final Pattern INSTALL_NOOP_PATTERN = Pattern.compile("(?dm)^Nothing to do$"); + private static final Pattern UPGRADE_NOOP_PATTERN = Pattern.compile("(?dm)^No packages marked for update$"); + private static final Pattern REMOVE_NOOP_PATTERN = Pattern.compile("(?dm)^No Packages marked for removal$"); private final TaskContext taskContext; private final Supplier<Command> commandSupplier; @@ -58,7 +56,7 @@ public class Yum { } public static class GenericYumCommand { - private static Logger logger = Logger.getLogger(Yum.class.getName()); + private static Logger logger = Logger.getLogger(GenericYumCommand.class.getName()); private final TaskContext taskContext; private final Supplier<Command> commandSupplier; @@ -102,7 +100,7 @@ public class Yum { // There's no way to figure out whether a yum command would have been a no-op. // Therefore, run the command and parse the output to decide. String output = childProcess.getUtf8Output(); - if (commandOutputNoopPattern.matcher(output).matches()) { + if (commandOutputNoopPattern.matcher(output).find()) { return false; } else { childProcess.logAsModifyingSystemAfterAll(logger); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java index 4a3c1061ea6..c893c709950 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java @@ -26,7 +26,7 @@ public class YumTest { commandSupplier.expectCommand( "yum install --assumeyes --enablerepo=repo-name package-1 package-2", 0, - "\nNothing to do\n"); + "foobar\nNothing to do\n"); Yum yum = new Yum(taskContext, commandSupplier); assertFalse(yum @@ -40,7 +40,7 @@ public class YumTest { commandSupplier.expectCommand( "yum upgrade --assumeyes package-1 package-2", 0, - "\nNo packages marked for update\n"); + "foobar\nNo packages marked for update\n"); assertFalse(new Yum(taskContext, commandSupplier) .upgrade("package-1", "package-2") @@ -52,7 +52,7 @@ public class YumTest { commandSupplier.expectCommand( "yum remove --assumeyes package-1 package-2", 0, - "\nNo Packages marked for removal\n"); + "foobar\nNo Packages marked for removal\n"); assertFalse(new Yum(taskContext, commandSupplier) .remove("package-1", "package-2") |