interfaces: compose the base declaration from interfaces #3444

Merged
merged 6 commits into from Jun 9, 2017

Conversation

Projects
None yet
5 participants
Contributor

zyga commented Jun 8, 2017

Whenever a new interface is created the developer has to edit a number
of files. With the recent improvements those have shrinked to, almost,
just the interface module. This patch reduces this to exactly just the
new interface module. Now each interface can augment the base
declaration straight from the module file.

The split change nothing in how the policy looks like but sets the stage
for composing it out of meta-data coming from individual interfaces.

Upcoming branch will move the base declaration into separate interface files.

Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com

interfaces: compose the base declaration from interfaces
Whenever a new interface is created the developer has to edit a number
of files. With the recent improvements those have shrinked to, almost,
just the interface module. This patch reduces this to *exactly* just the
new interface module. Now each interface can augment the base
declaration straight from the module file.

The split change nothing in how the policy looks like but sets the stage
for composing it out of meta-data coming from individual interfaces.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/core.go
@@ -142,6 +142,9 @@ type MetaData struct {
ImplicitOnCore bool `json:"implicit-on-core,omitempty"`
// ImplicitOnClassic controls if a slot is automatically added to classic systems.
ImplicitOnClassic bool `json:"implicit-on-classic,omitempty"`
+
+ BaseDeclarationPlugs string
@morphis

morphis Jun 8, 2017

Contributor

A description of both variables would be nice

@zyga

zyga Jun 8, 2017

Contributor

Sure, I'll add those in a moment

interfaces/policy/basedeclaration.go
+ // Trim newlines at the end of the string. All the elements may have
+ // spurious trailing newlines. All elements start with a leading newline.
+ // We don't want any blanks as that would no longer parse.
+ tr := func(s string) string { return strings.TrimRight(s, "\n") }
@morphis

morphis Jun 8, 2017

Contributor

Would like a better name for tr here as it doesn't say much if you look at something like tr(baseDeclarationHeader). Something like trimTrailingNewLine or so would make it obvious fo the reader.

@zyga

zyga Jun 8, 2017

Contributor

Done

@@ -760,3 +761,14 @@ plugs:
err = cand.Check()
c.Check(err, NotNil)
}
+
+func (s *baseDeclSuite) TestComposeBaseDeclaration(c *C) {
+ decl, err := policy.ComposeBaseDeclaration(nil)
@morphis

morphis Jun 8, 2017

Contributor

Are the other tests exercising ComposeBaseDeclaration too?

@zyga

zyga Jun 8, 2017

Contributor

Yes, they do

zyga added some commits Jun 8, 2017

interfaces: document additional meta-data fields
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: use more descriptive helper name
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: use regular helper function
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

codecov-io commented Jun 8, 2017

Codecov Report

Merging #3444 into master will decrease coverage by 0.02%.
The diff coverage is 30.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3444      +/-   ##
==========================================
- Coverage   77.26%   77.23%   -0.03%     
==========================================
  Files         373      373              
  Lines       25687    25713      +26     
==========================================
+ Hits        19846    19860      +14     
- Misses       4097     4103       +6     
- Partials     1744     1750       +6
Impacted Files Coverage Δ
interfaces/core.go 86.36% <ø> (ø) ⬆️
interfaces/builtin/unity8_pim_common.go 78.04% <0%> (-1.96%) ⬇️
interfaces/builtin/common.go 45.09% <0%> (-1.85%) ⬇️
interfaces/policy/basedeclaration.go 40.74% <41.66%> (-9.26%) ⬇️
overlord/snapstate/snapstate.go 81.52% <0%> (+0.23%) ⬆️
overlord/ifacestate/helpers.go 66.38% <0%> (+0.84%) ⬆️
interfaces/sorting.go 96.66% <0%> (+3.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2b5530...2aaa40a. Read the comment docs.

morphis approved these changes Jun 8, 2017

LGTM

interfaces/policy/basedeclaration.go
+ return strings.TrimRight(s, "\n")
+}
+
+func ComposeBaseDeclaration(ifaces []interfaces.Interface) ([]byte, error) {
@pedronis

pedronis Jun 8, 2017

Contributor

why public and without doc? it could be private and then tested using export_test?

@zyga

zyga Jun 8, 2017

Contributor

Ah, indeed. I don't need this to be public actually. I'll make it private

@zyga

zyga Jun 8, 2017

Contributor

Done now

interfaces: make composeBaseDeclaration private
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

"Whenever a new interface is created the developer has to edit a number of files. With the recent improvements those have shrinked to, almost, just the interface module. This patch reduces this to exactly just the new interface module. Now each interface can augment the base declaration straight from the module file."

This PR didn't do what I expected from the quoted description. I thought this PR was going to move the interface specific parts out of basedeclaration.go into the interfaces files themselves (eg, docker-support in baseDeclarationPlugs to interfaces/builtin/docker_support.go and account-control in baseDeclarationSlots to interfaces/builtin/account_control.go and then compose baseDeclarationPlugs and baseDeclarationSlots from the interfaces.

Instead it only split the headers, plugs and slots and you compose the declaration from those. This change alone is fine from my perspective, but it doesn't achieve the goal of "exactly just the new interface module".

Contributor

zyga commented Jun 9, 2017

@jdstrand I have that in another branch, I didn't want to make the review too hard. With https://github.com/zyga/snapd/tree/feature/metadata-defines-base-policy it will be exactly as you had hoped.

Contributor

pedronis commented Jun 9, 2017

@zyga that's ok there's another branch that refines this but then the description of this one that will go in the commit is very confusing

Thanks for the extra info @zyga. Approving, but please adjust the commit message like @pedronis suggested.

@zyga zyga merged commit 7b21775 into snapcore:master Jun 9, 2017

7 checks passed

artful-amd64 autopkgtest finished (success)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
xenial-amd64 autopkgtest finished (success)
Details
xenial-i386 autopkgtest finished (success)
Details
xenial-ppc64el autopkgtest finished (success)
Details
yakkety-amd64 autopkgtest finished (success)
Details
zesty-amd64 autopkgtest finished (success)
Details

@zyga zyga deleted the zyga:feature/composed-base-declaration branch Aug 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment