From 28d14ad12791b73b652685cc9c810a2a209a748d Mon Sep 17 00:00:00 2001 From: Matthew Sykes Date: Thu, 24 May 2018 14:21:56 -0400 Subject: [PATCH] [FAB-10329] Fail fast when required image missing The integration tests expect ccenv and third party docker images have been pulled before the tests start. When any of these images are missing, fail the tests quickly with a clear message. Change-Id: If183a531c7fcee01e01191b04ccfc746dd19ffbc Signed-off-by: Matthew Sykes --- integration/helpers/images.go | 32 ++++++++++++++++++++++++++++++++ integration/runner/couchdb.go | 4 ++-- integration/world/components.go | 10 ++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 integration/helpers/images.go diff --git a/integration/helpers/images.go b/integration/helpers/images.go new file mode 100644 index 00000000000..50309387a83 --- /dev/null +++ b/integration/helpers/images.go @@ -0,0 +1,32 @@ +/* +Copyright IBM Corp All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package helpers + +import ( + "fmt" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + docker "github.com/fsouza/go-dockerclient" +) + +func AssertImagesExist(imageNames ...string) { + dockerClient, err := docker.NewClientFromEnv() + Expect(err).NotTo(HaveOccurred()) + + for _, imageName := range imageNames { + images, err := dockerClient.ListImages(docker.ListImagesOptions{ + Filter: imageName, + }) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + + if len(images) != 1 { + Fail(fmt.Sprintf("missing required image: %s", imageName), 1) + } + } +} diff --git a/integration/runner/couchdb.go b/integration/runner/couchdb.go index dbb56f7b859..90a55cfd3bc 100644 --- a/integration/runner/couchdb.go +++ b/integration/runner/couchdb.go @@ -22,7 +22,7 @@ import ( "github.com/tedsuo/ifrit" ) -const DefaultCouchDBImage = "hyperledger/fabric-couchdb:latest" +const CouchDBDefaultImage = "hyperledger/fabric-couchdb:latest" // CouchDB manages the execution of an instance of a dockerized CounchDB // for tests. @@ -50,7 +50,7 @@ type CouchDB struct { // Run runs a CouchDB container. It implements the ifrit.Runner interface func (c *CouchDB) Run(sigCh <-chan os.Signal, ready chan<- struct{}) error { if c.Image == "" { - c.Image = DefaultCouchDBImage + c.Image = CouchDBDefaultImage } if c.Name == "" { diff --git a/integration/world/components.go b/integration/world/components.go index 09b84074039..3e0460996f6 100644 --- a/integration/world/components.go +++ b/integration/world/components.go @@ -11,6 +11,7 @@ import ( "time" docker "github.com/fsouza/go-dockerclient" + "github.com/hyperledger/fabric/integration/helpers" "github.com/hyperledger/fabric/integration/runner" . "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" @@ -21,7 +22,16 @@ type Components struct { Paths map[string]string } +var RequiredImages = []string{ + "hyperledger/fabric-ccenv:latest", + runner.CouchDBDefaultImage, + runner.KafkaDefaultImage, + runner.ZookeeperDefaultImage, +} + func (c *Components) Build(args ...string) { + helpers.AssertImagesExist(RequiredImages...) + if c.Paths == nil { c.Paths = map[string]string{} }