Skip to content

Commit b18dcfc

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add "consistency-group-snapshot" option to consistency group create"
2 parents a9be7a6 + 3e9109b commit b18dcfc

3 files changed

Lines changed: 61 additions & 7 deletions

File tree

doc/source/command-objects/consistency-group.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Create new consistency group.
1313
.. code:: bash
1414
1515
os consistency group create
16-
--volume-type <volume-type> | --consistency-group-source <consistency-group>
16+
--volume-type <volume-type> | --consistency-group-source <consistency-group> | --consistency-group-snapshot <consistency-group-snapshot>
1717
[--description <description>]
1818
[--availability-zone <availability-zone>]
1919
[<name>]
@@ -26,6 +26,10 @@ Create new consistency group.
2626

2727
Existing consistency group (name or ID)
2828

29+
.. option:: --consistency-group-snapshot <consistency-group-snapshot>
30+
31+
Existing consistency group snapshot (name or ID)
32+
2933
.. option:: --description <description>
3034

3135
Description of this consistency group

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def setUp(self):
3232
self.app.client_manager.volume.consistencygroups)
3333
self.consistencygroups_mock.reset_mock()
3434

35+
self.cgsnapshots_mock = (
36+
self.app.client_manager.volume.cgsnapshots)
37+
self.cgsnapshots_mock.reset_mock()
38+
3539
self.types_mock = self.app.client_manager.volume.volume_types
3640
self.types_mock.reset_mock()
3741

@@ -41,6 +45,11 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
4145
volume_type = volume_fakes.FakeType.create_one_type()
4246
new_consistency_group = (
4347
volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
48+
consistency_group_snapshot = (
49+
volume_fakes.
50+
FakeConsistencyGroupSnapshot.
51+
create_one_consistency_group_snapshot()
52+
)
4453

4554
columns = (
4655
'availability_zone',
@@ -70,6 +79,8 @@ def setUp(self):
7079
self.consistencygroups_mock.get.return_value = (
7180
self.new_consistency_group)
7281
self.types_mock.get.return_value = self.volume_type
82+
self.cgsnapshots_mock.get.return_value = (
83+
self.consistency_group_snapshot)
7384

7485
# Get the command object to test
7586
self.cmd = consistency_group.CreateConsistencyGroup(self.app, None)
@@ -164,6 +175,34 @@ def test_consistency_group_create_from_source(self):
164175
self.assertEqual(self.columns, columns)
165176
self.assertEqual(self.data, data)
166177

178+
def test_consistency_group_create_from_snapshot(self):
179+
arglist = [
180+
'--consistency-group-snapshot', self.consistency_group_snapshot.id,
181+
'--description', self.new_consistency_group.description,
182+
self.new_consistency_group.name,
183+
]
184+
verifylist = [
185+
('consistency_group_snapshot', self.consistency_group_snapshot.id),
186+
('description', self.new_consistency_group.description),
187+
('name', self.new_consistency_group.name),
188+
]
189+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
190+
191+
columns, data = self.cmd.take_action(parsed_args)
192+
193+
self.types_mock.get.assert_not_called()
194+
self.cgsnapshots_mock.get.assert_called_once_with(
195+
self.consistency_group_snapshot.id)
196+
self.consistencygroups_mock.create_from_src.assert_called_with(
197+
self.consistency_group_snapshot.id,
198+
None,
199+
name=self.new_consistency_group.name,
200+
description=self.new_consistency_group.description,
201+
)
202+
203+
self.assertEqual(self.columns, columns)
204+
self.assertEqual(self.data, data)
205+
167206

168207
class TestConsistencyGroupDelete(TestConsistencyGroup):
169208

openstackclient/volume/v2/consistency_group.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ def get_parser(self, prog_name):
9494
metavar="<consistency-group>",
9595
help=_("Existing consistency group (name or ID)")
9696
)
97+
exclusive_group.add_argument(
98+
"--consistency-group-snapshot",
99+
metavar="<consistency-group-snapshot>",
100+
help=_("Existing consistency group snapshot (name or ID)")
101+
)
97102
parser.add_argument(
98103
"--description",
99104
metavar="<description>",
@@ -120,17 +125,23 @@ def take_action(self, parsed_args):
120125
description=parsed_args.description,
121126
availability_zone=parsed_args.availability_zone
122127
)
123-
elif parsed_args.consistency_group_source:
128+
else:
124129
if parsed_args.availability_zone:
125130
msg = _("'--availability-zone' option will not work "
126131
"if creating consistency group from source")
127132
LOG.warning(msg)
128-
consistency_group_id = utils.find_resource(
129-
volume_client.consistencygroups,
130-
parsed_args.consistency_group_source).id
133+
134+
consistency_group_id = None
131135
consistency_group_snapshot = None
132-
# TODO(Huanxuan Ao): Support for creating from consistency group
133-
# snapshot after adding "consistency_group_snapshot" resource
136+
if parsed_args.consistency_group_source:
137+
consistency_group_id = utils.find_resource(
138+
volume_client.consistencygroups,
139+
parsed_args.consistency_group_source).id
140+
elif parsed_args.consistency_group_snapshot:
141+
consistency_group_snapshot = utils.find_resource(
142+
volume_client.cgsnapshots,
143+
parsed_args.consistency_group_snapshot).id
144+
134145
consistency_group = (
135146
volume_client.consistencygroups.create_from_src(
136147
consistency_group_snapshot,

0 commit comments

Comments
 (0)