Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions overlord/devicestate/devicestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"github.com/snapcore/snapd/asserts"
"github.com/snapcore/snapd/boot"
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/gadget"
"github.com/snapcore/snapd/i18n"
"github.com/snapcore/snapd/logger"
Expand Down Expand Up @@ -129,6 +130,15 @@ func canAutoRefresh(st *state.State) (bool, error) {
return false, nil
}

// Syncloud runs no serial vault and deliberately skips registration via
// the noregister marker, so ensureOperational never attempts registration
// and ensureOperationalAttempts stays at 0. Without this the serial check
// below would disable auto-refresh forever. Allow it when registration was
// intentionally opted out.
if osutil.FileExists(filepath.Join(dirs.SnapRunDir, "noregister")) {
return true, nil
}

// Either we have a serial or we try anyway if we attempted
// for a while to get a serial, this would allow us to at
// least upgrade core if that can help.
Expand Down
31 changes: 31 additions & 0 deletions overlord/devicestate/devicestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,37 @@ func (s *deviceMgrSuite) TestCanAutoRefreshNoSerialFallback(c *C) {
c.Check(canAutoRefresh(), Equals, true)
}

func (s *deviceMgrSuite) TestCanAutoRefreshNoRegister(c *C) {
s.state.Lock()
defer s.state.Unlock()

canAutoRefresh := func() bool {
ok, err := devicestate.CanAutoRefresh(s.state)
c.Assert(err, IsNil)
return ok
}

// seeded, model, no serial, no registration attempts -> no auto-refresh
s.state.Set("seeded", true)
devicestatetest.SetDevice(s.state, &auth.DeviceState{
Brand: "canonical",
Model: "pc",
})
s.makeModelAssertionInState(c, "canonical", "pc", map[string]interface{}{
"architecture": "amd64",
"kernel": "pc-kernel",
"gadget": "pc",
})
c.Check(devicestate.EnsureOperationalAttempts(s.state), Equals, 0)
c.Check(canAutoRefresh(), Equals, false)

// registration deliberately skipped via the noregister marker
// -> auto-refresh without a serial or any registration attempts
c.Assert(os.MkdirAll(dirs.SnapRunDir, 0755), IsNil)
c.Assert(ioutil.WriteFile(filepath.Join(dirs.SnapRunDir, "noregister"), nil, 0644), IsNil)
c.Check(canAutoRefresh(), Equals, true)
}

func (s *deviceMgrSuite) TestCanAutoRefreshOnClassic(c *C) {
release.OnClassic = true

Expand Down
Loading