summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/volume
diff options
context:
space:
mode:
authorwhoami-rajat <rajatdhasmana@gmail.com>2022-11-22 19:25:39 +0530
committerwhoami-rajat <rajatdhasmana@gmail.com>2022-11-23 14:20:06 +0530
commit4710cbeca6638cc78880f2c4fc22d74aa7bb7c41 (patch)
tree5b7b4fa2d2758202a5c4f4824ed9e7c0dde3c059 /openstackclient/tests/unit/volume
parent96162c24eaba5ba70a6d8f61da815d2d6ffea7ed (diff)
downloadpython-openstackclient-4710cbeca6638cc78880f2c4fc22d74aa7bb7c41.tar.gz
Add test for creating volume from source
This patch adds a test to create a new volume from source. We also include code changes to pass the right size i.e. either size passed by the user via --size argument or the source volume size. This case is already handled at the API layer[1] but it helps being consistent with passing the right size value as in case of creating a volume from snapshot or backup. [1] https://github.com/openstack/cinder/blob/7c1a5ce7b11964da4537fd6a7d157ede646b9e94/cinder/api/v3/volumes.py#L381-L382 Change-Id: Idc71636dad6bb678fe24f19b0836d2e9bd92d7d2
Diffstat (limited to 'openstackclient/tests/unit/volume')
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py
index ef9c2fab..c930002f 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume.py
@@ -398,6 +398,43 @@ class TestVolumeCreate(TestVolume):
parsed_args)
self.assertIn("--os-volume-api-version 3.47 or greater", str(exc))
+ def test_volume_create_with_source_volume(self):
+ source_vol = "source_vol"
+ arglist = [
+ '--source', self.new_volume.id,
+ source_vol,
+ ]
+ verifylist = [
+ ('source', self.new_volume.id),
+ ('name', source_vol),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.volumes_mock.get.return_value = self.new_volume
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.volumes_mock.create.assert_called_once_with(
+ size=self.new_volume.size,
+ snapshot_id=None,
+ name=source_vol,
+ description=None,
+ volume_type=None,
+ availability_zone=None,
+ metadata=None,
+ imageRef=None,
+ source_volid=self.new_volume.id,
+ consistencygroup_id=None,
+ scheduler_hints=None,
+ backup_id=None,
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertCountEqual(self.datalist, data)
+
def test_volume_create_with_bootable_and_readonly(self):
arglist = [
'--bootable',