Skip to content

Commit 767ae79

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "volume: Add v3-specific consistency group module"
2 parents 423f203 + 0ce4928 commit 767ae79

4 files changed

Lines changed: 1222 additions & 7 deletions

File tree

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def __init__(self, **kwargs):
4646
self.availability_zones.resource_class = fakes.FakeResource(None, {})
4747
self.backups = mock.Mock()
4848
self.backups.resource_class = fakes.FakeResource(None, {})
49+
self.cgsnapshots = mock.Mock()
50+
self.cgsnapshots.resource_class = fakes.FakeResource(None, {})
4951
self.consistencygroups = mock.Mock()
5052
self.consistencygroups.resource_class = fakes.FakeResource(None, {})
5153
self.clusters = mock.Mock()
@@ -234,6 +236,99 @@ def create_consistency_groups(attrs=None, count=2):
234236
return consistency_groups
235237

236238

239+
def get_consistency_groups(consistency_groups=None, count=2):
240+
"""Note:
241+
242+
Get an iterable MagicMock object with a list of faked
243+
consistency_groups.
244+
245+
If consistency_groups list is provided, then initialize
246+
the Mock object with the list. Otherwise create one.
247+
248+
:param List consistency_groups:
249+
A list of FakeResource objects faking consistency_groups
250+
:param Integer count:
251+
The number of consistency_groups to be faked
252+
:return
253+
An iterable Mock object with side_effect set to a list of faked
254+
consistency_groups
255+
"""
256+
if consistency_groups is None:
257+
consistency_groups = create_consistency_groups(count)
258+
259+
return mock.Mock(side_effect=consistency_groups)
260+
261+
262+
def create_one_consistency_group_snapshot(attrs=None):
263+
"""Create a fake consistency group snapshot.
264+
265+
:param dict attrs:
266+
A dictionary with all attributes
267+
:return:
268+
A FakeResource object with id, name, description, etc.
269+
"""
270+
attrs = attrs or {}
271+
272+
# Set default attributes.
273+
consistency_group_snapshot_info = {
274+
"id": 'id-' + uuid.uuid4().hex,
275+
"name": 'backup-name-' + uuid.uuid4().hex,
276+
"description": 'description-' + uuid.uuid4().hex,
277+
"status": "error",
278+
"consistencygroup_id": 'consistency-group-id' + uuid.uuid4().hex,
279+
"created_at": 'time-' + uuid.uuid4().hex,
280+
}
281+
282+
# Overwrite default attributes.
283+
consistency_group_snapshot_info.update(attrs)
284+
285+
consistency_group_snapshot = fakes.FakeResource(
286+
info=copy.deepcopy(consistency_group_snapshot_info), loaded=True
287+
)
288+
return consistency_group_snapshot
289+
290+
291+
def create_consistency_group_snapshots(attrs=None, count=2):
292+
"""Create multiple fake consistency group snapshots.
293+
294+
:param dict attrs:
295+
A dictionary with all attributes
296+
:param int count:
297+
The number of consistency group snapshots to fake
298+
:return:
299+
A list of FakeResource objects faking the
300+
consistency group snapshots
301+
"""
302+
consistency_group_snapshots = []
303+
for i in range(0, count):
304+
consistency_group_snapshot = create_one_consistency_group_snapshot(
305+
attrs,
306+
)
307+
consistency_group_snapshots.append(consistency_group_snapshot)
308+
309+
return consistency_group_snapshots
310+
311+
312+
def get_consistency_group_snapshots(snapshots=None, count=2):
313+
"""Get an iterable MagicMock object with a list of faked cgsnapshots.
314+
315+
If consistenct group snapshots list is provided, then initialize
316+
the Mock object with the list. Otherwise create one.
317+
318+
:param List snapshots:
319+
A list of FakeResource objects faking consistency group snapshots
320+
:param Integer count:
321+
The number of consistency group snapshots to be faked
322+
:return
323+
An iterable Mock object with side_effect set to a list of faked
324+
consistency groups
325+
"""
326+
if snapshots is None:
327+
snapshots = create_consistency_group_snapshots(count)
328+
329+
return mock.Mock(side_effect=snapshots)
330+
331+
237332
def create_one_extension(attrs=None):
238333
"""Create a fake extension.
239334

0 commit comments

Comments
 (0)