From 5bd0437eedf8036b9648dd095b22d0772fa47e4d Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 20 Sep 2013 12:46:24 +0000 Subject: [PATCH 1/3] abord build if mergeConfig returns an error and fix duplicate error message --- api.go | 3 +-- runtime.go | 4 +++- utils.go | 8 ++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/api.go b/api.go index f984b1c49f..9bba627743 100644 --- a/api.go +++ b/api.go @@ -892,8 +892,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ b := NewBuildFile(srv, utils.NewWriteFlusher(w), !suppressOutput, !noCache, rm) id, err := b.Build(context) if err != nil { - fmt.Fprintf(w, "Error build: %s\n", err) - return err + return fmt.Errorf("Error build: %s", err) } if repoName != "" { srv.runtime.repositories.Set(repoName, tag, id, false) diff --git a/runtime.go b/runtime.go index aff1773fdf..cb37a82304 100644 --- a/runtime.go +++ b/runtime.go @@ -282,7 +282,9 @@ func (runtime *Runtime) Create(config *Config) (*Container, error) { } if img.Config != nil { - MergeConfig(config, img.Config) + if err := MergeConfig(config, img.Config); err != nil { + return nil, err + } } if len(config.Entrypoint) != 0 && config.Cmd == nil { diff --git a/utils.go b/utils.go index aed8ffdd76..769f49919a 100644 --- a/utils.go +++ b/utils.go @@ -65,7 +65,7 @@ func CompareConfig(a, b *Config) bool { return true } -func MergeConfig(userConf, imageConf *Config) { +func MergeConfig(userConf, imageConf *Config) error { if userConf.User == "" { userConf.User = imageConf.User } @@ -85,7 +85,10 @@ func MergeConfig(userConf, imageConf *Config) { found := false imageNat, _ := parseNat(imagePortSpec) for _, userPortSpec := range userConf.PortSpecs { - userNat, _ := parseNat(userPortSpec) + userNat, err := parseNat(userPortSpec) + if err != nil { + return err + } if imageNat.Proto == userNat.Proto && imageNat.Backend == userNat.Backend { found = true } @@ -146,6 +149,7 @@ func MergeConfig(userConf, imageConf *Config) { userConf.Volumes[k] = v } } + return nil } func parseLxcConfOpts(opts ListOpts) ([]KeyValuePair, error) { From 1328be7c299417aa8c8740ac4901a978724afa9b Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 3 Oct 2013 14:46:07 +0000 Subject: [PATCH 2/3] Add test --- runtime_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/runtime_test.go b/runtime_test.go index f4f5d5af1e..09056aafd1 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -203,6 +203,29 @@ func TestRuntimeCreate(t *testing.T) { if err == nil { t.Fatal("Builder.Create should throw an error when Cmd is empty") } + + config := &Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"/bin/ls"}, + PortSpecs: []string{"80"}, + } + container, err = runtime.Create(config) + + image, err := runtime.Commit(container, "testrepo", "testtag", "", "", config) + if err != nil { + t.Error(err) + } + + _, err = runtime.Create( + &Config{ + Image: image.ID, + PortSpecs: []string{"80000:80"}, + }, + ) + if err == nil { + t.Fatal("Builder.Create should throw an error when PortSpecs is invalid") + } + } func TestDestroy(t *testing.T) { From f84dc1e90858924f9fafe89e81005842a6b4f166 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 3 Oct 2013 22:33:00 +0000 Subject: [PATCH 3/3] add missing error check --- utils.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 769f49919a..8d821e87ff 100644 --- a/utils.go +++ b/utils.go @@ -83,7 +83,10 @@ func MergeConfig(userConf, imageConf *Config) error { } else { for _, imagePortSpec := range imageConf.PortSpecs { found := false - imageNat, _ := parseNat(imagePortSpec) + imageNat, err := parseNat(imagePortSpec) + if err != nil { + return err + } for _, userPortSpec := range userConf.PortSpecs { userNat, err := parseNat(userPortSpec) if err != nil {