mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
Merge pull request #11182 from mvo5/crash-less-for-ondra
gadget: do not crash if gadget.yaml has an empty Volumes section
This commit is contained in:
@@ -462,7 +462,11 @@ func InfoFromGadgetYaml(gadgetYaml []byte, model Model) (*Info, error) {
|
||||
// basic validation
|
||||
var bootloadersFound int
|
||||
knownFsLabelsPerVolume := make(map[string]map[string]bool, len(gi.Volumes))
|
||||
for name, v := range gi.Volumes {
|
||||
for name := range gi.Volumes {
|
||||
v := gi.Volumes[name]
|
||||
if v == nil {
|
||||
return nil, fmt.Errorf("volume %q stanza is empty", name)
|
||||
}
|
||||
// set the VolumeName for the volume
|
||||
v.Name = name
|
||||
if err := validateVolume(v, knownFsLabelsPerVolume); err != nil {
|
||||
|
||||
@@ -621,6 +621,19 @@ func (s *gadgetYamlTestSuite) TestCoreConfigDefaults(c *C) {
|
||||
})
|
||||
}
|
||||
|
||||
var mockGadgetWithEmptyVolumes = `device-tree-origin: kernel
|
||||
volumes:
|
||||
lun-0:
|
||||
`
|
||||
|
||||
func (s *gadgetYamlTestSuite) TestRegressionGadgetWithEmptyVolume(c *C) {
|
||||
err := ioutil.WriteFile(s.gadgetYamlPath, []byte(mockGadgetWithEmptyVolumes), 0644)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
_, err = gadget.ReadInfo(s.dir, nil)
|
||||
c.Assert(err, ErrorMatches, `volume "lun-0" stanza is empty`)
|
||||
}
|
||||
|
||||
func (s *gadgetYamlTestSuite) TestReadGadgetDefaultsMultiline(c *C) {
|
||||
err := ioutil.WriteFile(s.gadgetYamlPath, mockClassicGadgetMultilineDefaultsYaml, 0644)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
Reference in New Issue
Block a user