Skip to content

Commit

Permalink
wip testing debug outside of e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kannon92 committed Mar 28, 2024
1 parent c1ff2e5 commit 0d874e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 5 additions & 3 deletions pkg/monitortests/node/kubeletselinuxlabels/monitortest.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,17 @@ func (lw *selinuxLabelWatcher) EvaluateTestsFromConstructedIntervals(ctx context
// calls ps -Z -C kubelet
out, err := exutil.DebugNodeRetryWithOptionsAndChroot(lw.oc, val.Name, "default", "/bin/bash", "-c", "ps -Z -C kubelet")
if err != nil {
return []*junitapi.JUnitTestCase{&testCaseJunit}, fmt.Errorf("unable to call debug node %v", err)
return []*junitapi.JUnitTestCase{{Name: testName, SystemOut: "unable to call debug node", SystemErr: err.Error()}}, fmt.Errorf("unable to call debug node %v", err)

}
// kubelet_t should be found somewhere in the output
if foundProcess := strings.Contains(out, kubeletProcessLabel); !foundProcess {
return []*junitapi.JUnitTestCase{&testCaseJunit}, fmt.Errorf("kubelet label expected %s got %s", kubeletProcessLabel, out)
return []*junitapi.JUnitTestCase{{Name: testName, SystemOut: "kubelet label mismatch", FailureOutput: &junitapi.FailureOutput{
Message: fmt.Sprintf("kubelet label expected %s got %s", kubeletProcessLabel, out),
}}}, nil
}
}
return []*junitapi.JUnitTestCase{&testCaseJunit}, nil
return []*junitapi.JUnitTestCase{{Name: testName, SystemOut: "kubelet selinux labels match expected"}}, nil
}

func (*selinuxLabelWatcher) WriteContentToStorage(ctx context.Context, storageDir, timeSuffix string, finalIntervals monitorapi.Intervals, finalResourceState monitorapi.ResourcesMap) error {
Expand Down
18 changes: 15 additions & 3 deletions test/extended/util/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,10 @@ func (c *CLI) setOutput(out io.Writer) *CLI {
return c
}

// Run executes given OpenShift CLI command verb (iow. "oc <verb>").
// runInternal executes given OpenShift CLI command verb (iow. "oc <verb>").
// This function also override the default 'stdout' to redirect all output
// to a buffer and prepare the global flags such as namespace and config path.
func (c *CLI) Run(commands ...string) *CLI {
requiresTestStart()
func (c *CLI) runInternal(commands ...string) *CLI {
in, out, errout := &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{}
nc := &CLI{
execPath: c.execPath,
Expand All @@ -813,6 +812,19 @@ func (c *CLI) Run(commands ...string) *CLI {
return nc.setOutput(c.stdout)
}

// Run executes runInternal inside of a test.
func (c *CLI) Run(commands ...string) *CLI {
requiresTestStart()
return c.runInternal(commands...)
}

// RunOutsideTests executes given OpenShift CLI command verb (iow. "oc <verb>").
// This function also override the default 'stdout' to redirect all output
// to a buffer and prepare the global flags such as namespace and config path.
func (c *CLI) RunOutsideTests(commands ...string) *CLI {
return c.runInternal(commands...)
}

// InputString adds expected input to the command
func (c *CLI) InputString(input string) *CLI {
c.stdin.WriteString(input)
Expand Down
2 changes: 1 addition & 1 deletion test/extended/util/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func DebugNodeRetryWithOptionsAndChroot(oc *CLI, nodeName string, debugNodeNames
cargs = []string{"node/" + nodeName, "-n" + debugNodeNamespace, "--", "chroot", "/host"}
cargs = append(cargs, cmd...)
wait.Poll(3*time.Second, 30*time.Second, func() (bool, error) {
stdOut, _, err = oc.AsAdmin().WithoutNamespace().Run("debug").Args(cargs...).Outputs()
stdOut, _, err = oc.AsAdmin().WithoutNamespace().RunOutsideTests("debug").Args(cargs...).Outputs()
if err != nil {
return false, nil
}
Expand Down

0 comments on commit 0d874e6

Please sign in to comment.