docker/bsc1128746-0001-integration-cli-don-t-build-test-images-if-they-alre.patch

96 lines
3.5 KiB
Diff
Raw Normal View History

From 911af815ea12dacb81afef0a6704c73d48df01d3 Mon Sep 17 00:00:00 2001
From: Aleksa Sarai <asarai@suse.de>
Date: Tue, 12 Mar 2019 18:48:38 +1100
Subject: [PATCH] integration-cli: don't build -test images if they already
exist
There's no need to try to re-build the test images if they already
exist. This change makes basically no difference to the upstream
integration test-suite running, but for users who want to run the
integration-cli suite on a host machine (such as distributions doing
tests) this change allows images to be pre-loaded such that compilers
aren't needed on the test machine.
SUSE-Bugs: bsc#1128746
Signed-off-by: Aleksa Sarai <asarai@suse.de>
---
.../fixtures_linux_daemon_test.go | 20 +++++++++++--------
.../internal/test/environment/environment.go | 20 +++++++++++++++++++
2 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/components/engine/integration-cli/fixtures_linux_daemon_test.go b/components/engine/integration-cli/fixtures_linux_daemon_test.go
index 2387a9ebee2b..ae01180d8523 100644
--- a/components/engine/integration-cli/fixtures_linux_daemon_test.go
+++ b/components/engine/integration-cli/fixtures_linux_daemon_test.go
@@ -24,17 +24,13 @@ type logT interface {
Logf(string, ...interface{})
}
-var ensureSyscallTestOnce sync.Once
-
func ensureSyscallTest(c *check.C) {
- var doIt bool
- ensureSyscallTestOnce.Do(func() {
- doIt = true
- })
- if !doIt {
+ defer testEnv.ProtectImage(c, "syscall-test:latest")
+
+ // If the image already exists, there's nothing left to do.
+ if testEnv.HasExistingImage(c, "syscall-test:latest") {
return
}
- defer testEnv.ProtectImage(c, "syscall-test:latest")
// if no match, must build in docker, which is significantly slower
// (slower mostly because of the vfs graphdriver)
@@ -93,6 +89,14 @@ func ensureSyscallTestBuild(c *check.C) {
func ensureNNPTest(c *check.C) {
defer testEnv.ProtectImage(c, "nnp-test:latest")
+
+ // If the image already exists, there's nothing left to do.
+ if testEnv.HasExistingImage(c, "nnp-test:latest") {
+ return
+ }
+
+ // if no match, must build in docker, which is significantly slower
+ // (slower mostly because of the vfs graphdriver)
if testEnv.OSType != runtime.GOOS {
ensureNNPTestBuild(c)
return
diff --git a/components/engine/internal/test/environment/environment.go b/components/engine/internal/test/environment/environment.go
index 74c8e2ce0ad7..56692a4f6594 100644
--- a/components/engine/internal/test/environment/environment.go
+++ b/components/engine/internal/test/environment/environment.go
@@ -145,6 +145,26 @@ func (e *Execution) APIClient() client.APIClient {
return e.client
}
+// HasExistingImage checks whether there is an image with the given reference.
+// Note that this is done by filtering and then checking whether there were any
+// results -- so ambiguous references might result in false-positives.
+func (e *Execution) HasExistingImage(t TestingT, reference string) bool {
+ if ht, ok := t.(test.HelperT); ok {
+ ht.Helper()
+ }
+ client := e.APIClient()
+ filter := filters.NewArgs()
+ filter.Add("dangling", "false")
+ filter.Add("reference", reference)
+ imageList, err := client.ImageList(context.Background(), types.ImageListOptions{
+ All: true,
+ Filters: filter,
+ })
+ assert.NilError(t, err, "failed to list images")
+
+ return len(imageList) > 0
+}
+
// EnsureFrozenImagesLinux loads frozen test images into the daemon
// if they aren't already loaded
func EnsureFrozenImagesLinux(testEnv *Execution) error {
--
2.21.0