@@ -224,6 +224,8 @@ def __init__(self, **kwargs):
224224 self .quota_classes .resource_class = fakes .FakeResource (None , {})
225225 self .consistencygroups = mock .Mock ()
226226 self .consistencygroups .resource_class = fakes .FakeResource (None , {})
227+ self .cgsnapshots = mock .Mock ()
228+ self .cgsnapshots .resource_class = fakes .FakeResource (None , {})
227229 self .auth_token = kwargs ['token' ]
228230 self .management_url = kwargs ['endpoint' ]
229231
@@ -548,6 +550,82 @@ def create_consistency_groups(attrs=None, count=2):
548550 return consistency_groups
549551
550552
553+ class FakeConsistencyGroupSnapshot (object ):
554+ """Fake one or more consistency group snapshot."""
555+
556+ @staticmethod
557+ def create_one_consistency_group_snapshot (attrs = None ):
558+ """Create a fake consistency group snapshot.
559+
560+ :param Dictionary attrs:
561+ A dictionary with all attributes
562+ :return:
563+ A FakeResource object with id, name, description, etc.
564+ """
565+ attrs = attrs or {}
566+
567+ # Set default attributes.
568+ consistency_group_snapshot_info = {
569+ "id" : 'id-' + uuid .uuid4 ().hex ,
570+ "name" : 'backup-name-' + uuid .uuid4 ().hex ,
571+ "description" : 'description-' + uuid .uuid4 ().hex ,
572+ "status" : "error" ,
573+ "consistencygroup_id" : 'consistency-group-id' + uuid .uuid4 ().hex ,
574+ "created_at" : 'time-' + uuid .uuid4 ().hex ,
575+ }
576+
577+ # Overwrite default attributes.
578+ consistency_group_snapshot_info .update (attrs )
579+
580+ consistency_group_snapshot = fakes .FakeResource (
581+ info = copy .deepcopy (consistency_group_snapshot_info ),
582+ loaded = True )
583+ return consistency_group_snapshot
584+
585+ @staticmethod
586+ def create_consistency_group_snapshots (attrs = None , count = 2 ):
587+ """Create multiple fake consistency group snapshots.
588+
589+ :param Dictionary attrs:
590+ A dictionary with all attributes
591+ :param int count:
592+ The number of consistency group snapshots to fake
593+ :return:
594+ A list of FakeResource objects faking the
595+ consistency group snapshots
596+ """
597+ consistency_group_snapshots = []
598+ for i in range (0 , count ):
599+ consistency_group_snapshot = (
600+ FakeConsistencyGroupSnapshot .
601+ create_one_consistency_group_snapshot (attrs )
602+ )
603+ consistency_group_snapshots .append (consistency_group_snapshot )
604+
605+ return consistency_group_snapshots
606+
607+ @staticmethod
608+ def get_consistency_group_snapshots (snapshots = None , count = 2 ):
609+ """Get an iterable MagicMock object with a list of faked cgsnapshots.
610+
611+ If consistenct group snapshots list is provided, then initialize
612+ the Mock object with the list. Otherwise create one.
613+
614+ :param List snapshots:
615+ A list of FakeResource objects faking consistency group snapshots
616+ :param Integer count:
617+ The number of consistency group snapshots to be faked
618+ :return
619+ An iterable Mock object with side_effect set to a list of faked
620+ consistency groups
621+ """
622+ if snapshots is None :
623+ snapshots = (FakeConsistencyGroupSnapshot .
624+ create_consistency_group_snapshots (count ))
625+
626+ return mock .Mock (side_effect = snapshots )
627+
628+
551629class FakeExtension (object ):
552630 """Fake one or more extension."""
553631
0 commit comments