Skip to content

Commit

Permalink
imgtype: don't log at Fatal level
Browse files Browse the repository at this point in the history
Logging at Fatal calls os.Exit(), which keeps us from shutting down
storage properly, which prevents test cleanup from succeeding.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #162
Approved by: rhatdan
  • Loading branch information
nalind authored and rh-atomic-bot committed Jun 28, 2017
1 parent a2bd274 commit 7225365
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions tests/imgtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"flag"
"fmt"
"os"
"strings"

"github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -49,8 +50,9 @@ func main() {
expectedManifestType = ""
expectedConfigType = ""
default:
logrus.Fatalf("unknown -expected-manifest-type value, expected either %q or %q or %q",
logrus.Errorf("unknown -expected-manifest-type value, expected either %q or %q or %q",
buildah.OCIv1ImageManifest, buildah.Dockerv2ImageManifest, "*")
return
}
if root != nil {
storeOptions.GraphRoot = *root
Expand All @@ -74,10 +76,17 @@ func main() {
}
store, err := storage.GetStore(storeOptions)
if err != nil {
logrus.Fatalf("error opening storage: %v", err)
logrus.Errorf("error opening storage: %v", err)
return
}
defer store.Shutdown(false)

errors := false
defer func() {
store.Shutdown(false)
if errors {
os.Exit(1)
}
}()
for _, image := range args {
oImage := v1.Image{}
dImage := docker.V2Image{}
Expand All @@ -88,54 +97,74 @@ func main() {

ref, err := is.Transport.ParseStoreReference(store, image)
if err != nil {
logrus.Fatalf("error parsing reference %q: %v", image, err)
logrus.Errorf("error parsing reference %q: %v", image, err)
errors = true
continue
}

img, err := ref.NewImage(systemContext)
if err != nil {
logrus.Fatalf("error opening image %q: %v", image, err)
logrus.Errorf("error opening image %q: %v", image, err)
errors = true
continue
}
defer img.Close()

config, err := img.ConfigBlob()
if err != nil {
logrus.Fatalf("error reading configuration from %q: %v", image, err)
logrus.Errorf("error reading configuration from %q: %v", image, err)
errors = true
continue
}

manifest, manifestType, err := img.Manifest()
if err != nil {
logrus.Fatalf("error reading manifest from %q: %v", image, err)
logrus.Errorf("error reading manifest from %q: %v", image, err)
errors = true
continue
}

switch expectedManifestType {
case buildah.OCIv1ImageManifest:
err = json.Unmarshal(manifest, &oManifest)
if err != nil {
logrus.Fatalf("error parsing manifest from %q: %v", image, err)
logrus.Errorf("error parsing manifest from %q: %v", image, err)
errors = true
continue
}
err = json.Unmarshal(config, &oImage)
if err != nil {
logrus.Fatalf("error parsing config from %q: %v", image, err)
logrus.Errorf("error parsing config from %q: %v", image, err)
errors = true
continue
}
manifestType = v1.MediaTypeImageManifest
configType = oManifest.Config.MediaType
case buildah.Dockerv2ImageManifest:
err = json.Unmarshal(manifest, &dManifest)
if err != nil {
logrus.Fatalf("error parsing manifest from %q: %v", image, err)
logrus.Errorf("error parsing manifest from %q: %v", image, err)
errors = true
continue
}
err = json.Unmarshal(config, &dImage)
if err != nil {
logrus.Fatalf("error parsing config from %q: %v", image, err)
logrus.Errorf("error parsing config from %q: %v", image, err)
errors = true
continue
}
manifestType = dManifest.MediaType
configType = dManifest.Config.MediaType
}
if expectedManifestType != "" && manifestType != expectedManifestType {
logrus.Fatalf("expected manifest type %q in %q, got %q", expectedManifestType, image, manifestType)
logrus.Errorf("expected manifest type %q in %q, got %q", expectedManifestType, image, manifestType)
errors = true
continue
}
if expectedConfigType != "" && configType != expectedConfigType {
logrus.Fatalf("expected config type %q in %q, got %q", expectedConfigType, image, configType)
logrus.Errorf("expected config type %q in %q, got %q", expectedConfigType, image, configType)
errors = true
continue
}
if showm != nil && *showm {
fmt.Println(string(manifest))
Expand Down

0 comments on commit 7225365

Please sign in to comment.