mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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). Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
d283c7fa2b
commit
175b1d7830
2 changed files with 35 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -151,6 +154,26 @@ func (e *Execution) IsUserNamespace() bool {
|
|||
return root != ""
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
|
Loading…
Reference in a new issue