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.
This commit is contained in:
Ondřej Budai 2020-03-27 13:02:53 +01:00 committed by Tom Gundersen
parent cd51cfdcdf
commit ca3c469bdc

View file

@ -206,33 +206,41 @@ func testSSH(t *testing.T, address string, ns *netNS) {
// in defined number of attempts and systemd-is-running returns running // in defined number of attempts and systemd-is-running returns running
// or degraded status. // or degraded status.
func testBoot(t *testing.T, imagePath string, bootType string, outputID string) { func testBoot(t *testing.T, imagePath string, bootType string, outputID string) {
err := withNetworkNamespace(func(ns netNS) error { switch bootType {
switch bootType { case "qemu":
case "qemu": fallthrough
fallthrough case "qemu-extract":
case "qemu-extract": err := withNetworkNamespace(func(ns netNS) error {
return withBootedQemuImage(imagePath, ns, func() error { return withBootedQemuImage(imagePath, ns, func() error {
testSSH(t, "localhost", &ns) testSSH(t, "localhost", &ns)
return nil return nil
}) })
case "nspawn": })
require.NoError(t, err)
case "nspawn":
err := withNetworkNamespace(func(ns netNS) error {
return withBootedNspawnImage(imagePath, outputID, ns, func() error { return withBootedNspawnImage(imagePath, outputID, ns, func() error {
testSSH(t, "localhost", &ns) testSSH(t, "localhost", &ns)
return nil 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 withExtractedTarArchive(imagePath, func(dir string) error {
return withBootedNspawnDirectory(dir, outputID, ns, func() error { return withBootedNspawnDirectory(dir, outputID, ns, func() error {
testSSH(t, "localhost", &ns) testSSH(t, "localhost", &ns)
return nil 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 // testImage performs a series of tests specified in the testcase