Skip to content

Commit 92a1c85

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add test for creating volume from source"
2 parents 9481986 + 4710cbe commit 92a1c85

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,43 @@ def test_volume_create_with_backup_pre_347(self):
398398
parsed_args)
399399
self.assertIn("--os-volume-api-version 3.47 or greater", str(exc))
400400

401+
def test_volume_create_with_source_volume(self):
402+
source_vol = "source_vol"
403+
arglist = [
404+
'--source', self.new_volume.id,
405+
source_vol,
406+
]
407+
verifylist = [
408+
('source', self.new_volume.id),
409+
('name', source_vol),
410+
]
411+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
412+
413+
self.volumes_mock.get.return_value = self.new_volume
414+
415+
# In base command class ShowOne in cliff, abstract method take_action()
416+
# returns a two-part tuple with a tuple of column names and a tuple of
417+
# data to be shown.
418+
columns, data = self.cmd.take_action(parsed_args)
419+
420+
self.volumes_mock.create.assert_called_once_with(
421+
size=self.new_volume.size,
422+
snapshot_id=None,
423+
name=source_vol,
424+
description=None,
425+
volume_type=None,
426+
availability_zone=None,
427+
metadata=None,
428+
imageRef=None,
429+
source_volid=self.new_volume.id,
430+
consistencygroup_id=None,
431+
scheduler_hints=None,
432+
backup_id=None,
433+
)
434+
435+
self.assertEqual(self.columns, columns)
436+
self.assertCountEqual(self.datalist, data)
437+
401438
def test_volume_create_with_bootable_and_readonly(self):
402439
arglist = [
403440
'--bootable',

openstackclient/volume/v2/volume.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ def get_parser(self, prog_name):
183183

184184
def take_action(self, parsed_args):
185185
_check_size_arg(parsed_args)
186+
# size is validated in the above call to
187+
# _check_size_arg where we check that size
188+
# should be passed if we are not creating a
189+
# volume from snapshot, backup or source volume
190+
size = parsed_args.size
186191

187192
volume_client = self.app.client_manager.volume
188193
image_client = self.app.client_manager.image
@@ -195,9 +200,11 @@ def take_action(self, parsed_args):
195200

196201
source_volume = None
197202
if parsed_args.source:
198-
source_volume = utils.find_resource(
203+
source_volume_obj = utils.find_resource(
199204
volume_client.volumes,
200-
parsed_args.source).id
205+
parsed_args.source)
206+
source_volume = source_volume_obj.id
207+
size = max(size or 0, source_volume_obj.size)
201208

202209
consistency_group = None
203210
if parsed_args.consistency_group:
@@ -210,8 +217,6 @@ def take_action(self, parsed_args):
210217
image = image_client.find_image(parsed_args.image,
211218
ignore_missing=False).id
212219

213-
size = parsed_args.size
214-
215220
snapshot = None
216221
if parsed_args.snapshot:
217222
snapshot_obj = utils.find_resource(

0 commit comments

Comments
 (0)