Skip to content

Commit 52ee904

Browse files
#1568 fixed up snapshot-notification cli commands
1 parent 6d3b2d6 commit 52ee904

File tree

6 files changed

+74
-29
lines changed

6 files changed

+74
-29
lines changed

SoftLayer/CLI/block/snapshot/get_notify_status.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ def cli(env, volume_id):
1414
block_manager = SoftLayer.BlockStorageManager(env.client)
1515
enabled = block_manager.get_volume_snapshot_notification_status(volume_id)
1616

17-
if enabled == '':
18-
click.echo("""
19-
Enabled:Snapshots space usage warning flag is null. Set to default value enable. For volume %s
20-
""" % (volume_id))
21-
elif enabled == 'True':
22-
click.echo(
23-
'Enabled:Snapshots space usage threshold warning flag setting is enabled for volume %s'
24-
% (volume_id))
17+
if enabled == 0:
18+
click.echo("Disabled: Snapshots space usage threshold is disabled for volume {}".format(volume_id))
2519
else:
26-
click.echo(
27-
'Disabled:Snapshots space usage threshold warning flag setting is disabled for volume %s'
28-
% (volume_id))
20+
click.echo("Enabled: Snapshots space usage threshold is enabled for volume {}".format(volume_id))

SoftLayer/CLI/file/snapshot/get_notify_status.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ def cli(env, volume_id):
1515
file_manager = SoftLayer.FileStorageManager(env.client)
1616
enabled = file_manager.get_volume_snapshot_notification_status(volume_id)
1717

18-
if enabled == '':
19-
click.echo(
20-
'Enabled:Snapshots space usage threshold warning flag is null. Set to default value enable. For volume %s'
21-
% (volume_id))
22-
elif enabled == 'True':
23-
click.echo(
24-
'Enabled:Snapshots space usage threshold warning flag setting is enabled for volume %s'
25-
% (volume_id))
18+
if enabled == 0:
19+
click.echo("Disabled: Snapshots space usage threshold is disabled for volume {}".format(volume_id))
2620
else:
27-
click.echo(
28-
'Disabled:Snapshots space usage threshold warning flag setting is disabled for volume %s'
29-
% (volume_id))
21+
click.echo("Enabled: Snapshots space usage threshold is enabled for volume {}".format(volume_id))

SoftLayer/managers/storage.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ class StorageManager(utils.IdentifierMixin, object):
1919
2020
:param SoftLayer.API.BaseClient client: the client instance
2121
"""
22+
2223
def __init__(self, client):
2324
self.configuration = {}
2425
self.client = client
2526
self.resolvers = [self._get_ids_from_username]
2627

28+
def _get_ids_from_username(self, username):
29+
"""Should only be actually called from the block/file manager"""
30+
return []
31+
2732
def get_volume_count_limits(self):
2833
"""Returns a list of block volume count limit.
2934
@@ -122,20 +127,21 @@ def set_volume_snapshot_notification(self, volume_id, enable):
122127
:return: Enables/Disables snapshot space usage threshold warning for a given volume.
123128
"""
124129

125-
return self.client.call('Network_Storage',
126-
'setSnapshotNotification',
127-
enable,
128-
id=volume_id)
130+
return self.client.call('Network_Storage', 'setSnapshotNotification', enable, id=volume_id)
129131

130132
def get_volume_snapshot_notification_status(self, volume_id):
131133
"""returns Enabled/Disabled status of snapshot space usage threshold warning for a given volume.
132134
133135
:param volume_id: ID of volume.
134136
:return: Enables/Disables snapshot space usage threshold warning for a given volume.
135137
"""
136-
return self.client.call('Network_Storage',
137-
'getSnapshotNotificationStatus',
138-
id=volume_id)
138+
status = self.client.call('Network_Storage', 'getSnapshotNotificationStatus', id=volume_id)
139+
# A None status is enabled as well.
140+
if status is None:
141+
status = 1
142+
# We need to force int on the return because otherwise the API will return the string '0'
143+
# instead of either a boolean or real int...
144+
return int(status)
139145

140146
def authorize_host_to_volume(self,
141147
volume_id,

tests/CLI/modules/block_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,3 +812,13 @@ def test_volume_not_set_note(self, set_note):
812812

813813
self.assert_no_fail(result)
814814
self.assertIn("Note could not be set!", result.output)
815+
816+
@mock.patch('SoftLayer.BlockStorageManager.get_volume_snapshot_notification_status')
817+
def test_snapshot_get_notification_status(self, status):
818+
status.side_effect = [None, 1, 0]
819+
expected = ['Enabled', 'Enabled', 'Disabled']
820+
821+
for expect in expected:
822+
result = self.run_command(['block', 'snapshot-get-notification-status', '999'])
823+
self.assert_no_fail(result)
824+
self.assertIn(expect, result.output)

tests/CLI/modules/file_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,3 +791,13 @@ def test_volume_not_set_note(self, set_note):
791791

792792
self.assert_no_fail(result)
793793
self.assertIn("Note could not be set!", result.output)
794+
795+
@mock.patch('SoftLayer.FileStorageManager.get_volume_snapshot_notification_status')
796+
def test_snapshot_get_notification_status(self, status):
797+
status.side_effect = [None, 1, 0]
798+
expected = ['Enabled', 'Enabled', 'Disabled']
799+
800+
for expect in expected:
801+
result = self.run_command(['file', 'snapshot-get-notification-status', '999'])
802+
self.assert_no_fail(result)
803+
self.assertIn(expect, result.output)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
SoftLayer.tests.managers.storage_generic_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
:license: MIT, see LICENSE for more details.
6+
"""
7+
8+
import copy
9+
import SoftLayer
10+
from SoftLayer import exceptions
11+
from SoftLayer import testing
12+
13+
14+
class StorageGenericTests(testing.TestCase):
15+
def set_up(self):
16+
self.storage = SoftLayer.managers.storage.StorageManager(self.client)
17+
18+
def test_get_volume_snapshot_notification_status(self):
19+
mock = self.set_mock('SoftLayer_Network_Storage', 'getSnapshotNotificationStatus')
20+
# These are the values we expect from the API as of 2021-12-01, FBLOCK4193
21+
mock.side_effect = [None, '1', '0']
22+
expected = [1, 1, 0]
23+
24+
for expect in expected:
25+
result = self.storage.get_volume_snapshot_notification_status(12345)
26+
self.assert_called_with('SoftLayer_Network_Storage', 'getSnapshotNotificationStatus', identifier=12345)
27+
self.assertEqual(expect, result)
28+
29+
def test_set_volume_snapshot_notification(self):
30+
mock = self.set_mock('SoftLayer_Network_Storage', 'setSnapshotNotification')
31+
mock.return_value = None
32+
33+
result = self.storage.set_volume_snapshot_notification(12345, False)
34+
self.assert_called_with('SoftLayer_Network_Storage', 'setSnapshotNotification',
35+
identifier=12345, args=(False,))

0 commit comments

Comments
 (0)