Skip to content

Commit 3f63cf7

Browse files
got block_tests to 100% and changed max-line-length to 120 for flake8
1 parent f3f5abf commit 3f63cf7

File tree

9 files changed

+85
-91
lines changed

9 files changed

+85
-91
lines changed

SoftLayer/fixtures/SoftLayer_Metric_Tracking_Object.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

SoftLayer/fixtures/SoftLayer_Network_Storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'password': '',
2222
'serviceProviderId': 1,
2323
'iops': 1000,
24-
'storageTierLevel': {'description': '2 IOPS per GB'},
24+
'storageTierLevel': 'READHEAVY_TIER',
2525
'snapshotCapacityGb': '10',
2626
'parentVolume': {'snapshotSizeBytes': 1024},
2727
'osType': {'keyName': 'LINUX'},

SoftLayer/fixtures/SoftLayer_Network_Storage_Iscsi.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

SoftLayer/fixtures/SoftLayer_User_Customer.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

SoftLayer/managers/storage_utils.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,24 +189,21 @@ def find_endurance_tier_iops_per_gb(volume):
189189
:param volume: The volume for which the tier level is desired
190190
:return: Returns a float value indicating the IOPS per GB for the volume
191191
"""
192-
tier_description_split = volume['storageTierLevel']['description'].split()
193-
194-
if tier_description_split != []:
195-
iops_per_gb = tier_description_split[0]
196-
197-
if iops_per_gb == '0.25':
198-
return 0.25
199-
200-
if iops_per_gb == '2':
201-
return 2.0
202-
203-
if iops_per_gb == '4':
204-
return 4.0
205-
206-
if iops_per_gb == '10':
207-
return 10.0
192+
tier = volume['storageTierLevel']
193+
iops_per_gb = 0.25
194+
195+
if tier == "LOW_INTENSITY_TIER":
196+
iops_per_gb = 0.25
197+
elif tier == "READHEAVY_TIER":
198+
iops_per_gb = 2
199+
elif tier == "WRITEHEAVY_TIER":
200+
iops_per_gb = 4
201+
elif tier == "10_IOPS_PER_GB":
202+
iops_per_gb = 10
203+
else:
204+
raise ValueError("Could not find tier IOPS per GB for this volume")
208205

209-
raise ValueError("Could not find tier IOPS per GB for this volume")
206+
return iops_per_gb
210207

211208

212209
def find_performance_price(package, price_category):

tests/CLI/modules/block_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_volume_detail(self):
7171
self.assertEqual({
7272
'Username': 'username',
7373
'LUN Id': '2',
74-
'Endurance Tier': '2 IOPS per GB',
74+
'Endurance Tier': 'READHEAVY_TIER',
7575
'IOPs': 1000,
7676
'Snapshot Capacity (GB)': '10',
7777
'Snapshot Used (Bytes)': 1024,

tests/CLI/modules/file_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_volume_detail(self):
121121
self.assertEqual({
122122
'Username': 'username',
123123
'Used Space': '0B',
124-
'Endurance Tier': '2 IOPS per GB',
124+
'Endurance Tier': 'READHEAVY_TIER',
125125
'IOPs': 1000,
126126
'Mount Address': '127.0.0.1:/TEST',
127127
'Snapshot Capacity (GB)': '10',

tests/managers/block_tests.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def test_list_block_volumes(self):
4444

4545
self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage')
4646

47+
result = self.block.list_block_volumes(datacenter="dal09", storage_type="Endurance", username="username")
48+
self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage')
49+
4750
def test_get_block_volume_access_list(self):
4851
result = self.block.get_block_volume_access_list(100)
4952

@@ -133,6 +136,47 @@ def test_cancel_snapshot_immediately(self):
133136
identifier=123,
134137
)
135138

139+
def test_cancel_snapshot_exception_1(self):
140+
mock = self.set_mock('SoftLayer_Network_Storage', 'getObject')
141+
mock.return_value = {
142+
'capacityGb': 20,
143+
'snapshotCapacityGb': '10',
144+
'schedules': [{
145+
'id': 7770,
146+
'type': {'keyname': 'SNAPSHOT_WEEKLY'}
147+
}],
148+
'billingItem': {
149+
'categoryCode': 'storage_service_enterprise',
150+
'cancellationDate': '2016-09-04T22:00:00-07:00'
151+
}
152+
}
153+
self.assertRaises(
154+
exceptions.SoftLayerError,
155+
self.block.cancel_snapshot_space,
156+
12345,
157+
immediate=True
158+
)
159+
160+
def test_cancel_snapshot_exception_2(self):
161+
mock = self.set_mock('SoftLayer_Network_Storage', 'getObject')
162+
mock.return_value = {
163+
'capacityGb': 20,
164+
'snapshotCapacityGb': '10',
165+
'schedules': [{
166+
'id': 7770,
167+
'type': {'keyname': 'SNAPSHOT_WEEKLY'}
168+
}],
169+
'billingItem': {
170+
'activeChildren': []
171+
}
172+
}
173+
self.assertRaises(
174+
exceptions.SoftLayerError,
175+
self.block.cancel_snapshot_space,
176+
12345,
177+
immediate=True
178+
)
179+
136180
def test_replicant_failover(self):
137181
result = self.block.failover_to_replicant(1234, 5678, immediate=True)
138182

@@ -595,6 +639,26 @@ def test_order_snapshot_space(self):
595639
'setupFee': '1'}],
596640
},
597641
)
642+
result = self.block.order_snapshot_space(100, 5, None, True)
643+
644+
self.assertEqual(
645+
result,
646+
{
647+
'orderId': 1234,
648+
'orderDate': '2013-08-01 15:23:45',
649+
'prices': [{
650+
'hourlyRecurringFee': '2',
651+
'id': 1,
652+
'item': {'description': 'this is a thing', 'id': 1},
653+
'laborFee': '2',
654+
'oneTimeFee': '2',
655+
'oneTimeFeeTax': '.1',
656+
'quantity': 1,
657+
'recurringFee': '2',
658+
'recurringFeeTax': '.1',
659+
'setupFee': '1'}],
660+
},
661+
)
598662

599663
def test_order_snapshot_space_invalid_category(self):
600664
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[tox]
22
envlist = py27,py33,py34,py35,py36,pypy,analysis,coverage
33

4+
[flake8]
5+
max-line-length=120
6+
47
[testenv]
58
deps = -r{toxinidir}/tools/test-requirements.txt
69
commands = py.test {posargs:tests}
@@ -34,7 +37,7 @@ commands =
3437
--max-branches=20 \
3538
--max-statements=60 \
3639
--min-public-methods=0 \
37-
--min-similarity-lines=30
40+
--min-similarity-lines=30
3841

3942
# invalid-name - Fixtures don't follow proper naming conventions
4043
# missing-docstring - Fixtures don't have docstrings

0 commit comments

Comments
 (0)