Skip to content

Commit 9d63f46

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #819 from SoftLayer/issues816
Adds Encryption status to file and block volume-detail commands
2 parents 0104441 + 6c677eb commit 9d63f46

8 files changed

Lines changed: 50 additions & 153 deletions

File tree

bin/buildAndDeploy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
from pathlib import Path
66
import os
7+
import sys
78
import re
89
import subprocess
910
import requests

plugin/commands/block/volume_detail.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ func (cmd *VolumeDetailCommand) Run(args []string) error {
135135
return slErr.NewAPIError(T("Failed to decoded the note.\n"), err.Error(), 2)
136136
}
137137
table.Add(T("Notes"), decodedValue)
138+
hasEncryption := T("False")
139+
if (blockVolume.HasEncryptionAtRest != nil && *blockVolume.HasEncryptionAtRest == true) {
140+
hasEncryption = T("True")
141+
}
142+
table.Add(T("Encrypted"), hasEncryption)
138143
table.Print()
139144
return nil
140145
}

plugin/commands/block/volume_detail_test.go

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
package block_test
22

33
import (
4-
"errors"
5-
6-
. "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/matchers"
74
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
85
. "github.com/onsi/ginkgo"
96
. "github.com/onsi/gomega"
107

11-
"github.com/softlayer/softlayer-go/datatypes"
128
"github.com/softlayer/softlayer-go/session"
13-
"github.com/softlayer/softlayer-go/sl"
149

1510
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/block"
1611
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
1712
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
1813
)
1914

20-
var _ = Describe("Volume detail", func() {
15+
var _ = Describe("Block Volume-Detail Tests", func() {
2116
var (
2217
fakeUI *terminal.FakeUI
23-
FakeStorageManager *testhelpers.FakeStorageManager
2418
cliCommand *block.VolumeDetailCommand
25-
fakeSession *session.Session
19+
fakeSession *session.Session
20+
fakeHandler *testhelpers.FakeTransportHandler
2621
slCommand *metadata.SoftlayerStorageCommand
2722
)
2823
BeforeEach(func() {
2924
fakeUI = terminal.NewFakeUI()
30-
FakeStorageManager = new(testhelpers.FakeStorageManager)
25+
fakeSession = testhelpers.NewFakeSoftlayerSession(nil)
26+
fakeHandler = testhelpers.GetSessionHandler(fakeSession)
3127
slCommand = metadata.NewSoftlayerStorageCommand(fakeUI, fakeSession, "block")
3228
cliCommand = block.NewVolumeDetailCommand(slCommand)
3329
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
34-
cliCommand.StorageManager = FakeStorageManager
30+
3531
})
3632

3733
Describe("Volume detail", func() {
@@ -52,7 +48,7 @@ var _ = Describe("Volume detail", func() {
5248

5349
Context("Volume detail with correct volume id but server API call fails", func() {
5450
BeforeEach(func() {
55-
FakeStorageManager.GetVolumeDetailsReturns(datatypes.Network_Storage{}, errors.New("Internal Server Error"))
51+
fakeHandler.AddApiError("SoftLayer_Network_Storage", "getObject", 500, "Internal Server Error")
5652
})
5753
It("return error", func() {
5854
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
@@ -63,75 +59,14 @@ var _ = Describe("Volume detail", func() {
6359
})
6460

6561
Context("Volume detail with correct volume id", func() {
66-
BeforeEach(func() {
67-
FakeStorageManager.GetVolumeDetailsReturns(datatypes.Network_Storage{
68-
Id: sl.Int(1234),
69-
Username: sl.String("myvolume"),
70-
CapacityGb: sl.Int(1000),
71-
Iops: sl.String("400"),
72-
StorageTierLevel: sl.String("HEAVY_WRITE"),
73-
StorageType: &datatypes.Network_Storage_Type{
74-
KeyName: sl.String("performance"),
75-
},
76-
ServiceResource: &datatypes.Network_Service_Resource{
77-
Datacenter: &datatypes.Location{
78-
Name: sl.String("tok02"),
79-
},
80-
},
81-
ServiceResourceBackendIpAddress: sl.String("9.9.9.9"),
82-
SnapshotCapacityGb: sl.String("500"),
83-
ParentVolume: &datatypes.Network_Storage{
84-
SnapshotSizeBytes: sl.String("10000"),
85-
},
86-
ActiveTransactionCount: sl.Uint(uint(1)),
87-
ActiveTransactions: []datatypes.Provisioning_Version1_Transaction{
88-
datatypes.Provisioning_Version1_Transaction{
89-
TransactionStatus: &datatypes.Provisioning_Version1_Transaction_Status{
90-
FriendlyName: sl.String("Restarting"),
91-
},
92-
},
93-
},
94-
ReplicationPartnerCount: sl.Uint(uint(1)),
95-
ReplicationStatus: sl.String("replication finished"),
96-
ReplicationPartners: []datatypes.Network_Storage{
97-
datatypes.Network_Storage{
98-
Id: sl.Int(5678),
99-
Username: sl.String("myreplicant"),
100-
ServiceResourceBackendIpAddress: sl.String("9.9.9.8"),
101-
ServiceResource: &datatypes.Network_Service_Resource{
102-
Datacenter: &datatypes.Location{
103-
Name: sl.String("dal10"),
104-
},
105-
},
106-
ReplicationSchedule: &datatypes.Network_Storage_Schedule{
107-
Type: &datatypes.Network_Storage_Schedule_Type{
108-
Keyname: sl.String("DAILY"),
109-
},
110-
},
111-
},
112-
},
113-
}, nil)
114-
})
11562
It("return no error", func() {
11663
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
11764
Expect(err).NotTo(HaveOccurred())
118-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"1234"}))
119-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"myvolume"}))
120-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"1000"}))
121-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"400"}))
122-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"HEAVY_WRITE"}))
123-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"tok02"}))
124-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"performance"}))
125-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"9.9.9.9"}))
126-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"500"}))
127-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"Restarting"}))
128-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"replication finished"}))
129-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"5678"}))
130-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"myreplicant"}))
131-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"9.9.9.8"}))
132-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"dal10"}))
133-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"DAILY"}))
134-
65+
Expect(fakeUI.Outputs()).To(ContainSubstring("ID 17336531"))
66+
Expect(fakeUI.Outputs()).To(ContainSubstring("User name IBM01SEL278444-16"))
67+
Expect(fakeUI.Outputs()).To(ContainSubstring("Endurance Tier WRITEHEAVY_TIER"))
68+
Expect(fakeUI.Outputs()).To(ContainSubstring("Notes -"))
69+
Expect(fakeUI.Outputs()).To(ContainSubstring("Encrypted False"))
13570
})
13671
})
13772
})

plugin/commands/file/volume_detail.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ func (cmd *VolumeDetailCommand) Run(args []string) error {
136136
return slErr.NewAPIError(T("Failed to decoded the note.\n"), err.Error(), 2)
137137
}
138138
table.Add(T("Notes"), decodedValue)
139+
hasEncryption := T("False")
140+
if (fileVolume.HasEncryptionAtRest != nil && *fileVolume.HasEncryptionAtRest == true) {
141+
hasEncryption = T("True")
142+
}
143+
table.Add(T("Encrypted"), hasEncryption)
139144
table.Print()
140145
return nil
141146
}

plugin/commands/file/volume_detail_test.go

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package file_test
22

33
import (
4-
"errors"
5-
64
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
75
. "github.com/onsi/ginkgo"
86
. "github.com/onsi/gomega"
97

10-
"github.com/softlayer/softlayer-go/datatypes"
118
"github.com/softlayer/softlayer-go/session"
12-
"github.com/softlayer/softlayer-go/sl"
139
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/file"
1410
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
1511
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
@@ -19,18 +15,18 @@ var _ = Describe("Volume detail", func() {
1915
var (
2016
fakeUI *terminal.FakeUI
2117
cliCommand *file.VolumeDetailCommand
22-
fakeSession *session.Session
18+
fakeSession *session.Session
19+
fakeHandler *testhelpers.FakeTransportHandler
2320
slCommand *metadata.SoftlayerStorageCommand
24-
FakeStorageManager *testhelpers.FakeStorageManager
21+
2522
)
2623
BeforeEach(func() {
2724
fakeUI = terminal.NewFakeUI()
28-
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
29-
FakeStorageManager = new(testhelpers.FakeStorageManager)
25+
fakeSession = testhelpers.NewFakeSoftlayerSession(nil)
26+
fakeHandler = testhelpers.GetSessionHandler(fakeSession)
3027
slCommand = metadata.NewSoftlayerStorageCommand(fakeUI, fakeSession, "file")
3128
cliCommand = file.NewVolumeDetailCommand(slCommand)
3229
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
33-
cliCommand.StorageManager = FakeStorageManager
3430
})
3531

3632
Describe("Volume detail", func() {
@@ -51,7 +47,7 @@ var _ = Describe("Volume detail", func() {
5147

5248
Context("Volume detail with correct volume id but server API call fails", func() {
5349
BeforeEach(func() {
54-
FakeStorageManager.GetVolumeDetailsReturns(datatypes.Network_Storage{}, errors.New("Internal Server Error"))
50+
fakeHandler.AddApiError("SoftLayer_Network_Storage", "getObject", 500, "Internal Server Error")
5551
})
5652
It("return error", func() {
5753
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
@@ -62,63 +58,14 @@ var _ = Describe("Volume detail", func() {
6258
})
6359

6460
Context("Volume detail with correct volume id", func() {
65-
BeforeEach(func() {
66-
FakeStorageManager.GetVolumeDetailsReturns(datatypes.Network_Storage{
67-
Id: sl.Int(1234),
68-
Username: sl.String("myvolume"),
69-
CapacityGb: sl.Int(1000),
70-
Iops: sl.String("400"),
71-
StorageTierLevel: sl.String("HEAVY_WRITE"),
72-
StorageType: &datatypes.Network_Storage_Type{
73-
KeyName: sl.String("performance"),
74-
},
75-
ServiceResource: &datatypes.Network_Service_Resource{
76-
Datacenter: &datatypes.Location{
77-
Name: sl.String("tok02"),
78-
},
79-
},
80-
ServiceResourceBackendIpAddress: sl.String("9.9.9.9"),
81-
SnapshotCapacityGb: sl.String("500"),
82-
ParentVolume: &datatypes.Network_Storage{
83-
SnapshotSizeBytes: sl.String("10000"),
84-
},
85-
ActiveTransactionCount: sl.Uint(uint(1)),
86-
ActiveTransactions: []datatypes.Provisioning_Version1_Transaction{
87-
datatypes.Provisioning_Version1_Transaction{
88-
TransactionStatus: &datatypes.Provisioning_Version1_Transaction_Status{
89-
FriendlyName: sl.String("Restarting"),
90-
},
91-
},
92-
},
93-
ReplicationPartnerCount: sl.Uint(uint(1)),
94-
ReplicationStatus: sl.String("replication finished"),
95-
ReplicationPartners: []datatypes.Network_Storage{
96-
datatypes.Network_Storage{
97-
Id: sl.Int(5678),
98-
Username: sl.String("myreplicant"),
99-
ServiceResourceBackendIpAddress: sl.String("9.9.9.8"),
100-
ServiceResource: &datatypes.Network_Service_Resource{
101-
Datacenter: &datatypes.Location{
102-
Name: sl.String("dal10"),
103-
},
104-
},
105-
ReplicationSchedule: &datatypes.Network_Storage_Schedule{
106-
Type: &datatypes.Network_Storage_Schedule_Type{
107-
Keyname: sl.String("DAILY"),
108-
},
109-
},
110-
},
111-
},
112-
}, nil)
113-
})
11461
It("return no error", func() {
11562
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
11663
Expect(err).NotTo(HaveOccurred())
117-
Expect(fakeUI.Outputs()).To(ContainSubstring("1234"))
118-
Expect(fakeUI.Outputs()).To(ContainSubstring("myvolume"))
119-
Expect(fakeUI.Outputs()).To(ContainSubstring("tok02"))
120-
Expect(fakeUI.Outputs()).To(ContainSubstring("9.9.9.9"))
121-
Expect(fakeUI.Outputs()).To(ContainSubstring("Restarting"))
64+
Expect(fakeUI.Outputs()).To(ContainSubstring("ID 17336531"))
65+
Expect(fakeUI.Outputs()).To(ContainSubstring("User name IBM01SEL278444-16"))
66+
Expect(fakeUI.Outputs()).To(ContainSubstring("Endurance Tier WRITEHEAVY_TIER"))
67+
Expect(fakeUI.Outputs()).To(ContainSubstring("Notes -"))
68+
Expect(fakeUI.Outputs()).To(ContainSubstring("Encrypted False"))
12269
})
12370
})
12471
})

plugin/i18n/resources/en_US.all.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,10 @@
27152715
"id": "Enables/Disables snapshot space usage threshold warning for a given volume.",
27162716
"translation": "Enables/Disables snapshot space usage threshold warning for a given volume."
27172717
},
2718+
{
2719+
"id": "Encrypted",
2720+
"translation": "Encrypted"
2721+
},
27182722
{
27192723
"id": "End",
27202724
"translation": "End"

plugin/managers/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434
BLOCK_VOLUME_DEFAULT_MASK = "id,username,lunId,capacityGb,bytesUsed,serviceResource.datacenter.name,serviceResourceBackendIpAddress,storageType.keyName,activeTransactionCount,billingItem.orderItem.order[id,userRecord.username],notes,iops," + "activeTransactionCount,replicationPartnerCount"
3535
BLOCK_VOLUME_DETAIL_MASK = "id,username,password,capacityGb,snapshotCapacityGb,parentVolume.snapshotSizeBytes,storageType.keyName," +
3636
"serviceResource.datacenter.name,serviceResourceBackendIpAddress,storageTierLevel,iops,lunId," +
37-
"originalVolumeName,originalSnapshotName,originalVolumeSize," +
37+
"originalVolumeName,originalSnapshotName,originalVolumeSize,hasEncryptionAtRest," +
3838
"activeTransactionCount,activeTransactions.transactionStatus.friendlyName," +
3939
"replicationPartnerCount,replicationStatus," +
4040
"replicationPartners[id,username,serviceResourceBackendIpAddress,serviceResource.datacenter.name,replicationSchedule.type.keyname],notes"

plugin/resources/i18n_resources.go

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)