From ca3c469bdc87440ab367eacd04fe377a2ffcdec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Fri, 27 Mar 2020 13:02:53 +0100 Subject: [PATCH] tests/image: move the namespace creation closer to the boot types Soon, images will be run non-locally (AWS, Azure). For those boot types there's no need to have an unshared network namespace. This commit prepares the code for that. --- cmd/osbuild-image-tests/main_test.go | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/cmd/osbuild-image-tests/main_test.go b/cmd/osbuild-image-tests/main_test.go index 598bce04c..d590dd8f4 100644 --- a/cmd/osbuild-image-tests/main_test.go +++ b/cmd/osbuild-image-tests/main_test.go @@ -206,33 +206,41 @@ func testSSH(t *testing.T, address string, ns *netNS) { // in defined number of attempts and systemd-is-running returns running // or degraded status. func testBoot(t *testing.T, imagePath string, bootType string, outputID string) { - err := withNetworkNamespace(func(ns netNS) error { - switch bootType { - case "qemu": - fallthrough - case "qemu-extract": + switch bootType { + case "qemu": + fallthrough + case "qemu-extract": + err := withNetworkNamespace(func(ns netNS) error { return withBootedQemuImage(imagePath, ns, func() error { testSSH(t, "localhost", &ns) return nil }) - case "nspawn": + }) + require.NoError(t, err) + + case "nspawn": + err := withNetworkNamespace(func(ns netNS) error { return withBootedNspawnImage(imagePath, outputID, ns, func() error { testSSH(t, "localhost", &ns) return nil }) - case "nspawn-extract": + }) + require.NoError(t, err) + + case "nspawn-extract": + err := withNetworkNamespace(func(ns netNS) error { return withExtractedTarArchive(imagePath, func(dir string) error { return withBootedNspawnDirectory(dir, outputID, ns, func() error { testSSH(t, "localhost", &ns) return nil }) }) - default: - panic("unknown boot type!") - } - }) + }) + require.NoError(t, err) - require.NoError(t, err) + default: + panic("unknown boot type!") + } } // testImage performs a series of tests specified in the testcase