Skip to content

Commit 965c61c

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add volume snapshot unmanage support"
2 parents e650c3e + 4e94c41 commit 965c61c

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

openstackclient/tests/unit/volume/v3/test_volume_snapshot.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
from osc_lib import utils
1818

1919
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
20+
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes_v3
2021
from openstackclient.volume.v3 import volume_snapshot
2122

2223

23-
class TestVolumeSnapshot(volume_fakes.TestVolume):
24+
class TestVolumeSnapshot(volume_fakes_v3.TestVolume):
2425
def setUp(self):
2526
super().setUp()
2627

2728
self.snapshots_mock = self.volume_client.volume_snapshots
2829
self.snapshots_mock.reset_mock()
2930

31+
self.volume_sdk_client.unmanage_snapshot.return_value = None
32+
3033

3134
class TestVolumeSnapshotDelete(TestVolumeSnapshot):
3235
snapshots = volume_fakes.create_snapshots(count=2)
@@ -111,3 +114,48 @@ def test_delete_multiple_snapshots_with_exception(self):
111114
self.snapshots_mock.delete.assert_called_once_with(
112115
self.snapshots[0].id, False
113116
)
117+
118+
def test_snapshot_delete_remote(self):
119+
arglist = ['--remote', self.snapshots[0].id]
120+
verifylist = [('remote', True), ("snapshots", [self.snapshots[0].id])]
121+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
122+
123+
result = self.cmd.take_action(parsed_args)
124+
125+
self.volume_sdk_client.unmanage_snapshot.assert_called_with(
126+
self.snapshots[0].id
127+
)
128+
self.assertIsNone(result)
129+
130+
def test_snapshot_delete_with_remote_force(self):
131+
arglist = ['--remote', '--force', self.snapshots[0].id]
132+
verifylist = [
133+
('remote', True),
134+
('force', True),
135+
("snapshots", [self.snapshots[0].id]),
136+
]
137+
138+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
139+
exc = self.assertRaises(
140+
exceptions.CommandError, self.cmd.take_action, parsed_args
141+
)
142+
self.assertIn(
143+
"The --force option is not supported with the --remote "
144+
"parameter.",
145+
str(exc),
146+
)
147+
148+
def test_delete_multiple_snapshots_remote(self):
149+
arglist = ['--remote']
150+
for s in self.snapshots:
151+
arglist.append(s.id)
152+
verifylist = [('remote', True), ('snapshots', arglist[1:])]
153+
154+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
155+
result = self.cmd.take_action(parsed_args)
156+
157+
calls = []
158+
for s in self.snapshots:
159+
calls.append(mock.call(s.id))
160+
self.volume_sdk_client.unmanage_snapshot.assert_has_calls(calls)
161+
self.assertIsNone(result)

openstackclient/volume/v3/volume_snapshot.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,41 @@ def get_parser(self, prog_name):
4444
"regardless of state (defaults to False)"
4545
),
4646
)
47+
parser.add_argument(
48+
'--remote',
49+
action='store_true',
50+
help=_(
51+
'Unmanage the snapshot, removing it from the Block Storage '
52+
'service management but not from the backend.'
53+
),
54+
)
4755
return parser
4856

4957
def take_action(self, parsed_args):
5058
volume_client = self.app.client_manager.volume
59+
volume_client_sdk = self.app.client_manager.sdk_connection.volume
60+
5161
result = 0
5262

63+
if parsed_args.remote:
64+
if parsed_args.force:
65+
msg = _(
66+
"The --force option is not supported with the "
67+
"--remote parameter."
68+
)
69+
raise exceptions.CommandError(msg)
70+
5371
for i in parsed_args.snapshots:
5472
try:
5573
snapshot_id = utils.find_resource(
5674
volume_client.volume_snapshots, i
5775
).id
58-
volume_client.volume_snapshots.delete(
59-
snapshot_id, parsed_args.force
60-
)
76+
if parsed_args.remote:
77+
volume_client_sdk.unmanage_snapshot(snapshot_id)
78+
else:
79+
volume_client.volume_snapshots.delete(
80+
snapshot_id, parsed_args.force
81+
)
6182
except Exception as e:
6283
result += 1
6384
LOG.error(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Added support for unmanaging snapshots with the
5+
``openstack snapshot delete --remote`` command.

0 commit comments

Comments
 (0)