Skip to content

Commit ad63bcb

Browse files
#722 finished adding GetVolumeId looks to block commands
1 parent 5476a00 commit ad63bcb

34 files changed

Lines changed: 110 additions & 123 deletions

plugin/commands/block/access_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package block
22

33
import (
4-
"sort"
54
"github.com/spf13/cobra"
5+
"sort"
66

77
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
88
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"

plugin/commands/block/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
1212
StorageCommand := &metadata.SoftlayerStorageCommand{
1313
SoftlayerCommand: sl,
1414
StorageI18n: map[string]interface{}{"storageType": "block"},
15-
StorageType: "block",
15+
StorageType: "block",
1616
}
1717
cobraCmd := &cobra.Command{
1818
Use: "block",

plugin/commands/block/snapshot-get_notification_status.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func (cmd *SnapshotGetNotificationStatusCommand) Run(args []string) error {
4141
return err
4242
}
4343

44-
4544
outputFormat := cmd.GetOutputFlag()
4645
subs := map[string]interface{}{"ID": volumeID}
4746
enabled, err := cmd.StorageManager.GetSnapshotNotificationStatus(volumeID)

plugin/commands/block/snapshot_create.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package block
22

33
import (
4-
"strconv"
5-
64
"github.com/spf13/cobra"
75

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -44,11 +42,10 @@ EXAMPLE:
4442

4543
func (cmd *SnapshotCreateCommand) Run(args []string) error {
4644

47-
volumeID, err := strconv.Atoi(args[0])
45+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
4846
if err != nil {
49-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
47+
return err
5048
}
51-
5249
outputFormat := cmd.GetOutputFlag()
5350

5451
snapshot, err := cmd.StorageManager.CreateSnapshot(volumeID, cmd.Note)

plugin/commands/block/snapshot_create_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var _ = Describe("Snapshot Create", func() {
3131
cliCommand = block.NewSnapshotCreateCommand(slCommand)
3232
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3333
cliCommand.StorageManager = FakeStorageManager
34+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3435
})
3536

3637
Describe("Snapshot create", func() {
@@ -41,14 +42,6 @@ var _ = Describe("Snapshot Create", func() {
4142
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
4243
})
4344
})
44-
Context("Snapshot create with wrong volume id", func() {
45-
It("error resolving volume ID", func() {
46-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
47-
Expect(err).To(HaveOccurred())
48-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
49-
})
50-
})
51-
5245
Context("Snapshot create with correct volume id", func() {
5346
BeforeEach(func() {
5447
FakeStorageManager.CreateSnapshotReturns(datatypes.Network_Storage{Id: sl.Int(5678)}, nil)

plugin/commands/block/snapshot_disable.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package block
22

33
import (
4-
"strconv"
5-
64
"github.com/spf13/cobra"
75

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -43,9 +41,9 @@ EXAMPLE:
4341

4442
func (cmd *SnapshotDisableCommand) Run(args []string) error {
4543

46-
volumeID, err := strconv.Atoi(args[0])
44+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
4745
if err != nil {
48-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
46+
return err
4947
}
5048
if cmd.Schedule_type == "" {
5149
return slErr.NewInvalidUsageError(T("[--schedule-type] is required, options are: HOURLY, DAILY, WEEKLY."))

plugin/commands/block/snapshot_disable_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var _ = Describe("Snapshot disable", func() {
3030
cliCommand = block.NewSnapshotDisableCommand(slCommand)
3131
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3232
cliCommand.StorageManager = FakeStorageManager
33+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3334
})
3435
Describe("Snapshot disable", func() {
3536
Context("Snapshot disable without volume id", func() {
@@ -39,14 +40,6 @@ var _ = Describe("Snapshot disable", func() {
3940
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
4041
})
4142
})
42-
Context("Snapshot disable with wrong volume id", func() {
43-
It("return error", func() {
44-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
45-
Expect(err).To(HaveOccurred())
46-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
47-
})
48-
})
49-
5043
Context("Snapshot disable without -s", func() {
5144
It("return error", func() {
5245
err := testhelpers.RunCobraCommand(cliCommand.Command, "123")

plugin/commands/block/snapshot_enable.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package block
33
import (
44
"github.com/spf13/cobra"
55
"slices"
6-
"strconv"
76
"strings"
87

98
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -72,9 +71,9 @@ EXAMPLE:
7271

7372
func (cmd *SnapshotEnableCommand) Run(args []string) error {
7473

75-
volumeID, err := strconv.Atoi(args[0])
74+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
7675
if err != nil {
77-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
76+
return err
7877
}
7978
if cmd.ScheduleType == "" {
8079
return slErr.NewInvalidUsageError(T("[-s|--schedule-type] is required, options are: HOURLY, DAILY, WEEKLY."))

plugin/commands/block/snapshot_enable_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var _ = Describe("Snapshot enable", func() {
2929
cliCommand = block.NewSnapshotEnableCommand(slCommand)
3030
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3131
cliCommand.StorageManager = FakeStorageManager
32+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3233
})
3334

3435
Describe("Snapshot enable", func() {
@@ -38,11 +39,6 @@ var _ = Describe("Snapshot enable", func() {
3839
Expect(err).To(HaveOccurred())
3940
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
4041
})
41-
It("Bad Volume ID", func() {
42-
err := testhelpers.RunCobraCommand(cliCommand.Command, "a1234", "-c=100", "-s=INTERVAL")
43-
Expect(err).To(HaveOccurred())
44-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
45-
})
4642
It("Bad Interval", func() {
4743
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--schedule-type=FAKE", "-c=100")
4844
Expect(err).To(HaveOccurred())
@@ -80,9 +76,9 @@ var _ = Describe("Snapshot enable", func() {
8076
Expect(fakeUI.Outputs()).To(ContainSubstring("HOURLY snapshots have been enabled for volume 1234."))
8177
})
8278
It("Happy Path min Options", func() {
83-
err := testhelpers.RunCobraCommand(cliCommand.Command, "9999", "-s", "INTERVAL", "-c", "500")
79+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "INTERVAL", "-c", "500")
8480
Expect(err).NotTo(HaveOccurred())
85-
Expect(fakeUI.Outputs()).To(ContainSubstring("INTERVAL snapshots have been enabled for volume 9999."))
81+
Expect(fakeUI.Outputs()).To(ContainSubstring("INTERVAL snapshots have been enabled for volume 1234."))
8682
})
8783
})
8884

plugin/commands/block/snapshot_list.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package block
22

33
import (
4-
"sort"
5-
"strconv"
6-
74
"github.com/spf13/cobra"
5+
"sort"
86

97
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
108
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
@@ -43,11 +41,10 @@ EXAMPLE:
4341
}
4442

4543
func (cmd *SnapshotListCommand) Run(args []string) error {
46-
volumeID, err := strconv.Atoi(args[0])
44+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
4745
if err != nil {
48-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
46+
return err
4947
}
50-
5148
outputFormat := cmd.GetOutputFlag()
5249

5350
snapshots, err := cmd.StorageManager.GetVolumeSnapshotList(volumeID)

0 commit comments

Comments
 (0)