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

interfaces: validate plug/slot uniqueness #3153

Merged
merged 13 commits into from Apr 11, 2017

Conversation

zyga
Copy link
Collaborator

@zyga zyga commented Apr 7, 2017

This branch improves validation of changes made to the interfaces repository. In the past this was done
at snap.Info level, specifically via snap.Validate but this was ignoring additional changes caused by
adding implicit plug or slot names. This has caused a bug where the core snap would define some plugs
directly in the YAML file (specifically network-bind plug) and and than would gain implicit network-bind slot through the implicit mechanism. Now direct additions of plugs and slots are also enforcing the uniqueness constraint.

NOTE: This branch might only be clean to land after the new core snap is released.

zyga added 7 commits April 7, 2017 09:12
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
@zyga zyga added this to the 2.24 milestone Apr 7, 2017
@zyga
Copy link
Collaborator Author

zyga commented Apr 7, 2017

This can only land after we land #3154

@zyga
Copy link
Collaborator Author

zyga commented Apr 10, 2017

This branch depends on #3154

Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

LGTM. Just a suggestion for the messaging:

if _, ok := r.plugs[plug.Snap.Name()][plug.Name]; ok {
return fmt.Errorf("cannot add plug, snap %q already has plug %q", plug.Snap.Name(), plug.Name)
if _, ok := r.plugs[snapName][plug.Name]; ok {
return fmt.Errorf("cannot add plug %q, snap %q already has a plug with that name", plug.Name, snapName)
Copy link
Contributor

@niemeyer niemeyer Apr 10, 2017

Choose a reason for hiding this comment

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

From the user perspective, there's no plug or slot being added. I suggest reporting this as:

"snap %q has plugs conflicting on name %q"
"snap %q has plug and slot conflicting on name %q"

and so on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aha, good point, this is just internal thing. I'll update this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Almost there. Per prior review:

if _, ok := r.plugs[plug.Snap.Name()][plug.Name]; ok {
return fmt.Errorf("cannot add plug, snap %q already has plug %q", plug.Snap.Name(), plug.Name)
if _, ok := r.plugs[snapName][plug.Name]; ok {
return fmt.Errorf("snap %q has plug and slot conflicting on name %q", snapName, plug.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case it's plug and plug. Per the original comment here:

"snap %q has plugs conflicting on name %q"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, sorry, missed this detail. Same below. Correcting now.

if _, ok := r.slots[slot.Snap.Name()][slot.Name]; ok {
return fmt.Errorf("cannot add slot, snap %q already has slot %q", slot.Snap.Name(), slot.Name)
if _, ok := r.slots[snapName][slot.Name]; ok {
return fmt.Errorf("snap %q has plug and slot conflicting on name %q", snapName, slot.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly:

"snap %q has slots conflicting on name %q"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Corrected as above.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
@mvo5 mvo5 modified the milestones: 2.25, 2.24 Apr 11, 2017
@zyga zyga merged commit 8ac2f82 into snapcore:master Apr 11, 2017
@zyga zyga deleted the unique-plug-slot-names branch April 11, 2017 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants