Browse code

[integration] ensure frozen images are loaded

Ensures that the frozen test images are loaded in the daemon
before any tests are run.

Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>

Christopher Jones authored on 2017/10/19 06:59:16
Showing 9 changed files
... ...
@@ -17,6 +17,7 @@ import (
17 17
 )
18 18
 
19 19
 func TestBuildWithRemoveAndForceRemove(t *testing.T) {
20
+	defer setupTest(t)()
20 21
 	t.Parallel()
21 22
 	cases := []struct {
22 23
 		name                           string
... ...
@@ -17,6 +17,11 @@ func TestMain(m *testing.M) {
17 17
 		fmt.Println(err)
18 18
 		os.Exit(1)
19 19
 	}
20
+	err = environment.EnsureFrozenImagesLinux(testEnv)
21
+	if err != nil {
22
+		fmt.Println(err)
23
+		os.Exit(1)
24
+	}
20 25
 
21 26
 	testEnv.Print()
22 27
 	os.Exit(m.Run())
... ...
@@ -17,6 +17,11 @@ func TestMain(m *testing.M) {
17 17
 		fmt.Println(err)
18 18
 		os.Exit(1)
19 19
 	}
20
+	err = environment.EnsureFrozenImagesLinux(testEnv)
21
+	if err != nil {
22
+		fmt.Println(err)
23
+		os.Exit(1)
24
+	}
20 25
 
21 26
 	testEnv.Print()
22 27
 	os.Exit(m.Run())
... ...
@@ -17,6 +17,11 @@ func TestMain(m *testing.M) {
17 17
 		fmt.Println(err)
18 18
 		os.Exit(1)
19 19
 	}
20
+	err = environment.EnsureFrozenImagesLinux(testEnv)
21
+	if err != nil {
22
+		fmt.Println(err)
23
+		os.Exit(1)
24
+	}
20 25
 
21 26
 	testEnv.Print()
22 27
 	os.Exit(m.Run())
... ...
@@ -33,6 +33,11 @@ func TestMain(m *testing.M) {
33 33
 		fmt.Println(err)
34 34
 		os.Exit(1)
35 35
 	}
36
+	err = environment.EnsureFrozenImagesLinux(testEnv)
37
+	if err != nil {
38
+		fmt.Println(err)
39
+		os.Exit(1)
40
+	}
36 41
 
37 42
 	testEnv.Print()
38 43
 	setupSuite()
... ...
@@ -19,6 +19,11 @@ func TestMain(m *testing.M) {
19 19
 		fmt.Println(err)
20 20
 		os.Exit(1)
21 21
 	}
22
+	err = environment.EnsureFrozenImagesLinux(testEnv)
23
+	if err != nil {
24
+		fmt.Println(err)
25
+		os.Exit(1)
26
+	}
22 27
 
23 28
 	testEnv.Print()
24 29
 	os.Exit(m.Run())
... ...
@@ -17,6 +17,11 @@ func TestMain(m *testing.M) {
17 17
 		fmt.Println(err)
18 18
 		os.Exit(1)
19 19
 	}
20
+	err = environment.EnsureFrozenImagesLinux(testEnv)
21
+	if err != nil {
22
+		fmt.Println(err)
23
+		os.Exit(1)
24
+	}
20 25
 
21 26
 	testEnv.Print()
22 27
 	os.Exit(m.Run())
... ...
@@ -8,6 +8,7 @@ import (
8 8
 
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/client"
11
+	"github.com/docker/docker/integration-cli/fixtures/load"
11 12
 	"github.com/pkg/errors"
12 13
 	"golang.org/x/net/context"
13 14
 )
... ...
@@ -128,3 +129,15 @@ func (e *Execution) Print() {
128 128
 func (e *Execution) APIClient() client.APIClient {
129 129
 	return e.client
130 130
 }
131
+
132
+// EnsureFrozenImagesLinux loads frozen test images into the daemon
133
+// if they aren't already loaded
134
+func EnsureFrozenImagesLinux(testEnv *Execution) error {
135
+	if testEnv.OSType == "linux" {
136
+		err := load.FrozenImagesLinux(testEnv.APIClient(), frozenImages...)
137
+		if err != nil {
138
+			return errors.Wrap(err, "error loading frozen images")
139
+		}
140
+	}
141
+	return nil
142
+}
... ...
@@ -6,10 +6,11 @@ import (
6 6
 	"github.com/docker/docker/api/types"
7 7
 	"github.com/docker/docker/api/types/filters"
8 8
 	dclient "github.com/docker/docker/client"
9
-	"github.com/docker/docker/integration-cli/fixtures/load"
10 9
 	"github.com/stretchr/testify/require"
11 10
 )
12 11
 
12
+var frozenImages = []string{"busybox:latest", "hello-world:frozen", "debian:jessie"}
13
+
13 14
 type protectedElements struct {
14 15
 	containers map[string]struct{}
15 16
 	images     map[string]struct{}
... ...
@@ -83,7 +84,7 @@ func ProtectImages(t testingT, testEnv *Execution) {
83 83
 	images := getExistingImages(t, testEnv)
84 84
 
85 85
 	if testEnv.OSType == "linux" {
86
-		images = append(images, ensureFrozenImagesLinux(t, testEnv)...)
86
+		images = append(images, frozenImages...)
87 87
 	}
88 88
 	testEnv.ProtectImage(t, images...)
89 89
 }
... ...
@@ -120,15 +121,6 @@ func tagsFromImageSummary(image types.ImageSummary) []string {
120 120
 	return result
121 121
 }
122 122
 
123
-func ensureFrozenImagesLinux(t testingT, testEnv *Execution) []string {
124
-	images := []string{"busybox:latest", "hello-world:frozen", "debian:jessie"}
125
-	err := load.FrozenImagesLinux(testEnv.APIClient(), images...)
126
-	if err != nil {
127
-		t.Fatalf("Failed to load frozen images: %s", err)
128
-	}
129
-	return images
130
-}
131
-
132 123
 // ProtectNetwork adds the specified network(s) to be protected in case of
133 124
 // clean
134 125
 func (e *Execution) ProtectNetwork(t testingT, networks ...string) {