From ce375503477c82a76ce8530e73655fbbf5046834 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Mon, 12 Dec 2016 09:33:58 +0100 Subject: [PATCH] Move debug functions to cli/debug package Signed-off-by: Vincent Demeester --- cli/command/system/info.go | 4 ++-- {utils => cli/debug}/debug.go | 14 +++++++------- {utils => cli/debug}/debug_test.go | 20 ++++++++++---------- cmd/docker/docker.go | 4 ++-- cmd/docker/docker_test.go | 4 ++-- cmd/dockerd/daemon.go | 12 ++++++------ daemon/info.go | 4 ++-- 7 files changed, 31 insertions(+), 31 deletions(-) rename {utils => cli/debug}/debug.go (55%) rename {utils => cli/debug}/debug_test.go (74%) diff --git a/cli/command/system/info.go b/cli/command/system/info.go index e0b8767377..6c3487de8a 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -12,8 +12,8 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" + "github.com/docker/docker/cli/debug" "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/utils" "github.com/docker/docker/utils/templates" "github.com/docker/go-units" "github.com/spf13/cobra" @@ -206,7 +206,7 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error { ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Name: %s\n", info.Name) ioutils.FprintfIfNotEmpty(dockerCli.Out(), "ID: %s\n", info.ID) fmt.Fprintf(dockerCli.Out(), "Docker Root Dir: %s\n", info.DockerRootDir) - fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", utils.IsDebugEnabled()) + fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", debug.IsEnabled()) fmt.Fprintf(dockerCli.Out(), "Debug Mode (server): %v\n", info.Debug) if info.Debug { diff --git a/utils/debug.go b/cli/debug/debug.go similarity index 55% rename from utils/debug.go rename to cli/debug/debug.go index d203891129..51dfab2a97 100644 --- a/utils/debug.go +++ b/cli/debug/debug.go @@ -1,4 +1,4 @@ -package utils +package debug import ( "os" @@ -6,21 +6,21 @@ import ( "github.com/Sirupsen/logrus" ) -// EnableDebug sets the DEBUG env var to true +// Enable sets the DEBUG env var to true // and makes the logger to log at debug level. -func EnableDebug() { +func Enable() { os.Setenv("DEBUG", "1") logrus.SetLevel(logrus.DebugLevel) } -// DisableDebug sets the DEBUG env var to false +// Disable sets the DEBUG env var to false // and makes the logger to log at info level. -func DisableDebug() { +func Disable() { os.Setenv("DEBUG", "") logrus.SetLevel(logrus.InfoLevel) } -// IsDebugEnabled checks whether the debug flag is set or not. -func IsDebugEnabled() bool { +// IsEnabled checks whether the debug flag is set or not. +func IsEnabled() bool { return os.Getenv("DEBUG") != "" } diff --git a/utils/debug_test.go b/cli/debug/debug_test.go similarity index 74% rename from utils/debug_test.go rename to cli/debug/debug_test.go index 6f9c4dfbb0..ad8412a944 100644 --- a/utils/debug_test.go +++ b/cli/debug/debug_test.go @@ -1,4 +1,4 @@ -package utils +package debug import ( "os" @@ -7,12 +7,12 @@ import ( "github.com/Sirupsen/logrus" ) -func TestEnableDebug(t *testing.T) { +func TestEnable(t *testing.T) { defer func() { os.Setenv("DEBUG", "") logrus.SetLevel(logrus.InfoLevel) }() - EnableDebug() + Enable() if os.Getenv("DEBUG") != "1" { t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG")) } @@ -21,8 +21,8 @@ func TestEnableDebug(t *testing.T) { } } -func TestDisableDebug(t *testing.T) { - DisableDebug() +func TestDisable(t *testing.T) { + Disable() if os.Getenv("DEBUG") != "" { t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG")) } @@ -31,13 +31,13 @@ func TestDisableDebug(t *testing.T) { } } -func TestDebugEnabled(t *testing.T) { - EnableDebug() - if !IsDebugEnabled() { +func TestEnabled(t *testing.T) { + Enable() + if !IsEnabled() { t.Fatal("expected debug enabled, got false") } - DisableDebug() - if IsDebugEnabled() { + Disable() + if IsEnabled() { t.Fatal("expected debug disabled, got true") } } diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index d4847a90ee..f4033738b7 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -10,11 +10,11 @@ import ( "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/commands" + "github.com/docker/docker/cli/debug" cliflags "github.com/docker/docker/cli/flags" "github.com/docker/docker/cliconfig" "github.com/docker/docker/dockerversion" "github.com/docker/docker/pkg/term" - "github.com/docker/docker/utils" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -130,7 +130,7 @@ func dockerPreRun(opts *cliflags.ClientOptions) { } if opts.Common.Debug { - utils.EnableDebug() + debug.Enable() } } diff --git a/cmd/docker/docker_test.go b/cmd/docker/docker_test.go index 8738f6005d..f8a5297ed4 100644 --- a/cmd/docker/docker_test.go +++ b/cmd/docker/docker_test.go @@ -7,12 +7,12 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/cli/command" + "github.com/docker/docker/cli/debug" "github.com/docker/docker/pkg/testutil/assert" - "github.com/docker/docker/utils" ) func TestClientDebugEnabled(t *testing.T) { - defer utils.DisableDebug() + defer debug.Disable() cmd := newDockerCommand(&command.DockerCli{}) cmd.Flags().Set("debug", "true") diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index be8025fd98..a223467821 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -26,6 +26,7 @@ import ( systemrouter "github.com/docker/docker/api/server/router/system" "github.com/docker/docker/api/server/router/volume" "github.com/docker/docker/builder/dockerfile" + "github.com/docker/docker/cli/debug" cliflags "github.com/docker/docker/cli/flags" "github.com/docker/docker/cliconfig" "github.com/docker/docker/daemon" @@ -44,7 +45,6 @@ import ( "github.com/docker/docker/plugin" "github.com/docker/docker/registry" "github.com/docker/docker/runconfig" - "github.com/docker/docker/utils" "github.com/docker/go-connections/tlsconfig" "github.com/spf13/pflag" ) @@ -137,7 +137,7 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) { } if cli.Config.Debug { - utils.EnableDebug() + debug.Enable() } if cli.Config.Experimental { @@ -351,13 +351,13 @@ func (cli *DaemonCli) reloadConfig() { } if config.IsValueSet("debug") { - debugEnabled := utils.IsDebugEnabled() + debugEnabled := debug.IsEnabled() switch { case debugEnabled && !config.Debug: // disable debug - utils.DisableDebug() + debug.Disable() cli.api.DisableProfiler() case config.Debug && !debugEnabled: // enable debug - utils.EnableDebug() + debug.Enable() cli.api.EnableProfiler() } @@ -488,7 +488,7 @@ func initRouter(s *apiserver.Server, d *daemon.Daemon, c *cluster.Cluster) { } } - s.InitRouter(utils.IsDebugEnabled(), routers...) + s.InitRouter(debug.IsEnabled(), routers...) } func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config) error { diff --git a/daemon/info.go b/daemon/info.go index 1ab9f29592..4ee5b1c377 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -10,6 +10,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/api" "github.com/docker/docker/api/types" + "github.com/docker/docker/cli/debug" "github.com/docker/docker/container" "github.com/docker/docker/dockerversion" "github.com/docker/docker/pkg/fileutils" @@ -19,7 +20,6 @@ import ( "github.com/docker/docker/pkg/sysinfo" "github.com/docker/docker/pkg/system" "github.com/docker/docker/registry" - "github.com/docker/docker/utils" "github.com/docker/docker/volume/drivers" "github.com/docker/go-connections/sockets" ) @@ -102,7 +102,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) { IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled, BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled, - Debug: utils.IsDebugEnabled(), + Debug: debug.IsEnabled(), NFd: fileutils.GetTotalUsedFds(), NGoroutines: runtime.NumGoroutine(), SystemTime: time.Now().Format(time.RFC3339Nano),