Skip to content

Commit 896a167

Browse files
committed
Cinder: Adds a api mv 3.66 check for snapshot creation
Since api mv 3.66 the --force parameter is not requied for snapshot creation. In-use volumes snapshot can be taken by default without requiring the force flag. This is already handled in cinder side. fixed conflict master -> 2026.1: added import: from openstack import utils as sdk_utils Closes-Bug: #2089188 Change-Id: I452ad973c76fa7f039797e8ea02556bf9fe7315c Signed-off-by: Amit Uniyal <auniyal@redhat.com> (cherry picked from commit ede91ec) (cherry picked from commit 97d6641)
1 parent cc866e7 commit 896a167

3 files changed

Lines changed: 83 additions & 8 deletions

File tree

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,59 @@ def test_snapshot_create_with_remote_source(self):
180180
)
181181
self.volume_sdk_client.create_snapshot.assert_not_called()
182182

183+
def test_snapshot_create_pre_v366(self):
184+
self.set_volume_api_version('3.65')
185+
186+
arglist = ["--force", self.snapshot.name]
187+
verifylist = [("force", True), ("snapshot_name", self.snapshot.name)]
188+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
189+
190+
self.cmd.take_action(parsed_args)
191+
192+
# force parameter should be passed
193+
self.volume_sdk_client.create_snapshot.assert_called_with(
194+
volume_id=self.snapshot.volume_id,
195+
force=True,
196+
name=self.snapshot.name,
197+
description=None,
198+
metadata=None,
199+
)
200+
201+
def test_snapshot_create_v366_or_later(self):
202+
self.set_volume_api_version('3.66')
203+
204+
arglist = [self.snapshot.name]
205+
verifylist = [("force", False), ("snapshot_name", self.snapshot.name)]
206+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
207+
208+
self.cmd.take_action(parsed_args)
209+
210+
# force parameter should not be passed, for >=3.66
211+
self.volume_sdk_client.create_snapshot.assert_called_with(
212+
volume_id=self.snapshot.volume_id,
213+
name=self.snapshot.name,
214+
description=None,
215+
metadata=None,
216+
)
217+
218+
def test_snapshot_create_v366_or_later_with_force(self):
219+
"""--force should be ignored for microversion >= 3.66."""
220+
self.set_volume_api_version('3.66')
221+
222+
arglist = ["--force", self.snapshot.name]
223+
verifylist = [("force", True), ("snapshot_name", self.snapshot.name)]
224+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
225+
226+
self.cmd.take_action(parsed_args)
227+
228+
# passed but ignored
229+
self.volume_sdk_client.create_snapshot.assert_called_with(
230+
volume_id=self.snapshot.volume_id,
231+
name=self.snapshot.name,
232+
description=None,
233+
metadata=None,
234+
)
235+
183236

184237
class TestVolumeSnapshotDelete(volume_fakes.TestVolume):
185238
def setUp(self):

openstackclient/volume/v3/volume_snapshot.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from cliff import columns as cliff_columns
2222
from openstack.block_storage.v3 import snapshot as _snapshot
23+
from openstack import utils as sdk_utils
2324
from osc_lib.cli import format_columns
2425
from osc_lib.cli import parseractions
2526
from osc_lib.command import command
@@ -123,7 +124,9 @@ def get_parser(self, prog_name):
123124
action="store_true",
124125
default=False,
125126
help=_(
126-
"Create a snapshot attached to an instance. Default is False"
127+
"Allow snapshot of in-use (attached) volume. "
128+
"Only needed for microversions prior to 3.66; "
129+
"ignored for 3.66+"
127130
),
128131
)
129132
parser.add_argument(
@@ -176,13 +179,23 @@ def take_action(self, parsed_args):
176179
)
177180
else:
178181
# Create a new snapshot from scratch
179-
snapshot = volume_client.create_snapshot(
180-
volume_id=volume_id,
181-
force=parsed_args.force,
182-
name=parsed_args.snapshot_name,
183-
description=parsed_args.description,
184-
metadata=parsed_args.properties,
185-
)
182+
# only for microversion < 3.66, pass force parameter
183+
# for backward compatibility
184+
if not sdk_utils.supports_microversion(volume_client, '3.66'):
185+
snapshot = volume_client.create_snapshot(
186+
volume_id=volume_id,
187+
force=parsed_args.force,
188+
name=parsed_args.snapshot_name,
189+
description=parsed_args.description,
190+
metadata=parsed_args.properties,
191+
)
192+
else:
193+
snapshot = volume_client.create_snapshot(
194+
volume_id=volume_id,
195+
name=parsed_args.snapshot_name,
196+
description=parsed_args.description,
197+
metadata=parsed_args.properties,
198+
)
186199

187200
data = _format_snapshot(snapshot)
188201
return zip(*sorted(data.items()))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
fixes:
3+
- |
4+
Fix ``volume snapshot create`` to work with Cinder API microversion 3.66
5+
and later. Since version 3.66, the 'force' parameter is no longer
6+
needed for snapshot creation as in-use volumes can be snapshotted by
7+
default. The command now only passes the 'force' parameter for version
8+
prior to 3.66.
9+
[Bug `2089188 <https://bugs.launchpad.net/python-openstackclient/+bug/2089188>`_]

0 commit comments

Comments
 (0)