diff --git a/SoftLayer/CLI/block/detail.py b/SoftLayer/CLI/block/detail.py index 51a1fbd4f..d1461df2e 100644 --- a/SoftLayer/CLI/block/detail.py +++ b/SoftLayer/CLI/block/detail.py @@ -34,7 +34,7 @@ def cli(env, volume_id): if block_volume.get('storageTierLevel'): table.add_row([ 'Endurance Tier', - block_volume['storageTierLevel']['description'], + block_volume['storageTierLevel'], ]) table.add_row([ diff --git a/SoftLayer/CLI/file/detail.py b/SoftLayer/CLI/file/detail.py index 25cdb956a..8f7024aab 100644 --- a/SoftLayer/CLI/file/detail.py +++ b/SoftLayer/CLI/file/detail.py @@ -43,7 +43,7 @@ def cli(env, volume_id): if file_volume.get('storageTierLevel'): table.add_row([ 'Endurance Tier', - file_volume['storageTierLevel']['description'], + file_volume['storageTierLevel'], ]) table.add_row([ diff --git a/SoftLayer/fixtures/SoftLayer_Metric_Tracking_Object.py b/SoftLayer/fixtures/SoftLayer_Metric_Tracking_Object.py deleted file mode 100644 index d03859ea1..000000000 --- a/SoftLayer/fixtures/SoftLayer_Metric_Tracking_Object.py +++ /dev/null @@ -1 +0,0 @@ -getSummaryData = [] diff --git a/SoftLayer/fixtures/SoftLayer_Network_Storage.py b/SoftLayer/fixtures/SoftLayer_Network_Storage.py index 91162e892..ea5b91e6c 100644 --- a/SoftLayer/fixtures/SoftLayer_Network_Storage.py +++ b/SoftLayer/fixtures/SoftLayer_Network_Storage.py @@ -21,7 +21,7 @@ 'password': '', 'serviceProviderId': 1, 'iops': 1000, - 'storageTierLevel': {'description': '2 IOPS per GB'}, + 'storageTierLevel': 'READHEAVY_TIER', 'snapshotCapacityGb': '10', 'parentVolume': {'snapshotSizeBytes': 1024}, 'osType': {'keyName': 'LINUX'}, diff --git a/SoftLayer/fixtures/SoftLayer_Network_Storage_Iscsi.py b/SoftLayer/fixtures/SoftLayer_Network_Storage_Iscsi.py deleted file mode 100644 index bccf440c8..000000000 --- a/SoftLayer/fixtures/SoftLayer_Network_Storage_Iscsi.py +++ /dev/null @@ -1,68 +0,0 @@ -getObject = { - 'accountId': 1111, - 'billingItem': {'id': 600}, - 'capacityGb': 20, - 'createDate': '2014:50:15-04:00', - 'guestId': '', - 'hardwareId': '', - 'hostId': '', - 'id': 100, - 'nasType': 'ISCSI', - 'notes': """{'status': 'available'}""", - 'password': 'abcdef', - 'serviceProviderId': 1, - 'serviceResource': {'datacenter': {'id': 138124}}, - 'serviceResourceBackendIpAddress': '10.0.1.1', - 'serviceResourceName': 'storagesng0101', - 'username': 'username' -} - -createSnapshot = { - 'accountId': 1111, - 'capacityGb': 20, - 'createDate': '2014:51:11-04:00', - 'guestId': '', - 'hardwareId': '', - 'hostId': '', - 'id': 101, - 'nasType': 'ISCSI_SNAPSHOT', - 'parentVolume': { - 'accountId': 1111, - 'capacityGb': 20, - 'createDate': '2014:38:47-04:00', - 'guestId': '', - 'hardwareId': '', - 'hostId': '', - 'id': 100, - 'nasType': 'ISCSI', - 'password': 'abcdef', - 'properties': [ - {'createDate': '2014:40:22-04:00', - 'modifyDate': '', - 'type': { - 'description': - 'Percent of reserved snapshot space that is available', - 'keyname': 'SNAPSHOT_RESERVE_AVAILABLE', - 'name': 'Snaphot Reserve Available'}, - - 'value': '100', - 'volumeId': 2233}], - - 'propertyCount': 0, - 'serviceProviderId': 1, - 'name': 'storagedal05', - 'snapshotCapacityGb': '40', - 'username': 'username'}, - 'password': 'abcdef', - 'serviceProviderId': 1, - 'serviceResource': {'backendIpAddress': '10.1.0.1', - 'name': 'storagedal05', - 'type': {'type': 'ISCSI'}}, - 'serviceResourceBackendIpAddress': '10.1.0.1', - 'serviceResourceName': 'storagedal05', - 'username': 'username'} - -restoreFromSnapshot = True -editObject = True -createObject = getObject -deleteObject = True diff --git a/SoftLayer/fixtures/SoftLayer_User_Customer.py b/SoftLayer/fixtures/SoftLayer_User_Customer.py deleted file mode 100644 index 72d28db8a..000000000 --- a/SoftLayer/fixtures/SoftLayer_User_Customer.py +++ /dev/null @@ -1 +0,0 @@ -addApiAuthenticationKey = "A" * 64 diff --git a/SoftLayer/managers/storage_utils.py b/SoftLayer/managers/storage_utils.py index 6c840a730..dcd7f04fb 100644 --- a/SoftLayer/managers/storage_utils.py +++ b/SoftLayer/managers/storage_utils.py @@ -189,24 +189,21 @@ def find_endurance_tier_iops_per_gb(volume): :param volume: The volume for which the tier level is desired :return: Returns a float value indicating the IOPS per GB for the volume """ - tier_description_split = volume['storageTierLevel']['description'].split() - - if tier_description_split != []: - iops_per_gb = tier_description_split[0] - - if iops_per_gb == '0.25': - return 0.25 - - if iops_per_gb == '2': - return 2.0 - - if iops_per_gb == '4': - return 4.0 - - if iops_per_gb == '10': - return 10.0 + tier = volume['storageTierLevel'] + iops_per_gb = 0.25 + + if tier == "LOW_INTENSITY_TIER": + iops_per_gb = 0.25 + elif tier == "READHEAVY_TIER": + iops_per_gb = 2 + elif tier == "WRITEHEAVY_TIER": + iops_per_gb = 4 + elif tier == "10_IOPS_PER_GB": + iops_per_gb = 10 + else: + raise ValueError("Could not find tier IOPS per GB for this volume") - raise ValueError("Could not find tier IOPS per GB for this volume") + return iops_per_gb def find_performance_price(package, price_category): diff --git a/tests/CLI/modules/block_tests.py b/tests/CLI/modules/block_tests.py index f65d1cbc9..58c46a0e9 100644 --- a/tests/CLI/modules/block_tests.py +++ b/tests/CLI/modules/block_tests.py @@ -71,7 +71,7 @@ def test_volume_detail(self): self.assertEqual({ 'Username': 'username', 'LUN Id': '2', - 'Endurance Tier': '2 IOPS per GB', + 'Endurance Tier': 'READHEAVY_TIER', 'IOPs': 1000, 'Snapshot Capacity (GB)': '10', 'Snapshot Used (Bytes)': 1024, diff --git a/tests/CLI/modules/file_tests.py b/tests/CLI/modules/file_tests.py index df8abec92..c3b3b7a40 100644 --- a/tests/CLI/modules/file_tests.py +++ b/tests/CLI/modules/file_tests.py @@ -121,7 +121,7 @@ def test_volume_detail(self): self.assertEqual({ 'Username': 'username', 'Used Space': '0B', - 'Endurance Tier': '2 IOPS per GB', + 'Endurance Tier': 'READHEAVY_TIER', 'IOPs': 1000, 'Mount Address': '127.0.0.1:/TEST', 'Snapshot Capacity (GB)': '10', diff --git a/tests/managers/block_tests.py b/tests/managers/block_tests.py index 99ec24411..e336fbbbf 100644 --- a/tests/managers/block_tests.py +++ b/tests/managers/block_tests.py @@ -44,6 +44,9 @@ def test_list_block_volumes(self): self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage') + result = self.block.list_block_volumes(datacenter="dal09", storage_type="Endurance", username="username") + self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage') + def test_get_block_volume_access_list(self): result = self.block.get_block_volume_access_list(100) @@ -133,6 +136,47 @@ def test_cancel_snapshot_immediately(self): identifier=123, ) + def test_cancel_snapshot_exception_1(self): + mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') + mock.return_value = { + 'capacityGb': 20, + 'snapshotCapacityGb': '10', + 'schedules': [{ + 'id': 7770, + 'type': {'keyname': 'SNAPSHOT_WEEKLY'} + }], + 'billingItem': { + 'categoryCode': 'storage_service_enterprise', + 'cancellationDate': '2016-09-04T22:00:00-07:00' + } + } + self.assertRaises( + exceptions.SoftLayerError, + self.block.cancel_snapshot_space, + 12345, + immediate=True + ) + + def test_cancel_snapshot_exception_2(self): + mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') + mock.return_value = { + 'capacityGb': 20, + 'snapshotCapacityGb': '10', + 'schedules': [{ + 'id': 7770, + 'type': {'keyname': 'SNAPSHOT_WEEKLY'} + }], + 'billingItem': { + 'activeChildren': [] + } + } + self.assertRaises( + exceptions.SoftLayerError, + self.block.cancel_snapshot_space, + 12345, + immediate=True + ) + def test_replicant_failover(self): result = self.block.failover_to_replicant(1234, 5678, immediate=True) @@ -595,6 +639,26 @@ def test_order_snapshot_space(self): 'setupFee': '1'}], }, ) + result = self.block.order_snapshot_space(100, 5, None, True) + + self.assertEqual( + result, + { + 'orderId': 1234, + 'orderDate': '2013-08-01 15:23:45', + 'prices': [{ + 'hourlyRecurringFee': '2', + 'id': 1, + 'item': {'description': 'this is a thing', 'id': 1}, + 'laborFee': '2', + 'oneTimeFee': '2', + 'oneTimeFeeTax': '.1', + 'quantity': 1, + 'recurringFee': '2', + 'recurringFeeTax': '.1', + 'setupFee': '1'}], + }, + ) def test_order_snapshot_space_invalid_category(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') diff --git a/tox.ini b/tox.ini index 61bf0480c..c11a205ad 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,9 @@ [tox] envlist = py27,py33,py34,py35,py36,pypy,analysis,coverage +[flake8] +max-line-length=120 + [testenv] deps = -r{toxinidir}/tools/test-requirements.txt commands = py.test {posargs:tests} @@ -34,7 +37,7 @@ commands = --max-branches=20 \ --max-statements=60 \ --min-public-methods=0 \ - --min-similarity-lines=30 + --min-similarity-lines=30 # invalid-name - Fixtures don't follow proper naming conventions # missing-docstring - Fixtures don't have docstrings