Skip to content

Commit

Permalink
cmd/configure_raid.go,pkg/model/{model_test.go,raid_array.go}: Use bm…
Browse files Browse the repository at this point in the history
…c-toolbox/common constants for RAID implementations
  • Loading branch information
splaspood committed Nov 15, 2022
1 parent 69115fa commit d5af507
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
11 changes: 6 additions & 5 deletions cmd/configure_raid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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") {
Expand All @@ -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.")
Expand All @@ -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{
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 3 additions & 2 deletions pkg/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/model/raid_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d5af507

Please sign in to comment.