1818from openstack .block_storage .v3 import _proxy
1919from openstack .block_storage .v3 import availability_zone as _availability_zone
2020from openstack .block_storage .v3 import extension as _extension
21+ from openstack .block_storage .v3 import volume as _volume
2122
2223from openstackclient .tests .unit .compute .v2 import fakes as compute_fakes
2324from openstackclient .tests .unit import fakes
@@ -32,6 +33,8 @@ def __init__(self, **kwargs):
3233 self .management_url = kwargs ['endpoint' ]
3334 self .api_version = api_versions .APIVersion ('3.0' )
3435
36+ self .availability_zones = mock .Mock ()
37+ self .availability_zones .resource_class = fakes .FakeResource (None , {})
3538 self .attachments = mock .Mock ()
3639 self .attachments .resource_class = fakes .FakeResource (None , {})
3740 self .clusters = mock .Mock ()
@@ -44,10 +47,16 @@ def __init__(self, **kwargs):
4447 self .group_types .resource_class = fakes .FakeResource (None , {})
4548 self .messages = mock .Mock ()
4649 self .messages .resource_class = fakes .FakeResource (None , {})
50+ self .quota_classes = mock .Mock ()
51+ self .quota_classes .resource_class = fakes .FakeResource (None , {})
52+ self .quotas = mock .Mock ()
53+ self .quotas .resource_class = fakes .FakeResource (None , {})
4754 self .resource_filters = mock .Mock ()
4855 self .resource_filters .resource_class = fakes .FakeResource (None , {})
4956 self .volumes = mock .Mock ()
5057 self .volumes .resource_class = fakes .FakeResource (None , {})
58+ self .volume_snapshots = mock .Mock ()
59+ self .volume_snapshots .resource_class = fakes .FakeResource (None , {})
5160 self .volume_types = mock .Mock ()
5261 self .volume_types .resource_class = fakes .FakeResource (None , {})
5362 self .services = mock .Mock ()
@@ -56,7 +65,7 @@ def __init__(self, **kwargs):
5665 self .workers .resource_class = fakes .FakeResource (None , {})
5766
5867
59- class TestVolume ( utils . TestCommand ) :
68+ class FakeClientMixin :
6069 def setUp (self ):
6170 super ().setUp ()
6271
@@ -72,6 +81,11 @@ def setUp(self):
7281 )
7382 self .volume_sdk_client = self .app .client_manager .sdk_connection .volume
7483
84+
85+ class TestVolume (FakeClientMixin , utils .TestCommand ):
86+ def setUp (self ):
87+ super ().setUp ()
88+
7589 self .app .client_manager .identity = identity_fakes .FakeIdentityv3Client (
7690 endpoint = fakes .AUTH_URL , token = fakes .AUTH_TOKEN
7791 )
@@ -82,6 +96,7 @@ def setUp(self):
8296
8397
8498# TODO(stephenfin): Check if the responses are actually the same
99+ create_one_snapshot = volume_v2_fakes .create_one_snapshot
85100create_one_volume = volume_v2_fakes .create_one_volume
86101create_one_volume_type = volume_v2_fakes .create_one_volume_type
87102
@@ -243,6 +258,62 @@ def create_resource_filters(attrs=None, count=2):
243258 return resource_filters
244259
245260
261+ def create_one_sdk_volume (attrs = None ):
262+ """Create a fake volume.
263+
264+ :param dict attrs:
265+ A dictionary with all attributes of volume
266+ :return:
267+ A FakeResource object with id, name, status, etc.
268+ """
269+ attrs = attrs or {}
270+
271+ # Set default attribute
272+ volume_info = {
273+ 'id' : 'volume-id' + uuid .uuid4 ().hex ,
274+ 'name' : 'volume-name' + uuid .uuid4 ().hex ,
275+ 'description' : 'description' + uuid .uuid4 ().hex ,
276+ 'status' : random .choice (['available' , 'in_use' ]),
277+ 'size' : random .randint (1 , 20 ),
278+ 'volume_type' : random .choice (['fake_lvmdriver-1' , 'fake_lvmdriver-2' ]),
279+ 'bootable' : random .choice (['true' , 'false' ]),
280+ 'metadata' : {
281+ 'key' + uuid .uuid4 ().hex : 'val' + uuid .uuid4 ().hex ,
282+ 'key' + uuid .uuid4 ().hex : 'val' + uuid .uuid4 ().hex ,
283+ 'key' + uuid .uuid4 ().hex : 'val' + uuid .uuid4 ().hex ,
284+ },
285+ 'snapshot_id' : random .randint (1 , 5 ),
286+ 'availability_zone' : 'zone' + uuid .uuid4 ().hex ,
287+ 'attachments' : [
288+ {
289+ 'device' : '/dev/' + uuid .uuid4 ().hex ,
290+ 'server_id' : uuid .uuid4 ().hex ,
291+ },
292+ ],
293+ }
294+
295+ # Overwrite default attributes if there are some attributes set
296+ volume_info .update (attrs )
297+ return _volume .Volume (** volume_info )
298+
299+
300+ def create_sdk_volumes (attrs = None , count = 2 ):
301+ """Create multiple fake volumes.
302+
303+ :param dict attrs:
304+ A dictionary with all attributes of volume
305+ :param Integer count:
306+ The number of volumes to be faked
307+ :return:
308+ A list of FakeResource objects
309+ """
310+ volumes = []
311+ for n in range (0 , count ):
312+ volumes .append (create_one_sdk_volume (attrs ))
313+
314+ return volumes
315+
316+
246317def create_one_volume_group (attrs = None ):
247318 """Create a fake group.
248319
0 commit comments