From bc737f04b426fbb424a6e22bc7a99304671adfc1 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 25 Oct 2023 12:26:58 -0400 Subject: [PATCH] tests/blackbox: allow skipping critical logging check In the context of the test added in the previous patch, it's normal for the first `sgdisk --zap-all` invocation to fail. Add a knob to allow the harness to tolerate this and make use of it in the new test. --- tests/blackbox_test.go | 20 ++++++++++---------- tests/filesystem.go | 4 ++-- tests/positive/partitions/wipe.go | 2 ++ tests/types/types.go | 1 + 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/blackbox_test.go b/tests/blackbox_test.go index 88de68fb5..086d65666 100644 --- a/tests/blackbox_test.go +++ b/tests/blackbox_test.go @@ -278,11 +278,11 @@ func outer(t *testing.T, test types.Test, negativeTests bool) error { appendEnv = append(appendEnv, "IGNITION_SYSTEM_CONFIG_DIR="+systemConfigDir) if !negativeTests { - if err := runIgnition(t, ctx, "fetch", "", tmpDirectory, appendEnv); err != nil { + if err := runIgnition(t, ctx, "fetch", "", tmpDirectory, appendEnv, test.SkipCriticalCheck); err != nil { return err } - if err := runIgnition(t, ctx, "disks", "", tmpDirectory, appendEnv); err != nil { + if err := runIgnition(t, ctx, "disks", "", tmpDirectory, appendEnv, test.SkipCriticalCheck); err != nil { return err } @@ -290,12 +290,12 @@ func outer(t *testing.T, test types.Test, negativeTests bool) error { return err } - if err := runIgnition(t, ctx, "mount", rootPartition.MountPath, tmpDirectory, appendEnv); err != nil { + if err := runIgnition(t, ctx, "mount", rootPartition.MountPath, tmpDirectory, appendEnv, test.SkipCriticalCheck); err != nil { return err } - filesErr := runIgnition(t, ctx, "files", rootPartition.MountPath, tmpDirectory, appendEnv) - if err := runIgnition(t, ctx, "umount", rootPartition.MountPath, tmpDirectory, appendEnv); err != nil { + filesErr := runIgnition(t, ctx, "files", rootPartition.MountPath, tmpDirectory, appendEnv, test.SkipCriticalCheck) + if err := runIgnition(t, ctx, "umount", rootPartition.MountPath, tmpDirectory, appendEnv, test.SkipCriticalCheck); err != nil { return err } if err := umountPartition(rootPartition); err != nil { @@ -318,11 +318,11 @@ func outer(t *testing.T, test types.Test, negativeTests bool) error { } return nil } else { - if err := runIgnition(t, ctx, "fetch", "", tmpDirectory, appendEnv); err != nil { + if err := runIgnition(t, ctx, "fetch", "", tmpDirectory, appendEnv, test.SkipCriticalCheck); err != nil { return nil // error is expected } - if err := runIgnition(t, ctx, "disks", "", tmpDirectory, appendEnv); err != nil { + if err := runIgnition(t, ctx, "disks", "", tmpDirectory, appendEnv, test.SkipCriticalCheck); err != nil { return nil // error is expected } @@ -330,12 +330,12 @@ func outer(t *testing.T, test types.Test, negativeTests bool) error { return err } - if err := runIgnition(t, ctx, "mount", rootPartition.MountPath, tmpDirectory, appendEnv); err != nil { + if err := runIgnition(t, ctx, "mount", rootPartition.MountPath, tmpDirectory, appendEnv, test.SkipCriticalCheck); err != nil { return nil // error is expected } - filesErr := runIgnition(t, ctx, "files", rootPartition.MountPath, tmpDirectory, appendEnv) - if err := runIgnition(t, ctx, "umount", rootPartition.MountPath, tmpDirectory, appendEnv); err != nil { + filesErr := runIgnition(t, ctx, "files", rootPartition.MountPath, tmpDirectory, appendEnv, test.SkipCriticalCheck) + if err := runIgnition(t, ctx, "umount", rootPartition.MountPath, tmpDirectory, appendEnv, test.SkipCriticalCheck); err != nil { return nil } if err := umountPartition(rootPartition); err != nil { diff --git a/tests/filesystem.go b/tests/filesystem.go index f63365e28..2d9c676bb 100644 --- a/tests/filesystem.go +++ b/tests/filesystem.go @@ -116,7 +116,7 @@ func umountPartition(p *types.Partition) error { } // returns true if no error, false if error -func runIgnition(t *testing.T, ctx context.Context, stage, root, cwd string, appendEnv []string) error { +func runIgnition(t *testing.T, ctx context.Context, stage, root, cwd string, appendEnv []string, skipCriticalCheck bool) error { args := []string{"-platform", "file", "-stage", stage, "-root", root, "-log-to-stdout", "-config-cache", filepath.Join(cwd, "ignition.json"), @@ -141,7 +141,7 @@ func runIgnition(t *testing.T, ctx context.Context, stage, root, cwd string, app if strings.Contains(string(out), "panic") { return fmt.Errorf("ignition panicked") } - if strings.Contains(string(out), "CRITICAL") { + if !skipCriticalCheck && strings.Contains(string(out), "CRITICAL") { return fmt.Errorf("found critical ignition log") } return err diff --git a/tests/positive/partitions/wipe.go b/tests/positive/partitions/wipe.go index d51b5d59f..da8b34bf9 100644 --- a/tests/positive/partitions/wipe.go +++ b/tests/positive/partitions/wipe.go @@ -59,5 +59,7 @@ func WipeBadTable() types.Test { Out: out, Config: config, ConfigMinVersion: configMinVersion, + // the first `sgdisk --zap-all` is expected to fail + SkipCriticalCheck: true, } } diff --git a/tests/types/types.go b/tests/types/types.go index 4405cb6f0..46de2bfa1 100644 --- a/tests/types/types.go +++ b/tests/types/types.go @@ -104,6 +104,7 @@ type Test struct { ConfigMinVersion string ConfigVersion string ConfigShouldBeBad bool // Set to true to skip config validation step + SkipCriticalCheck bool // Set to true to skip critical logging check } func (ps Partitions) GetPartition(label string) *Partition {