summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwanghao <sxmatch1986@gmail.com>2018-06-19 11:52:36 +0800
committerwanghao <sxmatch1986@gmail.com>2018-06-20 09:09:54 +0800
commit83864a25e226df33cc2faccca1c77ed69b063b18 (patch)
tree664fd0e289597c252c2f51cbb982ffd3bd87e46f
parent36275be1c10c53ad5c7813f60331285726324abf (diff)
downloadpython-cinderclient-83864a25e226df33cc2faccca1c77ed69b063b18.tar.gz
unable to create group from src in cinderclient
According the api schema of cinder, create_group_from_src should only specify one of arguments from [group_snapshot_id, source_group_id]. Now cinderclient specified them both even if one of them is None. This patch fix this issue to just pass one argument. Change-Id: Idef51ab9a1452dd5eb3be4d4b6dca095a777d611 Closes-Bug: #1777555
-rw-r--r--cinderclient/tests/unit/v3/test_groups.py6
-rw-r--r--cinderclient/tests/unit/v3/test_shell.py9
-rw-r--r--cinderclient/v3/groups.py14
3 files changed, 20 insertions, 9 deletions
diff --git a/cinderclient/tests/unit/v3/test_groups.py b/cinderclient/tests/unit/v3/test_groups.py
index e776f0a..dec17d0 100644
--- a/cinderclient/tests/unit/v3/test_groups.py
+++ b/cinderclient/tests/unit/v3/test_groups.py
@@ -130,8 +130,7 @@ class GroupsTest(utils.TestCase):
'create-from-src': {
'description': None,
'name': 'group',
- 'group_snapshot_id': '5678',
- 'source_group_id': None
+ 'group_snapshot_id': '5678'
}
}
cs.assert_called('POST', '/groups/action',
@@ -145,8 +144,7 @@ class GroupsTest(utils.TestCase):
'create-from-src': {
'description': None,
'name': 'group',
- 'source_group_id': '5678',
- 'group_snapshot_id': None
+ 'source_group_id': '5678'
}
}
cs.assert_called('POST', '/groups/action',
diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py
index 651fd50..761994c 100644
--- a/cinderclient/tests/unit/v3/test_shell.py
+++ b/cinderclient/tests/unit/v3/test_shell.py
@@ -679,9 +679,12 @@ class ShellTest(utils.TestCase):
@ddt.unpack
def test_group_create_from_src(self, grp_snap_id, src_grp_id, src):
expected = {'create-from-src': {'name': 'test-1',
- 'description': 'test-1-desc',
- 'group_snapshot_id': grp_snap_id,
- 'source_group_id': src_grp_id}}
+ 'description': 'test-1-desc'}}
+ if grp_snap_id:
+ expected['create-from-src']['group_snapshot_id'] = grp_snap_id
+ elif src_grp_id:
+ expected['create-from-src']['source_group_id'] = src_grp_id
+
cmd = ('--os-volume-api-version 3.14 '
'group-create-from-src --name test-1 '
'--description test-1-desc ')
diff --git a/cinderclient/v3/groups.py b/cinderclient/v3/groups.py
index d15e98e..c042e28 100644
--- a/cinderclient/v3/groups.py
+++ b/cinderclient/v3/groups.py
@@ -111,10 +111,20 @@ class GroupManager(base.ManagerWithFind):
:param project_id: Project id derived from context
:rtype: A dictionary containing Group metadata
"""
+
+ # NOTE(wanghao): According the API schema in cinder side, client
+ # should NOT specify the group_snapshot_id and source_group_id at
+ # same time, even one of them is None.
+ if group_snapshot_id:
+ create_key = 'group_snapshot_id'
+ create_value = group_snapshot_id
+ elif source_group_id:
+ create_key = 'source_group_id'
+ create_value = source_group_id
+
body = {'create-from-src': {'name': name,
'description': description,
- 'group_snapshot_id': group_snapshot_id,
- 'source_group_id': source_group_id, }}
+ create_key: create_value}}
self.run_hooks('modify_body_for_action', body,
'create-from-src')