From d3f074494a9594bc268bf4c639a7aea0934ec7c0 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sun, 27 Oct 2013 07:16:32 +0000 Subject: [PATCH] Better error reporting in engine logs and unit tests --- runtime_test.go | 2 +- server.go | 7 ++++++- utils_test.go | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/runtime_test.go b/runtime_test.go index 4aac2f3442..946a8ebf61 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -183,7 +183,7 @@ func GetTestImage(runtime *Runtime) *Image { return image } } - log.Fatalf("Test image %v not found", unitTestImageID) + log.Fatalf("Test image %v not found in %s: %s", unitTestImageID, runtime.graph.Root, imgs) return nil } diff --git a/server.go b/server.go index c041491ead..0a1270bede 100644 --- a/server.go +++ b/server.go @@ -40,6 +40,7 @@ func init() { // Only one api server can run at the same time - this is enforced by a pidfile. // The signals SIGINT, SIGKILL and SIGTERM are intercepted for cleanup. func jobInitApi(job *engine.Job) string { + job.Logf("Creating server") srv, err := NewServer(job.Eng, ConfigFromJob(job)) if err != nil { return err.Error() @@ -50,6 +51,7 @@ func jobInitApi(job *engine.Job) string { log.Fatal(err) } } + job.Logf("Setting up signal traps") c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, os.Kill, os.Signal(syscall.SIGTERM)) go func() { @@ -1288,7 +1290,7 @@ func (srv *Server) RegisterLinks(name string, hostConfig *HostConfig) error { return fmt.Errorf("No such container: %s", name) } - if hostConfig.Links != nil { + if hostConfig != nil && hostConfig.Links != nil { for _, l := range hostConfig.Links { parts, err := parseLink(l) if err != nil { @@ -1317,11 +1319,14 @@ func (srv *Server) RegisterLinks(name string, hostConfig *HostConfig) error { } func (srv *Server) ContainerStart(job *engine.Job) string { + job.Logf("srv engine = %s", srv.Eng.Root()) + job.Logf("job engine = %s", job.Eng.Root()) if len(job.Args) < 1 { return fmt.Sprintf("Usage: %s container_id", job.Name) } name := job.Args[0] runtime := srv.runtime + job.Logf("loading containers from %s", runtime.repository) container := runtime.Get(name) if container == nil { return fmt.Sprintf("No such container: %s", name) diff --git a/utils_test.go b/utils_test.go index 95e12b6393..529af127e5 100644 --- a/utils_test.go +++ b/utils_test.go @@ -41,11 +41,11 @@ func mkRuntime(f utils.Fataler) *Runtime { func mkServerFromEngine(eng *engine.Engine, t utils.Fataler) *Server { iSrv := eng.Hack_GetGlobalVar("httpapi.server") if iSrv == nil { - t.Fatal("Legacy server field not set in engine") + panic("Legacy server field not set in engine") } srv, ok := iSrv.(*Server) if !ok { - t.Fatal("Legacy server field in engine does not cast to *Server") + panic("Legacy server field in engine does not cast to *Server") } return srv }