summaryrefslogtreecommitdiff
diff options
-rw-r--r--snap/info.go31
-rw-r--r--snap/kernel.go41
-rw-r--r--snap/legacy.go5
-rw-r--r--snappy/kernel_os.go8
-rw-r--r--snappy/snapp_snapfs_test.go21
-rw-r--r--snappy/undo_test.go10
6 files changed, 90 insertions, 26 deletions
diff --git a/snap/info.go b/snap/info.go
index f7f9db2b85..407c54f96e 100644
--- a/snap/info.go
+++ b/snap/info.go
@@ -109,6 +109,9 @@ type Info struct {
// legacy fields collected
Legacy *LegacyYaml
+ // kernel fields collected
+ Kernel *KernelYaml
+
// The information in all the remaining fields is not sourced from the snap blob itself.
SideInfo
@@ -283,7 +286,23 @@ func ReadInfo(name string, si *SideInfo) (*Info, error) {
return nil, err
}
- return infoFromSnapYamlWithSideInfo(meta, si)
+ info, err := infoFromSnapYamlWithSideInfo(meta, si)
+ if err != nil {
+ return nil, err
+ }
+
+ if info.Type == TypeKernel {
+ kernelYamlFn := filepath.Join(MountDir(name, si.Revision), "meta", "kernel.yaml")
+ kmeta, err := ioutil.ReadFile(kernelYamlFn)
+ if err != nil {
+ return nil, err
+ }
+ if err := addKernelToInfo(kmeta, info); err != nil {
+ return nil, err
+ }
+ }
+
+ return info, nil
}
// ReadInfoFromSnapFile reads the snap information from the given File
@@ -299,6 +318,16 @@ func ReadInfoFromSnapFile(snapf File, si *SideInfo) (*Info, error) {
return nil, err
}
+ if info.Type == TypeKernel {
+ kmeta, err := snapf.ReadFile("meta/kernel.yaml")
+ if err != nil {
+ return nil, err
+ }
+ if err := addKernelToInfo(kmeta, info); err != nil {
+ return nil, err
+ }
+ }
+
err = Validate(info)
if err != nil {
return nil, err
diff --git a/snap/kernel.go b/snap/kernel.go
new file mode 100644
index 0000000000..a92640d272
--- /dev/null
+++ b/snap/kernel.go
@@ -0,0 +1,41 @@
+// -*- Mode: Go; indent-tabs-mode: t -*-
+
+/*
+ * Copyright (C) 2016 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 snap
+
+import (
+ "fmt"
+
+ "gopkg.in/yaml.v2"
+)
+
+// KernelYaml contains the kernel.yaml specific data
+type KernelYaml struct {
+ Version string `yaml:"kernel,omitempty"`
+}
+
+func addKernelToInfo(kmeta []byte, info *Info) error {
+ var ky KernelYaml
+ if err := yaml.Unmarshal(kmeta, &ky); err != nil {
+ return fmt.Errorf("info failed to parse: %s", err)
+ }
+
+ info.Kernel = &ky
+ return nil
+}
diff --git a/snap/legacy.go b/snap/legacy.go
index 61003ee9cc..df835e1fe1 100644
--- a/snap/legacy.go
+++ b/snap/legacy.go
@@ -28,9 +28,4 @@ type LegacyYaml struct {
// gadget snap only
Gadget legacygadget.Gadget `yaml:"gadget,omitempty"`
Config legacygadget.SystemConfig `yaml:"config,omitempty"`
-
- // legacy kernel snap support
- Kernel string `yaml:"kernel,omitempty"`
- Initrd string `yaml:"initrd,omitempty"`
- Dtbs string `yaml:"dtbs,omitempty"`
}
diff --git a/snappy/kernel_os.go b/snappy/kernel_os.go
index c7652be5f3..51b2411848 100644
--- a/snappy/kernel_os.go
+++ b/snappy/kernel_os.go
@@ -27,6 +27,7 @@ import (
"strings"
"github.com/ubuntu-core/snappy/logger"
+ "github.com/ubuntu-core/snappy/osutil"
"github.com/ubuntu-core/snappy/partition"
"github.com/ubuntu-core/snappy/progress"
"github.com/ubuntu-core/snappy/snap"
@@ -93,7 +94,7 @@ func extractKernelAssets(s *snap.Info, snapf snap.File, flags InstallFlags, inte
}
defer dir.Close()
- for _, src := range []string{s.Legacy.Kernel, s.Legacy.Initrd} {
+ for _, src := range []string{"vmlinuz", "initrd.img"} {
if src == "" {
continue
}
@@ -109,8 +110,9 @@ func extractKernelAssets(s *snap.Info, snapf snap.File, flags InstallFlags, inte
return err
}
}
- if s.Legacy.Dtbs != "" {
- src := filepath.Join(s.Legacy.Dtbs, "*")
+ dtbsDir := "dtbs"
+ if osutil.FileExists(dtbsDir) {
+ src := filepath.Join(dtbsDir, "*")
dst := dstDir
if err := snapf.Unpack(src, dst); err != nil {
return err
diff --git a/snappy/snapp_snapfs_test.go b/snappy/snapp_snapfs_test.go
index ecf37ac634..967cb8a82b 100644
--- a/snappy/snapp_snapfs_test.go
+++ b/snappy/snapp_snapfs_test.go
@@ -244,15 +244,13 @@ name: ubuntu-kernel
version: 4.0-1
type: kernel
vendor: Someone
-
-kernel: vmlinuz-4.2
-initrd: initrd.img-4.2
`
func (s *SquashfsTestSuite) TestInstallKernelSnapUpdatesBootloader(c *C) {
files := [][]string{
- {"vmlinuz-4.2", "I'm a kernel"},
- {"initrd.img-4.2", "...and I'm an initrd"},
+ {"vmlinuz", "I'm a kernel"},
+ {"initrd.img", "...and I'm an initrd"},
+ {"meta/kernel.yaml", "version: 4.2"},
}
snapPkg := makeTestSnapPackageWithFiles(c, packageKernel, files)
si := &snap.SideInfo{
@@ -270,8 +268,9 @@ func (s *SquashfsTestSuite) TestInstallKernelSnapUpdatesBootloader(c *C) {
func (s *SquashfsTestSuite) TestInstallKernelSnapUnpacksKernel(c *C) {
files := [][]string{
- {"vmlinuz-4.2", "I'm a kernel"},
- {"initrd.img-4.2", "...and I'm an initrd"},
+ {"vmlinuz", "I'm a kernel"},
+ {"initrd.img", "...and I'm an initrd"},
+ {"meta/kernel.yaml", "version: 4.2"},
}
snapPkg := makeTestSnapPackageWithFiles(c, packageKernel, files)
si := &snap.SideInfo{
@@ -299,8 +298,9 @@ func (s *SquashfsTestSuite) TestInstallKernelSnapUnpacksKernel(c *C) {
func (s *SquashfsTestSuite) TestInstallKernelSnapRemovesKernelAssets(c *C) {
files := [][]string{
- {"vmlinuz-4.2", "I'm a kernel"},
- {"initrd.img-4.2", "...and I'm an initrd"},
+ {"vmlinuz", "I'm a kernel"},
+ {"initrd.img", "...and I'm an initrd"},
+ {"meta/kernel.yaml", "version: 4.2"},
}
snapPkg := makeTestSnapPackageWithFiles(c, packageKernel, files)
si := &snap.SideInfo{
@@ -400,7 +400,8 @@ func (s *SquashfsTestSuite) TestInstallKernelSnapNoUnpacksKernelForGrub(c *C) {
getGadget = getFakeGrubGadget
files := [][]string{
- {"vmlinuz-4.2", "I'm a kernel"},
+ {"vmlinuz", "I'm a kernel"},
+ {"meta/kernel.yaml", "version: 4.2"},
}
snapPkg := makeTestSnapPackageWithFiles(c, packageKernel, files)
_, err := (&Overlord{}).Install(snapPkg, 0, &MockProgressMeter{})
diff --git a/snappy/undo_test.go b/snappy/undo_test.go
index 4f0ce5a2f8..d4a1bf7516 100644
--- a/snappy/undo_test.go
+++ b/snappy/undo_test.go
@@ -86,19 +86,15 @@ func (s *undoTestSuite) TestUndoForSetupSnapKernelUboot(c *C) {
}
testFiles := [][]string{
- {"vmlinuz-4.4.0-14-generic.efi.signed", "kernel"},
- {"initrd.img-4.4.0-14-generic", "initrd"},
+ {"vmlinuz", "kernel"},
+ {"initrd.img", "initrd"},
{"lib/modules/4.4.0-14-generic/foo.ko", "a module"},
{"lib/firmware/bar.bin", "some firmware"},
+ {"meta/kernel.yaml", "version: 4.4.0-14-generic"},
}
snapPath := makeTestSnapPackageWithFiles(c, `name: kernel-snap
version: 1.0
type: kernel
-
-kernel: vmlinuz-4.4.0-14-generic.efi.signed
-initrd: initrd.img-4.4.0-14-generic
-modules: lib/modules/4.4.0-14-generic
-firmware: lib/firmware
`, testFiles)
si := snap.SideInfo{