Skip to content

Commit

Permalink
config/fcos: warn if the partition number for root isn't correct
Browse files Browse the repository at this point in the history
Fixes coreos#243

This change warns if the partition number for the root label is not
specified or wrongly mentioned.
  • Loading branch information
sohankunkerkar committed Sep 15, 2021
1 parent dcc128a commit d330de2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ var (
ErrUnknownBootDeviceLayout = errors.New("layout must be one of: aarch64, ppc64le, x86_64")
ErrTooFewMirrorDevices = errors.New("mirroring requires at least two devices")

// partition
ErrWrongPartitionNumber = errors.New("incorrect partition number for the default partlabel")
ErrWrongPartitionNumberForRoot = errors.New("incorrect partition number; a new partition will be created using reserved label \"root\"")

// MachineConfigs
ErrFieldElided = errors.New("field ignored in raw mode")
ErrNameRequired = errors.New("metadata.name is required")
Expand Down
14 changes: 14 additions & 0 deletions config/fcos/v1_3/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (c Config) ToIgn3_2Unvalidated(options common.TranslateOptions) (types.Conf
return types.Config{}, translate.TranslationSet{}, r
}
r.Merge(c.processBootDevice(&ret, &ts, options))
for i, disk := range ret.Storage.Disks {
for j, partition := range disk.Partitions {
// check for default partlabels
if partition.Label != nil {
if (*partition.Label == "BIOS-BOOT" && partition.Number != 1) || (*partition.Label == "boot" && partition.Number != 3) ||
(*partition.Label == "EFI-SYSTEM" && partition.Number != 2) || (*partition.Label == "reserved" && partition.Number != 1) || (*partition.Label == "reserved" && partition.Number != 2) || (*partition.Label == "PowerPC-PReP-boot" && partition.Number != 1) {
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, *partition.Label), common.ErrWrongPartitionNumber)
}
if *partition.Label == "root" && partition.Number != 4 {
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, *partition.Label), common.ErrWrongPartitionNumberForRoot)
}
}
}
}
return ret, ts, r
}

Expand Down
14 changes: 14 additions & 0 deletions config/fcos/v1_4/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (c Config) ToIgn3_3Unvalidated(options common.TranslateOptions) (types.Conf
return types.Config{}, translate.TranslationSet{}, r
}
r.Merge(c.processBootDevice(&ret, &ts, options))
for i, disk := range ret.Storage.Disks {
for j, partition := range disk.Partitions {
// check for default partlabels
if partition.Label != nil {
if (*partition.Label == "BIOS-BOOT" && partition.Number != 1) || (*partition.Label == "boot" && partition.Number != 3) ||
(*partition.Label == "EFI-SYSTEM" && partition.Number != 2) || (*partition.Label == "reserved" && partition.Number != 1) || (*partition.Label == "reserved" && partition.Number != 2) || (*partition.Label == "PowerPC-PReP-boot" && partition.Number != 1) {
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, *partition.Label), common.ErrWrongPartitionNumber)
}
if *partition.Label == "root" && partition.Number != 4 {
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, *partition.Label), common.ErrWrongPartitionNumberForRoot)
}
}
}
}
return ret, ts, r
}

Expand Down
14 changes: 14 additions & 0 deletions config/fcos/v1_5_exp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (c Config) ToIgn3_4Unvalidated(options common.TranslateOptions) (types.Conf
return types.Config{}, translate.TranslationSet{}, r
}
r.Merge(c.processBootDevice(&ret, &ts, options))
for i, disk := range ret.Storage.Disks {
for j, partition := range disk.Partitions {
// check for default partlabels
if partition.Label != nil {
if (*partition.Label == "BIOS-BOOT" && partition.Number != 1) || (*partition.Label == "boot" && partition.Number != 3) ||
(*partition.Label == "EFI-SYSTEM" && partition.Number != 2) || (*partition.Label == "reserved" && partition.Number != 1) || (*partition.Label == "reserved" && partition.Number != 2) || (*partition.Label == "PowerPC-PReP-boot" && partition.Number != 1) {

}
if *partition.Label == "root" && partition.Number != 4 {
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, *partition.Label), common.ErrWrongPartitionNumberForRoot)
}
}
}
}
return ret, ts, r
}

Expand Down
2 changes: 1 addition & 1 deletion config/fcos/v1_5_exp/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ func TestTranslateBootDevice(t *testing.T) {
for i, test := range tests {
actual, translations, r := test.in.ToIgn3_4Unvalidated(common.TranslateOptions{})
assert.Equal(t, test.out, actual, "#%d: translation mismatch", i)
assert.Equal(t, report.Report{}, r, "#%d: non-empty report", i)
assert.Equal(t, report.Report{}, r, "#%d: report mismatch", i)
baseutil.VerifyTranslations(t, translations, test.exceptions, "#%d", i)
assert.NoError(t, translations.DebugVerifyCoverage(actual), "#%d: incomplete TranslationSet coverage", i)
}
Expand Down

0 comments on commit d330de2

Please sign in to comment.