-
Notifications
You must be signed in to change notification settings - Fork 562
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/builtin: refine the content interface rules using $SLOT #2712
Changes from 1 commit
15f6574
9535c01
826a779
7700ee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,9 +195,28 @@ slots: | |
slot-snap-type: | ||
- app | ||
- gadget | ||
allow-connection: | ||
- | ||
plug-attributes: | ||
content: $SLOT(content) | ||
- | ||
plug-attributes: | ||
content: $MISSING | ||
slot-attributes: | ||
content: $MISSING | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm.. that doesn't seem right. What would be a content interface with a missing "content" field? I thought the $MISSING case was for a future need. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this is meant to address the 'default' from https://github.com/snapcore/snapd/wiki/Interfaces#content?
That said, it seems that the first alternation addresses the default case just fine, unless I am missing something:
|
||
allow-auto-connection: | ||
plug-publisher-id: | ||
- $SLOT_PUBLISHER_ID | ||
- | ||
plug-publisher-id: | ||
- $SLOT_PUBLISHER_ID | ||
plug-attributes: | ||
content: $SLOT(content) | ||
- | ||
plug-publisher-id: | ||
- $SLOT_PUBLISHER_ID | ||
plug-attributes: | ||
content: $MISSING | ||
slot-attributes: | ||
content: $MISSING | ||
cups-control: | ||
allow-installation: | ||
slot-snap-type: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,78 @@ func (s *baseDeclSuite) TestAutoConnectionContent(c *C) { | |
cand := s.connectCand(c, "content", "", "") | ||
err := cand.CheckAutoConnect() | ||
c.Check(err, NotNil) | ||
|
||
slotDecl1 := s.mockSnapDecl(c, "slot-snap", "slot-snap-id", "pub1", "") | ||
plugDecl1 := s.mockSnapDecl(c, "plug-snap", "plug-snap-id", "pub1", "") | ||
plugDecl2 := s.mockSnapDecl(c, "plug-snap", "plug-snap-id", "pub2", "") | ||
|
||
// same publisher, same content | ||
cand = s.connectCand(c, "stuff", `name: slot-snap | ||
slots: | ||
stuff: | ||
interface: content | ||
content: mk1`, `name: plug-snap | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks really weird to my eye (the backticks for the two strings). If this is valid style, fine, but it seems it could be more clearly written. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a valid style, and we use it here and there already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with jdstrand.. this is super hard to read properly. Can we please make it:
|
||
plugs: | ||
stuff: | ||
interface: content | ||
content: mk1 | ||
`) | ||
cand.SlotSnapDeclaration = slotDecl1 | ||
cand.PlugSnapDeclaration = plugDecl1 | ||
err = cand.CheckAutoConnect() | ||
c.Check(err, IsNil) | ||
|
||
// different publisher, same content | ||
cand.SlotSnapDeclaration = slotDecl1 | ||
cand.PlugSnapDeclaration = plugDecl2 | ||
err = cand.CheckAutoConnect() | ||
c.Check(err, NotNil) | ||
|
||
// same publisher, different content | ||
tests := []struct { | ||
slotContent string | ||
plugContent string | ||
}{ | ||
{"mk1", "mk2"}, | ||
{"mk1", ""}, | ||
{"", "mk1"}, | ||
} | ||
for _, t := range tests { | ||
slotSnippet := "" | ||
if t.slotContent != "" { | ||
slotSnippet = "content: " + t.slotContent | ||
} | ||
plugSnippet := "" | ||
if t.plugContent != "" { | ||
plugSnippet = "content: " + t.plugContent | ||
} | ||
cand := s.connectCand(c, "stuff", fmt.Sprintf(`name: slot-snap | ||
slots: | ||
stuff: | ||
interface: content | ||
%s`, slotSnippet), fmt.Sprintf(`name: plug-snap | ||
plugs: | ||
stuff: | ||
interface: content | ||
%s`, plugSnippet)) | ||
cand.SlotSnapDeclaration = slotDecl1 | ||
cand.PlugSnapDeclaration = plugDecl1 | ||
err = cand.CheckAutoConnect() | ||
c.Check(err, NotNil) | ||
} | ||
|
||
// same publisher, no content | ||
cand = s.connectCand(c, "stuff", `name: slot-snap | ||
slots: | ||
stuff: | ||
interface: content`, `name: plug-snap | ||
plugs: | ||
stuff: | ||
interface: content`) | ||
cand.SlotSnapDeclaration = slotDecl1 | ||
cand.PlugSnapDeclaration = plugDecl1 | ||
err = cand.CheckAutoConnect() | ||
c.Check(err, IsNil) | ||
} | ||
|
||
func (s *baseDeclSuite) TestAutoConnectionLxdSupportOverride(c *C) { | ||
|
@@ -569,3 +641,83 @@ func (s *baseDeclSuite) TestSanity(c *C) { | |
} | ||
} | ||
} | ||
|
||
func (s *baseDeclSuite) TestConnectionContent(c *C) { | ||
// we let connect explicitly as long as content matches (or is absent on both sides) | ||
|
||
cand := s.connectCand(c, "content", "", "") | ||
err := cand.Check() | ||
c.Check(err, IsNil) | ||
|
||
slotDecl1 := s.mockSnapDecl(c, "slot-snap", "slot-snap-id", "pub1", "") | ||
plugDecl1 := s.mockSnapDecl(c, "plug-snap", "plug-snap-id", "pub1", "") | ||
plugDecl2 := s.mockSnapDecl(c, "plug-snap", "plug-snap-id", "pub2", "") | ||
|
||
// same publisher, same content | ||
cand = s.connectCand(c, "stuff", `name: slot-snap | ||
slots: | ||
stuff: | ||
interface: content | ||
content: mk1`, `name: plug-snap | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here and below. |
||
plugs: | ||
stuff: | ||
interface: content | ||
content: mk1 | ||
`) | ||
cand.SlotSnapDeclaration = slotDecl1 | ||
cand.PlugSnapDeclaration = plugDecl1 | ||
err = cand.Check() | ||
c.Check(err, IsNil) | ||
|
||
// different publisher, same content | ||
cand.SlotSnapDeclaration = slotDecl1 | ||
cand.PlugSnapDeclaration = plugDecl2 | ||
err = cand.Check() | ||
c.Check(err, IsNil) | ||
|
||
// same publisher, different content | ||
tests := []struct { | ||
slotContent string | ||
plugContent string | ||
}{ | ||
{"mk1", "mk2"}, | ||
{"mk1", ""}, | ||
{"", "mk1"}, | ||
} | ||
for _, t := range tests { | ||
slotSnippet := "" | ||
if t.slotContent != "" { | ||
slotSnippet = "content: " + t.slotContent | ||
} | ||
plugSnippet := "" | ||
if t.plugContent != "" { | ||
plugSnippet = "content: " + t.plugContent | ||
} | ||
cand := s.connectCand(c, "stuff", fmt.Sprintf(`name: slot-snap | ||
slots: | ||
stuff: | ||
interface: content | ||
%s`, slotSnippet), fmt.Sprintf(`name: plug-snap | ||
plugs: | ||
stuff: | ||
interface: content | ||
%s`, plugSnippet)) | ||
cand.SlotSnapDeclaration = slotDecl1 | ||
cand.PlugSnapDeclaration = plugDecl1 | ||
err = cand.Check() | ||
c.Check(err, NotNil) | ||
} | ||
|
||
// same publisher, no content | ||
cand = s.connectCand(c, "stuff", `name: slot-snap | ||
slots: | ||
stuff: | ||
interface: content`, `name: plug-snap | ||
plugs: | ||
stuff: | ||
interface: content`) | ||
cand.SlotSnapDeclaration = slotDecl1 | ||
cand.PlugSnapDeclaration = plugDecl1 | ||
err = cand.Check() | ||
c.Check(err, IsNil) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,5 +184,6 @@ func (iface *ContentInterface) PermanentPlugSnippet(plug *interfaces.Plug, secur | |
} | ||
|
||
func (iface *ContentInterface) AutoConnect(plug *interfaces.Plug, slot *interfaces.Slot) bool { | ||
return plug.Attrs["content"] == slot.Attrs["content"] | ||
// allow what declarations allowed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. \o/ |
||
return true | ||
} |
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.
Is this meaning to say that the connection should be allowed if the content attribute of the plug matches the content attribute of the slot? It seems so, but want to make doubly sure.
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.
yes