Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -435,22 +435,19 @@ func (d *Daemon) getBaseDeviceSize(c *check.C) int64 {
|
| 435 | 435 |
|
| 436 | 436 |
// Cmd will execute a docker CLI command against this Daemon. |
| 437 | 437 |
// Example: d.Cmd("version") will run docker -H unix://path/to/unix.sock version
|
| 438 |
-func (d *Daemon) Cmd(name string, arg ...string) (string, error) {
|
|
| 439 |
- args := []string{"--host", d.sock(), name}
|
|
| 440 |
- args = append(args, arg...) |
|
| 441 |
- c := exec.Command(dockerBinary, args...) |
|
| 438 |
+func (d *Daemon) Cmd(args ...string) (string, error) {
|
|
| 439 |
+ c := exec.Command(dockerBinary, d.prependHostArg(args)...) |
|
| 442 | 440 |
b, err := c.CombinedOutput() |
| 443 | 441 |
return string(b), err |
| 444 | 442 |
} |
| 445 | 443 |
|
| 446 |
-// CmdWithArgs will execute a docker CLI command against a daemon with the |
|
| 447 |
-// given additional arguments |
|
| 448 |
-func (d *Daemon) CmdWithArgs(daemonArgs []string, name string, arg ...string) (string, error) {
|
|
| 449 |
- args := append(daemonArgs, name) |
|
| 450 |
- args = append(args, arg...) |
|
| 451 |
- c := exec.Command(dockerBinary, args...) |
|
| 452 |
- b, err := c.CombinedOutput() |
|
| 453 |
- return string(b), err |
|
| 444 |
+func (d *Daemon) prependHostArg(args []string) []string {
|
|
| 445 |
+ for _, arg := range args {
|
|
| 446 |
+ if arg == "--host" || arg == "-H" {
|
|
| 447 |
+ return args |
|
| 448 |
+ } |
|
| 449 |
+ } |
|
| 450 |
+ return append([]string{"--host", d.sock()}, args...)
|
|
| 454 | 451 |
} |
| 455 | 452 |
|
| 456 | 453 |
// 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 {
|
| 15 | 15 |
} |
| 16 | 16 |
|
| 17 | 17 |
// nodeCmd executes a command on a given node via the normal docker socket |
| 18 |
-func (s *DockerSwarmSuite) nodeCmd(c *check.C, id, cmd string, args ...string) (string, error) {
|
|
| 19 |
- return s.getDaemon(c, id).Cmd(cmd, args...) |
|
| 18 |
+func (s *DockerSwarmSuite) nodeCmd(c *check.C, id string, args ...string) (string, error) {
|
|
| 19 |
+ return s.getDaemon(c, id).Cmd(args...) |
|
| 20 | 20 |
} |
| ... | ... |
@@ -987,8 +987,8 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
|
| 987 | 987 |
|
| 988 | 988 |
// But, Pinging external or a Host interface must succeed |
| 989 | 989 |
pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String())
|
| 990 |
- runArgs := []string{"--rm", "busybox", "sh", "-c", pingCmd}
|
|
| 991 |
- _, err = d.Cmd("run", runArgs...)
|
|
| 990 |
+ runArgs := []string{"run", "--rm", "busybox", "sh", "-c", pingCmd}
|
|
| 991 |
+ _, err = d.Cmd(runArgs...) |
|
| 992 | 992 |
c.Assert(err, check.IsNil) |
| 993 | 993 |
} |
| 994 | 994 |
|
| ... | ... |
@@ -1433,8 +1433,14 @@ func (s *DockerDaemonSuite) TestHttpsInfo(c *check.C) {
|
| 1433 | 1433 |
c.Fatalf("Could not start daemon with busybox: %v", err)
|
| 1434 | 1434 |
} |
| 1435 | 1435 |
|
| 1436 |
- daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-cert.pem", "--tlskey", "fixtures/https/client-key.pem"}
|
|
| 1437 |
- out, err := s.d.CmdWithArgs(daemonArgs, "info") |
|
| 1436 |
+ args := []string{
|
|
| 1437 |
+ "--host", testDaemonHTTPSAddr, |
|
| 1438 |
+ "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", |
|
| 1439 |
+ "--tlscert", "fixtures/https/client-cert.pem", |
|
| 1440 |
+ "--tlskey", "fixtures/https/client-key.pem", |
|
| 1441 |
+ "info", |
|
| 1442 |
+ } |
|
| 1443 |
+ out, err := s.d.Cmd(args...) |
|
| 1438 | 1444 |
if err != nil {
|
| 1439 | 1445 |
c.Fatalf("Error Occurred: %s and output: %s", err, out)
|
| 1440 | 1446 |
} |
| ... | ... |
@@ -1452,8 +1458,14 @@ func (s *DockerDaemonSuite) TestHttpsRun(c *check.C) {
|
| 1452 | 1452 |
c.Fatalf("Could not start daemon with busybox: %v", err)
|
| 1453 | 1453 |
} |
| 1454 | 1454 |
|
| 1455 |
- daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-cert.pem", "--tlskey", "fixtures/https/client-key.pem"}
|
|
| 1456 |
- out, err := s.d.CmdWithArgs(daemonArgs, "run", "busybox", "echo", "TLS response") |
|
| 1455 |
+ args := []string{
|
|
| 1456 |
+ "--host", testDaemonHTTPSAddr, |
|
| 1457 |
+ "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", |
|
| 1458 |
+ "--tlscert", "fixtures/https/client-cert.pem", |
|
| 1459 |
+ "--tlskey", "fixtures/https/client-key.pem", |
|
| 1460 |
+ "run", "busybox", "echo", "TLS response", |
|
| 1461 |
+ } |
|
| 1462 |
+ out, err := s.d.Cmd(args...) |
|
| 1457 | 1463 |
if err != nil {
|
| 1458 | 1464 |
c.Fatalf("Error Occurred: %s and output: %s", err, out)
|
| 1459 | 1465 |
} |
| ... | ... |
@@ -1484,8 +1496,14 @@ func (s *DockerDaemonSuite) TestHttpsInfoRogueCert(c *check.C) {
|
| 1484 | 1484 |
c.Fatalf("Could not start daemon with busybox: %v", err)
|
| 1485 | 1485 |
} |
| 1486 | 1486 |
|
| 1487 |
- daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
|
|
| 1488 |
- out, err := s.d.CmdWithArgs(daemonArgs, "info") |
|
| 1487 |
+ args := []string{
|
|
| 1488 |
+ "--host", testDaemonHTTPSAddr, |
|
| 1489 |
+ "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", |
|
| 1490 |
+ "--tlscert", "fixtures/https/client-rogue-cert.pem", |
|
| 1491 |
+ "--tlskey", "fixtures/https/client-rogue-key.pem", |
|
| 1492 |
+ "info", |
|
| 1493 |
+ } |
|
| 1494 |
+ out, err := s.d.Cmd(args...) |
|
| 1489 | 1495 |
if err == nil || !strings.Contains(out, errBadCertificate) {
|
| 1490 | 1496 |
c.Fatalf("Expected err: %s, got instead: %s and output: %s", errBadCertificate, err, out)
|
| 1491 | 1497 |
} |
| ... | ... |
@@ -1503,8 +1521,14 @@ func (s *DockerDaemonSuite) TestHttpsInfoRogueServerCert(c *check.C) {
|
| 1503 | 1503 |
c.Fatalf("Could not start daemon with busybox: %v", err)
|
| 1504 | 1504 |
} |
| 1505 | 1505 |
|
| 1506 |
- daemonArgs := []string{"--host", testDaemonRogueHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
|
|
| 1507 |
- out, err := s.d.CmdWithArgs(daemonArgs, "info") |
|
| 1506 |
+ args := []string{
|
|
| 1507 |
+ "--host", testDaemonRogueHTTPSAddr, |
|
| 1508 |
+ "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", |
|
| 1509 |
+ "--tlscert", "fixtures/https/client-rogue-cert.pem", |
|
| 1510 |
+ "--tlskey", "fixtures/https/client-rogue-key.pem", |
|
| 1511 |
+ "info", |
|
| 1512 |
+ } |
|
| 1513 |
+ out, err := s.d.Cmd(args...) |
|
| 1508 | 1514 |
if err == nil || !strings.Contains(out, errCaUnknown) {
|
| 1509 | 1515 |
c.Fatalf("Expected err: %s, got instead: %s and output: %s", errCaUnknown, err, out)
|
| 1510 | 1516 |
} |
| ... | ... |
@@ -1970,9 +1994,9 @@ func (s *DockerDaemonSuite) TestDaemonRestartContainerLinksRestart(c *check.C) {
|
| 1970 | 1970 |
parent2Args = append([]string{"run", "-d"}, parent2Args...)
|
| 1971 | 1971 |
parent2Args = append(parent2Args, []string{"--name=parent2", "--restart=always", "busybox", "top"}...)
|
| 1972 | 1972 |
|
| 1973 |
- _, err = d.Cmd(parent1Args[0], parent1Args[1:]...) |
|
| 1973 |
+ _, err = d.Cmd(parent1Args...) |
|
| 1974 | 1974 |
c.Assert(err, check.IsNil) |
| 1975 |
- _, err = d.Cmd(parent2Args[0], parent2Args[1:]...) |
|
| 1975 |
+ _, err = d.Cmd(parent2Args...) |
|
| 1976 | 1976 |
c.Assert(err, check.IsNil) |
| 1977 | 1977 |
|
| 1978 | 1978 |
err = d.Stop() |
| ... | ... |
@@ -14,10 +14,10 @@ func (s *DockerSwarmSuite) TestServiceUpdatePort(c *check.C) {
|
| 14 | 14 |
d := s.AddDaemon(c, true, true) |
| 15 | 15 |
|
| 16 | 16 |
serviceName := "TestServiceUpdatePort" |
| 17 |
- serviceArgs := append([]string{"create", "--name", serviceName, "-p", "8080:8081", defaultSleepImage}, defaultSleepCommand...)
|
|
| 17 |
+ serviceArgs := append([]string{"service", "create", "--name", serviceName, "-p", "8080:8081", defaultSleepImage}, defaultSleepCommand...)
|
|
| 18 | 18 |
|
| 19 | 19 |
// Create a service with a port mapping of 8080:8081. |
| 20 |
- out, err := d.Cmd("service", serviceArgs...)
|
|
| 20 |
+ out, err := d.Cmd(serviceArgs...) |
|
| 21 | 21 |
c.Assert(err, checker.IsNil) |
| 22 | 22 |
waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) |
| 23 | 23 |
|
| ... | ... |
@@ -10,9 +10,9 @@ import ( |
| 10 | 10 |
func (s *DockerSwarmSuite) TestStackRemove(c *check.C) {
|
| 11 | 11 |
d := s.AddDaemon(c, true, true) |
| 12 | 12 |
|
| 13 |
- stackArgs := append([]string{"remove", "UNKNOWN_STACK"})
|
|
| 13 |
+ stackArgs := append([]string{"stack", "remove", "UNKNOWN_STACK"})
|
|
| 14 | 14 |
|
| 15 |
- out, err := d.Cmd("stack", stackArgs...)
|
|
| 15 |
+ out, err := d.Cmd(stackArgs...) |
|
| 16 | 16 |
c.Assert(err, checker.IsNil) |
| 17 | 17 |
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n") |
| 18 | 18 |
} |
| ... | ... |
@@ -20,9 +20,9 @@ func (s *DockerSwarmSuite) TestStackRemove(c *check.C) {
|
| 20 | 20 |
func (s *DockerSwarmSuite) TestStackTasks(c *check.C) {
|
| 21 | 21 |
d := s.AddDaemon(c, true, true) |
| 22 | 22 |
|
| 23 |
- stackArgs := append([]string{"ps", "UNKNOWN_STACK"})
|
|
| 23 |
+ stackArgs := append([]string{"stack", "ps", "UNKNOWN_STACK"})
|
|
| 24 | 24 |
|
| 25 |
- out, err := d.Cmd("stack", stackArgs...)
|
|
| 25 |
+ out, err := d.Cmd(stackArgs...) |
|
| 26 | 26 |
c.Assert(err, checker.IsNil) |
| 27 | 27 |
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n") |
| 28 | 28 |
} |
| ... | ... |
@@ -30,9 +30,9 @@ func (s *DockerSwarmSuite) TestStackTasks(c *check.C) {
|
| 30 | 30 |
func (s *DockerSwarmSuite) TestStackServices(c *check.C) {
|
| 31 | 31 |
d := s.AddDaemon(c, true, true) |
| 32 | 32 |
|
| 33 |
- stackArgs := append([]string{"services", "UNKNOWN_STACK"})
|
|
| 33 |
+ stackArgs := append([]string{"stack", "services", "UNKNOWN_STACK"})
|
|
| 34 | 34 |
|
| 35 |
- out, err := d.Cmd("stack", stackArgs...)
|
|
| 35 |
+ out, err := d.Cmd(stackArgs...) |
|
| 36 | 36 |
c.Assert(err, checker.IsNil) |
| 37 | 37 |
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n") |
| 38 | 38 |
} |
| ... | ... |
@@ -61,8 +61,8 @@ func (s *DockerHubPullSuite) SetUpTest(c *check.C) {
|
| 61 | 61 |
func (s *DockerHubPullSuite) TearDownTest(c *check.C) {
|
| 62 | 62 |
out := s.Cmd(c, "images", "-aq") |
| 63 | 63 |
images := strings.Split(out, "\n") |
| 64 |
- images = append([]string{"-f"}, images...)
|
|
| 65 |
- s.d.Cmd("rmi", images...)
|
|
| 64 |
+ images = append([]string{"rmi", "-f"}, images...)
|
|
| 65 |
+ s.d.Cmd(images...) |
|
| 66 | 66 |
s.ds.TearDownTest(c) |
| 67 | 67 |
} |
| 68 | 68 |
|