Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: validate disk size earlier, update error wording (backport #596) #603

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/config/cos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ func TestCalcCosPersistentPartSize(t *testing.T) {
{
diskSize: 150,
partitionSize: "100Gi",
err: "Disk size is too small. Minimum 250Gi is required",
err: "Installation disk size is too small. Minimum 250Gi is required",
},
{
diskSize: 300,
partitionSize: "153600Ki",
err: "Partition size should be ended with 'Mi', 'Gi', and no dot and negative is allowed",
err: "Partition size must end with 'Mi' or 'Gi'. Decimals and negatives are not allowed.",
},
{
diskSize: 2000,
partitionSize: "1.5Ti",
err: "Partition size should be ended with 'Mi', 'Gi', and no dot and negative is allowed",
err: "Partition size must end with 'Mi' or 'Gi'. Decimals and negatives are not allowed.",
},
{
diskSize: 500,
partitionSize: "abcd",
err: "Partition size should be ended with 'Mi', 'Gi', and no dot and negative is allowed",
err: "Partition size must end with 'Mi' or 'Gi'. Decimals and negatives are not allowed.",
},
}

Expand Down
49 changes: 33 additions & 16 deletions pkg/console/install_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,24 @@ func addDiskPanel(c *Console) error {
c.AddElement(diskValidatorPanel, diskValidatorV)

// Helper functions
validateAllDiskSizes := func() (bool, error) {
installDisk := c.config.Install.Device
dataDisk := c.config.Install.DataDisk

if dataDisk == "" || installDisk == dataDisk {
if err := validateDiskSize(installDisk, true); err != nil {
return false, updateValidatorMessage(err.Error())
}
} else {
if err := validateDiskSize(installDisk, false); err != nil {
return false, updateValidatorMessage(err.Error())
}
if err := validateDataDiskSize(dataDisk); err != nil {
return false, updateValidatorMessage(err.Error())
}
}
return true, nil;
}
closeThisPage := func() {
c.CloseElements(
diskPanel,
Expand All @@ -424,29 +442,22 @@ func addDiskPanel(c *Console) error {
return showNext(c, askCreatePanel)
}
gotoNextPage := func(g *gocui.Gui, v *gocui.View) error {
// Don't proceed to the next page if disk size validation fails
if valid, err := validateAllDiskSizes(); !valid || err != nil {
return err;
}

installDisk := c.config.Install.Device
dataDisk := c.config.Install.DataDisk
persistentSize := c.config.Install.PersistentPartitionSize

if dataDisk == "" || installDisk == dataDisk {
if err := validateDiskSize(installDisk, true); err != nil {
return updateValidatorMessage(err.Error())
}

diskSize, err := util.GetDiskSizeBytes(c.config.Install.Device)
if err != nil {
return err
}
if _, err := util.ParsePartitionSize(diskSize, persistentSize); err != nil {
return updateValidatorMessage(err.Error())
}
} else {
if err := validateDiskSize(installDisk, false); err != nil {
return updateValidatorMessage(err.Error())
}
if err := validateDataDiskSize(dataDisk); err != nil {
return updateValidatorMessage(err.Error())
}
}

if !diskConfirmed {
Expand Down Expand Up @@ -479,8 +490,9 @@ func addDiskPanel(c *Console) error {
c.config.Install.Device = device

if len(diskOpts) > 1 {
if err := updateValidatorMessage(""); err != nil {
return err
// Show error if disk size validation fails, but allow proceeding to next field
if _, err := validateAllDiskSizes(); err != nil {
return err;
}
if device == dataDisk {
return showNext(c, persistentSizePanel, dataDiskPanel)
Expand All @@ -491,8 +503,9 @@ func addDiskPanel(c *Console) error {
if err := c.setContentByName(diskNotePanel, persistentSizeNote); err != nil {
return err
}
if err := updateValidatorMessage(""); err != nil {
return err
// Show error if disk size validation fails, but allow proceeding to next field
if _, err := validateAllDiskSizes(); err != nil {
return err;
}
return showNext(c, persistentSizePanel)
}
Expand Down Expand Up @@ -525,6 +538,10 @@ func addDiskPanel(c *Console) error {
if err := c.setContentByName(diskNotePanel, persistentSizeNote); err != nil {
return err
}
// Show error if disk size validation fails, but allow proceeding to next field
if _, err := validateAllDiskSizes(); err != nil {
return err;
}
return showNext(c, persistentSizePanel)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/console/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func validateDiskSize(devPath string, single bool) error {
limit = config.MultipleDiskMinSizeGiB
}
if util.ByteToGi(diskSizeBytes) < uint64(limit) {
return fmt.Errorf("Disk size is too small. Minimum %dGi is required", limit)
return fmt.Errorf("Installation disk size is too small. Minimum %dGi is required", limit)
}

return nil
Expand All @@ -650,7 +650,7 @@ func validateDataDiskSize(devPath string) error {
return err
}
if util.ByteToGi(diskSizeBytes) < config.HardMinDataDiskSizeGiB {
return fmt.Errorf("Disk size is too small. Minimum %dGi is required", config.HardMinDataDiskSizeGiB)
return fmt.Errorf("Data disk size is too small. Minimum %dGi is required", config.HardMinDataDiskSizeGiB)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const (

func ParsePartitionSize(diskSizeBytes uint64, partitionSize string) (uint64, error) {
if diskSizeBytes < MinDiskSize {
return 0, fmt.Errorf("Disk size is too small. Minimum %dGi is required", ByteToGi(MinDiskSize))
return 0, fmt.Errorf("Installation disk size is too small. Minimum %dGi is required", ByteToGi(MinDiskSize))
}
actualDiskSizeBytes := diskSizeBytes - fixedOccupiedSize

if !sizeRegexp.MatchString(partitionSize) {
return 0, fmt.Errorf("Partition size should be ended with 'Mi', 'Gi', and no dot and negative is allowed")
return 0, fmt.Errorf("Partition size must end with 'Mi' or 'Gi'. Decimals and negatives are not allowed.")
}

size, err := strconv.ParseUint(partitionSize[:len(partitionSize)-2], 10, 64)
Expand Down
12 changes: 6 additions & 6 deletions pkg/util/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,32 @@ func TestParsePartitionSize(t *testing.T) {
{
diskSize: 100 * GiByteMultiplier,
partitionSize: "50Gi",
err: "Disk size is too small. Minimum 250Gi is required",
err: "Installation disk size is too small. Minimum 250Gi is required",
},
{
diskSize: 249 * GiByteMultiplier,
partitionSize: "50Gi",
err: "Disk size is too small. Minimum 250Gi is required",
err: "Installation disk size is too small. Minimum 250Gi is required",
},
{
diskSize: 2000 * GiByteMultiplier,
partitionSize: "abcd",
err: "Partition size should be ended with 'Mi', 'Gi', and no dot and negative is allowed",
err: "Partition size must end with 'Mi' or 'Gi'. Decimals and negatives are not allowed.",
},
{
diskSize: 2000 * GiByteMultiplier,
partitionSize: "1Ti",
err: "Partition size should be ended with 'Mi', 'Gi', and no dot and negative is allowed",
err: "Partition size must end with 'Mi' or 'Gi'. Decimals and negatives are not allowed.",
},
{
diskSize: 2000 * GiByteMultiplier,
partitionSize: "50Ki",
err: "Partition size should be ended with 'Mi', 'Gi', and no dot and negative is allowed",
err: "Partition size must end with 'Mi' or 'Gi'. Decimals and negatives are not allowed.",
},
{
diskSize: 2000 * GiByteMultiplier,
partitionSize: "5.5",
err: "Partition size should be ended with 'Mi', 'Gi', and no dot and negative is allowed",
err: "Partition size must end with 'Mi' or 'Gi'. Decimals and negatives are not allowed.",
},
{
diskSize: 400 * GiByteMultiplier,
Expand Down