Skip to content

Commit

Permalink
snap: introduce the StandardComponent type (#14412)
Browse files Browse the repository at this point in the history
* many: introduce the StandardComponent type

StandardComponent is the type of vanilla components that do not have
any special behavior from the snapd perspective and that are simply
mounted and made available to the snap. Add it and change most of the
tests so the new type is used.

* tests/main/component: make component type in component and snap the same (standard)

---------

Co-authored-by: ernestl <ernest.lotter@canonical.com>
  • Loading branch information
alfonsosanchezbeato and ernestl authored Oct 4, 2024
1 parent 9a82ad9 commit 37eb0a3
Show file tree
Hide file tree
Showing 52 changed files with 466 additions and 454 deletions.
36 changes: 18 additions & 18 deletions asserts/snapasserts/snapasserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,12 @@ func (s *snapassertsSuite) TestCheckComponentProvenanceWithVerifiedRevision(c *C
"timestamp": time.Now().Format(time.RFC3339),
}).(*asserts.SnapResourceRevision)
compPath := snaptest.MakeTestComponentWithFiles(c, "comp1", `component: snap+comp1
type: test
type: standard
provenance: prov
version: 1.0.2
`, nil)
compPath2 := snaptest.MakeTestComponentWithFiles(c, "comp1", `component: snap+comp1
type: test
type: standard
version: 1.0.2
`, nil)

Expand Down Expand Up @@ -900,7 +900,7 @@ func (s *snapassertsSuite) TestDeriveComponentSideInfoFromDigestAndSize(c *C) {
model := s.makeUC20Model(c, nil)

compPath := snaptest.MakeTestComponentWithFiles(c, "comp1", `component: snap+comp1
type: test
type: standard
version: 1.0.2
`, nil)
digest, size, err := asserts.SnapFileSHA3_384(compPath)
Expand Down Expand Up @@ -940,7 +940,7 @@ version: 1.0.2
func (s *snapassertsSuite) TestDeriveComponentSideInfoFromDigestAndSizeWrongSize(c *C) {
model := s.makeUC20Model(c, nil)
compPath := snaptest.MakeTestComponentWithFiles(c, "comp1", `component: snap+comp1
type: test
type: standard
version: 1.0.2
`, nil)
digest, size, err := asserts.SnapFileSHA3_384(compPath)
Expand Down Expand Up @@ -971,7 +971,7 @@ version: 1.0.2
func (s *snapassertsSuite) TestDeriveComponentSideInfoFromDigestAndSizeWithProvenance(c *C) {
model := s.makeUC20Model(c, map[string]interface{}{"store": "store1"})
compPath := snaptest.MakeTestComponentWithFiles(c, "comp1", `component: snap+comp1
type: test
type: standard
provenance: prov
version: 1.0.2
`, nil)
Expand Down Expand Up @@ -1061,7 +1061,7 @@ func (s *snapassertsSuite) TestCrossCheckResource(c *C) {
componentRev := snap.R(24)
snapRev := snap.R(12)
const size = uint64(1024)
const resourceName = "test-component"
const resourceName = "standard-component"
const snapID = "snap-id-1"

revHeaders := map[string]interface{}{
Expand Down Expand Up @@ -1099,7 +1099,7 @@ func (s *snapassertsSuite) TestCrossCheckResource(c *C) {
}

csi := &snap.ComponentSideInfo{
Component: naming.NewComponentRef("snap", "test-component"),
Component: naming.NewComponentRef("snap", "standard-component"),
Revision: snap.R(24),
}

Expand All @@ -1118,15 +1118,15 @@ func (s *snapassertsSuite) TestCrossCheckResourceProvenanceMissingRevisionAssert

func (s *snapassertsSuite) testCrossCheckResourceMissingRevisionAssertion(c *C, provenance string) {
digest := makeDigest(12)
const resourceName = "test-component"
const resourceName = "standard-component"

si := &snap.SideInfo{
SnapID: "snap-id-1",
Revision: snap.R(12),
}

csi := &snap.ComponentSideInfo{
Component: naming.NewComponentRef("snap", "test-component"),
Component: naming.NewComponentRef("snap", "standard-component"),
Revision: snap.R(24),
}

Expand Down Expand Up @@ -1171,7 +1171,7 @@ func (s *snapassertsSuite) TestCrossCheckResourceProvenance(c *C) {
componentRev := snap.R(24)
const (
size = uint64(1024)
resourceName = "test-component"
resourceName = "standard-component"
)

revHeaders := map[string]interface{}{
Expand Down Expand Up @@ -1213,7 +1213,7 @@ func (s *snapassertsSuite) TestCrossCheckResourceProvenance(c *C) {
}

csi := &snap.ComponentSideInfo{
Component: naming.NewComponentRef("snap", "test-component"),
Component: naming.NewComponentRef("snap", "standard-component"),
Revision: snap.R(24),
}

Expand Down Expand Up @@ -1243,7 +1243,7 @@ func (s *snapassertsSuite) TestCrossCheckResourceProvenance(c *C) {
c.Assert(err, IsNil)

err = snapasserts.CrossCheckResource(resourceName, digest, provenance, size, csi, si, nil, s.localDB)
c.Assert(err, ErrorMatches, `snap resource \"test-component\" revision assertion with provenance \"prov\" is not signed by an authority authorized on this device:.*`)
c.Assert(err, ErrorMatches, `snap resource \"standard-component\" revision assertion with provenance \"prov\" is not signed by an authority authorized on this device:.*`)
}

func (s *snapassertsSuite) TestCrossCheckResourceErrors(c *C) {
Expand All @@ -1252,7 +1252,7 @@ func (s *snapassertsSuite) TestCrossCheckResourceErrors(c *C) {
snapRev := snap.R(12)
const (
size = uint64(1024)
resourceName = "test-component"
resourceName = "standard-component"
snapID = "snap-id-1"
)

Expand Down Expand Up @@ -1296,25 +1296,25 @@ func (s *snapassertsSuite) TestCrossCheckResourceErrors(c *C) {
revisionOverrides: map[string]interface{}{
"resource-size": "1023",
},
err: `resource \"test-component\" file does not have expected size according to signatures \(download is broken or tampered\): 1024 != 1023`,
err: `resource \"standard-component\" file does not have expected size according to signatures \(download is broken or tampered\): 1024 != 1023`,
},
{
revisionOverrides: map[string]interface{}{
"resource-revision": "25",
},
err: `resource \"test-component\" does not have expected revision according to assertions \(metadata is broken or tampered\): 24 != 25`,
err: `resource \"standard-component\" does not have expected revision according to assertions \(metadata is broken or tampered\): 24 != 25`,
},
{
pairOverrides: map[string]interface{}{
"resource-revision": "25",
},
err: `cannot find snap-resource-pair for test-component: snap-resource-pair assertion not found`,
err: `cannot find snap-resource-pair for standard-component: snap-resource-pair assertion not found`,
},
{
revisionOverrides: map[string]interface{}{
"resource-name": "nope",
},
err: `internal error: cannot find pre-populated snap-resource-revision assertion for \"test-component\": .*`,
err: `internal error: cannot find pre-populated snap-resource-revision assertion for \"standard-component\": .*`,
},
}

Expand Down Expand Up @@ -1352,7 +1352,7 @@ func (s *snapassertsSuite) TestCrossCheckResourceErrors(c *C) {
}

csi := &snap.ComponentSideInfo{
Component: naming.NewComponentRef("snap", "test-component"),
Component: naming.NewComponentRef("snap", "standard-component"),
Revision: snap.R(24),
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/snap-exec/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ apps:
command: nostop
components:
comp:
type: test
type: standard
hooks:
install:
`)

var mockClassicYaml = append([]byte("confinement: classic\n"), mockYaml...)

var mockComponentYaml = []byte(`component: snapname+comp
type: test
type: standard
version: 1.0
`)

Expand All @@ -103,7 +103,7 @@ hooks:
command-chain: [chain1, chain2]
components:
comp:
type: test
type: standard
hooks:
install:
command-chain: [chain3, chain4]
Expand Down
4 changes: 2 additions & 2 deletions cmd/snap/cmd_pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ esac
func (s *SnapSuite) TestPackComponentHappy(c *check.C) {
const compYaml = `component: snap+comp
version: 12a
type: test
type: standard
`
_, r := logger.MockLogger()
defer r()
Expand All @@ -219,7 +219,7 @@ type: test
func (s *SnapSuite) TestPackComponentBadName(c *check.C) {
const compYaml = `component: snapcomp
version: 12a
type: test
type: standard
`
_, r := logger.MockLogger()
defer r()
Expand Down
4 changes: 2 additions & 2 deletions cmd/snap/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ var mockYamlWithComponent = []byte(`name: snapname
version: 1.0
components:
comp:
type: test
type: standard
hooks:
install:
hooks:
configure:
`)

var mockComponentYaml = []byte(`component: snapname+comp
type: test
type: standard
version: 1.0
`)

Expand Down
4 changes: 2 additions & 2 deletions daemon/api_sideload_n_try_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (s *sideloadSuite) TestSideloadComponentForNotInstalledSnap(c *check.C) {
defer daemon.MockReadComponentInfoFromCont(func(tempPath string, csi *snap.ComponentSideInfo) (*snap.ComponentInfo, error) {
return &snap.ComponentInfo{
Component: naming.NewComponentRef("local", "comp"),
Type: snap.TestComponent,
Type: snap.StandardComponent,
Version: "1.0",
}, nil
})()
Expand Down Expand Up @@ -447,7 +447,7 @@ func (s *sideloadSuite) sideloadComponentCheck(c *check.C, content string,
defer daemon.MockReadComponentInfoFromCont(func(tempPath string, csi *snap.ComponentSideInfo) (*snap.ComponentInfo, error) {
return snap.NewComponentInfo(
expectedCompSideInfo.Component,
snap.TestComponent,
snap.StandardComponent,
"1.0", "", "", "", nil,
), nil
})()
Expand Down
28 changes: 14 additions & 14 deletions daemon/api_snaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1743,23 +1743,23 @@ func (s *snapsSuite) TestMapLocalFieldsWithComponents(c *check.C) {
Components: map[string]*snap.Component{
"comp-1": {
Name: "comp-1",
Type: "test",
Type: "standard",
},
"comp-2": {
Name: "comp-2",
Type: "test",
Type: "standard",
Summary: "summary 2",
Description: "description 2",
},
"comp-3": {
Name: "comp-3",
Type: "test",
Type: "standard",
Summary: "summary 3",
Description: "description 3",
},
"comp-4": {
Name: "comp-4",
Type: "test",
Type: "standard",
},
},
}
Expand All @@ -1775,12 +1775,12 @@ func (s *snapsSuite) TestMapLocalFieldsWithComponents(c *check.C) {

const comp1yaml = `
component: some-snap+comp-1
type: test
type: standard
version: 1.0
`
const comp2yaml = `
component: some-snap+comp-2
type: test
type: standard
version: 1.0
summary: summary 2
description: description 2
Expand All @@ -1791,9 +1791,9 @@ name: some-snap
version: 1
components:
comp-1:
type: test
type: standard
comp-2:
type: test
type: standard
`

// Mock snap.yaml/component.yaml files for installed components
Expand All @@ -1805,8 +1805,8 @@ components:
csi2 := snap.NewComponentSideInfo(naming.NewComponentRef("some-snap", "comp-2"), snap.R(34))
snaptest.MockComponent(c, comp2yaml, info, *csi2)
comps := []*sequence.ComponentState{
sequence.NewComponentState(csi, snap.TestComponent),
sequence.NewComponentState(csi2, snap.TestComponent),
sequence.NewComponentState(csi, snap.StandardComponent),
sequence.NewComponentState(csi2, snap.StandardComponent),
}

// make InstallDate/InstalledSize work for comp1 and comp2
Expand Down Expand Up @@ -1877,14 +1877,14 @@ components:
{Snap: "some-snap", Name: "foo"},
},
Components: []client.Component{
{Name: "comp-1", Type: "test", Version: "1.0", Revision: snap.R(33),
{Name: "comp-1", Type: "standard", Version: "1.0", Revision: snap.R(33),
InstallDate: snap.ComponentInstallDate(cpi, snap.R(7)), InstalledSize: 2},
{Name: "comp-2", Type: "test", Version: "1.0", Revision: snap.R(34),
{Name: "comp-2", Type: "standard", Version: "1.0", Revision: snap.R(34),
Summary: "summary 2", Description: "description 2",
InstallDate: snap.ComponentInstallDate(cpi2, snap.R(7)), InstalledSize: 3},
{Name: "comp-3", Type: "test",
{Name: "comp-3", Type: "standard",
Summary: "summary 3", Description: "description 3"},
{Name: "comp-4", Type: "test"},
{Name: "comp-4", Type: "standard"},
},
}
c.Check(daemon.MapLocal(about, nil), check.DeepEquals, expected)
Expand Down
2 changes: 1 addition & 1 deletion image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5340,5 +5340,5 @@ func (s *imageSuite) TestSetupSeedLocalComponentBadType(c *C) {
}

err := image.SetupSeed(s.tsto, model, opts)
c.Assert(err, ErrorMatches, "component comp1 has type kernel-modules while snap required20 defines type test for it")
c.Assert(err, ErrorMatches, "component comp1 has type kernel-modules while snap required20 defines type standard for it")
}
4 changes: 2 additions & 2 deletions interfaces/apparmor/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ name: snap
version: 1
components:
comp:
type: test
type: standard
hooks:
install:
plugs:
Expand All @@ -415,7 +415,7 @@ name: snap
version: 1
components:
comp:
type: test
type: standard
plugs:
iface:
`
Expand Down
8 changes: 4 additions & 4 deletions interfaces/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,15 @@ hooks:
plugs: [plug, hook-plug]
components:
comp:
type: test
type: standard
hooks:
install:
plugs: [plug, comp-plug]
`

const componentYaml = `
component: consumer+comp
type: test
type: standard
version: 1
`

Expand Down Expand Up @@ -461,14 +461,14 @@ hooks:
slots: [slot, hook-slot]
components:
comp:
type: test
type: standard
hooks:
install:
`

const componentYaml = `
component: producer+comp
type: test
type: standard
version: 1
`

Expand Down
4 changes: 2 additions & 2 deletions interfaces/ifacetest/backendtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ apps:
app:
components:
comp:
type: test
type: standard
hooks:
install:
plugs:
Expand All @@ -205,7 +205,7 @@ plugs:

var ComponentYaml = `
component: snap+comp
type: test
type: standard
version: 1
`

Expand Down
Loading

0 comments on commit 37eb0a3

Please sign in to comment.