Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output some details when stack name does not exist #24051

Merged

Conversation

allencloud
Copy link
Contributor

@allencloud allencloud commented Jun 28, 2016

fix #23727

return err when stack name does not exist

Since there is no stack concept in the docker engine side, so check this in the client side.

As a result, output shows like this:

root@10-11-17-53:~/docker/bundles/1.12.0-dev/binary-client# ./docker stack tasks asasas
Nothing found in stack: asasas
root@10-11-17-53:~/docker/bundles/1.12.0-dev/binary-client# ./docker stack rm dsadasdsa
Nothing found in stack: dsadasdsa

This PR did:

  1. add hint with nothing found in stack in command docker stack service xxx and docker stack remove xxx
  2. add test for stack
  3. fix some typos

Signed-off-by: allencloud allen.sun@daocloud.io

@cpuguy83
Copy link
Member

ping @aanand

@aanand
Copy link
Contributor

aanand commented Jun 28, 2016

Nice, thanks. Error message wording is a little inconsistent when a name isn't found, but the most common phrase seems to be "No such [thing]: [name]". Would you mind updating the message accordingly, so it reads "No such stack: %s"?

@aanand
Copy link
Contributor

aanand commented Jun 28, 2016

Hmm. Reading over the change to remove.go, I don't think it should abort at that point. If a stack's services have been manually removed but there are still networks sitting around, then it'll never get around to removing them.

Perhaps it should only error out if there are no resources of any kind found which match the stack name. @dnephin?

@dnephin
Copy link
Member

dnephin commented Jun 28, 2016

I don't think either of these changes are correct. The current behaviour is correct.

Think of tasks like ps. If you run ps and it doesn't list any containers, that isn't an error, it's just an empty table.

For remove, I think we should consider the operation idempotent. So running remove again and having it remove nothing is fine. This is a bit different from other rm commands, but all other rm commands operate on a single object. In this case we're operating on a collection of objects. So it's more of a "remove things from this namespace". So if the namespace is empty, it's not really an error.

Ssaying remove object with id x, and that object not existing would be an error.

@thaJeztah
Copy link
Member

moving back to design review pending the discussion

@thaJeztah
Copy link
Member

ping @dnephin @aanand what's the status on this one; should we move this forward, or close?

@aanand
Copy link
Contributor

aanand commented Jul 1, 2016

I'm fine with neither condition being an error, but I think we can still try to help with typos, at least in the stack down case. We could print something like Nothing found for 'stackname' and exit 0, maybe?

@allencloud
Copy link
Contributor Author

allencloud commented Jul 3, 2016

@dnephin
Thanks for your feedback. I agree with your namespace concept totally.
In a namespace, ps output nothing, then we show nothing. That is reasonable.
While, I think there is a little bit difference between two kinds of scenes. Correct me if I did the wrong assumption. Since docker ps by default has a namespace of locally the whole engine, we can treat it as default. In a default namespace, there may be no namespace mistake.
On the other hand, if there are several namespaces like stack on a single engine. First, we should specify one stack, then in the stack namespace, we do ps or list or something else. Maybe if a user typed some typos, and docker can do a little bit thing to remind our users on stack name.

@allencloud allencloud force-pushed the return-err-when-stack-name-nonexist branch 2 times, most recently from 6627058 to 4bea57c Compare July 3, 2016 16:15
@allencloud
Copy link
Contributor Author

@aanand
If this PR makes sense, I have already avoided the network missing removal in stack if there is no such stack name.

@dnephin
Copy link
Member

dnephin commented Jul 3, 2016

We could print something like "Nothing found for 'stackname'" and exit 0

This sounds good to me

@allencloud
Copy link
Contributor Author

@dnephin
Thanks. I am thinking that way for a while and just do not make sure. I will update the PR in 12 hours, midnight here. :)

@allencloud allencloud force-pushed the return-err-when-stack-name-nonexist branch from 4bea57c to b78fde5 Compare July 4, 2016 02:50
@allencloud
Copy link
Contributor Author

@dnephin @aanand @thaJeztah
PR updated, PTAL.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I don't think we should add another API call.

We could add the warning if len(tasks) == 0, or we could just not warn.

@allencloud allencloud force-pushed the return-err-when-stack-name-nonexist branch 3 times, most recently from 49c63f6 to 17534bb Compare July 5, 2016 08:54
@allencloud
Copy link
Contributor Author

Updated.PATL @dnephin @aanand

@icecrime
Copy link
Contributor

icecrime commented Jul 5, 2016

LGTM, thanks!

@icecrime
Copy link
Contributor

icecrime commented Jul 5, 2016

Also bonus points if we can add a test ;-)

@thaJeztah
Copy link
Member

LGTM, but agree that a test would be nice to prevent future regressions

@@ -63,6 +63,11 @@ func runRemove(dockerCli *client.DockerCli, opts removeOptions) error {
}
}

if len(services) == 0 && len(networks) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allencloud i might be missing something but what does this mean wrt a stack? As in, what's a stack with no services but only networks? just trying to make sense of this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the stack rm command which also removes the networks, so if a network existed this command wouldn't be a no-op, hence no warning. I believe that's the idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. If a stack was brought up with both networks and services, then the services were all manually deleted, you'd expect stack rm to still remove the networks.

@vdemeester
Copy link
Member

LGTM 🐯

@allencloud
Copy link
Contributor Author

I agree with adding test. I will ping you guys once added. Thank all of you.

@allencloud allencloud force-pushed the return-err-when-stack-name-nonexist branch 4 times, most recently from f7083fa to e524014 Compare July 6, 2016 17:04
@tiborvass
Copy link
Contributor

LGTM

@thaJeztah
Copy link
Member

Looks like tests are failing:

https://jenkins.dockerproject.org/job/Docker-PRs/29613/console

8:28:42 
18:28:42 ----------------------------------------------------------------------
18:28:42 FAIL: docker_cli_stack_test.go:10: DockerSwarmSuite.TestStackRemove
18:28:42 
18:28:42 [d7838666] waiting for daemon to start
18:28:42 [d7838666] daemon started
18:28:42 docker_cli_stack_test.go:16:
18:28:42     c.Assert(err, checker.IsNil)
18:28:42 ... value *exec.ExitError = &exec.ExitError{ProcessState:(*os.ProcessState)(0xc82030ece0), Stderr:[]uint8(nil)} ("exit status 1")
18:28:42 
18:28:42 [d7838666] exiting daemon
18:28:45 
18:28:45 ----------------------------------------------------------------------
18:28:45 FAIL: docker_cli_stack_test.go:20: DockerSwarmSuite.TestStackTasks
18:28:45 
18:28:45 [d28599362] waiting for daemon to start
18:28:45 [d28599362] daemon started
18:28:45 docker_cli_stack_test.go:26:
18:28:45     c.Assert(err, checker.IsNil)
18:28:45 ... value *exec.ExitError = &exec.ExitError{ProcessState:(*os.ProcessState)(0xc8203f8800), Stderr:[]uint8(nil)} ("exit status 1")
18:28:45 
18:28:45 [d28599362] exiting daemon
18:28:55 
18:28:55 ----------------------------------------------------------------------

and on experimental:
https://jenkins.dockerproject.org/job/Docker-PRs-experimental/20917/console

18:02:44 
18:02:44 ----------------------------------------------------------------------
18:02:44 FAIL: docker_cli_stack_test.go:10: DockerSwarmSuite.TestStackRemove
18:02:44 
18:02:44 [d31394419] waiting for daemon to start
18:02:44 [d31394419] daemon started
18:02:44 docker_cli_stack_test.go:17:
18:02:44     c.Assert(out, check.DeepEquals, "Nothing found in stack: UNKNOWN_STACK")
18:02:44 ... obtained string = "Nothing found in stack: UNKNOWN_STACK\n"
18:02:44 ... expected string = "Nothing found in stack: UNKNOWN_STACK"
18:02:44 
18:02:44 [d31394419] exiting daemon
18:02:45 
18:02:45 ----------------------------------------------------------------------
18:02:45 FAIL: docker_cli_stack_test.go:20: DockerSwarmSuite.TestStackTasks
18:02:45 
18:02:45 [d63031334] waiting for daemon to start
18:02:45 [d63031334] daemon started
18:02:45 docker_cli_stack_test.go:27:
18:02:45     c.Assert(out, check.DeepEquals, "Nothing found in stack: UNKNOWN_STACK")
18:02:45 ... obtained string = "Nothing found in stack: UNKNOWN_STACK\n"
18:02:45 ... expected string = "Nothing found in stack: UNKNOWN_STACK"
18:02:45 
18:02:45 [d63031334] exiting daemon
18:02:54 

@thaJeztah thaJeztah added the status/failing-ci Indicates that the PR in its current state fails the test suite label Jul 6, 2016
@allencloud allencloud changed the title return err when stack name does not exist [WIP] return err when stack name does not exist Jul 7, 2016
@allencloud allencloud force-pushed the return-err-when-stack-name-nonexist branch 2 times, most recently from 0255390 to 667024a Compare July 8, 2016 03:30
@cpuguy83
Copy link
Member

cpuguy83 commented Jul 8, 2016

CI still failing.

@allencloud allencloud force-pushed the return-err-when-stack-name-nonexist branch from 667024a to b4e7b06 Compare July 11, 2016 10:54
Signed-off-by: allencloud <allen.sun@daocloud.io>
@allencloud allencloud force-pushed the return-err-when-stack-name-nonexist branch from b4e7b06 to 416613f Compare July 11, 2016 16:59
@allencloud allencloud changed the title [WIP] return err when stack name does not exist output some details when stack name does not exist Jul 11, 2016
@allencloud
Copy link
Contributor Author

PR updated and test updated. PTAL.
ping @vdemeester @tiborvass

@vdemeester vdemeester added process/cherry-pick and removed status/failing-ci Indicates that the PR in its current state fails the test suite labels Jul 11, 2016
@vdemeester
Copy link
Member

Still LGTM and it's all green, merging 😉

@vdemeester vdemeester merged commit 4664975 into moby:master Jul 11, 2016
@allencloud allencloud deleted the return-err-when-stack-name-nonexist branch July 12, 2016 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[1.12-rc2] docker stack tasks and docker stack rm silently ignore invalid stack names
9 participants