Skip to content

Commit

Permalink
Bug 1871653: baremetal: set root device hints on host resources
Browse files Browse the repository at this point in the history
Pass the root device hints given by the user in the install-config to
the BareMetalHost resources created in the cluster.

Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
  • Loading branch information
dhellmann committed Aug 24, 2020
1 parent c22eb4b commit b2ef77e
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/asset/machines/baremetal/hosts.go
Expand Up @@ -80,6 +80,7 @@ func Hosts(config *types.InstallConfig, machines []machineapi.Machine) (*HostSet
BootMACAddress: host.BootMACAddress,
HardwareProfile: host.HardwareProfile,
BootMode: baremetalhost.BootMode(host.BootMode),
RootDeviceHints: host.RootDeviceHints.MakeCRDHints(),
},
}
if i < len(machines) {
Expand Down
22 changes: 22 additions & 0 deletions pkg/types/baremetal/rootdevice.go
Expand Up @@ -5,6 +5,8 @@ package baremetal

import (
"fmt"

"github.com/metal3-io/baremetal-operator/pkg/apis/metal3/v1alpha1"
)

// RootDeviceHints holds the hints for specifying the storage location
Expand Down Expand Up @@ -96,3 +98,23 @@ func (source *RootDeviceHints) MakeHintMap() map[string]string {

return hints
}

// MakeCRDHints returns the hints in the format needed to pass to
// create a BareMetalHost resource.
func (source *RootDeviceHints) MakeCRDHints() *v1alpha1.RootDeviceHints {
if source == nil {
return nil
}
return &v1alpha1.RootDeviceHints{
DeviceName: source.DeviceName,
HCTL: source.HCTL,
Model: source.Model,
Vendor: source.Vendor,
SerialNumber: source.SerialNumber,
MinSizeGigabytes: source.MinSizeGigabytes,
WWN: source.WWN,
WWNWithExtension: source.WWNWithExtension,
WWNVendorExtension: source.WWNVendorExtension,
Rotational: source.Rotational,
}
}
155 changes: 155 additions & 0 deletions pkg/types/baremetal/rootdevice_test.go
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/metal3-io/baremetal-operator/pkg/apis/metal3/v1alpha1"
)

func TestMakeHintMap(t *testing.T) {
Expand Down Expand Up @@ -153,3 +155,156 @@ func TestMakeHintMap(t *testing.T) {
})
}
}

func TestMakeCRDHints(t *testing.T) {
addressableTrue := true
addressableFalse := false

for _, tc := range []struct {
Scenario string
Hints *RootDeviceHints
Expected *v1alpha1.RootDeviceHints
}{
{
Scenario: "nil",
Hints: nil,
Expected: nil,
},
{
Scenario: "device-name",
Hints: &RootDeviceHints{
DeviceName: "userd_devicename",
},
Expected: &v1alpha1.RootDeviceHints{
DeviceName: "userd_devicename",
},
},
{
Scenario: "hctl",
Hints: &RootDeviceHints{
HCTL: "1:2:3:4",
},
Expected: &v1alpha1.RootDeviceHints{
HCTL: "1:2:3:4",
},
},
{
Scenario: "model",
Hints: &RootDeviceHints{
Model: "userd_model",
},
Expected: &v1alpha1.RootDeviceHints{
Model: "userd_model",
},
},
{
Scenario: "vendor",
Hints: &RootDeviceHints{
Vendor: "userd_vendor",
},
Expected: &v1alpha1.RootDeviceHints{
Vendor: "userd_vendor",
},
},
{
Scenario: "serial-number",
Hints: &RootDeviceHints{
SerialNumber: "userd_serial",
},
Expected: &v1alpha1.RootDeviceHints{
SerialNumber: "userd_serial",
},
},
{
Scenario: "min-size",
Hints: &RootDeviceHints{
MinSizeGigabytes: 40,
},
Expected: &v1alpha1.RootDeviceHints{
MinSizeGigabytes: 40,
},
},
{
Scenario: "wwn",
Hints: &RootDeviceHints{
WWN: "userd_wwn",
},
Expected: &v1alpha1.RootDeviceHints{
WWN: "userd_wwn",
},
},
{
Scenario: "wwn-with-extension",
Hints: &RootDeviceHints{
WWNWithExtension: "userd_with_extension",
},
Expected: &v1alpha1.RootDeviceHints{
WWNWithExtension: "userd_with_extension",
},
},
{
Scenario: "wwn-extension",
Hints: &RootDeviceHints{
WWNVendorExtension: "userd_vendor_extension",
},
Expected: &v1alpha1.RootDeviceHints{
WWNVendorExtension: "userd_vendor_extension",
},
},
{
Scenario: "rotational-true",
Hints: &RootDeviceHints{
Rotational: &addressableTrue,
},
Expected: &v1alpha1.RootDeviceHints{
Rotational: &addressableTrue,
},
},
{
Scenario: "rotational-false",
Hints: &RootDeviceHints{
Rotational: &addressableFalse,
},
Expected: &v1alpha1.RootDeviceHints{
Rotational: &addressableFalse,
},
},
{
Scenario: "everything-bagel",
Hints: &RootDeviceHints{
DeviceName: "userd_devicename",
HCTL: "1:2:3:4",
Model: "userd_model",
Vendor: "userd_vendor",
SerialNumber: "userd_serial",
MinSizeGigabytes: 40,
WWN: "userd_wwn",
WWNWithExtension: "userd_with_extension",
WWNVendorExtension: "userd_vendor_extension",
Rotational: &addressableTrue,
},
Expected: &v1alpha1.RootDeviceHints{
DeviceName: "userd_devicename",
HCTL: "1:2:3:4",
Model: "userd_model",
Vendor: "userd_vendor",
SerialNumber: "userd_serial",
MinSizeGigabytes: 40,
WWN: "userd_wwn",
WWNWithExtension: "userd_with_extension",
WWNVendorExtension: "userd_vendor_extension",
Rotational: &addressableTrue,
},
},
{
Scenario: "empty",
Hints: &RootDeviceHints{},
Expected: &v1alpha1.RootDeviceHints{},
},
} {
t.Run(tc.Scenario, func(t *testing.T) {
actual := tc.Hints.MakeCRDHints()
assert.Equal(t, tc.Expected, actual, "hint map does not match")
})
}
}

0 comments on commit b2ef77e

Please sign in to comment.