Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SoftLayer/managers/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
26 changes: 26 additions & 0 deletions tests/CLI/modules/file_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

:license: MIT, see LICENSE for more details.
"""
from SoftLayer import exceptions
from SoftLayer import testing

import json
Expand Down Expand Up @@ -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'])

Expand Down