ea139541fa
OBS-URL: https://build.opensuse.org/package/show/Virtualization:containers/docker?expand=0&rev=302
122 lines
4.2 KiB
Diff
122 lines
4.2 KiB
Diff
From 87416bfab7420bb5d0b18269909eb71dcb8632c6 Mon Sep 17 00:00:00 2001
|
|
From: Aleksa Sarai <asarai@suse.de>
|
|
Date: Tue, 12 Mar 2019 18:37:31 +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.
|
|
|
|
However, this does remove the accidental re-compilation of nnp-test, as
|
|
well as handling errors far more cleanly (previously if an error
|
|
occurred during a test build, further tests won't attempt to rebuild
|
|
it).
|
|
|
|
SUSE-Bugs: bsc#1128746
|
|
Signed-off-by: Aleksa Sarai <asarai@suse.de>
|
|
---
|
|
.../fixtures_linux_daemon_test.go | 21 +++++++++--------
|
|
.../internal/test/environment/environment.go | 23 +++++++++++++++++++
|
|
2 files changed, 35 insertions(+), 9 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..0a770a76a2a9 100644
|
|
--- a/components/engine/integration-cli/fixtures_linux_daemon_test.go
|
|
+++ b/components/engine/integration-cli/fixtures_linux_daemon_test.go
|
|
@@ -8,7 +8,6 @@ import (
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
- "sync"
|
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
"github.com/docker/docker/internal/test/fixtures/load"
|
|
@@ -24,17 +23,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 +88,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..e1c8a49ea8cb 100644
|
|
--- a/components/engine/internal/test/environment/environment.go
|
|
+++ b/components/engine/internal/test/environment/environment.go
|
|
@@ -8,9 +8,12 @@ import (
|
|
"strings"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
+ "github.com/docker/docker/api/types/filters"
|
|
"github.com/docker/docker/client"
|
|
+ "github.com/docker/docker/internal/test"
|
|
"github.com/docker/docker/internal/test/fixtures/load"
|
|
"github.com/pkg/errors"
|
|
+ "gotest.tools/assert"
|
|
)
|
|
|
|
// Execution contains information about the current test execution and daemon
|
|
@@ -145,6 +148,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
|
|
|