Skip to content

Commit

Permalink
return err when stack name does not exist
Browse files Browse the repository at this point in the history
Signed-off-by: allencloud <allen.sun@daocloud.io>
  • Loading branch information
allencloud committed Jul 11, 2016
1 parent bd37b83 commit 416613f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/client/node/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewNodeCommand(dockerCli *client.DockerCli) *cobra.Command {
return cmd
}

// Reference return the reference of a node. The special value "self" for a node
// Reference returns the reference of a node. The special value "self" for a node
// reference is mapped to the current node, hence the node ID is retrieved using
// the `/info` endpoint.
func Reference(client apiclient.APIClient, ctx context.Context, ref string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion api/client/stack/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewStackCommand(dockerCli *client.DockerCli) *cobra.Command {
return cmd
}

// NewTopLevelDeployCommand return a command for `docker deploy`
// NewTopLevelDeployCommand returns a command for `docker deploy`
func NewTopLevelDeployCommand(dockerCli *client.DockerCli) *cobra.Command {
cmd := newDeployCommand(dockerCli)
// Remove the aliases at the top level
Expand Down
5 changes: 5 additions & 0 deletions api/client/stack/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func runRemove(dockerCli *client.DockerCli, opts removeOptions) error {
}
}

if len(services) == 0 && len(networks) == 0 {
fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace)
return nil
}

if hasError {
return fmt.Errorf("Failed to remove some resources")
}
Expand Down
8 changes: 8 additions & 0 deletions api/client/stack/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package stack

import (
"fmt"

"golang.org/x/net/context"

"github.com/docker/docker/api/client"
Expand Down Expand Up @@ -43,6 +45,7 @@ func newTasksCommand(dockerCli *client.DockerCli) *cobra.Command {
}

func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error {
namespace := opts.namespace
client := dockerCli.Client()
ctx := context.Background()

Expand All @@ -58,5 +61,10 @@ func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error {
return err
}

if len(tasks) == 0 {
fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace)
return nil
}

return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve))
}
28 changes: 28 additions & 0 deletions integration-cli/docker_cli_stack_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// +build experimental

package main

import (
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
)

func (s *DockerSwarmSuite) TestStackRemove(c *check.C) {
d := s.AddDaemon(c, true, true)

stackArgs := append([]string{"remove", "UNKNOWN_STACK"})

out, err := d.Cmd("stack", stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
}

func (s *DockerSwarmSuite) TestStackTasks(c *check.C) {
d := s.AddDaemon(c, true, true)

stackArgs := append([]string{"tasks", "UNKNOWN_STACK"})

out, err := d.Cmd("stack", stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
}
2 changes: 1 addition & 1 deletion pkg/integration/checker/checker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package checker provide Docker specific implementations of the go-check.Checker interface.
// Package checker provides Docker specific implementations of the go-check.Checker interface.
package checker

import (
Expand Down

0 comments on commit 416613f

Please sign in to comment.