Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into bboozzoo/performa…
Browse files Browse the repository at this point in the history
…nce-parallel-seccomp-compile
  • Loading branch information
bboozzoo committed Dec 3, 2019
2 parents 4d2c7d0 + fa16b1e commit 87723d6
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 2 deletions.
6 changes: 6 additions & 0 deletions boot/modeenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Modeenv struct {
Mode string
RecoverySystem string
Base string
Kernel string
}

func ReadModeenv(rootdir string) (*Modeenv, error) {
Expand All @@ -49,10 +50,12 @@ func ReadModeenv(rootdir string) (*Modeenv, error) {
recoverySystem, _ := cfg.Get("", "recovery_system")
mode, _ := cfg.Get("", "mode")
base, _ := cfg.Get("", "base")
kernel, _ := cfg.Get("", "kernel")
return &Modeenv{
Mode: mode,
RecoverySystem: recoverySystem,
Base: base,
Kernel: kernel,
}, nil
}

Expand All @@ -72,6 +75,9 @@ func (m *Modeenv) Write(rootdir string) error {
if m.Base != "" {
fmt.Fprintf(buf, "base=%s\n", m.Base)
}
if m.Kernel != "" {
fmt.Fprintf(buf, "kernel=%s\n", m.Kernel)
}
if err := osutil.AtomicWriteFile(modeenvPath, buf.Bytes(), 0644, 0); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions boot/modeenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ func (s *modeenvSuite) TestReadModeWithBase(c *C) {
s.makeMockModeenvFile(c, `mode=recovery
recovery_system=20191126
base=core20_123.snap
kernel=pc-kernel_987.snap
`)

modeenv, err := boot.ReadModeenv(s.tmpdir)
c.Assert(err, IsNil)
c.Check(modeenv.Mode, Equals, "recovery")
c.Check(modeenv.RecoverySystem, Equals, "20191126")
c.Check(modeenv.Base, Equals, "core20_123.snap")
c.Check(modeenv.Kernel, Equals, "pc-kernel_987.snap")
}

func (s *modeenvSuite) TestWriteNonExisting(c *C) {
Expand Down Expand Up @@ -131,12 +133,14 @@ func (s *modeenvSuite) TestWriteNonExistingFull(c *C) {
Mode: "run",
RecoverySystem: "20191128",
Base: "core20_321.snap",
Kernel: "pc-kernel_456.snap",
}
err := modeenv.Write(s.tmpdir)
c.Assert(err, IsNil)

c.Assert(s.mockModeenvPath, testutil.FileEquals, `mode=run
recovery_system=20191128
base=core20_321.snap
kernel=pc-kernel_456.snap
`)
}
48 changes: 48 additions & 0 deletions overlord/devicestate/devicemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type DeviceManager struct {

ensureSeedInConfigRan bool

ensureInstalledRan bool

lastBecomeOperationalAttempt time.Time
becomeOperationalBackoff time.Duration
registered bool
Expand Down Expand Up @@ -103,6 +105,7 @@ func Manager(s *state.State, hookManager *hookstate.HookManager, runner *state.T
runner.AddHandler("generate-device-key", m.doGenerateDeviceKey, nil)
runner.AddHandler("request-serial", m.doRequestSerial, nil)
runner.AddHandler("mark-seeded", m.doMarkSeeded, nil)
runner.AddHandler("setup-run-system", m.doSetupRunSystem, nil)
runner.AddHandler("prepare-remodeling", m.doPrepareRemodeling, nil)
runner.AddCleanup("prepare-remodeling", m.cleanupRemodel)
// this *must* always run last and finalizes a remodel
Expand Down Expand Up @@ -487,6 +490,47 @@ func (m *DeviceManager) ensureBootOk() error {
return nil
}

func (m *DeviceManager) ensureInstalled() error {
m.state.Lock()
defer m.state.Unlock()

if release.OnClassic {
return nil
}

if m.ensureInstalledRan {
return nil
}

if m.operatingMode != "install" {
return nil
}

var seeded bool
err := m.state.Get("seeded", &seeded)
if err != nil {
return err
}
if !seeded {
return nil
}

if m.changeInFlight("install-system") {
return nil
}

m.ensureInstalledRan = true

tasks := []*state.Task{}
setupRunSystem := m.state.NewTask("setup-run-system", i18n.G("Setup system for run mode"))
tasks = append(tasks, setupRunSystem)

chg := m.state.NewChange("install-system", i18n.G("Install the system"))
chg.AddAll(state.NewTaskSet(tasks...))

return nil
}

func markSeededInConfig(st *state.State) error {
var seedDone bool
tr := config.NewTransaction(st)
Expand Down Expand Up @@ -566,6 +610,10 @@ func (m *DeviceManager) Ensure() error {
errs = append(errs, err)
}

if err := m.ensureInstalled(); err != nil {
errs = append(errs, err)
}

if len(errs) > 0 {
return &ensureError{errs}
}
Expand Down
105 changes: 105 additions & 0 deletions overlord/devicestate/devicestate_install_mode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2019 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package devicestate_test

import (
. "gopkg.in/check.v1"

"github.com/snapcore/snapd/overlord/devicestate"
"github.com/snapcore/snapd/overlord/state"
"github.com/snapcore/snapd/release"
)

type deviceMgrInstallModeSuite struct {
deviceMgrBaseSuite
}

var _ = Suite(&deviceMgrInstallModeSuite{})

func (s *deviceMgrInstallModeSuite) findInstallSystem() *state.Change {
for _, chg := range s.state.Changes() {
if chg.Kind() == "install-system" {
return chg
}
}
return nil
}

func (s *deviceMgrInstallModeSuite) SetUpTest(c *C) {
s.deviceMgrBaseSuite.SetUpTest(c)

s.state.Lock()
defer s.state.Unlock()
s.state.Set("seeded", true)
}

func (s *deviceMgrInstallModeSuite) TestInstallModeCreatesChangeHappy(c *C) {
restore := release.MockOnClassic(false)
defer restore()

s.state.Lock()
devicestate.SetOperatingMode(s.mgr, "install")
s.state.Unlock()

s.settle(c)

s.state.Lock()
defer s.state.Unlock()

// the install-system change is created
createPartitions := s.findInstallSystem()
c.Assert(createPartitions, NotNil)
}

func (s *deviceMgrInstallModeSuite) TestInstallModeNotInstallmodeNoChg(c *C) {
restore := release.MockOnClassic(false)
defer restore()

s.state.Lock()
devicestate.SetOperatingMode(s.mgr, "")
s.state.Unlock()

s.settle(c)

s.state.Lock()
defer s.state.Unlock()

// the install-system change is *not* created (not in install mode)
createPartitions := s.findInstallSystem()
c.Assert(createPartitions, IsNil)
}

func (s *deviceMgrInstallModeSuite) TestInstallModeNotClassic(c *C) {
restore := release.MockOnClassic(true)
defer restore()

s.state.Lock()
devicestate.SetOperatingMode(s.mgr, "install")
s.state.Unlock()

s.settle(c)

s.state.Lock()
defer s.state.Unlock()

// the install-system change is *not* created (we're on classic)
createPartitions := s.findInstallSystem()
c.Assert(createPartitions, IsNil)
}
40 changes: 40 additions & 0 deletions overlord/devicestate/handlers_install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2019 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package devicestate

import (
"gopkg.in/tomb.v2"

"github.com/snapcore/snapd/overlord/state"
"github.com/snapcore/snapd/timings"
)

func (m *DeviceManager) doSetupRunSystem(t *state.Task, _ *tomb.Tomb) error {
st := t.State()
st.Lock()
defer st.Unlock()

perfTimings := timings.NewForTask(t)
defer perfTimings.Save(st)

// XXX: add handler content

return nil
}
4 changes: 2 additions & 2 deletions tests/lib/hotplug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ check_slot_connected() {
verify_apparmor_profile() {
DEVPATH=$1
for _ in $(seq 10); do
if execute_remote "cat /var/lib/snapd/apparmor/profiles/snap.serial-port-hotplug.consumer" | MATCH "$DEVPATH rw,"; then
if execute_remote "cat /var/lib/snapd/apparmor/profiles/snap.serial-port-hotplug.consumer" | MATCH "$DEVPATH rwk,"; then
break
fi
sleep 1
done
execute_remote "cat /var/lib/snapd/apparmor/profiles/snap.serial-port-hotplug.consumer" | MATCH "$DEVPATH rw,"
execute_remote "cat /var/lib/snapd/apparmor/profiles/snap.serial-port-hotplug.consumer" | MATCH "$DEVPATH rwk,"
}

wait_for_all_changes() {
Expand Down

0 comments on commit 87723d6

Please sign in to comment.