From d5af507706a828daaa41b4ca90283684f39ce5d1 Mon Sep 17 00:00:00 2001 From: "James W. Brinkerhoff IV" Date: Tue, 15 Nov 2022 08:51:13 -0500 Subject: [PATCH] cmd/configure_raid.go,pkg/model/{model_test.go,raid_array.go}: Use bmc-toolbox/common constants for RAID implementations --- cmd/configure_raid.go | 11 ++++++----- go.mod | 2 +- go.sum | 4 ++++ pkg/model/model_test.go | 5 +++-- pkg/model/raid_array.go | 8 ++++---- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cmd/configure_raid.go b/cmd/configure_raid.go index 92b5103..a9ac586 100644 --- a/cmd/configure_raid.go +++ b/cmd/configure_raid.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" + "github.com/bmc-toolbox/common" "github.com/metal-toolbox/vogelkop/internal/command" "github.com/metal-toolbox/vogelkop/pkg/model" ) @@ -18,7 +19,7 @@ var configureRaidCmd = &cobra.Command{ ctx := command.NewContextWithLogger(cmd.Context(), logger) raidType := GetString(cmd, "raid-type") if raidType == "" { - raidType = "linuxsw" + raidType = common.SlugRAIDImplLinuxSoftware } if GetBool(cmd, "delete") { @@ -30,7 +31,7 @@ var configureRaidCmd = &cobra.Command{ } func init() { - configureRaidCmd.PersistentFlags().String("raid-type", "linuxsw", "RAID Type (linuxsw,hardware)") + configureRaidCmd.PersistentFlags().String("raid-type", common.SlugRAIDImplLinuxSoftware, "RAID Type (linuxsw,hardware)") configureRaidCmd.PersistentFlags().Bool("delete", false, "Delete virtual disk") configureRaidCmd.PersistentFlags().StringSlice("devices", []string{}, "List of underlying physical block devices.") @@ -56,7 +57,7 @@ func deleteArray(ctx context.Context, raidType, arrayName string) { func createArray(ctx context.Context, arrayName, raidType, raidLevel string, arrayDevices []string) { if raidType == "" { - raidType = "linuxsw" + raidType = common.SlugRAIDImplLinuxSoftware } raidArray := model.RaidArray{ @@ -73,9 +74,9 @@ func createArray(ctx context.Context, arrayName, raidType, raidLevel string, arr func processDevices(arrayDevices []string, raidType string) []*model.BlockDevice { switch raidType { - case "linuxsw": + case common.SlugRAIDImplLinuxSoftware: return processDevicesLinuxSw(arrayDevices) - case "hardware": + case common.SlugRAIDImplHardware: return processDevicesHardware(arrayDevices) default: err := model.InvalidRaidTypeError(raidType) diff --git a/go.mod b/go.mod index 0246c33..37c7569 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/Sytten/logrus-zap-hook v0.1.0 - github.com/bmc-toolbox/common v0.0.0-20221027142600-dd231ee11e95 + github.com/bmc-toolbox/common v0.0.0-20221115135648-0b584f504396 github.com/freddierice/go-losetup/v2 v2.0.1 github.com/metal-toolbox/ironlib v0.1.1-staging.0.20221101172719-9d149abd382c github.com/sirupsen/logrus v1.9.0 diff --git a/go.sum b/go.sum index 890e893..1427374 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,10 @@ github.com/bmc-toolbox/common v0.0.0-20221018142844-ecac9b89512c h1:O1BfqKvmqr3T github.com/bmc-toolbox/common v0.0.0-20221018142844-ecac9b89512c/go.mod h1:SY//n1PJjZfbFbmAsB6GvEKbc7UXz3d30s3kWxfJQ/c= github.com/bmc-toolbox/common v0.0.0-20221027142600-dd231ee11e95 h1:ZKq2USYtq9S0uujNIsJzkufk4C/n4vPhKzH2nO02hwE= github.com/bmc-toolbox/common v0.0.0-20221027142600-dd231ee11e95/go.mod h1:SY//n1PJjZfbFbmAsB6GvEKbc7UXz3d30s3kWxfJQ/c= +github.com/bmc-toolbox/common v0.0.0-20221115133735-6fe3d560cc4d h1:Fbrw9pb04HXn3QL8Owrm0yPLwEyRGnlUFlDsogjhlcc= +github.com/bmc-toolbox/common v0.0.0-20221115133735-6fe3d560cc4d/go.mod h1:SY//n1PJjZfbFbmAsB6GvEKbc7UXz3d30s3kWxfJQ/c= +github.com/bmc-toolbox/common v0.0.0-20221115135648-0b584f504396 h1:MAIYVFtt/Hnhx0Cth6T9pnLTJnZKppzi7LHue4KpPtg= +github.com/bmc-toolbox/common v0.0.0-20221115135648-0b584f504396/go.mod h1:SY//n1PJjZfbFbmAsB6GvEKbc7UXz3d30s3kWxfJQ/c= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/pkg/model/model_test.go b/pkg/model/model_test.go index bdd371d..a1fe470 100644 --- a/pkg/model/model_test.go +++ b/pkg/model/model_test.go @@ -11,6 +11,7 @@ import ( diskfs "github.com/diskfs/go-diskfs" losetup "github.com/freddierice/go-losetup/v2" + "github.com/bmc-toolbox/common" "github.com/metal-toolbox/vogelkop/internal/command" "github.com/metal-toolbox/vogelkop/pkg/model" ) @@ -183,7 +184,7 @@ func TestConfigureRaid(t *testing.T) { } // Apply the partition to the block device - if err := r.Create(ctx, "linuxsw"); err != nil { + if err := r.Create(ctx, common.SlugRAIDImplLinuxSoftware); err != nil { t.Error(err) } @@ -197,7 +198,7 @@ func TestConfigureRaid(t *testing.T) { // Disable any active raid arrays for _, r := range tc.RaidArrays { - if out, err := r.Delete(ctx, "linuxsw"); err != nil { + if out, err := r.Delete(ctx, common.SlugRAIDImplLinuxSoftware); err != nil { t.Log(out) t.Error(err) } diff --git a/pkg/model/raid_array.go b/pkg/model/raid_array.go index 18ba41f..4e458af 100644 --- a/pkg/model/raid_array.go +++ b/pkg/model/raid_array.go @@ -49,9 +49,9 @@ func (a *RaidArray) Create(ctx context.Context, raidType string) (err error) { } switch raidType { - case "linuxsw": + case common.SlugRAIDImplLinuxSoftware: return a.CreateLinux(ctx) - case "hardware": + case common.SlugRAIDImplHardware: return a.CreateHardware(ctx) default: err = InvalidRaidTypeError(raidType) @@ -66,9 +66,9 @@ func (a *RaidArray) DeleteLinux(ctx context.Context) (out string, err error) { func (a *RaidArray) Delete(ctx context.Context, raidType string) (out string, err error) { switch raidType { - case "linuxsw": + case common.SlugRAIDImplLinuxSoftware: return a.DeleteLinux(ctx) - case "hardware": + case common.SlugRAIDImplHardware: return "", a.DeleteHardware(ctx) default: err = InvalidRaidTypeError(raidType)