Skip to content

Commit

Permalink
fcos/1.6.0-exp: Fix context for boot_device.layout errors
Browse files Browse the repository at this point in the history
- Use "layout" in the context path for errors related to the layout
  entry in the boot_device  configuration.
- Add tests for those error cases.
- Refactor mirror boot_device check for s390x.

Fixes: coreos#484
  • Loading branch information
travier committed Nov 21, 2024
1 parent 40fa2dd commit 6531c7f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
16 changes: 8 additions & 8 deletions config/fcos/v1_6_exp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package v1_6_exp

import (
"regexp"
"strings"

"github.com/coreos/butane/config/common"
"github.com/coreos/ignition/v2/config/util"
Expand Down Expand Up @@ -56,25 +57,24 @@ func (d BootDevice) Validate(c path.ContextPath) (r report.Report) {
case "aarch64", "ppc64le", "x86_64":
case "s390x-eckd":
if util.NilOrEmpty(d.Luks.Device) {
r.AddOnError(c.Append(*d.Layout), common.ErrNoLuksBootDevice)
r.AddOnError(c.Append("layout"), common.ErrNoLuksBootDevice)
} else if !dasdRe.MatchString(*d.Luks.Device) {
r.AddOnError(c.Append(*d.Layout), common.ErrLuksBootDeviceBadName)
r.AddOnError(c.Append("layout"), common.ErrLuksBootDeviceBadName)
}
case "s390x-zfcp":
if util.NilOrEmpty(d.Luks.Device) {
r.AddOnError(c.Append(*d.Layout), common.ErrNoLuksBootDevice)
r.AddOnError(c.Append("layout"), common.ErrNoLuksBootDevice)
} else if !sdRe.MatchString(*d.Luks.Device) {
r.AddOnError(c.Append(*d.Layout), common.ErrLuksBootDeviceBadName)
r.AddOnError(c.Append("layout"), common.ErrLuksBootDeviceBadName)
}
case "s390x-virt":
default:
r.AddOnError(c.Append("layout"), common.ErrUnknownBootDeviceLayout)
}

if *d.Layout == "s390x-eckd" || *d.Layout == "s390x-zfcp" || *d.Layout == "s390x-virt" {
if len(d.Mirror.Devices) > 0 {
r.AddOnError(c.Append(*d.Layout), common.ErrMirrorNotSupport)
}
// Mirroring the boot disk is not supported on s390x
if strings.HasPrefix(*d.Layout, "s390x") && len(d.Mirror.Devices) > 0 {
r.AddOnError(c.Append("layout"), common.ErrMirrorNotSupport)
}
}
r.Merge(d.Mirror.Validate(c.Append("mirror")))
Expand Down
50 changes: 50 additions & 0 deletions config/fcos/v1_6_exp/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,56 @@ func TestValidateBootDevice(t *testing.T) {
common.ErrTooFewMirrorDevices,
path.New("yaml", "mirror", "devices"),
},
// s390x-eckd/s390x-zfcp layouts require a boot device with luks
{
BootDevice{
Layout: util.StrToPtr("s390x-eckd"),
},
common.ErrNoLuksBootDevice,
path.New("yaml", "layout"),
},
// s390x-eckd/s390x-zfcp layouts do not support mirroring
{
BootDevice{
Layout: util.StrToPtr("s390x-zfcp"),
Luks: BootDeviceLuks{
Device: util.StrToPtr("/dev/sda"),
Tpm2: util.BoolToPtr(true),
},
Mirror: BootDeviceMirror{
Devices: []string{
"/dev/sda",
"/dev/sdb",
},
},
},
common.ErrMirrorNotSupport,
path.New("yaml", "layout"),
},
// s390x-eckd devices must start with /dev/dasd
{
BootDevice{
Layout: util.StrToPtr("s390x-eckd"),
Luks: BootDeviceLuks{
Device: util.StrToPtr("/dev/sda"),
Tpm2: util.BoolToPtr(true),
},
},
common.ErrLuksBootDeviceBadName,
path.New("yaml", "layout"),
},
// s390x-zfcp devices must start with /dev/sd
{
BootDevice{
Layout: util.StrToPtr("s390x-eckd"),
Luks: BootDeviceLuks{
Device: util.StrToPtr("/dev/dasd"),
Tpm2: util.BoolToPtr(true),
},
},
common.ErrLuksBootDeviceBadName,
path.New("yaml", "layout"),
},
}

for i, test := range tests {
Expand Down

0 comments on commit 6531c7f

Please sign in to comment.