Skip to content

Commit

Permalink
Write test run config into yaml file for reproducing
Browse files Browse the repository at this point in the history
Signed-off-by: David Kornel <[email protected]>
  • Loading branch information
kornys committed Jan 15, 2024
1 parent 313175d commit 754f76a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/java/io/odh/test/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -144,4 +153,31 @@ private static Map<String, Object> loadConfigurationFile() {
return Collections.emptyMap();
}
}

private static void saveConfigurationFile() throws IOException {
Path logPath = Environment.LOG_DIR;
Files.createDirectories(logPath);

LinkedHashMap<String, String> 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");
}
}

0 comments on commit 754f76a

Please sign in to comment.