From 754f76a2cb5a89fbcd01d9721b038dd0fd9eff94 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Mon, 15 Jan 2024 17:36:55 +0100 Subject: [PATCH] Write test run config into yaml file for reproducing Signed-off-by: David Kornel --- src/main/java/io/odh/test/Environment.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main/java/io/odh/test/Environment.java b/src/main/java/io/odh/test/Environment.java index c20c1fb5..c602c943 100644 --- a/src/main/java/io/odh/test/Environment.java +++ b/src/main/java/io/odh/test/Environment.java @@ -7,17 +7,21 @@ import io.odh.test.install.InstallTypes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import java.util.function.Function; @@ -109,6 +113,11 @@ private Environment() { } }); LoggerUtils.logSeparator("-", 30); + try { + saveConfigurationFile(); + } catch (IOException e) { + LOGGER.warn("Yaml configuration can't be saved"); + } } public static void print() { @@ -144,4 +153,31 @@ private static Map loadConfigurationFile() { return Collections.emptyMap(); } } + + private static void saveConfigurationFile() throws IOException { + Path logPath = Environment.LOG_DIR; + Files.createDirectories(logPath); + + LinkedHashMap toSave = new LinkedHashMap<>(); + + VALUES.forEach((key, value) -> { + if (isWriteable(key, value)) { + toSave.put(key, value); + } + }); + + PrintWriter writer = new PrintWriter(logPath.resolve("config.yaml").toFile()); + final DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + options.setPrettyFlow(true); + Yaml yaml = new Yaml(options); + yaml.dump(toSave, writer); + } + + private static boolean isWriteable(String var, String value) { + return !value.equals("null") + && !var.equals(CONFIG_FILE_PATH_ENV) + && !var.equals(USER_PATH) + && !value.equals("USER"); + } }