Skip to content

Commit 5eaa9a2

Browse files
author
David Pickle
committed
Add unit tests for volume modification commands/functions
1 parent 35cc918 commit 5eaa9a2

File tree

7 files changed

+347
-8
lines changed

7 files changed

+347
-8
lines changed

SoftLayer/fixtures/SoftLayer_Network_Storage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939

4040
getObject = {
4141
'accountId': 1234,
42-
'activeTransactionCount': 0,
43-
'activeTransactions': None,
42+
'activeTransactionCount': 1,
43+
'activeTransactions': [{
44+
'transactionStatus': {'friendlyName': 'This is a buffer time in which the customer may cancel the server'}
45+
}],
4446
'allowedHardware': [{
4547
'allowedHost': {
4648
'credential': {'username': 'joe', 'password': '12345'},

SoftLayer/managers/storage_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ def prepare_modify_order_object(manager, volume, new_iops, new_tier, new_size):
10131013

10141014
# Verify that the origin volume has not been cancelled
10151015
if 'billingItem' not in volume:
1016-
raise exceptions.SoftLayerError("The volume has been cancelled; unable to modify volume")
1016+
raise exceptions.SoftLayerError("The volume has been cancelled; unable to modify volume.")
10171017

10181018
# Ensure the origin volume is STaaS v2 or higher and supports Encryption at Rest
10191019
if not _staas_version_is_v2_or_above(volume):
@@ -1035,7 +1035,7 @@ def prepare_modify_order_object(manager, volume, new_iops, new_tier, new_size):
10351035
elif new_iops is None:
10361036
new_iops = int(volume.get('provisionedIops', 0))
10371037
if new_iops <= 0:
1038-
raise exceptions.SoftLayerError("Cannot find volume's provisioned IOPS")
1038+
raise exceptions.SoftLayerError("Cannot find volume's provisioned IOPS.")
10391039

10401040
# Set up the prices array for the order
10411041
prices = [
@@ -1062,8 +1062,8 @@ def prepare_modify_order_object(manager, volume, new_iops, new_tier, new_size):
10621062
]
10631063

10641064
else:
1065-
raise exceptions.SoftLayerError("Origin volume does not have a valid storage type (with an appropriate "
1066-
"keyName to indicate the volume is a PERFORMANCE or an ENDURANCE volume)")
1065+
raise exceptions.SoftLayerError("Volume does not have a valid storage type (with an appropriate "
1066+
"keyName to indicate the volume is a PERFORMANCE or an ENDURANCE volume).")
10671067

10681068
modify_order = {
10691069
'complexType': 'SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade',

tests/CLI/modules/block_tests.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def test_volume_detail(self):
7171
'Data Center': 'dal05',
7272
'Type': 'ENDURANCE',
7373
'ID': 100,
74-
'# of Active Transactions': '0',
74+
'# of Active Transactions': '1',
75+
'Ongoing Transaction': 'This is a buffer time in which the customer may cancel the server',
7576
'Replicant Count': '1',
7677
'Replication Status': 'Replicant Volume Provisioning '
7778
'has completed.',
@@ -601,6 +602,37 @@ def test_duplicate_order_hourly_billing(self, order_mock):
601602
'Order #24602 placed successfully!\n'
602603
' > Storage as a Service\n')
603604

605+
@mock.patch('SoftLayer.BlockStorageManager.order_modified_volume')
606+
def test_modify_order_exception_caught(self, order_mock):
607+
order_mock.side_effect = ValueError('order attempt failed, noooo!')
608+
609+
result = self.run_command(['block', 'volume-modify', '102', '--new-size=1000'])
610+
611+
self.assertEqual(2, result.exit_code)
612+
self.assertEqual('Argument Error: order attempt failed, noooo!', result.exception.message)
613+
614+
@mock.patch('SoftLayer.BlockStorageManager.order_modified_volume')
615+
def test_modify_order_order_not_placed(self, order_mock):
616+
order_mock.return_value = {}
617+
618+
result = self.run_command(['block', 'volume-modify', '102', '--new-iops=1400'])
619+
620+
self.assert_no_fail(result)
621+
self.assertEqual('Order could not be placed! Please verify your options and try again.\n', result.output)
622+
623+
@mock.patch('SoftLayer.BlockStorageManager.order_modified_volume')
624+
def test_modify_order(self, order_mock):
625+
order_mock.return_value = {'placedOrder': {'id': 24602, 'items': [{'description': 'Storage as a Service'},
626+
{'description': '1000 GBs'},
627+
{'description': '4 IOPS per GB'}]}}
628+
629+
result = self.run_command(['block', 'volume-modify', '102', '--new-size=1000', '--new-tier=4'])
630+
631+
order_mock.assert_called_with('102', new_size=1000, new_iops=None, new_tier_level=4)
632+
self.assert_no_fail(result)
633+
self.assertEqual('Order #24602 placed successfully!\n > Storage as a Service\n > 1000 GBs\n > 4 IOPS per GB\n',
634+
result.output)
635+
604636
def test_set_password(self):
605637
result = self.run_command(['block', 'access-password', '1234', '--password=AAAAA'])
606638
self.assert_no_fail(result)

tests/CLI/modules/file_tests.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def test_volume_detail(self):
111111
'Data Center': 'dal05',
112112
'Type': 'ENDURANCE',
113113
'ID': 100,
114-
'# of Active Transactions': '0',
114+
'# of Active Transactions': '1',
115+
'Ongoing Transaction': 'This is a buffer time in which the customer may cancel the server',
115116
'Replicant Count': '1',
116117
'Replication Status': 'Replicant Volume Provisioning '
117118
'has completed.',
@@ -579,3 +580,34 @@ def test_duplicate_order_hourly_billing(self, order_mock):
579580
self.assertEqual(result.output,
580581
'Order #24602 placed successfully!\n'
581582
' > Storage as a Service\n')
583+
584+
@mock.patch('SoftLayer.FileStorageManager.order_modified_volume')
585+
def test_modify_order_exception_caught(self, order_mock):
586+
order_mock.side_effect = ValueError('order attempt failed, noooo!')
587+
588+
result = self.run_command(['file', 'volume-modify', '102', '--new-size=1000'])
589+
590+
self.assertEqual(2, result.exit_code)
591+
self.assertEqual('Argument Error: order attempt failed, noooo!', result.exception.message)
592+
593+
@mock.patch('SoftLayer.FileStorageManager.order_modified_volume')
594+
def test_modify_order_order_not_placed(self, order_mock):
595+
order_mock.return_value = {}
596+
597+
result = self.run_command(['file', 'volume-modify', '102', '--new-iops=1400'])
598+
599+
self.assert_no_fail(result)
600+
self.assertEqual('Order could not be placed! Please verify your options and try again.\n', result.output)
601+
602+
@mock.patch('SoftLayer.FileStorageManager.order_modified_volume')
603+
def test_modify_order(self, order_mock):
604+
order_mock.return_value = {'placedOrder': {'id': 24602, 'items': [{'description': 'Storage as a Service'},
605+
{'description': '1000 GBs'},
606+
{'description': '4 IOPS per GB'}]}}
607+
608+
result = self.run_command(['file', 'volume-modify', '102', '--new-size=1000', '--new-tier=4'])
609+
610+
order_mock.assert_called_with('102', new_size=1000, new_iops=None, new_tier_level=4)
611+
self.assert_no_fail(result)
612+
self.assertEqual('Order #24602 placed successfully!\n > Storage as a Service\n > 1000 GBs\n > 4 IOPS per GB\n',
613+
result.output)

tests/managers/block_tests.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,50 @@ def test_order_block_duplicate_endurance(self):
832832
'useHourlyPricing': False
833833
},))
834834

835+
def test_order_block_modified_performance(self):
836+
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
837+
mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE]
838+
839+
mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME)
840+
mock_volume['storageType']['keyName'] = 'PERFORMANCE_BLOCK_STORAGE'
841+
mock = self.set_mock('SoftLayer_Network_Storage', 'getObject')
842+
mock.return_value = mock_volume
843+
844+
result = self.block.order_modified_volume(102, new_size=1000, new_iops=2000, new_tier_level=None)
845+
846+
self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result)
847+
self.assert_called_with(
848+
'SoftLayer_Product_Order',
849+
'placeOrder',
850+
args=({'complexType': 'SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade',
851+
'packageId': 759,
852+
'prices': [{'id': 189433}, {'id': 190113}, {'id': 190173}],
853+
'volume': {'id': 102},
854+
'volumeSize': 1000,
855+
'iops': 2000},)
856+
)
857+
858+
def test_order_block_modified_endurance(self):
859+
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
860+
mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE]
861+
862+
mock_volume = fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME
863+
mock = self.set_mock('SoftLayer_Network_Storage', 'getObject')
864+
mock.return_value = mock_volume
865+
866+
result = self.block.order_modified_volume(102, new_size=1000, new_iops=None, new_tier_level=4)
867+
868+
self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result)
869+
self.assert_called_with(
870+
'SoftLayer_Product_Order',
871+
'placeOrder',
872+
args=({'complexType': 'SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade',
873+
'packageId': 759,
874+
'prices': [{'id': 189433}, {'id': 194763}, {'id': 194703}],
875+
'volume': {'id': 102},
876+
'volumeSize': 1000},)
877+
)
878+
835879
def test_setCredentialPassword(self):
836880
mock = self.set_mock('SoftLayer_Network_Storage_Allowed_Host', 'setCredentialPassword')
837881
mock.return_value = True

tests/managers/file_tests.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,3 +785,48 @@ def test_order_file_duplicate_endurance(self):
785785
'duplicateOriginSnapshotId': 470,
786786
'useHourlyPricing': False
787787
},))
788+
789+
def test_order_file_modified_performance(self):
790+
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
791+
mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE]
792+
793+
mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME)
794+
mock_volume['storageType']['keyName'] = 'PERFORMANCE_FILE_STORAGE'
795+
mock = self.set_mock('SoftLayer_Network_Storage', 'getObject')
796+
mock.return_value = mock_volume
797+
798+
result = self.file.order_modified_volume(102, new_size=1000, new_iops=2000, new_tier_level=None)
799+
800+
self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result)
801+
self.assert_called_with(
802+
'SoftLayer_Product_Order',
803+
'placeOrder',
804+
args=({'complexType': 'SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade',
805+
'packageId': 759,
806+
'prices': [{'id': 189433}, {'id': 190113}, {'id': 190173}],
807+
'volume': {'id': 102},
808+
'volumeSize': 1000,
809+
'iops': 2000},)
810+
)
811+
812+
def test_order_file_modified_endurance(self):
813+
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
814+
mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE]
815+
816+
mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME)
817+
mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE'
818+
mock = self.set_mock('SoftLayer_Network_Storage', 'getObject')
819+
mock.return_value = mock_volume
820+
821+
result = self.file.order_modified_volume(102, new_size=1000, new_iops=None, new_tier_level=4)
822+
823+
self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result)
824+
self.assert_called_with(
825+
'SoftLayer_Product_Order',
826+
'placeOrder',
827+
args=({'complexType': 'SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade',
828+
'packageId': 759,
829+
'prices': [{'id': 189433}, {'id': 194763}, {'id': 194703}],
830+
'volume': {'id': 102},
831+
'volumeSize': 1000},)
832+
)

0 commit comments

Comments
 (0)