Skip to content

Modify docker volume inspect to return existed volumes and the names of the unexsited volumes - #17788

Merged
thaJeztah merged 1 commit into
moby:masterfrom
haoshuwei:modify-volume-inspect-multi
Dec 6, 2015
Merged

thaJeztah merged 1 commit into
moby:masterfrom
haoshuwei:modify-volume-inspect-multi

Conversation

@haoshuwei

Copy link
Copy Markdown
Contributor

When I used the "docker volume inspect" command to get the info about volumes,I found that if I give an existed volume name and an unexisted volume name,it returns only error infos,like below:

root@324fca3aedab:/go/src/github.com/docker/docker# docker volume ls
DRIVER VOLUME NAME
local hao
local hao1
local hao3

root@324fca3aedab:/go/src/github.com/docker/docker# docker volume inspect hao
[
{
"Name": "hao",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/hao/_data"
}
]

root@324fca3aedab:/go/src/github.com/docker/docker# docker volume inspect hao hao2
Error response from daemon: no such volume

So I modify the command to return the existed volumes even when I give an unexisted volume name,like below:
root@3c7deed66fd2:/go/src/github.com/docker/docker# docker volume inspect hao1 hao4
Error:No such volume: hao4
[
{
"Name": "hao1",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/hao1/_data"
}
]

Signed-off-by: Shuwei Hao [email protected]

@thaJeztah

Copy link
Copy Markdown
Member

hm I'm not sure; why would we output an error, and still continue?

how does, e.g docker inspect handle this? (not behind my computer)

@haoshuwei

Copy link
Copy Markdown
Contributor Author

@thaJeztah ,docker inspect return errors and the names of the unexisted containers or images and continue to return the existed containers or images,like below

root@324fca3aedab:/go/src/github.com/docker/docker# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77a82517c1d3 ubuntu "sh -c 'while true;do" 41 hours ago Up 41 hours hungry_hugle
186ba03b1fc8 ubuntu "/bin/sh -c 'while tr" 42 hours ago Up 42 hours hao

root@324fca3aedab:/go/src/github.com/docker/docker# docker inspect hao1 hao
Error: No such image or container: hao1
[
{
"Id": "186ba03b1fc8a150dbafffc535401e60164382bbb3c0f13219185b2b9d3e2a5b",
"Created": "2015-11-06T09:22:03.533994305Z",
"Path": "/bin/sh",
"Args": [
"-c",
"while true;do echo hello world;sleep 1;done"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 464,
"ExitCode": 0,
"Error": "",
"StartedAt": "2015-11-06T09:22:06.626078606Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
........

It return errors and the name of the unexisted container "Error: No such image or container: hao1",then continue to return the existed container.So I think docker volume inspect should also be like this

@vdemeester

Copy link
Copy Markdown
Member

@calavera

calavera commented Nov 9, 2015

Copy link
Copy Markdown
Contributor

it makes me sad that we're not using the response status code to check if the volume exists or not, but this is not the only place where we have this hack 😭

So, it LGTM, I guess.

@cpuguy83

cpuguy83 commented Nov 9, 2015

Copy link
Copy Markdown
Member

Why aren't we? This should be giving a proper 404

@LK4D4

LK4D4 commented Nov 13, 2015

Copy link
Copy Markdown
Contributor

@cpuguy83 Is it? Then PR should be changed to check status instead of Contains.

@LK4D4

LK4D4 commented Nov 18, 2015

Copy link
Copy Markdown
Contributor

@haoshuwei Would you mind to try status instead of strings comparison?

@haoshuwei

Copy link
Copy Markdown
Contributor Author

@LK4D4 @cpuguy83 @calavera @vdemeester @thaJeztah it is not only the "docker volume inspect " use strings comparison to check if volumes are existed or not,but also others like "docker network inspect“ and "docker inspect".So should i try to modify all of them to check status on the client?
And another thing is that,if we want to check status instead of string comparison,i may need add a new int value on func type APIFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) (int, error) which is located in "../api/server/httputils/httputils.go".It will affect many funcs under "../api" including containers,networks,volumes and so on.Or do you have a better idea to do this?

@calavera

Copy link
Copy Markdown
Contributor

@haoshuwei let's focus on this one first.

You don't need to modify anything in the api, just check if resp.Code is 404. We expect the api to return already a 404 error when the volume does not exist. @cpuguy83 can confirm this because he wrote that code 😸

It would also be great if you could add a test case.

@cpuguy83

Copy link
Copy Markdown
Member

The one thing we don't an API test for for volumes :(

@cpuguy83

Copy link
Copy Markdown
Member

Yep, it is a 404.

curl -i localhost/volumes/notexist
DEBU[0047] Calling GET /volumes/notexist
INFO[0047] GET /volumes/notexist
ERRO[0047] Handler for GET /volumes/notexist returned error: get notexist: no such volume
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Server: Docker/1.10.0-dev (linux)
X-Content-Type-Options: nosniff
Date: Tue, 24 Nov 2015 02:00:27 GMT
Content-Length: 29

get notexist: no such volume

@haoshuwei

Copy link
Copy Markdown
Contributor Author

I have modified the client to check statuscode to see if volumes are existed.
Another thing is that i keep it continue even if a volume is not existed when multi voulmes are inspected just like "docker inspect" and "docker network inspect" do, is this ok or should i just return 404 Not Found if one of them is not existed?

@calavera

Copy link
Copy Markdown
Contributor

is this ok or should i just return 404 Not Found if one of them is not existed?

I'm okay with having the same behavior than the other commands, although I don't like it very much.

Just a minor comment about the message, but otherwise LGTM

Comment thread api/client/volume.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we use the previous message, it's more self explanatory than this 404: volume not found: %s\n.

@haoshuwei

Copy link
Copy Markdown
Contributor Author

Modified to use message "Error: No such volume: %s\n".
Then can i continue to modify others such as "docker volume rm" or "docker network inspect" to check using statuscode?create another PR?

@calavera

Copy link
Copy Markdown
Contributor

@haoshuwei it's better to have independent PRs for each change. It looks like the code is not properly formatted:

---> Making bundle: validate-gofmt (in bundles/1.10.0-dev/validate-gofmt)
These files are not properly gofmt'd:
 - api/client/volume.go

Can you also add a test in the integration-cli suite, otherwise, we cannot guarantee that this behavior works. You can copy part of the code in this test:

https://github.com/docker/docker/blob/master/integration-cli/docker_cli_volume_test.go#L53

@haoshuwei

Copy link
Copy Markdown
Contributor Author

Sorry,i forget to check code style. Have go-fmt the file and submmit a test in the integration-cli suite

Comment thread api/client/volume.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/404/http.StatusNotFound/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, minor style nit:

if err != nil {
    if resp.statusCode != http.StatusNotFound {
        return err
    }
    status = 1
    fmt.Fprintf(cli.err, "Error: No such volume: %s\n", name)
    continue
}

@haoshuwei

Copy link
Copy Markdown
Contributor Author

Recommit the code following cpuguy83's comments

@cpuguy83

cpuguy83 commented Dec 1, 2015

Copy link
Copy Markdown
Member

LGTM

@haoshuwei

Copy link
Copy Markdown
Contributor Author

em, is this patch ok to be merged?

@thaJeztah

Copy link
Copy Markdown
Member

I think @calavera needs to have another look after the code changes

ping @calavera can you have another look please?

@vdemeester

Copy link
Copy Markdown
Member

LGTM 🐰

@thaJeztah

Copy link
Copy Markdown
Member

Let's merge! Thanks @haoshuwei!!

thaJeztah added a commit that referenced this pull request Dec 6, 2015
Modify docker volume inspect to return existed volumes and the names of the unexsited volumes
@thaJeztah
thaJeztah merged commit 5b4734a into moby:master Dec 6, 2015
@vdemeester

Copy link
Copy Markdown
Member

Oh.. weirdly enough the CI might have been wrong because now any build is red because of this 😓 (see https://jenkins.dockerproject.org/job/Docker-PRs/20656/console).

Fixing it in #18458 😅

@thaJeztah

Copy link
Copy Markdown
Member

Oh, that's weird, because Janky was green on this one?

@cpuguy83

cpuguy83 commented Dec 7, 2015

Copy link
Copy Markdown
Member

Oh that's because a related (but different set of code) change was merged after these tests were run that fixed how we handle missing volumes on the client.

@lowenna

lowenna commented Dec 7, 2015

Copy link
Copy Markdown
Member

Hmm, this fails on Windows CI now 100% :( [Yes, there's a bug in Windows CI which causes a false positive if there's a test failure - have a script update to Jess out for that]

@lowenna

lowenna commented Dec 7, 2015

Copy link
Copy Markdown
Member

Oh, @vdemeester - yes, #18458 😺
Thank you!

@thaJeztah

Copy link
Copy Markdown
Member

Thanks @cpuguy83, makes sense now! (And thanks for the fix @vdemeester)

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.

8 participants