@@ -32,6 +32,8 @@ def __init__(self, **kwargs):
3232
3333 self .attachments = mock .Mock ()
3434 self .attachments .resource_class = fakes .FakeResource (None , {})
35+ self .clusters = mock .Mock ()
36+ self .clusters .resource_class = fakes .FakeResource (None , {})
3537 self .groups = mock .Mock ()
3638 self .groups .resource_class = fakes .FakeResource (None , {})
3739 self .group_snapshots = mock .Mock ()
@@ -70,6 +72,58 @@ def setUp(self):
7072FakeVolumeType = volume_v2_fakes .FakeVolumeType
7173
7274
75+ class FakeCluster :
76+ """Fake one or more clusters."""
77+
78+ @staticmethod
79+ def create_one_cluster (attrs = None ):
80+ """Create a fake service cluster.
81+
82+ :param attrs: A dictionary with all attributes of service cluster
83+ :return: A FakeResource object with id, name, status, etc.
84+ """
85+ attrs = attrs or {}
86+
87+ # Set default attribute
88+ cluster_info = {
89+ 'name' : f'cluster-{ uuid .uuid4 ().hex } ' ,
90+ 'binary' : f'binary-{ uuid .uuid4 ().hex } ' ,
91+ 'state' : random .choice (['up' , 'down' ]),
92+ 'status' : random .choice (['enabled' , 'disabled' ]),
93+ 'disabled_reason' : None ,
94+ 'num_hosts' : random .randint (1 , 64 ),
95+ 'num_down_hosts' : random .randint (1 , 64 ),
96+ 'last_heartbeat' : '2015-09-16T09:28:52.000000' ,
97+ 'created_at' : '2015-09-16T09:28:52.000000' ,
98+ 'updated_at' : '2015-09-16T09:28:52.000000' ,
99+ 'replication_status' : None ,
100+ 'frozen' : False ,
101+ 'active_backend_id' : None ,
102+ }
103+
104+ # Overwrite default attributes if there are some attributes set
105+ cluster_info .update (attrs )
106+
107+ return fakes .FakeResource (
108+ None ,
109+ cluster_info ,
110+ loaded = True )
111+
112+ @staticmethod
113+ def create_clusters (attrs = None , count = 2 ):
114+ """Create multiple fake service clusters.
115+
116+ :param attrs: A dictionary with all attributes of service cluster
117+ :param count: The number of service clusters to be faked
118+ :return: A list of FakeResource objects
119+ """
120+ clusters = []
121+ for n in range (0 , count ):
122+ clusters .append (FakeCluster .create_one_cluster (attrs ))
123+
124+ return clusters
125+
126+
73127class FakeVolumeGroup :
74128 """Fake one or more volume groups."""
75129
0 commit comments