From b0824f1bcdf93ece0a307e8ece816a302c484b99 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Tue, 27 Nov 2018 17:12:00 -0400 Subject: [PATCH] Fix file volume-cancel --- SoftLayer/managers/file.py | 3 +++ tests/CLI/modules/file_tests.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/SoftLayer/managers/file.py b/SoftLayer/managers/file.py index e0a250328..b6d16053f 100644 --- a/SoftLayer/managers/file.py +++ b/SoftLayer/managers/file.py @@ -482,6 +482,9 @@ def cancel_file_volume(self, volume_id, reason='No longer needed', immediate=Fal file_volume = self.get_file_volume_details( volume_id, mask='mask[id,billingItem[id,hourlyFlag]]') + + if 'billingItem' not in file_volume: + raise exceptions.SoftLayerError('The volume has already been canceled') billing_item_id = file_volume['billingItem']['id'] if utils.lookup(file_volume, 'billingItem', 'hourlyFlag'): diff --git a/tests/CLI/modules/file_tests.py b/tests/CLI/modules/file_tests.py index 9bc56320b..465e9ec03 100644 --- a/tests/CLI/modules/file_tests.py +++ b/tests/CLI/modules/file_tests.py @@ -4,6 +4,7 @@ :license: MIT, see LICENSE for more details. """ +from SoftLayer import exceptions from SoftLayer import testing import json @@ -94,6 +95,31 @@ def test_volume_cancel(self): self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem', args=(False, True, None)) + def test_volume_cancel_with_billing_item(self): + result = self.run_command([ + '--really', 'file', 'volume-cancel', '1234']) + + self.assert_no_fail(result) + self.assertEqual('File volume with id 1234 has been marked' + ' for cancellation\n', result.output) + self.assert_called_with('SoftLayer_Network_Storage', 'getObject') + + def test_volume_cancel_without_billing_item(self): + p_mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') + p_mock.return_value = { + "accountId": 1234, + "capacityGb": 20, + "createDate": "2015-04-29T06:55:55-07:00", + "id": 11111, + "nasType": "NAS", + "username": "SL01SEV307608_1" + } + + result = self.run_command([ + '--really', 'file', 'volume-cancel', '1234']) + + self.assertIsInstance(result.exception, exceptions.SoftLayerError) + def test_volume_detail(self): result = self.run_command(['file', 'volume-detail', '1234'])