Skip to content

Commit b0824f1

Browse files
author
Fernando Ojeda
committed
Fix file volume-cancel
1 parent 3a1e016 commit b0824f1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

SoftLayer/managers/file.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ def cancel_file_volume(self, volume_id, reason='No longer needed', immediate=Fal
482482
file_volume = self.get_file_volume_details(
483483
volume_id,
484484
mask='mask[id,billingItem[id,hourlyFlag]]')
485+
486+
if 'billingItem' not in file_volume:
487+
raise exceptions.SoftLayerError('The volume has already been canceled')
485488
billing_item_id = file_volume['billingItem']['id']
486489

487490
if utils.lookup(file_volume, 'billingItem', 'hourlyFlag'):

tests/CLI/modules/file_tests.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
:license: MIT, see LICENSE for more details.
66
"""
7+
from SoftLayer import exceptions
78
from SoftLayer import testing
89

910
import json
@@ -94,6 +95,31 @@ def test_volume_cancel(self):
9495
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
9596
args=(False, True, None))
9697

98+
def test_volume_cancel_with_billing_item(self):
99+
result = self.run_command([
100+
'--really', 'file', 'volume-cancel', '1234'])
101+
102+
self.assert_no_fail(result)
103+
self.assertEqual('File volume with id 1234 has been marked'
104+
' for cancellation\n', result.output)
105+
self.assert_called_with('SoftLayer_Network_Storage', 'getObject')
106+
107+
def test_volume_cancel_without_billing_item(self):
108+
p_mock = self.set_mock('SoftLayer_Network_Storage', 'getObject')
109+
p_mock.return_value = {
110+
"accountId": 1234,
111+
"capacityGb": 20,
112+
"createDate": "2015-04-29T06:55:55-07:00",
113+
"id": 11111,
114+
"nasType": "NAS",
115+
"username": "SL01SEV307608_1"
116+
}
117+
118+
result = self.run_command([
119+
'--really', 'file', 'volume-cancel', '1234'])
120+
121+
self.assertIsInstance(result.exception, exceptions.SoftLayerError)
122+
97123
def test_volume_detail(self):
98124
result = self.run_command(['file', 'volume-detail', '1234'])
99125

0 commit comments

Comments
 (0)