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

MGMT-14881 - return a valid error when no disks has been found #5430

Merged
merged 1 commit into from
Aug 23, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
92 changes: 92 additions & 0 deletions internal/host/validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2153,4 +2153,96 @@ var _ = Describe("Validations test", func() {
Expect(message).To(Equal(""))
})
})

Context("Has Min Valid Disks", func() {
var (
host models.Host
cluster common.Cluster
)

const (
diskNotDetected string = "Failed to detected disks"
failureMessage string = "No eligible disks were found, please check specific disks to see why they are not eligible"
successMessage string = "Sufficient disk capacity"
)

BeforeEach(func() {
// Create a test cluster
cluster = hostutil.GenerateTestCluster(clusterID)
Expect(db.Create(&cluster).Error).ToNot(HaveOccurred())

// Create a test host
hostId, infraEnvId := strfmt.UUID(uuid.New().String()), strfmt.UUID(uuid.New().String())
mockProviderRegistry.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
host = hostutil.GenerateTestHostByKind(hostId, infraEnvId, &clusterID, models.HostStatusKnown, models.HostKindHost, models.HostRoleMaster)
host.Inventory = hostutil.GenerateMasterInventory()
// Remove Disks
var inventory models.Inventory
err := json.Unmarshal([]byte(host.Inventory), &inventory)
Expect(err).ShouldNot(HaveOccurred())
inventory.Disks = []*models.Disk{}
inventoryByte, _ := json.Marshal(inventory)
host.Inventory = string(inventoryByte)

Expect(db.Create(&host).Error).ShouldNot(HaveOccurred())
host = hostutil.GetHostFromDB(*host.ID, host.InfraEnvID, db).Host
})

updateDiskInventory := func(h *models.Host, disk models.Disk) {
var inventory models.Inventory
err := json.Unmarshal([]byte(h.Inventory), &inventory)
Expect(err).ShouldNot(HaveOccurred())

inventory.Disks = []*models.Disk{&disk}

inventoryByte, _ := json.Marshal(inventory)
h.Inventory = string(inventoryByte)

Expect(db.Save(&host).Error).ShouldNot(HaveOccurred())
}

createDisk := func(size int64) models.Disk {
return models.Disk{
SizeBytes: conversions.GibToBytes(size),
Name: "nvme10",
DriveType: models.DriveTypeHDD,
ID: "/dev/sda",
HasUUID: true,
}
}

It("Sufficient disk", func() {
disk1 := createDisk(120)
mockHwValidator.EXPECT().ListEligibleDisks(gomock.Any()).Return([]*models.Disk{&disk1}).AnyTimes()

updateDiskInventory(&host, disk1)
mockAndRefreshStatus(&host)
host = hostutil.GetHostFromDB(*host.ID, host.InfraEnvID, db).Host

status, message, ok := getValidationResult(host.ValidationsInfo, HasMinValidDisks)
Expect(ok).To(BeTrue())
Expect(successMessage).To(Equal(message))
Expect(ValidationSuccess).To(Equal(status))
})
It("No eligible disks", func() {
updateDiskInventory(&host, createDisk(1))
mockAndRefreshStatus(&host)
host = hostutil.GetHostFromDB(*host.ID, host.InfraEnvID, db).Host

status, message, ok := getValidationResult(host.ValidationsInfo, HasMinValidDisks)
Expect(ok).To(BeTrue())
Expect(failureMessage).To(Equal(message))
Expect(ValidationFailure).To(Equal(status))

})
It("Disk not Detected", func() {
mockAndRefreshStatus(&host)
host = hostutil.GetHostFromDB(*host.ID, host.InfraEnvID, db).Host

status, message, ok := getValidationResult(host.ValidationsInfo, HasMinValidDisks)
Expect(ok).To(BeTrue())
Expect(diskNotDetected).To(Equal(message))
Expect(ValidationError).To(Equal(status))
})
})
})
15 changes: 13 additions & 2 deletions internal/host/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ func (c *validationContext) loadInventory() error {
if inventory == nil || err != nil {
return err
}
if inventory.CPU == nil || inventory.Memory == nil || len(inventory.Disks) == 0 {
return errors.New("Inventory is not valid")
if inventory.Memory == nil {
return errors.New("Inventory is not valid, Memory not detected")
}

if inventory.CPU == nil {
return errors.New("Inventory is not valid, CPU not detected")
}
eifrach marked this conversation as resolved.
Show resolved Hide resolved
c.inventory = inventory
return nil
Expand Down Expand Up @@ -502,6 +506,13 @@ func (v *validator) hasMinValidDisks(c *validationContext) (ValidationStatus, st
if c.inventory == nil {
return ValidationPending, "Missing inventory"
}
inventory, err := c.inventoryCache.GetOrUnmarshal(c.host)
if err != nil {
return ValidationError, "Failed to load inventory"
}
if len(inventory.Disks) == 0 {
return ValidationError, "Failed to detected disks"
}
disks := v.hwValidator.ListEligibleDisks(c.inventory)
if len(disks) > 0 {
return ValidationSuccess, "Sufficient disk capacity"
Expand Down