Skip to content

Commit

Permalink
Fix tests and windows service.
Browse files Browse the repository at this point in the history
Support args to RunCommand
Fix docker help text test.
Fix for ipv6 tests.
Fix TLSverify option.
Fix TestDaemonDiscoveryBackendConfigReload
Use tempfile for another test.
Restore missing flag.
Fix tests for removal of shlex.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
  • Loading branch information
dnephin committed Aug 25, 2016
1 parent 14712f9 commit 6e7405e
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 118 deletions.
5 changes: 4 additions & 1 deletion cli/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func FlagErrorFunc(cmd *cobra.Command, err error) error {
if cmd.HasSubCommands() {
usage = "\n\n" + cmd.UsageString()
}
return fmt.Errorf("%s\nSee '%s --help'.%s", err, cmd.CommandPath(), usage)
return StatusError{
Status: fmt.Sprintf("%s\nSee '%s --help'.%s", err, cmd.CommandPath(), usage),
StatusCode: 125,
}
}

var usageTemplate = `Usage: {{if not .HasSubCommands}}{{.UseLine}}{{end}}{{if .HasSubCommands}}{{ .CommandPath}} COMMAND{{end}}
Expand Down
3 changes: 2 additions & 1 deletion cmd/docker/daemon_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ package main

import (
"fmt"
"github.com/spf13/cobra"
"runtime"
"strings"

"github.com/spf13/cobra"
)

func newDaemonCommand() *cobra.Command {
Expand Down
21 changes: 16 additions & 5 deletions cmd/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import (

func newDockerCommand(dockerCli *client.DockerCli) *cobra.Command {
opts := cliflags.NewClientOptions()
var flags *pflag.FlagSet

cmd := &cobra.Command{
Use: "docker [OPTIONS] COMMAND [arg...]",
Short: "A self-sufficient runtime for containers.",
SilenceUsage: true,
SilenceErrors: true,
TraverseChildren: true,
Args: cli.NoArgs,
Args: noArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Version {
showVersion()
Expand All @@ -35,13 +37,15 @@ func newDockerCommand(dockerCli *client.DockerCli) *cobra.Command {
return nil
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
dockerPreRun(cmd.Flags(), opts)
// flags must be the top-level command flags, not cmd.Flags()
opts.Common.SetDefaultOptions(flags)
dockerPreRun(opts)
return dockerCli.Initialize(opts)
},
}
cli.SetupRootCommand(cmd)

flags := cmd.Flags()
flags = cmd.Flags()
flags.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit")
flags.StringVar(&opts.ConfigDir, "config", cliconfig.ConfigDir(), "Location of client config files")
opts.Common.InstallFlags(flags)
Expand All @@ -53,6 +57,14 @@ func newDockerCommand(dockerCli *client.DockerCli) *cobra.Command {
return cmd
}

func noArgs(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return nil
}
return fmt.Errorf(
"docker: '%s' is not a docker command.\nSee 'docker --help'%s", args[0], ".")
}

func main() {
// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()
Expand Down Expand Up @@ -86,8 +98,7 @@ func showVersion() {
}
}

func dockerPreRun(flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
opts.Common.SetDefaultOptions(flags)
func dockerPreRun(opts *cliflags.ClientOptions) {
cliflags.SetDaemonLogLevel(opts.Common.LogLevel)

if opts.ConfigDir != "" {
Expand Down
10 changes: 7 additions & 3 deletions cmd/dockerd/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"

"github.com/Sirupsen/logrus"
"github.com/docker/docker/cli"
Expand Down Expand Up @@ -58,9 +59,11 @@ func runDaemon(opts daemonOptions) error {
return nil
}

daemonCli := NewDaemonCli()

// On Windows, this may be launching as a service or with an option to
// register the service.
stop, err := initService()
stop, err := initService(daemonCli)
if err != nil {
logrus.Fatal(err)
}
Expand All @@ -69,7 +72,7 @@ func runDaemon(opts daemonOptions) error {
return nil
}

err = NewDaemonCli().start(opts)
err = daemonCli.start(opts)
notifyShutdown(err)
return err
}
Expand All @@ -94,6 +97,7 @@ func main() {
cmd := newDaemonCommand()
cmd.SetOutput(stdout)
if err := cmd.Execute(); err != nil {
logrus.Fatal(err)
fmt.Fprintf(stderr, "%s\n", err)
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion cmd/dockerd/service_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/pflag"
)

func initService() (bool, error) {
func initService(daemonCli *DaemonCli) (bool, error) {
return false, nil
}

Expand Down
19 changes: 10 additions & 9 deletions cmd/dockerd/service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -53,8 +52,9 @@ func installServiceFlags(flags *pflag.FlagSet) {
}

type handler struct {
tosvc chan bool
fromsvc chan error
tosvc chan bool
fromsvc chan error
daemonCli *DaemonCli
}

type etwHook struct {
Expand Down Expand Up @@ -211,7 +211,7 @@ func unregisterService() error {
return nil
}

func initService() (bool, error) {
func initService(daemonCli *DaemonCli) (bool, error) {
if *flUnregisterService {
if *flRegisterService {
return true, errors.New("--register-service and --unregister-service cannot be used together")
Expand All @@ -233,8 +233,9 @@ func initService() (bool, error) {
}

h := &handler{
tosvc: make(chan bool),
fromsvc: make(chan error),
tosvc: make(chan bool),
fromsvc: make(chan error),
daemonCli: daemonCli,
}

var log *eventlog.Log
Expand Down Expand Up @@ -269,7 +270,7 @@ func initService() (bool, error) {

func (h *handler) started() error {
// This must be delayed until daemonCli initializes Config.Root
err := initPanicFile(filepath.Join(daemonCli.Config.Root, "panic.log"))
err := initPanicFile(filepath.Join(h.daemonCli.Config.Root, "panic.log"))
if err != nil {
return err
}
Expand Down Expand Up @@ -306,12 +307,12 @@ Loop:
case c := <-r:
switch c.Cmd {
case svc.Cmd(windows.SERVICE_CONTROL_PARAMCHANGE):
daemonCli.reloadConfig()
h.daemonCli.reloadConfig()
case svc.Interrogate:
s <- c.CurrentStatus
case svc.Stop, svc.Shutdown:
s <- svc.Status{State: svc.StopPending, Accepts: 0}
daemonCli.stop()
h.daemonCli.stop()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions daemon/config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (config *Config) InstallFlags(flags *pflag.FlagSet) {

// Then platform-specific install flags
flags.BoolVar(&config.EnableSelinuxSupport, "selinux-enabled", false, "Enable selinux support")
flags.StringVarP(&config.SocketGroup, "group", "G", "docker", "Group for the unix socket")
flags.Var(runconfigopts.NewUlimitOpt(&config.Ulimits), "default-ulimit", "Default ulimits for containers")
flags.BoolVar(&config.bridgeConfig.EnableIPTables, "iptables", true, "Enable addition of iptables rules")
flags.BoolVar(&config.bridgeConfig.EnableIPForward, "ip-forward", true, "Enable net.ipv4.ip_forward")
Expand Down
12 changes: 6 additions & 6 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1555,12 +1555,12 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
c.Fatalf("failed to chmod file to 700: %s", err)
}

buildCmd := exec.Command("su", "unprivilegeduser", "-c", fmt.Sprintf("%s build -t %s .", dockerBinary, name))
buildCmd.Dir = ctx.Dir
if out, _, err := runCommandWithOutput(buildCmd); err != nil {
c.Fatalf("build should have worked: %s %s", err, out)
}

result := icmd.RunCmd(icmd.Cmd{
Dir: ctx.Dir,
Command: []string{"su", "unprivilegeduser", "-c",
fmt.Sprintf("%s build -t %s .", dockerBinary, name)},
})
result.Assert(c, icmd.Expected{})
}
}

Expand Down
8 changes: 4 additions & 4 deletions integration-cli/docker_cli_cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/docker/docker/pkg/integration/checker"
icmd "github.com/docker/docker/pkg/integration/cmd"
"github.com/go-check/check"
)

Expand Down Expand Up @@ -399,10 +400,9 @@ func (s *DockerSuite) TestCpUnprivilegedUser(c *check.C) {

c.Assert(os.Chmod(tmpdir, 0777), checker.IsNil)

path := cpTestName

_, _, err = runCommandWithOutput(exec.Command("su", "unprivilegeduser", "-c", dockerBinary+" cp "+containerID+":"+path+" "+tmpdir))
c.Assert(err, checker.IsNil, check.Commentf("couldn't copy with unprivileged user: %s:%s", containerID, path))
result := icmd.RunCommand("su", "unprivilegeduser", "-c",
fmt.Sprintf("%s cp %s:%s %s", dockerBinary, containerID, cpTestName, tmpdir))
result.Assert(c, icmd.Expected{})
}

func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
Expand Down

0 comments on commit 6e7405e

Please sign in to comment.