diff --git a/cmd/osbuild-image-tests/main_test.go b/cmd/osbuild-image-tests/main_test.go index 2b9c2e2f9..c82147487 100644 --- a/cmd/osbuild-image-tests/main_test.go +++ b/cmd/osbuild-image-tests/main_test.go @@ -125,19 +125,28 @@ func (*timeoutError) Error() string { return "" } // that 10 seconds or if systemd-is-running returns starting. // It returns nil if systemd-is-running returns running or degraded. // It can also return other errors in other error cases. -func trySSHOnce(ns netNS) error { +func trySSHOnce(ns *netNS) error { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - cmd := ns.NamespacedCommandContext( - ctx, - "ssh", + + cmdName := "ssh" + cmdArgs := []string{ "-p", "22", "-i", privateKeyPath, "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "redhat@localhost", "systemctl --wait is-system-running", - ) + } + + var cmd *exec.Cmd + + if ns != nil { + cmd = ns.NamespacedCommandContext(ctx, cmdName, cmdArgs...) + } else { + cmd = exec.CommandContext(ctx, cmdName, cmdArgs...) + } + output, err := cmd.Output() if ctx.Err() == context.DeadlineExceeded { @@ -171,7 +180,7 @@ func trySSHOnce(ns netNS) error { // testSSH tests the running image using ssh. // It tries 20 attempts before giving up. If a major error occurs, it might // return earlier. -func testSSH(t *testing.T, ns netNS) { +func testSSH(t *testing.T, ns *netNS) { const attempts = 20 for i := 0; i < attempts; i++ { err := trySSHOnce(ns) @@ -203,18 +212,18 @@ func testBoot(t *testing.T, imagePath string, bootType string, outputID string) fallthrough case "qemu-extract": return withBootedQemuImage(imagePath, ns, func() error { - testSSH(t, ns) + testSSH(t, &ns) return nil }) case "nspawn": return withBootedNspawnImage(imagePath, outputID, ns, func() error { - testSSH(t, ns) + testSSH(t, &ns) return nil }) case "nspawn-extract": return withExtractedTarArchive(imagePath, func(dir string) error { return withBootedNspawnDirectory(dir, outputID, ns, func() error { - testSSH(t, ns) + testSSH(t, &ns) return nil }) })