Skip to content

Commit

Permalink
Add validations for Image.DiskFormat
Browse files Browse the repository at this point in the history
Signed-off-by: Zhou Hao <zhouhao@fujitsu.com>
  • Loading branch information
zhouhao3 committed Aug 15, 2022
1 parent fb29032 commit 71ba67d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apis/metal3.io/v1alpha1/baremetalhost_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (host *BareMetalHost) validateChanges(old *BareMetalHost) []error {

func validateBMCAccess(s BareMetalHostSpec, bmcAccess bmc.AccessDetails) []error {
var errs []error
diskFormat := "live-iso"

if bmcAccess == nil {
return errs
Expand Down Expand Up @@ -108,6 +109,10 @@ func validateBMCAccess(s BareMetalHostSpec, bmcAccess bmc.AccessDetails) []error
errs = append(errs, fmt.Errorf("BMC driver %s does not support secure boot", bmcAccess.Type()))
}

if s.Image != nil && s.Image.DiskFormat != nil && *s.Image.DiskFormat == diskFormat && !bmcAccess.SupportsISOPreprovisioningImage() {
errs = append(errs, fmt.Errorf("BMC driver %s does not support live-iso image", bmcAccess.Type()))
}

return errs
}

Expand Down
20 changes: 20 additions & 0 deletions apis/metal3.io/v1alpha1/baremetalhost_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestValidateCreate(t *testing.T) {

// for RAID validation test cases
numberOfPhysicalDisks := 3
diskFormat := "live-iso"

tests := []struct {
name string
Expand Down Expand Up @@ -455,6 +456,25 @@ func TestValidateCreate(t *testing.T) {
oldBMH: nil,
wantedErr: "Image URL test1 is an invalid URL",
},
{
name: "liveISOImageWithUnsupportBMC",
newBMH: &BareMetalHost{
TypeMeta: tm,
ObjectMeta: om,
Spec: BareMetalHostSpec{
BMC: BMCDetails{
Address: "idrac://127.0.0.1",
CredentialsName: "test1",
},
Image: &Image{
URL: "http://127.0.0.1",
DiskFormat: &diskFormat,
},
}, // end of BMH spec
},
oldBMH: nil,
wantedErr: "BMC driver idrac does not support live-iso image",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 71ba67d

Please sign in to comment.