@@ -62,12 +62,18 @@ def __init__(self, **kwargs):
6262 self .resource_filters .resource_class = fakes .FakeResource (None , {})
6363 self .restores = mock .Mock ()
6464 self .restores .resource_class = fakes .FakeResource (None , {})
65- self .volumes = mock .Mock ()
66- self .volumes .resource_class = fakes .FakeResource (None , {})
65+ self .volume_encryption_types = mock .Mock ()
66+ self .volume_encryption_types .resource_class = fakes .FakeResource (
67+ None , {}
68+ )
6769 self .volume_snapshots = mock .Mock ()
6870 self .volume_snapshots .resource_class = fakes .FakeResource (None , {})
71+ self .volume_type_access = mock .Mock ()
72+ self .volume_type_access .resource_class = fakes .FakeResource (None , {})
6973 self .volume_types = mock .Mock ()
7074 self .volume_types .resource_class = fakes .FakeResource (None , {})
75+ self .volumes = mock .Mock ()
76+ self .volumes .resource_class = fakes .FakeResource (None , {})
7177 self .services = mock .Mock ()
7278 self .services .resource_class = fakes .FakeResource (None , {})
7379 self .workers = mock .Mock ()
@@ -118,7 +124,6 @@ def setUp(self):
118124
119125# TODO(stephenfin): Check if the responses are actually the same
120126create_one_snapshot = volume_v2_fakes .create_one_snapshot
121- create_one_volume_type = volume_v2_fakes .create_one_volume_type
122127
123128
124129def create_one_availability_zone (attrs = None ):
@@ -364,6 +369,34 @@ def create_clusters(attrs=None, count=2):
364369 return clusters
365370
366371
372+ def create_one_encryption_volume_type (attrs = None ):
373+ """Create a fake encryption volume type.
374+
375+ :param dict attrs:
376+ A dictionary with all attributes
377+ :return:
378+ A FakeResource object with volume_type_id etc.
379+ """
380+ attrs = attrs or {}
381+
382+ # Set default attributes.
383+ encryption_info = {
384+ "volume_type_id" : 'type-id-' + uuid .uuid4 ().hex ,
385+ 'provider' : 'LuksEncryptor' ,
386+ 'cipher' : None ,
387+ 'key_size' : None ,
388+ 'control_location' : 'front-end' ,
389+ }
390+
391+ # Overwrite default attributes.
392+ encryption_info .update (attrs )
393+
394+ encryption_type = fakes .FakeResource (
395+ info = copy .deepcopy (encryption_info ), loaded = True
396+ )
397+ return encryption_type
398+
399+
367400def create_one_resource_filter (attrs = None ):
368401 """Create a fake resource filter.
369402
@@ -405,6 +438,31 @@ def create_resource_filters(attrs=None, count=2):
405438 return resource_filters
406439
407440
441+ def create_one_type_access (attrs = None ):
442+ """Create a fake volume type access for project.
443+
444+ :param dict attrs:
445+ A dictionary with all attributes
446+ :return:
447+ A FakeResource object, with Volume_type_ID and Project_ID.
448+ """
449+ if attrs is None :
450+ attrs = {}
451+
452+ # Set default attributes.
453+ type_access_attrs = {
454+ 'volume_type_id' : 'volume-type-id-' + uuid .uuid4 ().hex ,
455+ 'project_id' : 'project-id-' + uuid .uuid4 ().hex ,
456+ }
457+
458+ # Overwrite default attributes.
459+ type_access_attrs .update (attrs )
460+
461+ type_access = fakes .FakeResource (None , type_access_attrs , loaded = True )
462+
463+ return type_access
464+
465+
408466def create_one_volume (attrs = None ):
409467 """Create a fake volume.
410468
@@ -821,6 +879,75 @@ def get_volume_attachments(attachments=None, count=2):
821879 return mock .Mock (side_effect = attachments )
822880
823881
882+ def create_one_volume_type (attrs = None , methods = None ):
883+ """Create a fake volume type.
884+
885+ :param dict attrs:
886+ A dictionary with all attributes
887+ :param dict methods:
888+ A dictionary with all methods
889+ :return:
890+ A FakeResource object with id, name, description, etc.
891+ """
892+ attrs = attrs or {}
893+ methods = methods or {}
894+
895+ # Set default attributes.
896+ volume_type_info = {
897+ "id" : 'type-id-' + uuid .uuid4 ().hex ,
898+ "name" : 'type-name-' + uuid .uuid4 ().hex ,
899+ "description" : 'type-description-' + uuid .uuid4 ().hex ,
900+ "extra_specs" : {"foo" : "bar" },
901+ "is_public" : True ,
902+ }
903+
904+ # Overwrite default attributes.
905+ volume_type_info .update (attrs )
906+
907+ volume_type = fakes .FakeResource (
908+ info = copy .deepcopy (volume_type_info ), methods = methods , loaded = True
909+ )
910+ return volume_type
911+
912+
913+ def create_volume_types (attrs = None , count = 2 ):
914+ """Create multiple fake volume_types.
915+
916+ :param dict attrs:
917+ A dictionary with all attributes
918+ :param int count:
919+ The number of types to fake
920+ :return:
921+ A list of FakeResource objects faking the types
922+ """
923+ volume_types = []
924+ for i in range (0 , count ):
925+ volume_type = create_one_volume_type (attrs )
926+ volume_types .append (volume_type )
927+
928+ return volume_types
929+
930+
931+ def get_volume_types (volume_types = None , count = 2 ):
932+ """Get an iterable MagicMock object with a list of faked volume types.
933+
934+ If volume_types list is provided, then initialize the Mock object with
935+ the list. Otherwise create one.
936+
937+ :param List volume_types:
938+ A list of FakeResource objects faking volume types
939+ :param Integer count:
940+ The number of volume types to be faked
941+ :return
942+ An iterable Mock object with side_effect set to a list of faked
943+ volume types
944+ """
945+ if volume_types is None :
946+ volume_types = create_volume_types (count )
947+
948+ return mock .Mock (side_effect = volume_types )
949+
950+
824951def create_service_log_level_entry (attrs = None ):
825952 service_log_level_info = {
826953 'host' : 'host_test' ,
0 commit comments