Skip to content

Commit ff83c78

Browse files
#722 Updated file commands to use getVolumeId
1 parent ad63bcb commit ff83c78

26 files changed

+69
-67
lines changed

plugin/commands/file/access_authorize.go

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

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

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -56,9 +54,9 @@ EXAMPLE:
5654

5755
func (cmd *AccessAuthorizeCommand) Run(args []string) error {
5856

59-
volumeID, err := strconv.Atoi(args[0])
57+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
6058
if err != nil {
61-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
59+
return err
6260
}
6361
IPIds := cmd.Ip_address_id
6462
IPs := cmd.Ip_address

plugin/commands/file/access_authorize_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var _ = Describe("Access Authorize", func() {
3535
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3636
cliCommand.StorageManager = FakeStorageManager
3737
cliCommand.NetworkManager = fakeNetworkManager
38+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3839
})
3940

4041
Describe("Access Authorize", func() {
@@ -48,9 +49,10 @@ var _ = Describe("Access Authorize", func() {
4849
})
4950
Context("Access Authorize with wrong volume id", func() {
5051
It("error resolving volume ID", func() {
52+
FakeStorageManager.GetVolumeIdReturns(0, errors.New("BAD Volume ID"))
5153
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
5254
Expect(err).To(HaveOccurred())
53-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
55+
Expect(err.Error()).To(ContainSubstring("BAD Volume ID"))
5456
})
5557
})
5658

plugin/commands/file/access_revoke.go

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

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

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -55,9 +53,9 @@ EXAMPLE:
5553
}
5654

5755
func (cmd *AccessRevokeCommand) Run(args []string) error {
58-
volumeID, err := strconv.Atoi(args[0])
56+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5957
if err != nil {
60-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
58+
return err
6159
}
6260

6361
if len(cmd.Hardware_id) == 0 && len(cmd.Virtual_id) == 0 && len(cmd.Ip_address_id) == 0 && len(cmd.Ip_address) == 0 && len(cmd.Subnet_id) == 0 {

plugin/commands/file/access_revoke_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var _ = Describe("Access Authorize", func() {
3535
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3636
cliCommand.StorageManager = FakeStorageManager
3737
cliCommand.NetworkManager = fakeNetworkManager
38+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3839
})
3940

4041
Describe("Access Revoke", func() {
@@ -47,9 +48,10 @@ var _ = Describe("Access Authorize", func() {
4748
})
4849
Context("Access revoke with wrong volume id", func() {
4950
It("error resolving volume ID", func() {
51+
FakeStorageManager.GetVolumeIdReturns(0, errors.New("BAD Volume ID"))
5052
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
5153
Expect(err).To(HaveOccurred())
52-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
54+
Expect(err.Error()).To(ContainSubstring("BAD Volume ID"))
5355
})
5456
})
5557

plugin/commands/file/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
2121
StorageCommand := &metadata.SoftlayerStorageCommand{
2222
SoftlayerCommand: sl,
2323
StorageI18n: map[string]interface{}{"storageType": "file"},
24-
StorageType: "file",
24+
StorageType: "file",
2525
}
2626
cobraCmd := &cobra.Command{
2727
Use: "file",

plugin/commands/file/replica_order.go

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

33
import (
44
"fmt"
5-
"strconv"
6-
75
"github.com/spf13/cobra"
86

97
"github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -53,9 +51,9 @@ EXAMPLE:
5351

5452
func (cmd *ReplicaOrderCommand) Run(args []string) error {
5553

56-
volumeID, err := strconv.Atoi(args[0])
54+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5755
if err != nil {
58-
return errors.NewInvalidSoftlayerIdInputError("Volume ID")
56+
return err
5957
}
6058

6159
snapshotSchedule := cmd.SnapshotSchedule

plugin/commands/file/replica_order_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var _ = Describe("Replica order", func() {
3131
cliCommand = file.NewReplicaOrderCommand(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("Replicant order", func() {
@@ -43,54 +44,55 @@ var _ = Describe("Replica order", func() {
4344
})
4445
Context("Replicant order with wrong volume id", func() {
4546
It("return error", func() {
47+
FakeStorageManager.GetVolumeIdReturns(0, errors.New("BAD Volume ID"))
4648
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
4749
Expect(err).To(HaveOccurred())
48-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
50+
Expect(err.Error()).To(ContainSubstring("BAD Volume ID"))
4951
})
5052
})
5153
Context("Replicant order without -s", func() {
5254
It("return error", func() {
53-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123")
55+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
5456
Expect(err).To(HaveOccurred())
5557
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: [-s|--snapshot-schedule] is required, options are: HOURLY, DAILY, WEEKLY."))
5658
})
5759
})
5860

5961
Context("Replicant order with wrong -s", func() {
6062
It("return error", func() {
61-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "yearly")
63+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "yearly")
6264
Expect(err).To(HaveOccurred())
6365
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: [-s|--snapshot-schedule] is required, options are: HOURLY, DAILY, WEEKLY."))
6466
})
6567
})
6668

6769
Context("Replicant order without -d", func() {
6870
It("return error", func() {
69-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "DAILY")
71+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "DAILY")
7072
Expect(err).To(HaveOccurred())
7173
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: [-d|--datacenter] is required."))
7274
})
7375
})
7476

7577
Context("Replicant order with wrong tier", func() {
7678
It("return error", func() {
77-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "DAILY", "-d", "dal09", "-t", "0.3")
79+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "DAILY", "-d", "dal09", "-t", "0.3")
7880
Expect(err).To(HaveOccurred())
7981
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: [-t|--tier] is optional, options are: 0.25,2,4,10."))
8082
})
8183
})
8284

8385
Context("Replicant order with wrong iops", func() {
8486
It("return error", func() {
85-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "DAILY", "-d", "dal09", "-i", "9")
87+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "DAILY", "-d", "dal09", "-i", "9")
8688
Expect(err).To(HaveOccurred())
8789
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: -i|--iops must be between 100 and 6000, inclusive."))
8890
})
8991
})
9092

9193
Context("Replicant order with wrong iops", func() {
9294
It("return error", func() {
93-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "DAILY", "-d", "dal09", "-i", "1234")
95+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "DAILY", "-d", "dal09", "-i", "1234")
9496
Expect(err).To(HaveOccurred())
9597
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: -i|--iops must be a multiple of 100."))
9698
})
@@ -101,9 +103,9 @@ var _ = Describe("Replica order", func() {
101103
FakeStorageManager.OrderReplicantVolumeReturns(datatypes.Container_Product_Order_Receipt{}, errors.New("Internal Server Error"))
102104
})
103105
It("return error", func() {
104-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "DAILY", "-d", "dal09", "-t", "4", "-f")
106+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "DAILY", "-d", "dal09", "-t", "4", "-f")
105107
Expect(err).To(HaveOccurred())
106-
Expect(err.Error()).To(ContainSubstring("Failed to order replicant for volume 123.Please verify your options and try again."))
108+
Expect(err.Error()).To(ContainSubstring("Failed to order replicant for volume 1234.Please verify your options and try again."))
107109
Expect(err.Error()).To(ContainSubstring("Internal Server Error"))
108110
})
109111
})
@@ -127,12 +129,12 @@ var _ = Describe("Replica order", func() {
127129
nil)
128130
})
129131
It("return no error", func() {
130-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "DAILY", "-d", "dal09", "-t", "4", "-f")
132+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "DAILY", "-d", "dal09", "-t", "4", "-f")
131133
Expect(err).NotTo(HaveOccurred())
132134
Expect(fakeUI.Outputs()).To(ContainSubstring("Order 123456 was placed."))
133135
})
134136
It("return no error", func() {
135-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "DAILY", "-d", "dal09", "-i", "3000", "-f")
137+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-s", "DAILY", "-d", "dal09", "-i", "3000", "-f")
136138
Expect(err).NotTo(HaveOccurred())
137139
Expect(fakeUI.Outputs()).To(ContainSubstring("Order 123456 was placed."))
138140
})

plugin/commands/file/snapshot_cancel.go

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

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

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -48,9 +46,9 @@ EXAMPLE:
4846

4947
func (cmd *SnapshotCancelCommand) Run(args []string) error {
5048

51-
volumeID, err := strconv.Atoi(args[0])
49+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5250
if err != nil {
53-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
51+
return err
5452
}
5553
subs := map[string]interface{}{"ID": volumeID}
5654
if !cmd.Force {

plugin/commands/file/snapshot_cancel_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var _ = Describe("Snapshot Cancel", func() {
2929
cliCommand = file.NewSnapshotCancelCommand(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 cancel", func() {
@@ -41,9 +42,10 @@ var _ = Describe("Snapshot Cancel", func() {
4142
})
4243
Context("Snapshot cancel with wrong volume id", func() {
4344
It("error resolving volume ID", func() {
45+
FakeStorageManager.GetVolumeIdReturns(0, errors.New("BAD Volume ID"))
4446
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
4547
Expect(err).To(HaveOccurred())
46-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
48+
Expect(err.Error()).To(ContainSubstring("BAD Volume ID"))
4749
})
4850
})
4951

plugin/commands/file/volume_cancel.go

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

33
import (
4-
"strconv"
54
"strings"
65

76
"github.com/spf13/cobra"
@@ -47,12 +46,12 @@ EXAMPLE:
4746
}
4847

4948
func (cmd *VolumeCancelCommand) Run(args []string) error {
50-
51-
volumeID, err := strconv.Atoi(args[0])
52-
subs := map[string]interface{}{"ID": volumeID, "VolumeId": volumeID}
49+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5350
if err != nil {
54-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
51+
return err
5552
}
53+
subs := map[string]interface{}{"ID": volumeID, "VolumeId": volumeID}
54+
5655
if !cmd.Force {
5756
confirm, err := cmd.UI.Confirm(T("This will cancel the file volume: {{.ID}} and cannot be undone. Continue?", subs))
5857
if err != nil {

0 commit comments

Comments
 (0)