Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into snapd-users-phase…
Browse files Browse the repository at this point in the history
…0.25-5-create-snap-daemon-user
  • Loading branch information
Jamie Strandboge committed Aug 15, 2019
2 parents 5b485bf + 1ceb215 commit 1daac64
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 22 deletions.
8 changes: 0 additions & 8 deletions gadget/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ var (
UpdaterForStructure = updaterForStructure
)

func MockUpdaterForStructure(mock func(ps *PositionedStructure, rootDir, rollbackDir string) (Updater, error)) (restore func()) {
old := updaterForStructure
updaterForStructure = mock
return func() {
updaterForStructure = old
}
}

func MockEvalSymlinks(mock func(path string) (string, error)) (restore func()) {
oldEvalSymlinks := evalSymlinks
evalSymlinks = mock
Expand Down
9 changes: 9 additions & 0 deletions gadget/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,12 @@ func updaterForStructureImpl(ps *PositionedStructure, newRootDir, rollbackDir st
}
return updater, err
}

// MockUpdaterForStructure replace internal call with a mocked one, for use in tests only
func MockUpdaterForStructure(mock func(ps *PositionedStructure, rootDir, rollbackDir string) (Updater, error)) (restore func()) {
old := updaterForStructure
updaterForStructure = mock
return func() {
updaterForStructure = old
}
}
5 changes: 0 additions & 5 deletions interfaces/builtin/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ func (iface *commonInterface) StaticInfo() interfaces.StaticInfo {
}
}

// BeforePrepareSlot checks and possibly modifies a slot.
func (iface *commonInterface) BeforePrepareSlot(slot *snap.SlotInfo) error {
return nil
}

func (iface *commonInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
if iface.usesPtraceTrace {
spec.SetUsesPtraceTrace()
Expand Down
1 change: 1 addition & 0 deletions overlord/configstate/configcore/picfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var piConfigKeys = map[string]bool{
"sdtv_aspect": true,
"config_hdmi_boost": true,
"hdmi_force_hotplug": true,
"start_x": true,
}

func init() {
Expand Down
99 changes: 99 additions & 0 deletions overlord/devicestate/devicestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -67,6 +68,7 @@ import (
"github.com/snapcore/snapd/snap/snaptest"
"github.com/snapcore/snapd/store/storetest"
"github.com/snapcore/snapd/strutil"
"github.com/snapcore/snapd/testutil"
"github.com/snapcore/snapd/timings"
)

Expand Down Expand Up @@ -3453,6 +3455,103 @@ func (s *deviceMgrSuite) TestUpdateGadgetOnClassicErrorsOut(c *C) {
c.Check(t.Status(), Equals, state.ErrorStatus)
}

type mockUpdater struct{}

func (m *mockUpdater) Backup() error { return nil }

func (m *mockUpdater) Rollback() error { return nil }

func (m *mockUpdater) Update() error { return nil }

func (s *deviceMgrSuite) TestUpdateGadgetCallsToGadget(c *C) {
siCurrent := &snap.SideInfo{
RealName: "foo-gadget",
Revision: snap.R(33),
SnapID: "foo-id",
}
si := &snap.SideInfo{
RealName: "foo-gadget",
Revision: snap.R(34),
SnapID: "foo-id",
}
var gadgetCurrentYaml = `
volumes:
pc:
bootloader: grub
structure:
- name: foo
size: 10M
type: bare
content:
- image: content.img
`
var gadgetUpdateYaml = `
volumes:
pc:
bootloader: grub
structure:
- name: foo
size: 10M
type: bare
content:
- image: content.img
update:
edition: 2
`
snaptest.MockSnapWithFiles(c, snapYaml, siCurrent, [][]string{
{"meta/gadget.yaml", gadgetCurrentYaml},
{"content.img", "some content"},
})
updateInfo := snaptest.MockSnapWithFiles(c, snapYaml, si, [][]string{
{"meta/gadget.yaml", gadgetUpdateYaml},
{"content.img", "updated content"},
})

expectedRollbackDir := filepath.Join(dirs.SnapRollbackDir, "foo-gadget_34")
updaterForStructureCalls := 0
gadget.MockUpdaterForStructure(func(ps *gadget.PositionedStructure, rootDir, rollbackDir string) (gadget.Updater, error) {
updaterForStructureCalls++

c.Assert(ps.Name, Equals, "foo")
c.Assert(rootDir, Equals, updateInfo.MountDir())
c.Assert(filepath.Join(rootDir, "content.img"), testutil.FileEquals, "updated content")
c.Assert(strings.HasPrefix(rollbackDir, expectedRollbackDir), Equals, true)
c.Assert(osutil.IsDirectory(rollbackDir), Equals, true)
return &mockUpdater{}, nil
})

s.state.Lock()

snapstate.Set(s.state, "foo-gadget", &snapstate.SnapState{
SnapType: "gadget",
Sequence: []*snap.SideInfo{siCurrent},
Current: siCurrent.Revision,
Active: true,
})

t := s.state.NewTask("update-gadget-assets", "update gadget")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: si,
Type: snap.TypeGadget,
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)

s.state.Unlock()

for i := 0; i < 6; i++ {
s.se.Ensure()
s.se.Wait()
}

s.state.Lock()
defer s.state.Unlock()
c.Assert(chg.IsReady(), Equals, true)
c.Check(t.Status(), Equals, state.DoneStatus)
c.Check(s.restartRequests, HasLen, 1)
c.Check(updaterForStructureCalls, Equals, 1)
}

func (s *deviceMgrSuite) TestCurrentAndUpdateInfo(c *C) {
siCurrent := &snap.SideInfo{
RealName: "foo-gadget",
Expand Down
6 changes: 1 addition & 5 deletions overlord/devicestate/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,13 +926,9 @@ func gadgetCurrentAndUpdate(st *state.State, snapsup *snapstate.SnapSetup) (curr
}

var (
gadgetUpdate = nopGadgetOp
gadgetUpdate = gadget.Update
)

func nopGadgetOp(current, update gadget.GadgetData, rollbackRootDir string) error {
return nil
}

func (m *DeviceManager) doUpdateGadgetAssets(t *state.Task, _ *tomb.Tomb) error {
if release.OnClassic {
return fmt.Errorf("cannot run update gadget assets task on a classic system")
Expand Down
2 changes: 1 addition & 1 deletion overlord/ifacestate/ifacestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3720,7 +3720,7 @@ slots:
c.Check(ifacestate.CheckInterfaces(s.state, snapInfo, deviceCtx), ErrorMatches, "installation denied.*")
}

func (s *interfaceManagerSuite) TestCheckInterfacesDenySkippedWithMinimalCheckIfNoDecl(c *C) {
func (s *interfaceManagerSuite) TestCheckInterfacesNoDenyIfNoDecl(c *C) {
deviceCtx := s.TrivialDeviceContext(c, nil)
restore := assertstest.MockBuiltinBaseDeclaration([]byte(`
type: base-declaration
Expand Down
2 changes: 1 addition & 1 deletion spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ backends:
- ubuntu-16.04-64:
workers: 8
- ubuntu-18.04-64:
workers: 6
workers: 8
- ubuntu-19.04-64:
workers: 6
- ubuntu-core-16-64:
Expand Down
21 changes: 19 additions & 2 deletions tests/lib/store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,30 @@ make_snap_installable(){
local dir="$1"
local snap_path="$2"

new_snap_declaration "$dir" "$snap_path"
new_snap_revision "$dir" "$snap_path"
}

new_snap_declaration(){
local dir="$1"
local snap_path="$2"
shift 2

cp -a "$snap_path" "$dir"
p=$(fakestore new-snap-declaration --dir "$dir" "${snap_path}")
p=$(fakestore new-snap-declaration --dir "$dir" "$@" "${snap_path}" )
snap ack "$p"
p=$(fakestore new-snap-revision --dir "$dir" "${snap_path}")
}

new_snap_revision(){
local dir="$1"
local snap_path="$2"
shift 2

p=$(fakestore new-snap-revision --dir "$dir" "$@" "${snap_path}")
snap ack "$p"
}


setup_fake_store(){
# before switching make sure we have a session macaroon
snap find test-snapd-tools
Expand Down
37 changes: 37 additions & 0 deletions tests/main/gadget-update-pc/pc-gadget-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
volumes:
pc:
bootloader: grub
structure:
- name: mbr
type: mbr
size: 440
content:
- image: pc-boot.img
- name: BIOS Boot
type: DA,21686148-6449-6E6F-744E-656564454649
size: 1M
offset: 1M
offset-write: mbr+92
content:
- image: pc-core.img
# write new content right after the previous one
- image: foo.img
update:
edition: 1
- name: EFI System
type: EF,C12A7328-F81F-11D2-BA4B-00A0C93EC93B
filesystem: vfat
filesystem-label: system-boot
size: 50M
content:
- source: grubx64.efi
target: EFI/boot/grubx64.efi
- source: shim.efi.signed
target: EFI/boot/bootx64.efi
- source: grub.cfg
target: EFI/ubuntu/grub.cfg
# drop a new file
- source: foo.cfg
target: foo.cfg
update:
edition: 1
44 changes: 44 additions & 0 deletions tests/main/gadget-update-pc/pc-gadget-3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
volumes:
pc:
bootloader: grub
structure:
- name: mbr
type: mbr
size: 440
content:
- image: pc-boot.img
- name: BIOS Boot
type: DA,21686148-6449-6E6F-744E-656564454649
size: 1M
offset: 1M
offset-write: mbr+92
content:
- image: pc-core.img
# content is modified again
- image: foo.img
update:
edition: 2
- name: EFI System
type: EF,C12A7328-F81F-11D2-BA4B-00A0C93EC93B
filesystem: vfat
filesystem-label: system-boot
size: 50M
content:
- source: grubx64.efi
target: EFI/boot/grubx64.efi
- source: shim.efi.signed
target: EFI/boot/bootx64.efi
- source: grub.cfg
target: EFI/ubuntu/grub.cfg
# drop new files
- source: foo.cfg
target: foo.cfg
- source: bar.cfg
target: bar.cfg
update:
edition: 2
preserve:
# foo is modified in the test and shall be preserved
- foo.cfg
# bar does not exist and will be installed
- bar.cfg
28 changes: 28 additions & 0 deletions tests/main/gadget-update-pc/pc-gadget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
volumes:
pc:
bootloader: grub
structure:
- name: mbr
type: mbr
size: 440
content:
- image: pc-boot.img
- name: BIOS Boot
type: DA,21686148-6449-6E6F-744E-656564454649
size: 1M
offset: 1M
offset-write: mbr+92
content:
- image: pc-core.img
- name: EFI System
type: EF,C12A7328-F81F-11D2-BA4B-00A0C93EC93B
filesystem: vfat
filesystem-label: system-boot
size: 50M
content:
- source: grubx64.efi
target: EFI/boot/grubx64.efi
- source: shim.efi.signed
target: EFI/boot/bootx64.efi
- source: grub.cfg
target: EFI/ubuntu/grub.cfg
Loading

0 comments on commit 1daac64

Please sign in to comment.