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
Conversation
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>
This can only land after we land #3154 |
This branch depends on #3154 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this 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:
interfaces/repo.go
Outdated
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
There was a problem hiding this 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:
interfaces/repo.go
Outdated
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) |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.
interfaces/repo.go
Outdated
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) |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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>
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
This branch improves validation of changes made to the interfaces repository. In the past this was done
at
snap.Info
level, specifically viasnap.Validate
but this was ignoring additional changes caused byadding implicit plug or slot names. This has caused a bug where the
core
snap would define some plugsdirectly in the YAML file (specifically
network-bind
plug) and and than would gain implicitnetwork-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.