Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into go-mod-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Aug 27, 2021
2 parents d65d959 + 5d21c72 commit 4e5553e
Show file tree
Hide file tree
Showing 34 changed files with 385 additions and 122 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ on:
jobs:
snap-builds:
runs-on: ubuntu-20.04
if: ${{ github.event_name != 'push' && github.ref != 'refs/heads/master' }}
# only build the snap for pull requests, it's not needed on release branches
# or on master since we have launchpad build recipes which do this already
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -208,7 +210,6 @@ jobs:
uses: codecov/codecov-action@v2
if: steps.cached-results.outputs.already-ran != 'true'
with:
# token: ${{ secrets.CODECOV_TOKEN }} # needed ?
fail_ci_if_error: true
flags: unittests
name: codecov-umbrella
Expand All @@ -221,7 +222,9 @@ jobs:
spread:
needs: [unit-tests]
if: ${{ github.event_name != 'push' && github.ref != 'refs/heads/master' }}
# have spread jobs run on master on PRs only, but on both PRs and pushes to
# release branches
if: ${{ github.event_name != 'push' || github.ref != 'refs/heads/master' }}
runs-on: self-hosted
strategy:
# FIXME: enable fail-fast mode once spread can cancel an executing job.
Expand Down Expand Up @@ -296,7 +299,9 @@ jobs:
spread-nested:
needs: [unit-tests]
if: ${{ github.event_name != 'push' && github.ref != 'refs/heads/master' }}
# have spread jobs run on master on PRs only, but on both PRs and pushes to
# release branches
if: ${{ github.event_name != 'push' || github.ref != 'refs/heads/master' }}
runs-on: self-hosted
strategy:
# FIXME: enable fail-fast mode once spread can cancel an executing job.
Expand Down
4 changes: 2 additions & 2 deletions cmd/snap/cmd_snap_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,9 @@ func (x *cmdRefresh) listRefresh() error {
defer w.Flush()

// TRANSLATORS: the %s is to insert a filler escape sequence (please keep it flush to the column header, with no extra spaces)
fmt.Fprintf(w, i18n.G("Name\tVersion\tRev\tPublisher%s\tNotes\n"), fillerPublisher(esc))
fmt.Fprintf(w, i18n.G("Name\tVersion\tRev\tSize\tPublisher%s\tNotes\n"), fillerPublisher(esc))
for _, snap := range snaps {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", snap.Name, snap.Version, snap.Revision, shortPublisher(esc, snap.Publisher), NotesFromRemote(snap, nil))
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n", snap.Name, snap.Version, snap.Revision, strutil.SizeToStr(snap.DownloadSize), shortPublisher(esc, snap.Publisher), NotesFromRemote(snap, nil))
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/snap/cmd_snap_op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ func (s *SnapSuite) TestRefreshList(c *check.C) {
c.Check(r.Method, check.Equals, "GET")
c.Check(r.URL.Path, check.Equals, "/v2/find")
c.Check(r.URL.Query().Get("select"), check.Equals, "refresh")
fmt.Fprintln(w, `{"type": "sync", "result": [{"name": "foo", "status": "active", "version": "4.2update1", "developer": "bar", "publisher": {"id": "bar-id", "username": "bar", "display-name": "Bar", "validation": "unproven"}, "revision":17,"summary":"some summary"}]}`)
fmt.Fprintln(w, `{"type": "sync", "result": [{"name": "foo", "status": "active", "version": "4.2update1", "developer": "bar", "download-size": 436375552, "publisher": {"id": "bar-id", "username": "bar", "display-name": "Bar", "validation": "unproven"}, "revision":17,"summary":"some summary"}]}`)
default:
c.Fatalf("expected to get 1 requests, now on %d", n+1)
}
Expand All @@ -1088,8 +1088,8 @@ func (s *SnapSuite) TestRefreshList(c *check.C) {
rest, err := snap.Parser(snap.Client()).ParseArgs([]string{"refresh", "--list"})
c.Assert(err, check.IsNil)
c.Assert(rest, check.DeepEquals, []string{})
c.Check(s.Stdout(), check.Matches, `Name +Version +Rev +Publisher +Notes
foo +4.2update1 +17 +bar +-.*
c.Check(s.Stdout(), check.Matches, `Name +Version +Rev +Size +Publisher +Notes
foo +4.2update1 +17 +436MB +bar +-.*
`)
c.Check(s.Stderr(), check.Equals, "")
// ensure that the fake server api was actually hit
Expand Down
4 changes: 2 additions & 2 deletions daemon/api_snaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func snapUpdate(inst *snapInstruction, st *state.State) (string, []*state.TaskSe
}

// we need refreshed snap-declarations to enforce refresh-control as best as we can
if err = assertstateRefreshSnapDeclarations(st, inst.userID); err != nil {
if err = assertstateRefreshSnapDeclarations(st, inst.userID, nil); err != nil {
return "", nil, err
}

Expand Down Expand Up @@ -585,7 +585,7 @@ func snapInstallMany(inst *snapInstruction, st *state.State) (*snapInstructionRe

func snapUpdateMany(inst *snapInstruction, st *state.State) (*snapInstructionResult, error) {
// we need refreshed snap-declarations to enforce refresh-control as best as we can, this also ensures that snap-declarations and their prerequisite assertions are updated regularly
if err := assertstateRefreshSnapDeclarations(st, inst.userID); err != nil {
if err := assertstateRefreshSnapDeclarations(st, inst.userID, nil); err != nil {
return nil, err
}

Expand Down
30 changes: 15 additions & 15 deletions daemon/api_snaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (s *snapsSuite) TestPostSnapsOpMoreComplexContentType(c *check.C) {
}

func (s *snapsSuite) testPostSnapsOp(c *check.C, contentType string) {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(*state.State, int) error { return nil })()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(*state.State, int, *assertstate.RefreshAssertionsOptions) error { return nil })()
defer daemon.MockSnapstateUpdateMany(func(_ context.Context, s *state.State, names []string, userID int, flags *snapstate.Flags) ([]string, []*state.TaskSet, error) {
c.Check(names, check.HasLen, 0)
t := s.NewTask("fake-refresh-all", "Refreshing everything")
Expand Down Expand Up @@ -519,9 +519,9 @@ func (s *snapsSuite) TestPostSnapsOpInvalidCharset(c *check.C) {

func (s *snapsSuite) TestRefreshAll(c *check.C) {
refreshSnapDecls := false
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, opts *assertstate.RefreshAssertionsOptions) error {
refreshSnapDecls = true
return assertstate.RefreshSnapDeclarations(s, userID)
return assertstate.RefreshSnapDeclarations(s, userID, opts)
})()

d := s.daemon(c)
Expand Down Expand Up @@ -555,9 +555,9 @@ func (s *snapsSuite) TestRefreshAll(c *check.C) {

func (s *snapsSuite) TestRefreshAllNoChanges(c *check.C) {
refreshSnapDecls := false
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, opts *assertstate.RefreshAssertionsOptions) error {
refreshSnapDecls = true
return assertstate.RefreshSnapDeclarations(s, userID)
return assertstate.RefreshSnapDeclarations(s, userID, opts)
})()

defer daemon.MockSnapstateUpdateMany(func(_ context.Context, s *state.State, names []string, userID int, flags *snapstate.Flags) ([]string, []*state.TaskSet, error) {
Expand All @@ -578,7 +578,7 @@ func (s *snapsSuite) TestRefreshAllNoChanges(c *check.C) {

func (s *snapsSuite) TestRefreshMany(c *check.C) {
refreshSnapDecls := false
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, _ *assertstate.RefreshAssertionsOptions) error {
refreshSnapDecls = true
return nil
})()
Expand All @@ -603,7 +603,7 @@ func (s *snapsSuite) TestRefreshMany(c *check.C) {

func (s *snapsSuite) TestRefreshMany1(c *check.C) {
refreshSnapDecls := false
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, _ *assertstate.RefreshAssertionsOptions) error {
refreshSnapDecls = true
return nil
})()
Expand Down Expand Up @@ -1434,7 +1434,7 @@ func (s *snapsSuite) TestInstallIgnoreValidation(c *check.C) {
t := s.NewTask("fake-install-snap", "Doing a fake install")
return state.NewTaskSet(t), nil
})()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, opts *assertstate.RefreshAssertionsOptions) error {
return nil
})()

Expand Down Expand Up @@ -1600,7 +1600,7 @@ func (s *snapsSuite) TestRefresh(c *check.C) {
t := s.NewTask("fake-refresh-snap", "Doing a fake install")
return state.NewTaskSet(t), nil
})()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, opts *assertstate.RefreshAssertionsOptions) error {
assertstateCalledUserID = userID
return nil
})()
Expand Down Expand Up @@ -1639,7 +1639,7 @@ func (s *snapsSuite) TestRefreshDevMode(c *check.C) {
t := s.NewTask("fake-refresh-snap", "Doing a fake install")
return state.NewTaskSet(t), nil
})()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, _ *assertstate.RefreshAssertionsOptions) error {
return nil
})()

Expand Down Expand Up @@ -1673,7 +1673,7 @@ func (s *snapsSuite) TestRefreshClassic(c *check.C) {
calledFlags = flags
return nil, nil
})()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, _ *assertstate.RefreshAssertionsOptions) error {
return nil
})()

Expand Down Expand Up @@ -1707,7 +1707,7 @@ func (s *snapsSuite) TestRefreshIgnoreValidation(c *check.C) {
t := s.NewTask("fake-refresh-snap", "Doing a fake install")
return state.NewTaskSet(t), nil
})()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, _ *assertstate.RefreshAssertionsOptions) error {
return nil
})()

Expand Down Expand Up @@ -1746,7 +1746,7 @@ func (s *snapsSuite) TestRefreshIgnoreRunning(c *check.C) {
t := s.NewTask("fake-refresh-snap", "Doing a fake install")
return state.NewTaskSet(t), nil
})()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, _ *assertstate.RefreshAssertionsOptions) error {
return nil
})()

Expand Down Expand Up @@ -1781,7 +1781,7 @@ func (s *snapsSuite) TestRefreshCohort(c *check.C) {
t := s.NewTask("fake-refresh-snap", "Doing a fake install")
return state.NewTaskSet(t), nil
})()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, _ *assertstate.RefreshAssertionsOptions) error {
return nil
})()

Expand Down Expand Up @@ -1811,7 +1811,7 @@ func (s *snapsSuite) TestRefreshLeaveCohort(c *check.C) {
t := s.NewTask("fake-refresh-snap", "Doing a fake install")
return state.NewTaskSet(t), nil
})()
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int) error {
defer daemon.MockAssertstateRefreshSnapDeclarations(func(s *state.State, userID int, _ *assertstate.RefreshAssertionsOptions) error {
return nil
})()

Expand Down
3 changes: 2 additions & 1 deletion daemon/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/gorilla/mux"

"github.com/snapcore/snapd/overlord"
"github.com/snapcore/snapd/overlord/assertstate"
"github.com/snapcore/snapd/overlord/snapstate"
"github.com/snapcore/snapd/overlord/state"
"github.com/snapcore/snapd/snap"
Expand Down Expand Up @@ -105,7 +106,7 @@ func MockUnsafeReadSnapInfo(mock func(string) (*snap.Info, error)) (restore func
}
}

func MockAssertstateRefreshSnapDeclarations(mock func(*state.State, int) error) (restore func()) {
func MockAssertstateRefreshSnapDeclarations(mock func(*state.State, int, *assertstate.RefreshAssertionsOptions) error) (restore func()) {
oldAssertstateRefreshSnapDeclarations := assertstateRefreshSnapDeclarations
assertstateRefreshSnapDeclarations = mock
return func() {
Expand Down
1 change: 0 additions & 1 deletion get-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

set -e


echo Obtaining dependencies
go mod vendor

Expand Down
36 changes: 26 additions & 10 deletions overlord/assertstate/assertstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ func findError(format string, ref *asserts.Ref, err error) error {
}
}

type RefreshAssertionsOptions struct {
IsAutoRefresh bool
}

// RefreshSnapDeclarations refetches all the current snap declarations and their prerequisites.
func RefreshSnapDeclarations(s *state.State, userID int) error {
func RefreshSnapDeclarations(s *state.State, userID int, opts *RefreshAssertionsOptions) error {
if opts == nil {
opts = &RefreshAssertionsOptions{}
}

deviceCtx, err := snapstate.DevicePastSeeding(s, nil)
if err != nil {
return err
Expand All @@ -67,7 +75,7 @@ func RefreshSnapDeclarations(s *state.State, userID int) error {
return nil
}

err = bulkRefreshSnapDeclarations(s, snapStates, userID, deviceCtx)
err = bulkRefreshSnapDeclarations(s, snapStates, userID, deviceCtx, opts)
if err == nil {
// done
return nil
Expand Down Expand Up @@ -336,15 +344,20 @@ func delayedCrossMgrInit() {

// AutoRefreshAssertions tries to refresh all assertions
func AutoRefreshAssertions(s *state.State, userID int) error {
if err := RefreshSnapDeclarations(s, userID); err != nil {
opts := &RefreshAssertionsOptions{IsAutoRefresh: true}
if err := RefreshSnapDeclarations(s, userID, opts); err != nil {
return err
}
return RefreshValidationSetAssertions(s, userID)
return RefreshValidationSetAssertions(s, userID, opts)
}

// RefreshValidationSetAssertions tries to refresh all validation set
// assertions.
func RefreshValidationSetAssertions(s *state.State, userID int) error {
func RefreshValidationSetAssertions(s *state.State, userID int, opts *RefreshAssertionsOptions) error {
if opts == nil {
opts = &RefreshAssertionsOptions{}
}

deviceCtx, err := snapstate.DevicePastSeeding(s, nil)
if err != nil {
return err
Expand Down Expand Up @@ -391,7 +404,7 @@ func RefreshValidationSetAssertions(s *state.State, userID int) error {
return nil
}

if err := bulkRefreshValidationSetAsserts(s, monitorModeSets, nil, userID, deviceCtx); err != nil {
if err := bulkRefreshValidationSetAsserts(s, monitorModeSets, nil, userID, deviceCtx, opts); err != nil {
return err
}
if err := updateTracking(monitorModeSets); err != nil {
Expand Down Expand Up @@ -430,7 +443,7 @@ func RefreshValidationSetAssertions(s *state.State, userID int) error {
return vsets.Conflict()
}

if err := bulkRefreshValidationSetAsserts(s, enforceModeSets, checkForConflicts, userID, deviceCtx); err != nil {
if err := bulkRefreshValidationSetAsserts(s, enforceModeSets, checkForConflicts, userID, deviceCtx, opts); err != nil {
if _, ok := err.(*snapasserts.ValidationSetsConflictError); ok {
logger.Noticef("cannot refresh to conflicting validation set assertions: %v", err)
return nil
Expand Down Expand Up @@ -514,7 +527,8 @@ func ValidationSetAssertionForMonitor(st *state.State, accountID, name string, s
}
}

if err := resolvePoolNoFallback(st, pool, nil, userID, deviceCtx); err != nil {
refreshOpts := &RefreshAssertionsOptions{IsAutoRefresh: false}
if err := resolvePoolNoFallback(st, pool, nil, userID, deviceCtx, refreshOpts); err != nil {
rerr, ok := err.(*resolvePoolError)
if ok && as != nil && opts.AllowLocalFallback {
if e := rerr.errors[atSeq.Unique()]; asserts.IsNotFound(e) {
Expand Down Expand Up @@ -549,9 +563,11 @@ func ValidationSetAssertionForEnforce(st *state.State, accountID, name string, s
return nil, err
}

opts := &RefreshAssertionsOptions{IsAutoRefresh: false}

// refresh all currently tracked validation set assertions (this may or may not
// include the one requested by the caller).
if err = RefreshValidationSetAssertions(st, userID); err != nil {
if err = RefreshValidationSetAssertions(st, userID, opts); err != nil {
return nil, err
}

Expand Down Expand Up @@ -664,7 +680,7 @@ func ValidationSetAssertionForEnforce(st *state.State, accountID, name string, s
return nil
}

if err := resolvePoolNoFallback(st, pool, checkBeforeCommit, userID, deviceCtx); err != nil {
if err := resolvePoolNoFallback(st, pool, checkBeforeCommit, userID, deviceCtx, opts); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit 4e5553e

Please sign in to comment.