Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

rkt/uuid: fix match when uuid is an empty string #2807

Merged
merged 1 commit into from
Jun 21, 2016

Conversation

alepuccetti
Copy link
Contributor

After the patch, if the uuid is an empty string then matchUUID(uuid string)
returns no matches instead of all the pods.
This is done to avoid rkt rm or rkt enter to delete or enter pods
without intending to.

Fixes #2806

@ghost
Copy link

ghost commented Jun 16, 2016

Can one of the admins verify this patch?

@iaguis
Copy link
Member

iaguis commented Jun 16, 2016

ok to test

@alban
Copy link
Member

alban commented Jun 16, 2016

How does it look like with this patch when users run rkt rm "" or rkt enter ""?

@alepuccetti
Copy link
Contributor Author

alepuccetti commented Jun 16, 2016

How does it look like with this patch when users run rkt rm "" or rkt enter ""?

rkt rm ""

rm: unable to resolve UUID: no matches found for ""
rm: failed to remove one or more pods

rkt enter ""
enter: problem retrieving pod: no matches found for ""

@alepuccetti
Copy link
Contributor Author

Maybe the second line of the error message can be avoided when there are no matches.

@lucab
Copy link
Member

lucab commented Jun 16, 2016

Two comments here:

  • this could benefit from using a ErrNoEmptyUUID
  • this is killing the (only?) way to act on all pods. I'm not sure if this feature has some real usecases. If so, should we introduce a special wildcard instead? Edit: nevermind, I later realized that the only caller of this explicitly expects a single result.

@alepuccetti
Copy link
Contributor Author

I agree on the wildcard, but before if you were running 'sudo rkt rm ""'
rkt was not going to delete all the pods anyway. It says 'ambiguous UUID'
this just catch a typing error.
That been said, I totally agree about the wildcard, but this should be a
RFE in a different PR. Which I can do it tomorrow.

On Thursday, June 16, 2016, Luca Bruno notifications@github.com wrote:

Two comments here:


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#2807 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AGRc7ydEaG2LSqcP6ShTLJJQEyrA5fyFks5qMZCFgaJpZM4I3RWH
.

@alepuccetti alepuccetti force-pushed the alessandro/resolve-uuid-fix branch from 70aafe9 to 4ef67fe Compare June 17, 2016 10:04
@alepuccetti
Copy link
Contributor Author

alepuccetti commented Jun 17, 2016

Patch updated.

@lucab I will open a specific an issue for wildcard

@alepuccetti
Copy link
Contributor Author

New error output

sudo rkt enter ""
enter: problem retrieving pod: UUID cannot be empty

sudo rkt rm ""
rm: unable to resolve UUID: UUID cannot be empty
rm: failed to remove one or more pods

@alepuccetti alepuccetti force-pushed the alessandro/resolve-uuid-fix branch from 4ef67fe to f83db18 Compare June 17, 2016 10:17
@@ -30,6 +30,10 @@ import (
// matchUUID attempts to match the uuid specified as uuid against all pods present.
// An array of matches is returned, which may be empty when nothing matches.
func matchUUID(uuid string) ([]string, error) {
if uuid == "" {
return []string{}, types.ErrNoEmptyUUID
Copy link
Member

Choose a reason for hiding this comment

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

You can directly return nil, types.ErrNoEmptyUUID here.

@lucab
Copy link
Member

lucab commented Jun 18, 2016

One comment inline and some additional notes:

  • No need to specify the function in commit title, rkt/uuid should be enough.
  • Can you please also add a test for this?

@lucab lucab self-assigned this Jun 18, 2016
@alepuccetti alepuccetti force-pushed the alessandro/resolve-uuid-fix branch 3 times, most recently from 00f3b32 to 4a2a791 Compare June 20, 2016 13:01
@alepuccetti
Copy link
Contributor Author

Patch updated. @lucab test added.

uuidFile := filepath.Join(tmpDir, "uuid-file")
if err := ioutil.WriteFile(uuidFile, []byte(nonexistentUUID), 0600); err != nil {
t.Fatalf("cannot write uuid-file: %v", err)
}
Copy link
Member

@lucab lucab Jun 20, 2016

Choose a reason for hiding this comment

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

I'm not sure I understood why you are creating this nonexistentUUID file here. What's its purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this can be deleted, I was not sure if it was necessary to have a some kind of data to be able to run rkt rm correctly, like the example before. I suppose that the creation of the uuid-file it is a precaution to avoid deleting an existing pod, isn't it?.

After the patch, if the uuid is an empty string then matchUUID(uuid string)
returns `UUID cannot be empty` error message instead of all the pods.
This is done to avoid `rkt rm` or `rkt enter` to delete or enter pods
without intending to.

Fixes rkt#2806
@alepuccetti alepuccetti force-pushed the alessandro/resolve-uuid-fix branch from 4a2a791 to 166b560 Compare June 21, 2016 07:10
@alepuccetti
Copy link
Contributor Author

patch updated. @lucab this should be cleaner

@lucab
Copy link
Member

lucab commented Jun 21, 2016

Yes, thanks! LGTM, mergeable once builders are done.

@alepuccetti
Copy link
Contributor Author

TestRmEmptyUUID passed, fedora-23 failure seems unrelated.

@lucab
Copy link
Member

lucab commented Jun 21, 2016

@alepuccetti yes that's #2287. I'm merging this.

@lucab lucab changed the title rkt/matchUUID: fix match when uuid is an empty string rkt/uuid: fix match when uuid is an empty string Jun 21, 2016
@lucab lucab merged commit 578e59a into rkt:master Jun 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants