Skip to content

Commit

Permalink
o/snapstate, daemon: respect lanes that are passed to snapstate.Insta…
Browse files Browse the repository at this point in the history
…llComponents, snapstate.InstallComponentPath (#14695)
  • Loading branch information
andrewphelpsj authored Nov 8, 2024
1 parent 2a2e6d1 commit 8f5a8aa
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 35 deletions.
4 changes: 3 additions & 1 deletion daemon/api_sideload_n_try.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ func sideloadSnap(_ context.Context, st *state.State, snapFile *uploadedSnap, fl
contType = "component"
message = fmt.Sprintf("%q component for %q snap",
compInfo.Component.ComponentName, instanceName)
tset, err = snapstateInstallComponentPath(st, snap.NewComponentSideInfo(compInfo.Component, snap.Revision{}), snapInfo, snapFile.tmpPath, flags.Flags)
tset, err = snapstateInstallComponentPath(st, snap.NewComponentSideInfo(compInfo.Component, snap.Revision{}), snapInfo, snapFile.tmpPath, snapstate.Options{
Flags: flags.Flags,
})
}
if err != nil {
return nil, errToResponse(err, []string{sideInfo.RealName}, InternalError, "cannot install %s file: %v", contType)
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 @@ -453,9 +453,9 @@ func (s *sideloadSuite) sideloadComponentCheck(c *check.C, content string,
})()

defer daemon.MockSnapstateInstallComponentPath(func(st *state.State, csi *snap.ComponentSideInfo, info *snap.Info,
path string, flags snapstate.Flags) (*state.TaskSet, error) {
path string, opts snapstate.Options) (*state.TaskSet, error) {
c.Check(csi, check.DeepEquals, expectedCompSideInfo)
c.Check(flags, check.DeepEquals, expectedFlags)
c.Check(opts.Flags, check.DeepEquals, expectedFlags)
c.Check(path, testutil.FileEquals, "xyzzy")

installQueue = append(installQueue, csi.Component.String()+"::"+path)
Expand Down
2 changes: 1 addition & 1 deletion daemon/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func MockSnapstateInstallPathMany(f func(context.Context, *state.State, []*snap.
}
}

func MockSnapstateInstallComponentPath(f func(st *state.State, csi *snap.ComponentSideInfo, info *snap.Info, path string, flags snapstate.Flags) (*state.TaskSet, error)) func() {
func MockSnapstateInstallComponentPath(f func(st *state.State, csi *snap.ComponentSideInfo, info *snap.Info, path string, opts snapstate.Options) (*state.TaskSet, error)) func() {
old := snapstateInstallComponentPath
snapstateInstallComponentPath = f
return func() {
Expand Down
39 changes: 33 additions & 6 deletions overlord/snapstate/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ import (
// InstallComponents installs all of the components in the given names list. The
// snap represented by info must already be installed, and all of the components
// in names should not be installed prior to calling this function.
//
// TODO:COMPS: respect the transaction that is passed to this function
func InstallComponents(ctx context.Context, st *state.State, names []string, info *snap.Info, opts Options) ([]*state.TaskSet, error) {
if err := opts.setDefaultLane(st); err != nil {
return nil, err
}

if err := setDefaultSnapstateOptions(st, &opts); err != nil {
return nil, err
}

var snapst SnapState
err := Get(st, info.InstanceName(), &snapst)
if err != nil {
Expand Down Expand Up @@ -83,6 +89,8 @@ func InstallComponents(ctx context.Context, st *state.State, names []string, inf
kmodSetup.Set("snap-setup-task", setupSecurity.ID())
}

lane := generateLane(st, opts)

tss := make([]*state.TaskSet, 0, len(compsups))
compSetupIDs := make([]string, 0, len(compsups))
for _, compsup := range compsups {
Expand All @@ -100,7 +108,11 @@ func InstallComponents(ctx context.Context, st *state.State, names []string, inf
}

compSetupIDs = append(compSetupIDs, componentTS.compSetupTaskID)
tss = append(tss, componentTS.taskSet())

ts := componentTS.taskSet()
ts.JoinLane(lane)

tss = append(tss, ts)
}

setupSecurity.Set("component-setup-tasks", compSetupIDs)
Expand All @@ -109,6 +121,10 @@ func InstallComponents(ctx context.Context, st *state.State, names []string, inf
if kmodSetup != nil {
ts.AddTask(kmodSetup)
}

// note that this must come after all tasks are added to the task set
ts.JoinLane(lane)

return append(tss, ts), nil
}

Expand Down Expand Up @@ -201,7 +217,15 @@ func installComponentAction(st *state.State, snapst SnapState, snapRev snap.Revi
// full metadata in which case the component will appear as installed from the
// store.
func InstallComponentPath(st *state.State, csi *snap.ComponentSideInfo, info *snap.Info,
path string, flags Flags) (*state.TaskSet, error) {
path string, opts Options) (*state.TaskSet, error) {
if err := opts.setDefaultLane(st); err != nil {
return nil, err
}

if err := setDefaultSnapstateOptions(st, &opts); err != nil {
return nil, err
}

var snapst SnapState
// owner snap must be already installed
err := Get(st, info.InstanceName(), &snapst)
Expand All @@ -223,7 +247,7 @@ func InstallComponentPath(st *state.State, csi *snap.ComponentSideInfo, info *sn
Base: info.Base,
SideInfo: &info.SideInfo,
Channel: info.Channel,
Flags: flags.ForSnapSetup(),
Flags: opts.Flags.ForSnapSetup(),
Type: info.Type(),
Version: info.Version,
PlugsOnly: len(info.Slots) == 0,
Expand All @@ -244,7 +268,10 @@ func InstallComponentPath(st *state.State, csi *snap.ComponentSideInfo, info *sn
return nil, err
}

return componentTS.taskSet(), nil
ts := componentTS.taskSet()
ts.JoinLane(generateLane(st, opts))

return ts, nil
}

type ComponentInstallFlags struct {
Expand Down
Loading

0 comments on commit 8f5a8aa

Please sign in to comment.