From 0bc6fdd4e902ff45c5c5b6fb863388b8ff7c91d0 Mon Sep 17 00:00:00 2001 From: madhu-pillai Date: Mon, 28 Aug 2023 09:50:31 +0530 Subject: [PATCH] Added the - fcos/validate.go s390x device identification with regex along with mirror check. - docs/config-openshift-v4_14-exp.md: updated the docs. - fcos/schema.go: renamed luks.device to luks.s390x-device. - fcos/translate.go: updated only one wantS390x condition to identify for device identification. - common/error.go: fixed the space issue it error.go. --- config/common/errors.go | 4 ++-- config/fcos/v1_6_exp/schema.go | 2 +- config/fcos/v1_6_exp/translate.go | 17 ++++++----------- config/fcos/v1_6_exp/validate.go | 27 ++++++++++++++++----------- docs/config-fcos-v1_6-exp.md | 2 +- docs/config-openshift-v4_14-exp.md | 2 +- docs/examples.md | 4 ++-- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/config/common/errors.go b/config/common/errors.go index 9fe172eb..2134d2e5 100644 --- a/config/common/errors.go +++ b/config/common/errors.go @@ -56,8 +56,8 @@ var ( // boot device ErrUnknownBootDeviceLayout = errors.New("layout must be one of: aarch64, ppc64le, x86_64") ErrTooFewMirrorDevices = errors.New("mirroring requires at least two devices") - ErrNoLuksBootDevice = errors.New("device-s390x is required if layout: s390x-eckd && device-s390x: /dev/dasd[a-z] or s390x-zfcp && device: /dev/sd[a-z]") - ErrMirrorNotSupport = errors.New("layout: s390x-zfcp or s390x-eckd does not support mirror") + ErrNoLuksBootDevice = errors.New("s390x-device is required if layout: s390x-eckd && s390x-device: /dev/dasd[a-z] or s390x-zfcp && s390x-device: /dev/sd[a-z]") + ErrMirrorNotSupport = errors.New("layout: s390x-zfcp or s390x-eckd does not support mirror") // partition ErrReuseByLabel = errors.New("partitions cannot be reused by label; number must be specified except on boot disk (/dev/disk/by-id/coreos-boot-disk) or when wipe_table is true") diff --git a/config/fcos/v1_6_exp/schema.go b/config/fcos/v1_6_exp/schema.go index f43c550e..799b9540 100644 --- a/config/fcos/v1_6_exp/schema.go +++ b/config/fcos/v1_6_exp/schema.go @@ -32,7 +32,7 @@ type BootDevice struct { type BootDeviceLuks struct { Discard *bool `yaml:"discard"` - Device *string `yaml:"device-s390x"` + Device *string `yaml:"s390x-device"` Tang []base.Tang `yaml:"tang"` Threshold *int `yaml:"threshold"` Tpm2 *bool `yaml:"tpm2"` diff --git a/config/fcos/v1_6_exp/translate.go b/config/fcos/v1_6_exp/translate.go index 8abacc79..806422b7 100644 --- a/config/fcos/v1_6_exp/translate.go +++ b/config/fcos/v1_6_exp/translate.go @@ -124,8 +124,7 @@ func (c Config) processBootDevice(config *types.Config, ts *translate.Translatio var wantBIOSPart bool var wantEFIPart bool var wantPRePPart bool - var wantMBR bool - var wantDasd bool + var wantS390x bool layout := c.BootDevice.Layout switch { case layout == nil || *layout == "x86_64": @@ -136,12 +135,12 @@ func (c Config) processBootDevice(config *types.Config, ts *translate.Translatio case *layout == "ppc64le": wantPRePPart = true case *layout == "s390x-eckd": - wantDasd = true + wantS390x = true + case *layout == "s390x-zfcp": + wantS390x = true case *layout == "s390x-virt": wantBIOSPart = true wantEFIPart = true - case *layout == "s390x-zfcp": - wantMBR = true default: // should have failed validation panic("unknown layout") @@ -251,12 +250,8 @@ func (c Config) processBootDevice(config *types.Config, ts *translate.Translatio var luksDevice string var device_s390x string switch { - case wantMBR: - //Luks Device for zFCP-scsi - device_s390x = *c.BootDevice.Luks.Device - luksDevice = device_s390x + "2" - case wantDasd: - //Luks Device for Dasd + case wantS390x: + //Luks Device for dasd and zFCP-scsi device_s390x = *c.BootDevice.Luks.Device luksDevice = device_s390x + "2" case wantMirror: diff --git a/config/fcos/v1_6_exp/validate.go b/config/fcos/v1_6_exp/validate.go index 121235d2..aa901ef7 100644 --- a/config/fcos/v1_6_exp/validate.go +++ b/config/fcos/v1_6_exp/validate.go @@ -27,7 +27,8 @@ import ( const rootDevice = "/dev/disk/by-id/coreos-boot-disk" var allowedMountpoints = regexp.MustCompile(`^/(etc|var)(/|$)`) -var s390xLayout []string +var dasdRe = regexp.MustCompile("(/dev/dasd[a-z]$)") +var sdRe = regexp.MustCompile("(/dev/sd[a-z]$)") // We can't define a Validate function directly on Disk because that's defined in base, // so we use a Validate function on the top-level Config instead. @@ -57,17 +58,21 @@ func (d BootDevice) Validate(c path.ContextPath) (r report.Report) { r.AddOnError(c.Append("layout"), common.ErrUnknownBootDeviceLayout) } } - //Validate s390x layout device specific luks.device-s390x. + //Validate s390x layout device specific luks.s390x-device. //s390x layout does not support Mirror. - if d.Layout != nil { - s390xLayout = []string{"s390x-zfcp", "s390x-eckd"} - for _, zlayout := range s390xLayout { - switch { - case *d.Layout == zlayout && util.NilOrEmpty(d.Luks.Device): - r.AddOnError(c.Append(zlayout), common.ErrNoLuksBootDevice) - case *d.Layout == zlayout && len(d.Mirror.Devices) > 0: - r.AddOnError(c.Append(zlayout), common.ErrMirrorNotSupport) - } + //Validate the s390x layout specific device + if d.Layout != nil && (*d.Layout == "s390x-zfcp" || *d.Layout == "s390x-eckd") { + if util.NilOrEmpty(d.Luks.Device) { + r.AddOnError(c.Append(*d.Layout), common.ErrNoLuksBootDevice) + } + if len(d.Mirror.Devices) > 0 { + r.AddOnError(c.Append(*d.Layout), common.ErrMirrorNotSupport) + } + if *d.Layout == "s390x-zfcp" && util.NotEmpty(d.Luks.Device) && !sdRe.MatchString(*d.Luks.Device) { + r.AddOnError(c.Append(*d.Layout), common.ErrNoLuksBootDevice) + } + if *d.Layout == "s390x-eckd" && util.NotEmpty(d.Luks.Device) && !dasdRe.MatchString(*d.Luks.Device) { + r.AddOnError(c.Append(*d.Layout), common.ErrNoLuksBootDevice) } } r.Merge(d.Mirror.Validate(c.Append("mirror"))) diff --git a/docs/config-fcos-v1_6-exp.md b/docs/config-fcos-v1_6-exp.md index bfb34b5b..b283d22d 100644 --- a/docs/config-fcos-v1_6-exp.md +++ b/docs/config-fcos-v1_6-exp.md @@ -211,7 +211,7 @@ The Fedora CoreOS configuration is a YAML document conforming to the following s * **_boot_device_** (object): describes the desired boot device configuration. At least one of `luks` or `mirror` must be specified. * **_layout_** (string): the disk layout of the target OS image. Supported values are `aarch64`, `ppc64le`, `s390x-eckd`, `s390x-virt`, `s390x-zfcp` and `x86_64`. Defaults to `x86_64`. * **_luks_** (object): describes the clevis configuration for encrypting the root filesystem. - * **device-s390x** (string): describes device specific to s390x `dasd[a-z]` or `sd[a-z]`. + * **s390x-device** (string): describes device specific to s390x `dasd[a-z]` or `sd[a-z]`. * **_tang_** (list of objects): describes a tang server. Every server must have a unique `url`. * **url** (string): url of the tang server. * **thumbprint** (string): thumbprint of a trusted signing key. diff --git a/docs/config-openshift-v4_14-exp.md b/docs/config-openshift-v4_14-exp.md index bb8febed..94d0b6d9 100644 --- a/docs/config-openshift-v4_14-exp.md +++ b/docs/config-openshift-v4_14-exp.md @@ -160,7 +160,7 @@ The OpenShift configuration is a YAML document conforming to the following speci * **_boot_device_** (object): describes the desired boot device configuration. At least one of `luks` or `mirror` must be specified. * **_layout_** (string): the disk layout of the target OS image. Supported values are `aarch64`, `ppc64le`, `s390x-eckd`, `s390x-virt`, `s390x-zfcp` and `x86_64`. Defaults to `x86_64`. * **_luks_** (object): describes the clevis configuration for encrypting the root filesystem. - * **device-s390x** (string): describes device specific to s390x `dasd[a-z]` or `sd[a-z]`. + * **s390x-device** (string): describes device specific to s390x `dasd[a-z]` or `sd[a-z]`. * **_tang_** (list of objects): describes a tang server. Every server must have a unique `url`. * **url** (string): url of the tang server. * **thumbprint** (string): thumbprint of a trusted signing key. diff --git a/docs/examples.md b/docs/examples.md index 3daaa8f3..d7eb3aaf 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -305,7 +305,7 @@ version: 1.6.0 boot_device: layout: s390x-eckd luks: - device-s390x: /dev/dasda + s390x-device: /dev/dasda tang: - url: https://tang.example.com thumbprint: REPLACE-THIS-WITH-YOUR-TANG-THUMBPRINT @@ -320,7 +320,7 @@ version: 1.6.0 boot_device: layout: s390x-zfcp luks: - device-s390x: /dev/sdb + s390x-device: /dev/sdb tang: - url: https://tang.example.com thumbprint: REPLACE-THIS-WITH-YOUR-TANG-THUMBPRINT