diff --git a/mantle/cmd/kola/testiso.go b/mantle/cmd/kola/testiso.go index 1d0821574f..dbe5584c72 100644 --- a/mantle/cmd/kola/testiso.go +++ b/mantle/cmd/kola/testiso.go @@ -657,6 +657,7 @@ func runTestIso(cmd *cobra.Command, args []string) (err error) { func awaitCompletion(ctx context.Context, inst *platform.QemuInstance, outdir string, qchan *os.File, booterrchan chan error, expected []string) (time.Duration, error) { start := time.Now() errchan := make(chan error) + consoleFilePath := filepath.Join(outdir, "console.txt") go func() { timeout := (time.Duration(installTimeoutMins*(100+kola.Options.ExtendTimeoutPercent)) * time.Minute) / 100 time.Sleep(timeout) @@ -678,106 +679,28 @@ func awaitCompletion(ctx context.Context, inst *platform.QemuInstance, outdir st if err != nil { errchan <- err } - - // Open the file - path := filepath.Join(outdir, "ignition-virtio-dump.txt") - file, err := os.Open(path) - if err != nil { - fmt.Println("Error opening file: \n", err) - // if file doesn't exist lets print contents of the directory - fmt.Println("Other files in this directory:") - filepath.Walk(outdir, func(path string, info os.FileInfo, err error) error { - if err != nil { - fmt.Println("Error accessing path", path, ":", err) - return err - } - fmt.Println(path) - return nil - }) - } - // fmt.Printf("FILE: %v\n", file) - defer file.Close() - // Open the console file - // consoleFile := filepath.Join(outdir, "console.txt") - // inst.CheckConsoleForBadness2(consoleFile) - // inst.CheckConsoleForBadness(ctx) - - -// maybe just run checkConsoleForBadness here, and try to refactor some code to open the file once ? -// ie open the file before and change WaitForIgnition to take a file descriptor -// 1 - open the file -// 2 - WAitforIgnitionError(file) -// 3 - CheckForBadness(file) -// since if ignition failed we don't really care for failed services anyway -}() + }() go func() { - fileName := "console.txt" - path := filepath.Join(outdir, fileName) - file, err := os.Open(path) - if err != nil { - fmt.Printf("Error opening %s file: \n", fileName) + file, err := os.Open(consoleFilePath) + if err != nil { + fmt.Printf("Error opening %s file: \n", consoleFilePath) + return + } + defer file.Close() + errBuf, err := inst.CheckConsoleForBadness(ctx) + if err == nil && errBuf != "" { + plog.Info("Badness identified") + if err := os.WriteFile(consoleFilePath, []byte(errBuf), 0644); err != nil { + plog.Errorf("Failed to write journal: %v", err) } - defer file.Close() - - errBuf, err := inst.CheckConsoleForBadness(ctx) - if err == nil { - if errBuf != "" { - plog.Info("Badness identified") - path := filepath.Join(outdir, fileName) - if err := os.WriteFile(path, []byte(errBuf), 0644); err != nil { - plog.Errorf("Failed to write journal: %v", err) - } - err = platform.ErrInitramfsEmergency // What does the ErrInitramfsEmergency do? - } - console, err := os.Open(path) - if err != nil { - fmt.Printf("error opening console file: %v", err) - } - fmt.Printf("File \"%v\" opened successfully", fileName) - - // Ensure the console file is closed after the function ends - defer console.Close() - // Read the file content - content, err := io.ReadAll(console) - if err != nil { - fmt.Printf("error reading file: %v", err) - } - // Print the whole file content - fmt.Printf("FILE:\n%s\n", content) - } - fmt.Println("This works o_0") - - }() + err = platform.ErrInitramfsEmergency + } - // TEMPORARY: Below is the function that calls inst.CreateLogFile in order to create - // and print contents of the temporary log file - // go func(inst *platform.QemuInstance, ctx context.Context) { //I'm new to routines - // // 1. figure out how to get console file from instance - // // HERE: use the journal file instead of the CreateLogFile function - - // inst.ReadJournal(ctx) - // // Run a sample Log File func - // filename := inst.CreateLogFile() - // // Read file - // fmt.Printf("\nTesting file:\n%v\n", filename) - // // Open file for reading - // file, err := os.Open(filename) - // if err != nil { - // fmt.Println("Error opening file:", err) - // return - // } - // defer file.Close() // When done, close file - // // Read and print contents - // scanner := bufio.NewScanner(file) - // for scanner.Scan() { - // fmt.Printf("File contents:\n%v\n",scanner.Text()) - // fmt.Println("") - // } - // if err := scanner.Err(); err != nil { - // fmt.Printf("Error reading %v.\nError: %v",filename, err) - // } - // }(inst,ctx) + if err != nil { + errchan <- errors.Wrapf(err, "CheckConsoleForBadness detected an error") + } + }() go func() { err := inst.Wait() diff --git a/mantle/platform/qemu.go b/mantle/platform/qemu.go index 7db691202b..880cc42606 100644 --- a/mantle/platform/qemu.go +++ b/mantle/platform/qemu.go @@ -261,8 +261,6 @@ func (inst *QemuInstance) WaitIgnitionError(ctx context.Context) (string, error) // be a newline-delimited stream of JSON strings, as returned // by `journalctl -o json`. -// TEMPORARY: How to modify CheckConsoleForBadness so that it calls WaitIgnitionError and returns -// string and error? func (inst *QemuInstance) CheckConsoleForBadness(ctx context.Context) (string, error) { b := bufio.NewReaderSize(inst.journalPipe, 64768) var r strings.Builder @@ -303,25 +301,6 @@ func (inst *QemuInstance) CheckConsoleForBadness(ctx context.Context) (string, e return r.String(), nil } -// TEMPORARY: CheckConsole func -func (inst *QemuInstance) CheckConsoleForBadness2(file string) (string, error) { - // Open the console file - console, err := os.Open(file) - if err != nil { - return "", fmt.Errorf("error opening console file: %v", err) - } - // Ensure the console file is closed after the function ends - defer console.Close() - // Read the file content - content, err := io.ReadAll(console) - if err != nil { - return "", fmt.Errorf("error reading file: %v", err) - } - // Print the whole file content - fmt.Printf("FILE:\n%s\n", content) - return string(content), nil -} - // WaitAll wraps the process exit as well as WaitIgnitionError, // returning an error if either fail. func (inst *QemuInstance) WaitAll(ctx context.Context) error {