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/builtin: refine the content interface rules using $SLOT #2712

Merged
merged 4 commits into from Jan 30, 2017

Conversation

pedronis
Copy link
Collaborator

@pedronis pedronis commented Jan 25, 2017

Allow connection and auto-connection only if plug and slot side content attributes match, using a $SLOT constraint.

Make the content attribute of the content interface mandatory temporarily until we have the right infrastructure to implement the initially intended defaults. (The previous behaviour letting leaving it out was unintended/buggy)

@pedronis
Copy link
Collaborator Author

based on #2698

@pedronis pedronis added this to the 2.22 milestone Jan 25, 2017
plug-attributes:
content: $MISSING
slot-attributes:
content: $MISSING
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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?

  • content (slot): reference to plug side of connection. Defaults to local slot name
  • content (plug): reference to slot side of connection. Defaults to local plug name

That said, it seems that the first alternation addresses the default case just fine, unless I am missing something:

plug-attributes:
    content: $SLOT(content)

@@ -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"]
Copy link
Contributor

Choose a reason for hiding this comment

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

\o/

@pedronis pedronis modified the milestones: 2.23, 2.22 Jan 25, 2017
}

var (
validEvalAttrMatcher = regexp.MustCompile(`^\$(SLOT|PLUG)\((.+)\)$`)
Copy link

@jdstrand jdstrand Jan 25, 2017

Choose a reason for hiding this comment

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

In the snap declarations spec, there is no reference to $SLOT and $PLUG. Are these meant to replace $same and/or $slot_publisher_id and $plug_publisher_id?

Copy link
Collaborator Author

@pedronis pedronis Jan 25, 2017

Choose a reason for hiding this comment

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

we never implemented $same, we implemented $SLOT_PUBLISHER_ID and $PLUG_PUBLISHER_ID those are used though only in the *-publisher-id: constraints.

$SLOT(dotted attr) and $PLUG(dotted attr) are meant for plug/slot-attributes constraints to retrieve the corresponding value of the attribute on the SLOT or on the PLUG,
mostly to implement $same (but Gustavo thinks they could be used in other cases, more generically)

Choose a reason for hiding this comment

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

I see from 15f6574 this is meant to say the $SLOT(something) in plug-attributes must match the 'something' attribute of the plug for this snap and that the $PLUG(else) in slot-attributes must match the 'else' attribute from the slot for this snap.

Choose a reason for hiding this comment

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

Can you update the specification for $SLOT/$PLUG/$MISSING?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jdstrand I'll try to make suggestions there, I don't have edit rights

Choose a reason for hiding this comment

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

@pedronis mentioned that a later commit removed $MISSING, so I'll ignore it.

maxSupportedFormat[SnapDeclarationType.Name] = 1

// 1: plugs and slots
// 2: support for $SLOT()/$PLUG()/$MISSING

Choose a reason for hiding this comment

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

What is $MISSING meant to be used for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we don't at the moment have a way to express the constraints that an attribute is omitted, $MISSING constraints the attribute not to be set

Choose a reason for hiding this comment

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

So $MISSING is for stating that the attribute must not be set at all? What would be an example use case of that? auto-connect only if an attribute is not set? If so, is $MISSING the right word; would $DEFAULT be better?

allow-connection:
-
plug-attributes:
content: $SLOT(content)

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

@jdstrand
Copy link

I was asked to take a look at this, but am having to come up to speed on context and piece together what this is meant to address. In the future if you can provide a description for the PR that details the problem and how the change addresses the problem?

@pedronis
Copy link
Collaborator Author

@jdstrand I added a description of the new constraints to #2698

@pedronis pedronis changed the title interfaces/builtin: refine the content interface rules using $SLOT/$MISSING interfaces/builtin: refine the content interface rules using $SLOT Jan 25, 2017
slots:
stuff:
interface: content
content: mk1`, `name: plug-snap

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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:

cand = s.connectCand(c, "stuff", `
name: slot-snap
...
`, `
name: plug-snap
...
`)

Copy link

@jdstrand jdstrand left a comment

Choose a reason for hiding this comment

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

Need a clarification on $MISSING in the base declaration, but the allow-connection for content: $SLOT(content) for plug-attributes looks good.

allow-auto-connection:
plug-publisher-id:
- $SLOT_PUBLISHER_ID
plug-attributes:
content: $SLOT(content)

Choose a reason for hiding this comment

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

The updated base declaration changes without $MISSING LGTM.

@jdstrand
Copy link

FYI, I updated https://github.com/snapcore/snapd/wiki/Interfaces#content to remove the text stating that the 'content' attribute for the 'content' interface has a default value.

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.

One superficial comment, and @jdstrand is right. The default case was supposed to make the logic more pleasant to use, and we screwed up the original implementation by not making the default do the right thing.

Suggested route: let's enforce content to be present and match, moving this PR in. Then, let's fix attribute mutation in the interface hooks series of PRs, and then come back to reintroduce the defaults here, which shall be trivial by then.

slots:
stuff:
interface: content
content: mk1`, `name: plug-snap
Copy link
Contributor

Choose a reason for hiding this comment

The 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:

cand = s.connectCand(c, "stuff", `
name: slot-snap
...
`, `
name: plug-snap
...
`)

slots:
stuff:
interface: content
content: mk1`, `name: plug-snap
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here and below.

Copy link

@jdstrand jdstrand left a comment

Choose a reason for hiding this comment

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

Thanks for the cleanups. As mentioned before, the base declaration changes LGTM. The changes requiring that the 'content' attribute look good and are consistent with how the current implementation is supposed to work.

@pedronis pedronis merged commit ee2506b into snapcore:master Jan 30, 2017
@pedronis pedronis deleted the iface-content-rules branch January 31, 2017 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants