mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove unnecessary CmdWithArgs
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
0ec20a3c01
commit
c0d2f7b338
6 changed files with 57 additions and 36 deletions
|
@ -435,22 +435,19 @@ func (d *Daemon) getBaseDeviceSize(c *check.C) int64 {
|
|||
|
||||
// Cmd will execute a docker CLI command against this Daemon.
|
||||
// Example: d.Cmd("version") will run docker -H unix://path/to/unix.sock version
|
||||
func (d *Daemon) Cmd(name string, arg ...string) (string, error) {
|
||||
args := []string{"--host", d.sock(), name}
|
||||
args = append(args, arg...)
|
||||
c := exec.Command(dockerBinary, args...)
|
||||
func (d *Daemon) Cmd(args ...string) (string, error) {
|
||||
c := exec.Command(dockerBinary, d.prependHostArg(args)...)
|
||||
b, err := c.CombinedOutput()
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// CmdWithArgs will execute a docker CLI command against a daemon with the
|
||||
// given additional arguments
|
||||
func (d *Daemon) CmdWithArgs(daemonArgs []string, name string, arg ...string) (string, error) {
|
||||
args := append(daemonArgs, name)
|
||||
args = append(args, arg...)
|
||||
c := exec.Command(dockerBinary, args...)
|
||||
b, err := c.CombinedOutput()
|
||||
return string(b), err
|
||||
func (d *Daemon) prependHostArg(args []string) []string {
|
||||
for _, arg := range args {
|
||||
if arg == "--host" || arg == "-H" {
|
||||
return args
|
||||
}
|
||||
}
|
||||
return append([]string{"--host", d.sock()}, args...)
|
||||
}
|
||||
|
||||
// SockRequest executes a socket request on a daemon and returns statuscode and output.
|
||||
|
|
|
@ -15,6 +15,6 @@ func (s *DockerSwarmSuite) getDaemon(c *check.C, nodeID string) *SwarmDaemon {
|
|||
}
|
||||
|
||||
// nodeCmd executes a command on a given node via the normal docker socket
|
||||
func (s *DockerSwarmSuite) nodeCmd(c *check.C, id, cmd string, args ...string) (string, error) {
|
||||
return s.getDaemon(c, id).Cmd(cmd, args...)
|
||||
func (s *DockerSwarmSuite) nodeCmd(c *check.C, id string, args ...string) (string, error) {
|
||||
return s.getDaemon(c, id).Cmd(args...)
|
||||
}
|
||||
|
|
|
@ -987,8 +987,8 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
|
|||
|
||||
// But, Pinging external or a Host interface must succeed
|
||||
pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String())
|
||||
runArgs := []string{"--rm", "busybox", "sh", "-c", pingCmd}
|
||||
_, err = d.Cmd("run", runArgs...)
|
||||
runArgs := []string{"run", "--rm", "busybox", "sh", "-c", pingCmd}
|
||||
_, err = d.Cmd(runArgs...)
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
|
||||
|
@ -1433,8 +1433,14 @@ func (s *DockerDaemonSuite) TestHttpsInfo(c *check.C) {
|
|||
c.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
}
|
||||
|
||||
daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-cert.pem", "--tlskey", "fixtures/https/client-key.pem"}
|
||||
out, err := s.d.CmdWithArgs(daemonArgs, "info")
|
||||
args := []string{
|
||||
"--host", testDaemonHTTPSAddr,
|
||||
"--tlsverify", "--tlscacert", "fixtures/https/ca.pem",
|
||||
"--tlscert", "fixtures/https/client-cert.pem",
|
||||
"--tlskey", "fixtures/https/client-key.pem",
|
||||
"info",
|
||||
}
|
||||
out, err := s.d.Cmd(args...)
|
||||
if err != nil {
|
||||
c.Fatalf("Error Occurred: %s and output: %s", err, out)
|
||||
}
|
||||
|
@ -1452,8 +1458,14 @@ func (s *DockerDaemonSuite) TestHttpsRun(c *check.C) {
|
|||
c.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
}
|
||||
|
||||
daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-cert.pem", "--tlskey", "fixtures/https/client-key.pem"}
|
||||
out, err := s.d.CmdWithArgs(daemonArgs, "run", "busybox", "echo", "TLS response")
|
||||
args := []string{
|
||||
"--host", testDaemonHTTPSAddr,
|
||||
"--tlsverify", "--tlscacert", "fixtures/https/ca.pem",
|
||||
"--tlscert", "fixtures/https/client-cert.pem",
|
||||
"--tlskey", "fixtures/https/client-key.pem",
|
||||
"run", "busybox", "echo", "TLS response",
|
||||
}
|
||||
out, err := s.d.Cmd(args...)
|
||||
if err != nil {
|
||||
c.Fatalf("Error Occurred: %s and output: %s", err, out)
|
||||
}
|
||||
|
@ -1484,8 +1496,14 @@ func (s *DockerDaemonSuite) TestHttpsInfoRogueCert(c *check.C) {
|
|||
c.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
}
|
||||
|
||||
daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
|
||||
out, err := s.d.CmdWithArgs(daemonArgs, "info")
|
||||
args := []string{
|
||||
"--host", testDaemonHTTPSAddr,
|
||||
"--tlsverify", "--tlscacert", "fixtures/https/ca.pem",
|
||||
"--tlscert", "fixtures/https/client-rogue-cert.pem",
|
||||
"--tlskey", "fixtures/https/client-rogue-key.pem",
|
||||
"info",
|
||||
}
|
||||
out, err := s.d.Cmd(args...)
|
||||
if err == nil || !strings.Contains(out, errBadCertificate) {
|
||||
c.Fatalf("Expected err: %s, got instead: %s and output: %s", errBadCertificate, err, out)
|
||||
}
|
||||
|
@ -1503,8 +1521,14 @@ func (s *DockerDaemonSuite) TestHttpsInfoRogueServerCert(c *check.C) {
|
|||
c.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
}
|
||||
|
||||
daemonArgs := []string{"--host", testDaemonRogueHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
|
||||
out, err := s.d.CmdWithArgs(daemonArgs, "info")
|
||||
args := []string{
|
||||
"--host", testDaemonRogueHTTPSAddr,
|
||||
"--tlsverify", "--tlscacert", "fixtures/https/ca.pem",
|
||||
"--tlscert", "fixtures/https/client-rogue-cert.pem",
|
||||
"--tlskey", "fixtures/https/client-rogue-key.pem",
|
||||
"info",
|
||||
}
|
||||
out, err := s.d.Cmd(args...)
|
||||
if err == nil || !strings.Contains(out, errCaUnknown) {
|
||||
c.Fatalf("Expected err: %s, got instead: %s and output: %s", errCaUnknown, err, out)
|
||||
}
|
||||
|
@ -1970,9 +1994,9 @@ func (s *DockerDaemonSuite) TestDaemonRestartContainerLinksRestart(c *check.C) {
|
|||
parent2Args = append([]string{"run", "-d"}, parent2Args...)
|
||||
parent2Args = append(parent2Args, []string{"--name=parent2", "--restart=always", "busybox", "top"}...)
|
||||
|
||||
_, err = d.Cmd(parent1Args[0], parent1Args[1:]...)
|
||||
_, err = d.Cmd(parent1Args...)
|
||||
c.Assert(err, check.IsNil)
|
||||
_, err = d.Cmd(parent2Args[0], parent2Args[1:]...)
|
||||
_, err = d.Cmd(parent2Args...)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = d.Stop()
|
||||
|
|
|
@ -14,10 +14,10 @@ func (s *DockerSwarmSuite) TestServiceUpdatePort(c *check.C) {
|
|||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
serviceName := "TestServiceUpdatePort"
|
||||
serviceArgs := append([]string{"create", "--name", serviceName, "-p", "8080:8081", defaultSleepImage}, defaultSleepCommand...)
|
||||
serviceArgs := append([]string{"service", "create", "--name", serviceName, "-p", "8080:8081", defaultSleepImage}, defaultSleepCommand...)
|
||||
|
||||
// Create a service with a port mapping of 8080:8081.
|
||||
out, err := d.Cmd("service", serviceArgs...)
|
||||
out, err := d.Cmd(serviceArgs...)
|
||||
c.Assert(err, checker.IsNil)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1)
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@ import (
|
|||
func (s *DockerSwarmSuite) TestStackRemove(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
stackArgs := append([]string{"remove", "UNKNOWN_STACK"})
|
||||
stackArgs := append([]string{"stack", "remove", "UNKNOWN_STACK"})
|
||||
|
||||
out, err := d.Cmd("stack", stackArgs...)
|
||||
out, err := d.Cmd(stackArgs...)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ func (s *DockerSwarmSuite) TestStackRemove(c *check.C) {
|
|||
func (s *DockerSwarmSuite) TestStackTasks(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
stackArgs := append([]string{"ps", "UNKNOWN_STACK"})
|
||||
stackArgs := append([]string{"stack", "ps", "UNKNOWN_STACK"})
|
||||
|
||||
out, err := d.Cmd("stack", stackArgs...)
|
||||
out, err := d.Cmd(stackArgs...)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ func (s *DockerSwarmSuite) TestStackTasks(c *check.C) {
|
|||
func (s *DockerSwarmSuite) TestStackServices(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
stackArgs := append([]string{"services", "UNKNOWN_STACK"})
|
||||
stackArgs := append([]string{"stack", "services", "UNKNOWN_STACK"})
|
||||
|
||||
out, err := d.Cmd("stack", stackArgs...)
|
||||
out, err := d.Cmd(stackArgs...)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
|
||||
}
|
||||
|
|
|
@ -61,8 +61,8 @@ func (s *DockerHubPullSuite) SetUpTest(c *check.C) {
|
|||
func (s *DockerHubPullSuite) TearDownTest(c *check.C) {
|
||||
out := s.Cmd(c, "images", "-aq")
|
||||
images := strings.Split(out, "\n")
|
||||
images = append([]string{"-f"}, images...)
|
||||
s.d.Cmd("rmi", images...)
|
||||
images = append([]string{"rmi", "-f"}, images...)
|
||||
s.d.Cmd(images...)
|
||||
s.ds.TearDownTest(c)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue