Skip to content

Commit d7c0b09

Browse files
Merge pull request #1569 from allmightyspiff/issues1568
fixed up snapshot-notification cli commands
2 parents 6d3b2d6 + 552784e commit d7c0b09

File tree

8 files changed

+75
-31
lines changed

8 files changed

+75
-31
lines changed

SoftLayer/CLI/block/count.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def cli(env, sortby, datacenter):
3030
service_resource = volume['serviceResource']
3131
if 'datacenter' in service_resource:
3232
datacenter_name = service_resource['datacenter']['name']
33-
if datacenter_name not in datacenters.keys():
33+
if datacenter_name not in datacenters.keys(): # pylint: disable=consider-iterating-dictionary
3434
datacenters[datacenter_name] = 1
3535
else:
3636
datacenters[datacenter_name] += 1

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/count.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def cli(env, sortby, datacenter):
2929
service_resource = volume['serviceResource']
3030
if 'datacenter' in service_resource:
3131
datacenter_name = service_resource['datacenter']['name']
32-
if datacenter_name not in datacenters.keys():
32+
if datacenter_name not in datacenters.keys(): # pylint: disable=consider-iterating-dictionary
3333
datacenters[datacenter_name] = 1
3434
else:
3535
datacenters[datacenter_name] += 1

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): # pylint: disable=unused-argument,no-self-use
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
SoftLayer.tests.managers.storage_generic_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
:license: MIT, see LICENSE for more details.
6+
"""
7+
8+
import SoftLayer
9+
from SoftLayer import testing
10+
11+
12+
class StorageGenericTests(testing.TestCase):
13+
def set_up(self):
14+
self.storage = SoftLayer.managers.storage.StorageManager(self.client)
15+
16+
def test_get_volume_snapshot_notification_status(self):
17+
mock = self.set_mock('SoftLayer_Network_Storage', 'getSnapshotNotificationStatus')
18+
# These are the values we expect from the API as of 2021-12-01, FBLOCK4193
19+
mock.side_effect = [None, '1', '0']
20+
expected = [1, 1, 0]
21+
22+
for expect in expected:
23+
result = self.storage.get_volume_snapshot_notification_status(12345)
24+
self.assert_called_with('SoftLayer_Network_Storage', 'getSnapshotNotificationStatus', identifier=12345)
25+
self.assertEqual(expect, result)
26+
27+
def test_set_volume_snapshot_notification(self):
28+
mock = self.set_mock('SoftLayer_Network_Storage', 'setSnapshotNotification')
29+
mock.return_value = None
30+
31+
result = self.storage.set_volume_snapshot_notification(12345, False)
32+
self.assert_called_with('SoftLayer_Network_Storage', 'setSnapshotNotification',
33+
identifier=12345, args=(False,))
34+
self.assertEqual(None, result)

0 commit comments

Comments
 (0)