Skip to content

Commit

Permalink
bindings tests: bail out early on image errors
Browse files Browse the repository at this point in the history
If Pull() fails, which it does on registry or network flakes,
bail out early: there's no point in continuing. Same with
Save() and restoreImageFromCache(), although those are
unlikely to fail.

Possibly better solution: retry with backoff. Left as exercise
for future maintainer.

Use Expect() for failure checks, and correct two existing
instances of Printf()/Exit() to also use Expect().

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed Apr 19, 2023
1 parent 53d8e4b commit 5f5bea0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pkg/bindings/test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
"github.com/containers/podman/v4/pkg/bindings/containers"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega/gexec"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

type testImage struct {
Expand Down Expand Up @@ -71,7 +72,7 @@ func (b *bindingTest) NewConnection() error {
return nil
}

func (b *bindingTest) runPodman(command []string) *gexec.Session {
func (b *bindingTest) runPodman(command []string) *Session {
var cmd []string
podmanBinary := getPodmanBinary()
val, ok := os.LookupEnv("PODMAN_BINARY")
Expand Down Expand Up @@ -123,7 +124,7 @@ func (b *bindingTest) runPodman(command []string) *gexec.Session {
cmd = append(cmd, command...)
c := exec.Command(podmanBinary, cmd...)
fmt.Printf("Running: %s %s\n", podmanBinary, strings.Join(cmd, " "))
session, err := gexec.Start(c, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
session, err := Start(c, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
if err != nil {
panic(fmt.Errorf("unable to run podman command: %q", cmd))
}
Expand All @@ -148,7 +149,7 @@ func createTempDirInTempDir() (string, error) {
return os.MkdirTemp("", "libpod_api")
}

func (b *bindingTest) startAPIService() *gexec.Session {
func (b *bindingTest) startAPIService() *Session {
cmd := []string{"--log-level=debug", "system", "service", "--timeout=0", b.sock}
session := b.runPodman(cmd)

Expand Down Expand Up @@ -178,11 +179,13 @@ func (b *bindingTest) cleanup() {
func (b *bindingTest) Pull(name string) {
p := b.runPodman([]string{"pull", name})
p.Wait(45)
Expect(p).To(Exit(0))
}

func (b *bindingTest) Save(i testImage) {
p := b.runPodman([]string{"save", "-o", filepath.Join(ImageCacheDir, i.tarballName), i.name})
p.Wait(45)
Expect(p).To(Exit(0))
}

func (b *bindingTest) RestoreImagesFromCache() {
Expand All @@ -193,6 +196,7 @@ func (b *bindingTest) RestoreImagesFromCache() {
func (b *bindingTest) restoreImageFromCache(i testImage) {
p := b.runPodman([]string{"load", "-i", filepath.Join(ImageCacheDir, i.tarballName)})
p.Wait(45)
Expect(p).To(Exit(0))
}

// Run a container within or without a pod
Expand Down Expand Up @@ -255,19 +259,15 @@ func StringInSlice(s string, sl []string) bool {

var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
// make cache dir
if err := os.MkdirAll(ImageCacheDir, 0777); err != nil {
fmt.Printf("%q\n", err)
os.Exit(1)
}
err := os.MkdirAll(ImageCacheDir, 0777)
Expect(err).ToNot(HaveOccurred())

// If running localized tests, the cache dir is created and populated. if the
// tests are remote, this is a no-op
createCache()
path, err := os.MkdirTemp("", "libpodlock")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
Expect(err).ToNot(HaveOccurred())

return []byte(path)
}, func(data []byte) {
LockTmpDir = string(data)
Expand Down

0 comments on commit 5f5bea0

Please sign in to comment.