Skip to content

Commit

Permalink
Add snap info to each task
Browse files Browse the repository at this point in the history
In order to allow Refresh Awareness to be able to link a task
to the corresponding snap being refreshed when a single notice
contains several snaps, it is a must to include that info into
each task.

This patch adds the snap name, snap instance and snap revision
(when available) into each task.
  • Loading branch information
sergio-costas committed Apr 26, 2024
1 parent 15b23e9 commit 78f76ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions client/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ type Task struct {

SpawnTime time.Time `json:"spawn-time,omitempty"`
ReadyTime time.Time `json:"ready-time,omitempty"`

SnapName string `json:"snap-name,omitempty"`
InstanceName string `json:"instance-name,omitempty"`
Revision string `json:"revision,omitempty"`
}

type TaskProgress struct {
Expand Down
15 changes: 9 additions & 6 deletions client/change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (cs *clientSuite) TestClientChangeError(c *check.C) {
"summary": "...",
"status": "Error",
"ready": true,
"tasks": [{"kind": "bar", "summary": "...", "status": "Error", "progress": {"done": 1, "total": 1}, "log": ["ERROR: something broke"]}],
"tasks": [{"kind": "bar", "summary": "...", "status": "Error", "progress": {"done": 1, "total": 1}, "log": ["ERROR: something broke"], "snap-name": "a_snap", "instance-name": "instance_value", "revision": "891"}],
"err": "error message"
}}`

Expand All @@ -119,11 +119,14 @@ func (cs *clientSuite) TestClientChangeError(c *check.C) {
Summary: "...",
Status: "Error",
Tasks: []*client.Task{{
Kind: "bar",
Summary: "...",
Status: "Error",
Progress: client.TaskProgress{Done: 1, Total: 1},
Log: []string{"ERROR: something broke"},
Kind: "bar",
Summary: "...",
Status: "Error",
Progress: client.TaskProgress{Done: 1, Total: 1},
Log: []string{"ERROR: something broke"},
SnapName: "a_snap",
InstanceName: "instance_value",
Revision: "891",
}},
Err: "error message",
Ready: true,
Expand Down
11 changes: 11 additions & 0 deletions daemon/api_general.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/snapcore/snapd/overlord/auth"
"github.com/snapcore/snapd/overlord/configstate/config"
"github.com/snapcore/snapd/overlord/devicestate"
"github.com/snapcore/snapd/overlord/snapstate"
"github.com/snapcore/snapd/overlord/state"
"github.com/snapcore/snapd/release"
"github.com/snapcore/snapd/sandbox"
Expand Down Expand Up @@ -336,6 +337,10 @@ type taskInfo struct {

SpawnTime time.Time `json:"spawn-time,omitempty"`
ReadyTime *time.Time `json:"ready-time,omitempty"`

SnapName string `json:"snap-name,omitempty"`
InstanceName string `json:"instance-name,omitempty"`
Revision string `json:"revision,omitempty"`
}

type taskInfoProgress struct {
Expand Down Expand Up @@ -381,6 +386,12 @@ func change2changeInfo(chg *state.Change) *changeInfo {
},
SpawnTime: t.SpawnTime(),
}
snapsup, err := snapstate.TaskSnapSetup(t)
if err == nil {
taskInfo.SnapName = snapsup.SnapName()
taskInfo.InstanceName = snapsup.InstanceName()
taskInfo.Revision = snapsup.Revision().String()
}
readyTime := t.ReadyTime()
if !readyTime.IsZero() {
taskInfo.ReadyTime = &readyTime
Expand Down

0 comments on commit 78f76ac

Please sign in to comment.