Skip to content

Commit 5e2b9b1

Browse files
Fixed up some unit tests
1 parent 6d6ab5a commit 5e2b9b1

File tree

6 files changed

+145
-198
lines changed

6 files changed

+145
-198
lines changed

Diff for: SoftLayer/CLI/block/detail.py

+19-40
Original file line numberDiff line numberDiff line change
@@ -31,72 +31,51 @@ def cli(env, volume_id):
3131
table.add_row(['Username', block_volume['username']])
3232
table.add_row(['Type', storage_type])
3333
table.add_row(['Capacity (GB)', capacity])
34-
table.add_row(['LUN Id', "%s" % block_volume['lunId']])
34+
table.add_row(['LUN Id', block_volume['lunId']])
3535

3636
if block_volume.get('provisionedIops'):
37-
table.add_row(['IOPs', float(block_volume['provisionedIops'])])
37+
table.add_row(['IOPs', block_volume['provisionedIops']])
3838

3939
if block_volume.get('storageTierLevel'):
40-
table.add_row([
41-
'Endurance Tier',
42-
block_volume['storageTierLevel'],
43-
])
44-
45-
table.add_row([
46-
'Data Center',
47-
block_volume['serviceResource']['datacenter']['name'],
48-
])
49-
table.add_row([
50-
'Target IP',
51-
block_volume['serviceResourceBackendIpAddress'],
52-
])
40+
table.add_row(['Endurance Tier', block_volume['storageTierLevel']])
41+
42+
table.add_row(['Data Center', block_volume['serviceResource']['datacenter']['name']])
43+
table.add_row(['Target IP', block_volume['serviceResourceBackendIpAddress']])
5344

5445
if block_volume['snapshotCapacityGb']:
55-
table.add_row([
56-
'Snapshot Capacity (GB)',
57-
block_volume['snapshotCapacityGb'],
58-
])
46+
table.add_row(['Snapshot Capacity (GB)', block_volume['snapshotCapacityGb']])
5947
if 'snapshotSizeBytes' in block_volume['parentVolume']:
60-
table.add_row([
61-
'Snapshot Used (Bytes)',
62-
block_volume['parentVolume']['snapshotSizeBytes'],
63-
])
48+
table.add_row(['Snapshot Used (Bytes)', block_volume['parentVolume']['snapshotSizeBytes']])
6449

65-
table.add_row(['# of Active Transactions', "%i"
66-
% block_volume['activeTransactionCount']])
50+
table.add_row(['# of Active Transactions', block_volume['activeTransactionCount']])
6751

6852
if block_volume['activeTransactions']:
6953
for trans in block_volume['activeTransactions']:
7054
if 'transactionStatus' in trans and 'friendlyName' in trans['transactionStatus']:
7155
table.add_row(['Ongoing Transaction', trans['transactionStatus']['friendlyName']])
7256

73-
table.add_row(['Replicant Count', "%u" % block_volume.get('replicationPartnerCount', 0)])
57+
table.add_row(['Replicant Count', block_volume.get('replicationPartnerCount', 0)])
7458

7559
if block_volume['replicationPartnerCount'] > 0:
7660
# This if/else temporarily handles a bug in which the SL API
7761
# returns a string or object for 'replicationStatus'; it seems that
7862
# the type is string for File volumes and object for Block volumes
7963
if 'message' in block_volume['replicationStatus']:
80-
table.add_row(['Replication Status', "%s"
81-
% block_volume['replicationStatus']['message']])
64+
table.add_row(['Replication Status', block_volume['replicationStatus']['message']])
8265
else:
83-
table.add_row(['Replication Status', "%s"
84-
% block_volume['replicationStatus']])
66+
table.add_row(['Replication Status', block_volume['replicationStatus']])
8567

86-
replicant_table = formatting.KeyValueTable(['Name', 'Value'])
68+
replicant_table = formatting.Table(['Id', 'Username', 'Target', 'Location', 'Schedule'])
8769
replicant_table.align['Name'] = 'r'
8870
replicant_table.align['Value'] = 'l'
8971
for replicant in block_volume['replicationPartners']:
9072
replicant_table.add_row([
91-
'Replicant Id', replicant['id']])
92-
replicant_table.add_row([
93-
'Volume Name', utils.lookup(replicant, 'username')])
94-
replicant_table.add_row([
95-
'Target IP', utils.lookup(replicant, 'serviceResourceBackendIpAddress')])
96-
replicant_table.add_row([
97-
'Data Center', utils.lookup(replicant, 'serviceResource', 'datacenter', 'name')])
98-
replicant_table.add_row([
99-
'Schedule', utils.lookup(replicant, 'replicationSchedule', 'type', 'keyname')])
73+
replicant.get('id'),
74+
utils.lookup(replicant, 'username'),
75+
utils.lookup(replicant, 'serviceResourceBackendIpAddress'),
76+
utils.lookup(replicant, 'serviceResource', 'datacenter', 'name'),
77+
utils.lookup(replicant, 'replicationSchedule', 'type', 'keyname')
78+
])
10079
table.add_row(['Replicant Volumes', replicant_table])
10180

10281
if block_volume.get('originalVolumeSize'):

Diff for: SoftLayer/CLI/exceptions.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ def __init__(self, code=0, *args):
1616
self.code = code
1717

1818
def __str__(self):
19-
return "<CLIHalt code=%s msg=%s>" % (self.code,
20-
getattr(self, 'message'))
21-
19+
message = getattr(self, 'message')
20+
return f"<CLIHalt code={self.code} msg={message}>"
2221
__repr__ = __str__
2322

2423

@@ -29,10 +28,20 @@ def __init__(self, msg, *args):
2928
super().__init__(code=2, *args)
3029
self.message = msg
3130

31+
def __str__(self):
32+
message = getattr(self, 'message')
33+
return f"<CLIAbort code={self.code} msg={message}>"
34+
__repr__ = __str__
35+
3236

3337
class ArgumentError(CLIAbort):
3438
"""Halt the execution of the command because of invalid arguments."""
3539

3640
def __init__(self, msg, *args):
3741
super().__init__(msg, *args)
3842
self.message = "Argument Error: %s" % msg
43+
44+
def __str__(self):
45+
message = getattr(self, 'message')
46+
return f"<ArgumentError code={self.code} msg={message}>"
47+
__repr__ = __str__

Diff for: SoftLayer/CLI/file/detail.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def cli(env, volume_id):
4141
table.add_row(['Used Space', used_space])
4242

4343
if file_volume.get('provisionedIops'):
44-
table.add_row(['IOPs', float(file_volume['provisionedIops'])])
44+
table.add_row(['IOPs', file_volume['provisionedIops']])
4545

4646
if file_volume.get('storageTierLevel'):
4747
table.add_row(['Endurance Tier', file_volume['storageTierLevel']])
@@ -75,20 +75,17 @@ def cli(env, volume_id):
7575
else:
7676
table.add_row(['Replication Status', file_volume['replicationStatus']])
7777

78-
replicant_table = formatting.KeyValueTable(['Name', 'Value'])
78+
replicant_table = formatting.Table(['Id', 'Username', 'Target', 'Location', 'Schedule'])
7979
replicant_table.align['Name'] = 'r'
8080
replicant_table.align['Value'] = 'l'
8181
for replicant in file_volume['replicationPartners']:
8282
replicant_table.add_row([
83-
'Volume ID', replicant.get('id')])
84-
replicant_table.add_row([
85-
'Volume Name', utils.lookup(replicant, 'username')])
86-
replicant_table.add_row([
87-
'Target IP', utils.lookup(replicant, 'serviceResourceBackendIpAddress')])
88-
replicant_table.add_row([
89-
'Data Center', utils.lookup(replicant, 'serviceResource', 'datacenter', 'name')])
90-
replicant_table.add_row([
91-
'Schedule', utils.lookup(replicant, 'replicationSchedule', 'type', 'keyname')])
83+
replicant.get('id'),
84+
utils.lookup(replicant, 'username'),
85+
utils.lookup(replicant, 'serviceResourceBackendIpAddress'),
86+
utils.lookup(replicant, 'serviceResource', 'datacenter', 'name'),
87+
utils.lookup(replicant, 'replicationSchedule', 'type', 'keyname')
88+
])
9289
table.add_row(['Replicant Volumes', replicant_table])
9390

9491
if file_volume.get('originalVolumeSize'):

Diff for: SoftLayer/testing/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def setUp(self): # NOQA
111111
self.env = environment.Environment()
112112
self.env.client = self.client
113113
self.set_up()
114+
self.maxDiff = None
114115

115116
def tearDown(self): # NOQA
116117
super().tearDown()

Diff for: tests/CLI/modules/block_tests.py

+29-23
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,41 @@ def test_volume_detail(self):
6565
self.assert_called_with('SoftLayer_Network_Storage', 'getObject', identifier=1234)
6666
self.assertEqual({
6767
'Username': 'username',
68-
'LUN Id': '2',
69-
'Notes': "{'status': 'available'}",
7068
'Endurance Tier': 'READHEAVY_TIER',
71-
'IOPs': 1000.0,
69+
'IOPs': "1000",
70+
'LUN Id': 2,
7271
'Snapshot Capacity (GB)': '10',
7372
'Snapshot Used (Bytes)': 1024,
7473
'Capacity (GB)': '20GB',
7574
'Target IP': '10.1.2.3',
7675
'Data Center': 'dal05',
7776
'Type': 'ENDURANCE',
7877
'ID': 100,
79-
'# of Active Transactions': '1',
78+
'Notes': "{'status': 'available'}",
79+
'# of Active Transactions': 1,
8080
'Ongoing Transaction': 'This is a buffer time in which the customer may cancel the server',
81-
'Replicant Count': '1',
82-
'Replication Status': 'Replicant Volume Provisioning '
83-
'has completed.',
84-
'Replicant Volumes': [
85-
{'Name': 'Replicant Id', 'Value': 1785},
86-
{'Name': 'Volume Name', 'Value': 'TEST_REP_2'},
87-
{'Name': 'Target IP', 'Value': '10.3.177.84'},
88-
{'Name': 'Data Center', 'Value': 'dal01'},
89-
{'Name': 'Schedule', 'Value': 'REPLICATION_DAILY'}],
81+
'Replicant Count': 1,
82+
'Replication Status': 'Replicant Volume Provisioning has completed.',
83+
"Replicant Volumes": [
84+
{
85+
"Id": 1784,
86+
"Username": "TEST_REP_1",
87+
"Target": "10.3.174.79",
88+
"Location": "wdc01",
89+
"Schedule": "REPLICATION_HOURLY"
90+
},
91+
{
92+
"Id": 1785,
93+
"Username": "TEST_REP_2",
94+
"Target": "10.3.177.84",
95+
"Location": "dal01",
96+
"Schedule": "REPLICATION_DAILY"
97+
}
98+
],
9099
'Original Volume Properties': [
91-
{'Property': 'Original Volume Size',
92-
'Value': '20'},
93-
{'Property': 'Original Volume Name',
94-
'Value': 'test-original-volume-name'},
95-
{'Property': 'Original Snapshot Name',
96-
'Value': 'test-original-snapshot-name'}
100+
{'Property': 'Original Volume Size', 'Value': '20'},
101+
{'Property': 'Original Volume Name', 'Value': 'test-original-volume-name'},
102+
{'Property': 'Original Snapshot Name', 'Value': 'test-original-snapshot-name'}
97103
]
98104
}, json.loads(result.output))
99105

@@ -102,10 +108,10 @@ def test_block_detail_issue1732(self):
102108
lun_mock.return_value = SoftLayer_Network_Storage.BLOCK_LIST_ISSUES_1732
103109
result = self.run_command(['--format=table', 'block', 'volume-detail', '1234'])
104110
self.assert_no_fail(result)
105-
self.assertIn('Username │ SL02SEL307608-60', result.output)
106-
self.assertIn('Capacity (GB) │ 16000GB', result.output)
107-
self.assertIn('Replication Status │ FAILBACK_COMPLETED', result.output)
108-
self.assertIn('Notes │ test', result.output)
111+
self.assertIn('Username │ SL02SEL307608-60', result.output)
112+
self.assertIn('Capacity (GB) │ 16000GB', result.output)
113+
self.assertIn('Replication Status │ FAILBACK_COMPLETED', result.output)
114+
self.assertIn('Notes │ test', result.output)
109115

110116
def test_volume_detail_name_identifier(self):
111117
result = self.run_command(['block', 'volume-detail', 'SL-12345'])

0 commit comments

Comments
 (0)