summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/volume/v2
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests/unit/volume/v2')
-rw-r--r--openstackclient/tests/unit/volume/v2/fakes.py2183
-rw-r--r--openstackclient/tests/unit/volume/v2/test_backup_record.py20
-rw-r--r--openstackclient/tests/unit/volume/v2/test_consistency_group.py74
-rw-r--r--openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py26
-rw-r--r--openstackclient/tests/unit/volume/v2/test_qos_specs.py26
-rw-r--r--openstackclient/tests/unit/volume/v2/test_service.py14
-rw-r--r--openstackclient/tests/unit/volume/v2/test_type.py94
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume.py170
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_backend.py8
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_backup.py112
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_host.py14
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_snapshot.py18
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py47
13 files changed, 1462 insertions, 1344 deletions
diff --git a/openstackclient/tests/unit/volume/v2/fakes.py b/openstackclient/tests/unit/volume/v2/fakes.py
index 96e381d3..a3ef142f 100644
--- a/openstackclient/tests/unit/volume/v2/fakes.py
+++ b/openstackclient/tests/unit/volume/v2/fakes.py
@@ -40,257 +40,7 @@ QUOTA = {
}
-class FakeTransfer(object):
- """Fake one or more Transfer."""
-
- @staticmethod
- def create_one_transfer(attrs=None):
- """Create a fake transfer.
-
- :param dict attrs:
- A dictionary with all attributes of Transfer Request
- :return:
- A FakeResource object with volume_id, name, id.
- """
- # Set default attribute
- transfer_info = {
- 'volume_id': 'volume-id-' + uuid.uuid4().hex,
- 'name': 'fake_transfer_name',
- 'id': 'id-' + uuid.uuid4().hex,
- 'links': 'links-' + uuid.uuid4().hex,
- }
-
- # Overwrite default attributes if there are some attributes set
- attrs = attrs or {}
-
- transfer_info.update(attrs)
-
- transfer = fakes.FakeResource(
- None,
- transfer_info,
- loaded=True)
-
- return transfer
-
- @staticmethod
- def create_transfers(attrs=None, count=2):
- """Create multiple fake transfers.
-
- :param dict attrs:
- A dictionary with all attributes of transfer
- :param Integer count:
- The number of transfers to be faked
- :return:
- A list of FakeResource objects
- """
- transfers = []
- for n in range(0, count):
- transfers.append(FakeTransfer.create_one_transfer(attrs))
-
- return transfers
-
- @staticmethod
- def get_transfers(transfers=None, count=2):
- """Get an iterable MagicMock object with a list of faked transfers.
-
- If transfers list is provided, then initialize the Mock object with the
- list. Otherwise create one.
-
- :param List transfers:
- A list of FakeResource objects faking transfers
- :param Integer count:
- The number of transfers to be faked
- :return
- An iterable Mock object with side_effect set to a list of faked
- transfers
- """
- if transfers is None:
- transfers = FakeTransfer.create_transfers(count)
-
- return mock.Mock(side_effect=transfers)
-
-
-class FakeTypeAccess(object):
- """Fake one or more volume type access."""
-
- @staticmethod
- def create_one_type_access(attrs=None):
- """Create a fake volume type access for project.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object, with Volume_type_ID and Project_ID.
- """
- if attrs is None:
- attrs = {}
-
- # Set default attributes.
- type_access_attrs = {
- 'volume_type_id': 'volume-type-id-' + uuid.uuid4().hex,
- 'project_id': 'project-id-' + uuid.uuid4().hex,
- }
-
- # Overwrite default attributes.
- type_access_attrs.update(attrs)
-
- type_access = fakes.FakeResource(
- None,
- type_access_attrs,
- loaded=True)
-
- return type_access
-
-
-class FakeService(object):
- """Fake one or more Services."""
-
- @staticmethod
- def create_one_service(attrs=None):
- """Create a fake service.
-
- :param dict attrs:
- A dictionary with all attributes of service
- :return:
- A FakeResource object with host, status, etc.
- """
- # Set default attribute
- service_info = {
- 'host': 'host_test',
- 'binary': 'cinder_test',
- 'status': 'enabled',
- 'disabled_reason': 'LongHoliday-GoldenWeek',
- 'zone': 'fake_zone',
- 'updated_at': 'fake_date',
- 'state': 'fake_state',
- }
-
- # Overwrite default attributes if there are some attributes set
- attrs = attrs or {}
-
- service_info.update(attrs)
-
- service = fakes.FakeResource(
- None,
- service_info,
- loaded=True)
-
- return service
-
- @staticmethod
- def create_services(attrs=None, count=2):
- """Create multiple fake services.
-
- :param dict attrs:
- A dictionary with all attributes of service
- :param Integer count:
- The number of services to be faked
- :return:
- A list of FakeResource objects
- """
- services = []
- for n in range(0, count):
- services.append(FakeService.create_one_service(attrs))
-
- return services
-
-
-class FakeCapability(object):
- """Fake capability."""
-
- @staticmethod
- def create_one_capability(attrs=None):
- """Create a fake volume backend capability.
-
- :param dict attrs:
- A dictionary with all attributes of the Capabilities.
- :return:
- A FakeResource object with capability name and attrs.
- """
- # Set default attribute
- capability_info = {
- "namespace": "OS::Storage::Capabilities::fake",
- "vendor_name": "OpenStack",
- "volume_backend_name": "lvmdriver-1",
- "pool_name": "pool",
- "driver_version": "2.0.0",
- "storage_protocol": "iSCSI",
- "display_name": "Capabilities of Cinder LVM driver",
- "description": "Blah, blah.",
- "visibility": "public",
- "replication_targets": [],
- "properties": {
- "compression": {
- "title": "Compression",
- "description": "Enables compression.",
- "type": "boolean"
- },
- "qos": {
- "title": "QoS",
- "description": "Enables QoS.",
- "type": "boolean"
- },
- "replication": {
- "title": "Replication",
- "description": "Enables replication.",
- "type": "boolean"
- },
- "thin_provisioning": {
- "title": "Thin Provisioning",
- "description": "Sets thin provisioning.",
- "type": "boolean"
- }
- }
- }
-
- # Overwrite default attributes if there are some attributes set
- capability_info.update(attrs or {})
-
- capability = fakes.FakeResource(
- None,
- capability_info,
- loaded=True)
-
- return capability
-
-
-class FakePool(object):
- """Fake Pools."""
-
- @staticmethod
- def create_one_pool(attrs=None):
- """Create a fake pool.
-
- :param dict attrs:
- A dictionary with all attributes of the pool
- :return:
- A FakeResource object with pool name and attrs.
- """
- # Set default attribute
- pool_info = {
- 'name': 'host@lvmdriver-1#lvmdriver-1',
- 'storage_protocol': 'iSCSI',
- 'thick_provisioning_support': False,
- 'thin_provisioning_support': True,
- 'total_volumes': 99,
- 'total_capacity_gb': 1000.00,
- 'allocated_capacity_gb': 100,
- 'max_over_subscription_ratio': 200.0,
- }
-
- # Overwrite default attributes if there are some attributes set
- pool_info.update(attrs or {})
-
- pool = fakes.FakeResource(
- None,
- pool_info,
- loaded=True)
-
- return pool
-
-
-class FakeVolumeClient(object):
-
+class FakeVolumeClient:
def __init__(self, **kwargs):
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
@@ -325,8 +75,9 @@ class FakeVolumeClient(object):
self.transfers = mock.Mock()
self.transfers.resource_class = fakes.FakeResource(None, {})
self.volume_encryption_types = mock.Mock()
- self.volume_encryption_types.resource_class = (
- fakes.FakeResource(None, {}))
+ self.volume_encryption_types.resource_class = fakes.FakeResource(
+ None, {}
+ )
self.volume_snapshots = mock.Mock()
self.volume_snapshots.resource_class = fakes.FakeResource(None, {})
self.volume_type_access = mock.Mock()
@@ -338,860 +89,1047 @@ class FakeVolumeClient(object):
class TestVolume(utils.TestCommand):
-
def setUp(self):
- super(TestVolume, self).setUp()
+ super().setUp()
self.app.client_manager.volume = FakeVolumeClient(
- endpoint=fakes.AUTH_URL,
- token=fakes.AUTH_TOKEN
+ endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN
)
self.app.client_manager.identity = identity_fakes.FakeIdentityv3Client(
- endpoint=fakes.AUTH_URL,
- token=fakes.AUTH_TOKEN
+ endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN
)
self.app.client_manager.image = image_fakes.FakeImagev2Client(
- endpoint=fakes.AUTH_URL,
- token=fakes.AUTH_TOKEN
+ endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN
)
-class FakeVolume(object):
- """Fake one or more volumes."""
-
- @staticmethod
- def create_one_volume(attrs=None):
- """Create a fake volume.
-
- :param dict attrs:
- A dictionary with all attributes of volume
- :return:
- A FakeResource object with id, name, status, etc.
- """
- attrs = attrs or {}
-
- # Set default attribute
- volume_info = {
- 'id': 'volume-id' + uuid.uuid4().hex,
- 'name': 'volume-name' + uuid.uuid4().hex,
- 'description': 'description' + uuid.uuid4().hex,
- 'status': random.choice(['available', 'in_use']),
- 'size': random.randint(1, 20),
- 'volume_type':
- random.choice(['fake_lvmdriver-1', 'fake_lvmdriver-2']),
- 'bootable':
- random.randint(0, 1),
- 'metadata': {
- 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
- 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
- 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex},
- 'snapshot_id': random.randint(1, 5),
- 'availability_zone': 'zone' + uuid.uuid4().hex,
- 'attachments': [{
- 'device': '/dev/' + uuid.uuid4().hex,
- 'server_id': uuid.uuid4().hex,
- }, ],
- }
+def create_one_transfer(attrs=None):
+ """Create a fake transfer.
- # Overwrite default attributes if there are some attributes set
- volume_info.update(attrs)
-
- volume = fakes.FakeResource(
- None,
- volume_info,
- loaded=True)
- return volume
-
- @staticmethod
- def create_volumes(attrs=None, count=2):
- """Create multiple fake volumes.
-
- :param dict attrs:
- A dictionary with all attributes of volume
- :param Integer count:
- The number of volumes to be faked
- :return:
- A list of FakeResource objects
- """
- volumes = []
- for n in range(0, count):
- volumes.append(FakeVolume.create_one_volume(attrs))
-
- return volumes
-
- @staticmethod
- def create_one_sdk_volume(attrs=None):
- """Create a fake volume.
-
- :param dict attrs:
- A dictionary with all attributes of volume
- :return:
- A FakeResource object with id, name, status, etc.
- """
- attrs = attrs or {}
-
- # Set default attribute
- volume_info = {
- 'id': 'volume-id' + uuid.uuid4().hex,
- 'name': 'volume-name' + uuid.uuid4().hex,
- 'description': 'description' + uuid.uuid4().hex,
- 'status': random.choice(['available', 'in_use']),
- 'size': random.randint(1, 20),
- 'volume_type':
- random.choice(['fake_lvmdriver-1', 'fake_lvmdriver-2']),
- 'bootable':
- random.choice(['true', 'false']),
- 'metadata': {
- 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
- 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
- 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex},
- 'snapshot_id': random.randint(1, 5),
- 'availability_zone': 'zone' + uuid.uuid4().hex,
- 'attachments': [{
- 'device': '/dev/' + uuid.uuid4().hex,
- 'server_id': uuid.uuid4().hex,
- }, ],
- }
+ :param dict attrs:
+ A dictionary with all attributes of Transfer Request
+ :return:
+ A FakeResource object with volume_id, name, id.
+ """
+ # Set default attribute
+ transfer_info = {
+ 'volume_id': 'volume-id-' + uuid.uuid4().hex,
+ 'name': 'fake_transfer_name',
+ 'id': 'id-' + uuid.uuid4().hex,
+ 'links': 'links-' + uuid.uuid4().hex,
+ }
- # Overwrite default attributes if there are some attributes set
- volume_info.update(attrs)
- return volume.Volume(**volume_info)
-
- @staticmethod
- def create_sdk_volumes(attrs=None, count=2):
- """Create multiple fake volumes.
-
- :param dict attrs:
- A dictionary with all attributes of volume
- :param Integer count:
- The number of volumes to be faked
- :return:
- A list of FakeResource objects
- """
- volumes = []
- for n in range(0, count):
- volumes.append(FakeVolume.create_one_sdk_volume(attrs))
-
- return volumes
-
- @staticmethod
- def get_volumes(volumes=None, count=2):
- """Get an iterable MagicMock object with a list of faked volumes.
-
- If volumes list is provided, then initialize the Mock object with the
- list. Otherwise create one.
-
- :param List volumes:
- A list of FakeResource objects faking volumes
- :param Integer count:
- The number of volumes to be faked
- :return
- An iterable Mock object with side_effect set to a list of faked
- volumes
- """
- if volumes is None:
- volumes = FakeVolume.create_volumes(count)
-
- return mock.Mock(side_effect=volumes)
-
- @staticmethod
- def get_volume_columns(volume=None):
- """Get the volume columns from a faked volume object.
-
- :param volume:
- A FakeResource objects faking volume
- :return
- A tuple which may include the following keys:
- ('id', 'name', 'description', 'status', 'size', 'volume_type',
- 'metadata', 'snapshot', 'availability_zone', 'attachments')
- """
- if volume is not None:
- return tuple(k for k in sorted(volume.keys()))
- return tuple([])
-
- @staticmethod
- def get_volume_data(volume=None):
- """Get the volume data from a faked volume object.
-
- :param volume:
- A FakeResource objects faking volume
- :return
- A tuple which may include the following values:
- ('ce26708d', 'fake_volume', 'fake description', 'available',
- 20, 'fake_lvmdriver-1', "Alpha='a', Beta='b', Gamma='g'",
- 1, 'nova', [{'device': '/dev/ice', 'server_id': '1233'}])
- """
- data_list = []
- if volume is not None:
- for x in sorted(volume.keys()):
- if x == 'tags':
- # The 'tags' should be format_list
- data_list.append(
- format_columns.ListColumn(volume.info.get(x)))
- else:
- data_list.append(volume.info.get(x))
- return tuple(data_list)
-
-
-class FakeAvailabilityZone(object):
- """Fake one or more volume availability zones (AZs)."""
-
- @staticmethod
- def create_one_availability_zone(attrs=None):
- """Create a fake AZ.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with zoneName, zoneState, etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- availability_zone = {
- 'zoneName': uuid.uuid4().hex,
- 'zoneState': {'available': True},
- }
+ # Overwrite default attributes if there are some attributes set
+ attrs = attrs or {}
- # Overwrite default attributes.
- availability_zone.update(attrs)
-
- availability_zone = fakes.FakeResource(
- info=copy.deepcopy(availability_zone),
- loaded=True)
- return availability_zone
-
- @staticmethod
- def create_availability_zones(attrs=None, count=2):
- """Create multiple fake AZs.
-
- :param dict attrs:
- A dictionary with all attributes
- :param int count:
- The number of AZs to fake
- :return:
- A list of FakeResource objects faking the AZs
- """
- availability_zones = []
- for i in range(0, count):
- availability_zone = \
- FakeAvailabilityZone.create_one_availability_zone(attrs)
- availability_zones.append(availability_zone)
-
- return availability_zones
-
-
-class FakeBackup(object):
- """Fake one or more backup."""
-
- @staticmethod
- def create_one_backup(attrs=None):
- """Create a fake backup.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with id, name, volume_id, etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- backup_info = {
- "id": 'backup-id-' + uuid.uuid4().hex,
- "name": 'backup-name-' + uuid.uuid4().hex,
- "volume_id": 'volume-id-' + uuid.uuid4().hex,
- "snapshot_id": 'snapshot-id' + uuid.uuid4().hex,
- "description": 'description-' + uuid.uuid4().hex,
- "object_count": None,
- "container": 'container-' + uuid.uuid4().hex,
- "size": random.randint(1, 20),
- "status": "error",
- "availability_zone": 'zone' + uuid.uuid4().hex,
- }
+ transfer_info.update(attrs)
- # Overwrite default attributes.
- backup_info.update(attrs)
-
- backup = fakes.FakeResource(
- info=copy.deepcopy(backup_info),
- loaded=True)
- return backup
-
- @staticmethod
- def create_backups(attrs=None, count=2):
- """Create multiple fake backups.
-
- :param dict attrs:
- A dictionary with all attributes
- :param int count:
- The number of backups to fake
- :return:
- A list of FakeResource objects faking the backups
- """
- backups = []
- for i in range(0, count):
- backup = FakeBackup.create_one_backup(attrs)
- backups.append(backup)
-
- return backups
-
- @staticmethod
- def get_backups(backups=None, count=2):
- """Get an iterable MagicMock object with a list of faked backups.
-
- If backups list is provided, then initialize the Mock object with the
- list. Otherwise create one.
-
- :param List backups:
- A list of FakeResource objects faking backups
- :param Integer count:
- The number of backups to be faked
- :return
- An iterable Mock object with side_effect set to a list of faked
- backups
- """
- if backups is None:
- backups = FakeBackup.create_backups(count)
-
- return mock.Mock(side_effect=backups)
-
- @staticmethod
- def create_backup_record():
- """Gets a fake backup record for a given backup.
-
- :return: An "exported" backup record.
- """
-
- return {
- 'backup_service': 'cinder.backup.drivers.swift.SwiftBackupDriver',
- 'backup_url': 'eyJzdGF0dXMiOiAiYXZh',
- }
-
- @staticmethod
- def import_backup_record():
- """Creates a fake backup record import response from a backup.
-
- :return: The fake backup object that was encoded.
- """
- return {
- 'backup': {
- 'id': 'backup.id',
- 'name': 'backup.name',
- 'links': [
- {'href': 'link1', 'rel': 'self'},
- {'href': 'link2', 'rel': 'bookmark'},
- ],
- },
- }
+ transfer = fakes.FakeResource(None, transfer_info, loaded=True)
+ return transfer
-class FakeConsistencyGroup(object):
- """Fake one or more consistency group."""
-
- @staticmethod
- def create_one_consistency_group(attrs=None):
- """Create a fake consistency group.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with id, name, description, etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- consistency_group_info = {
- "id": 'backup-id-' + uuid.uuid4().hex,
- "name": 'backup-name-' + uuid.uuid4().hex,
- "description": 'description-' + uuid.uuid4().hex,
- "status": "error",
- "availability_zone": 'zone' + uuid.uuid4().hex,
- "created_at": 'time-' + uuid.uuid4().hex,
- "volume_types": ['volume-type1'],
- }
-
- # Overwrite default attributes.
- consistency_group_info.update(attrs)
-
- consistency_group = fakes.FakeResource(
- info=copy.deepcopy(consistency_group_info),
- loaded=True)
- return consistency_group
-
- @staticmethod
- def create_consistency_groups(attrs=None, count=2):
- """Create multiple fake consistency groups.
-
- :param dict attrs:
- A dictionary with all attributes
- :param int count:
- The number of consistency groups to fake
- :return:
- A list of FakeResource objects faking the consistency groups
- """
- consistency_groups = []
- for i in range(0, count):
- consistency_group = (
- FakeConsistencyGroup.create_one_consistency_group(attrs))
- consistency_groups.append(consistency_group)
-
- return consistency_groups
-
- @staticmethod
- def get_consistency_groups(consistency_groups=None, count=2):
- """Note:
-
- Get an iterable MagicMock object with a list of faked
- consistency_groups.
-
- If consistency_groups list is provided, then initialize
- the Mock object with the list. Otherwise create one.
-
- :param List consistency_groups:
- A list of FakeResource objects faking consistency_groups
- :param Integer count:
- The number of consistency_groups to be faked
- :return
- An iterable Mock object with side_effect set to a list of faked
- consistency_groups
- """
- if consistency_groups is None:
- consistency_groups = (FakeConsistencyGroup.
- create_consistency_groups(count))
-
- return mock.Mock(side_effect=consistency_groups)
-
-
-class FakeConsistencyGroupSnapshot(object):
- """Fake one or more consistency group snapshot."""
-
- @staticmethod
- def create_one_consistency_group_snapshot(attrs=None):
- """Create a fake consistency group snapshot.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with id, name, description, etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- consistency_group_snapshot_info = {
- "id": 'id-' + uuid.uuid4().hex,
- "name": 'backup-name-' + uuid.uuid4().hex,
- "description": 'description-' + uuid.uuid4().hex,
- "status": "error",
- "consistencygroup_id": 'consistency-group-id' + uuid.uuid4().hex,
- "created_at": 'time-' + uuid.uuid4().hex,
- }
- # Overwrite default attributes.
- consistency_group_snapshot_info.update(attrs)
-
- consistency_group_snapshot = fakes.FakeResource(
- info=copy.deepcopy(consistency_group_snapshot_info),
- loaded=True)
- return consistency_group_snapshot
-
- @staticmethod
- def create_consistency_group_snapshots(attrs=None, count=2):
- """Create multiple fake consistency group snapshots.
-
- :param dict attrs:
- A dictionary with all attributes
- :param int count:
- The number of consistency group snapshots to fake
- :return:
- A list of FakeResource objects faking the
- consistency group snapshots
- """
- consistency_group_snapshots = []
- for i in range(0, count):
- consistency_group_snapshot = (
- FakeConsistencyGroupSnapshot.
- create_one_consistency_group_snapshot(attrs)
- )
- consistency_group_snapshots.append(consistency_group_snapshot)
-
- return consistency_group_snapshots
-
- @staticmethod
- def get_consistency_group_snapshots(snapshots=None, count=2):
- """Get an iterable MagicMock object with a list of faked cgsnapshots.
-
- If consistenct group snapshots list is provided, then initialize
- the Mock object with the list. Otherwise create one.
-
- :param List snapshots:
- A list of FakeResource objects faking consistency group snapshots
- :param Integer count:
- The number of consistency group snapshots to be faked
- :return
- An iterable Mock object with side_effect set to a list of faked
- consistency groups
- """
- if snapshots is None:
- snapshots = (FakeConsistencyGroupSnapshot.
- create_consistency_group_snapshots(count))
-
- return mock.Mock(side_effect=snapshots)
-
-
-class FakeExtension(object):
- """Fake one or more extension."""
-
- @staticmethod
- def create_one_extension(attrs=None):
- """Create a fake extension.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with name, namespace, etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- extension_info = {
- 'name': 'name-' + uuid.uuid4().hex,
- 'namespace': ('http://docs.openstack.org/'
- 'block-service/ext/scheduler-hints/api/v2'),
- 'description': 'description-' + uuid.uuid4().hex,
- 'updated': '2013-04-18T00:00:00+00:00',
- 'alias': 'OS-SCH-HNT',
- 'links': ('[{"href":'
- '"https://github.com/openstack/block-api", "type":'
- ' "text/html", "rel": "describedby"}]'),
- }
+def create_transfers(attrs=None, count=2):
+ """Create multiple fake transfers.
- # Overwrite default attributes.
- extension_info.update(attrs)
+ :param dict attrs:
+ A dictionary with all attributes of transfer
+ :param Integer count:
+ The number of transfers to be faked
+ :return:
+ A list of FakeResource objects
+ """
+ transfers = []
+ for n in range(0, count):
+ transfers.append(create_one_transfer(attrs))
- extension = fakes.FakeResource(
- info=copy.deepcopy(extension_info),
- loaded=True)
- return extension
+ return transfers
-class FakeQos(object):
- """Fake one or more Qos specification."""
+def get_transfers(transfers=None, count=2):
+ """Get an iterable MagicMock object with a list of faked transfers.
- @staticmethod
- def create_one_qos(attrs=None):
- """Create a fake Qos specification.
+ If transfers list is provided, then initialize the Mock object with the
+ list. Otherwise create one.
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with id, name, consumer, etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- qos_info = {
- "id": 'qos-id-' + uuid.uuid4().hex,
- "name": 'qos-name-' + uuid.uuid4().hex,
- "consumer": 'front-end',
- "specs": {"foo": "bar", "iops": "9001"},
- }
-
- # Overwrite default attributes.
- qos_info.update(attrs)
-
- qos = fakes.FakeResource(
- info=copy.deepcopy(qos_info),
- loaded=True)
- return qos
-
- @staticmethod
- def create_one_qos_association(attrs=None):
- """Create a fake Qos specification association.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with id, name, association_type, etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- qos_association_info = {
- "id": 'type-id-' + uuid.uuid4().hex,
- "name": 'type-name-' + uuid.uuid4().hex,
- "association_type": 'volume_type',
- }
-
- # Overwrite default attributes.
- qos_association_info.update(attrs)
-
- qos_association = fakes.FakeResource(
- info=copy.deepcopy(qos_association_info),
- loaded=True)
- return qos_association
-
- @staticmethod
- def create_qoses(attrs=None, count=2):
- """Create multiple fake Qos specifications.
-
- :param dict attrs:
- A dictionary with all attributes
- :param int count:
- The number of Qos specifications to fake
- :return:
- A list of FakeResource objects faking the Qos specifications
- """
- qoses = []
- for i in range(0, count):
- qos = FakeQos.create_one_qos(attrs)
- qoses.append(qos)
-
- return qoses
-
- @staticmethod
- def get_qoses(qoses=None, count=2):
- """Get an iterable MagicMock object with a list of faked qoses.
-
- If qoses list is provided, then initialize the Mock object with the
- list. Otherwise create one.
-
- :param List qoses:
- A list of FakeResource objects faking qoses
- :param Integer count:
- The number of qoses to be faked
- :return
- An iterable Mock object with side_effect set to a list of faked
- qoses
- """
- if qoses is None:
- qoses = FakeQos.create_qoses(count)
-
- return mock.Mock(side_effect=qoses)
-
-
-class FakeSnapshot(object):
- """Fake one or more snapshot."""
-
- @staticmethod
- def create_one_snapshot(attrs=None):
- """Create a fake snapshot.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with id, name, description, etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- snapshot_info = {
- "id": 'snapshot-id-' + uuid.uuid4().hex,
- "name": 'snapshot-name-' + uuid.uuid4().hex,
- "description": 'snapshot-description-' + uuid.uuid4().hex,
- "size": 10,
- "status": "available",
- "metadata": {"foo": "bar"},
- "created_at": "2015-06-03T18:49:19.000000",
- "volume_id": 'vloume-id-' + uuid.uuid4().hex,
- }
-
- # Overwrite default attributes.
- snapshot_info.update(attrs)
-
- snapshot = fakes.FakeResource(
- info=copy.deepcopy(snapshot_info),
- loaded=True)
- return snapshot
-
- @staticmethod
- def create_snapshots(attrs=None, count=2):
- """Create multiple fake snapshots.
-
- :param dict attrs:
- A dictionary with all attributes
- :param int count:
- The number of snapshots to fake
- :return:
- A list of FakeResource objects faking the snapshots
- """
- snapshots = []
- for i in range(0, count):
- snapshot = FakeSnapshot.create_one_snapshot(attrs)
- snapshots.append(snapshot)
-
- return snapshots
-
- @staticmethod
- def get_snapshots(snapshots=None, count=2):
- """Get an iterable MagicMock object with a list of faked snapshots.
-
- If snapshots list is provided, then initialize the Mock object with the
- list. Otherwise create one.
-
- :param List snapshots:
- A list of FakeResource objects faking snapshots
- :param Integer count:
- The number of snapshots to be faked
- :return
- An iterable Mock object with side_effect set to a list of faked
- snapshots
- """
- if snapshots is None:
- snapshots = FakeSnapshot.create_snapshots(count)
-
- return mock.Mock(side_effect=snapshots)
-
-
-class FakeVolumeType(object):
- """Fake one or more volume type."""
-
- @staticmethod
- def create_one_volume_type(attrs=None, methods=None):
- """Create a fake volume type.
-
- :param dict attrs:
- A dictionary with all attributes
- :param dict methods:
- A dictionary with all methods
- :return:
- A FakeResource object with id, name, description, etc.
- """
- attrs = attrs or {}
- methods = methods or {}
-
- # Set default attributes.
- volume_type_info = {
- "id": 'type-id-' + uuid.uuid4().hex,
- "name": 'type-name-' + uuid.uuid4().hex,
- "description": 'type-description-' + uuid.uuid4().hex,
- "extra_specs": {"foo": "bar"},
- "is_public": True,
- }
-
- # Overwrite default attributes.
- volume_type_info.update(attrs)
-
- volume_type = fakes.FakeResource(
- info=copy.deepcopy(volume_type_info),
- methods=methods,
- loaded=True)
- return volume_type
-
- @staticmethod
- def create_volume_types(attrs=None, count=2):
- """Create multiple fake volume_types.
-
- :param dict attrs:
- A dictionary with all attributes
- :param int count:
- The number of types to fake
- :return:
- A list of FakeResource objects faking the types
- """
- volume_types = []
- for i in range(0, count):
- volume_type = FakeVolumeType.create_one_volume_type(attrs)
- volume_types.append(volume_type)
-
- return volume_types
-
- @staticmethod
- def get_volume_types(volume_types=None, count=2):
- """Get an iterable MagicMock object with a list of faked volume types.
-
- If volume_types list is provided, then initialize the Mock object with
- the list. Otherwise create one.
-
- :param List volume_types:
- A list of FakeResource objects faking volume types
- :param Integer count:
- The number of volume types to be faked
- :return
- An iterable Mock object with side_effect set to a list of faked
- volume types
- """
- if volume_types is None:
- volume_types = FakeVolumeType.create_volume_types(count)
-
- return mock.Mock(side_effect=volume_types)
-
- @staticmethod
- def create_one_encryption_volume_type(attrs=None):
- """Create a fake encryption volume type.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object with volume_type_id etc.
- """
- attrs = attrs or {}
-
- # Set default attributes.
- encryption_info = {
- "volume_type_id": 'type-id-' + uuid.uuid4().hex,
- 'provider': 'LuksEncryptor',
- 'cipher': None,
- 'key_size': None,
- 'control_location': 'front-end',
- }
-
- # Overwrite default attributes.
- encryption_info.update(attrs)
-
- encryption_type = fakes.FakeResource(
- info=copy.deepcopy(encryption_info),
- loaded=True)
- return encryption_type
-
-
-class FakeQuota(object):
- """Fake quota"""
-
- @staticmethod
- def create_one_vol_quota(attrs=None):
- """Create one quota"""
- attrs = attrs or {}
-
- quota_attrs = {
- 'id': 'project-id-' + uuid.uuid4().hex,
- 'backups': 100,
- 'backup_gigabytes': 100,
- 'gigabytes': 10,
- 'per_volume_gigabytes': 10,
- 'snapshots': 0,
- 'volumes': 10}
-
- quota_attrs.update(attrs)
-
- quota = fakes.FakeResource(
- info=copy.deepcopy(quota_attrs),
- loaded=True)
- quota.project_id = quota_attrs['id']
-
- return quota
-
- @staticmethod
- def create_one_default_vol_quota(attrs=None):
- """Create one quota"""
- attrs = attrs or {}
-
- quota_attrs = {
- 'id': 'project-id-' + uuid.uuid4().hex,
- 'backups': 100,
- 'backup_gigabytes': 100,
- 'gigabytes': 100,
- 'per_volume_gigabytes': 100,
- 'snapshots': 100,
- 'volumes': 100}
+ :param List transfers:
+ A list of FakeResource objects faking transfers
+ :param Integer count:
+ The number of transfers to be faked
+ :return
+ An iterable Mock object with side_effect set to a list of faked
+ transfers
+ """
+ if transfers is None:
+ transfers = create_transfers(count)
+
+ return mock.Mock(side_effect=transfers)
+
+
+def create_one_type_access(attrs=None):
+ """Create a fake volume type access for project.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object, with Volume_type_ID and Project_ID.
+ """
+ if attrs is None:
+ attrs = {}
+
+ # Set default attributes.
+ type_access_attrs = {
+ 'volume_type_id': 'volume-type-id-' + uuid.uuid4().hex,
+ 'project_id': 'project-id-' + uuid.uuid4().hex,
+ }
+
+ # Overwrite default attributes.
+ type_access_attrs.update(attrs)
+
+ type_access = fakes.FakeResource(None, type_access_attrs, loaded=True)
+
+ return type_access
+
+
+def create_one_service(attrs=None):
+ """Create a fake service.
+
+ :param dict attrs:
+ A dictionary with all attributes of service
+ :return:
+ A FakeResource object with host, status, etc.
+ """
+ # Set default attribute
+ service_info = {
+ 'host': 'host_test',
+ 'binary': 'cinder_test',
+ 'status': 'enabled',
+ 'disabled_reason': 'LongHoliday-GoldenWeek',
+ 'zone': 'fake_zone',
+ 'updated_at': 'fake_date',
+ 'state': 'fake_state',
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ attrs = attrs or {}
+
+ service_info.update(attrs)
+
+ service = fakes.FakeResource(None, service_info, loaded=True)
+
+ return service
+
+
+def create_services(attrs=None, count=2):
+ """Create multiple fake services.
+
+ :param dict attrs:
+ A dictionary with all attributes of service
+ :param Integer count:
+ The number of services to be faked
+ :return:
+ A list of FakeResource objects
+ """
+ services = []
+ for n in range(0, count):
+ services.append(create_one_service(attrs))
+
+ return services
+
+
+def create_one_capability(attrs=None):
+ """Create a fake volume backend capability.
+
+ :param dict attrs:
+ A dictionary with all attributes of the Capabilities.
+ :return:
+ A FakeResource object with capability name and attrs.
+ """
+ # Set default attribute
+ capability_info = {
+ "namespace": "OS::Storage::Capabilities::fake",
+ "vendor_name": "OpenStack",
+ "volume_backend_name": "lvmdriver-1",
+ "pool_name": "pool",
+ "driver_version": "2.0.0",
+ "storage_protocol": "iSCSI",
+ "display_name": "Capabilities of Cinder LVM driver",
+ "description": "Blah, blah.",
+ "visibility": "public",
+ "replication_targets": [],
+ "properties": {
+ "compression": {
+ "title": "Compression",
+ "description": "Enables compression.",
+ "type": "boolean",
+ },
+ "qos": {
+ "title": "QoS",
+ "description": "Enables QoS.",
+ "type": "boolean",
+ },
+ "replication": {
+ "title": "Replication",
+ "description": "Enables replication.",
+ "type": "boolean",
+ },
+ "thin_provisioning": {
+ "title": "Thin Provisioning",
+ "description": "Sets thin provisioning.",
+ "type": "boolean",
+ },
+ },
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ capability_info.update(attrs or {})
+
+ capability = fakes.FakeResource(None, capability_info, loaded=True)
+
+ return capability
+
+
+def create_one_pool(attrs=None):
+ """Create a fake pool.
+
+ :param dict attrs:
+ A dictionary with all attributes of the pool
+ :return:
+ A FakeResource object with pool name and attrs.
+ """
+ # Set default attribute
+ pool_info = {
+ 'name': 'host@lvmdriver-1#lvmdriver-1',
+ 'storage_protocol': 'iSCSI',
+ 'thick_provisioning_support': False,
+ 'thin_provisioning_support': True,
+ 'total_volumes': 99,
+ 'total_capacity_gb': 1000.00,
+ 'allocated_capacity_gb': 100,
+ 'max_over_subscription_ratio': 200.0,
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ pool_info.update(attrs or {})
+
+ pool = fakes.FakeResource(None, pool_info, loaded=True)
+
+ return pool
+
+
+def create_one_volume(attrs=None):
+ """Create a fake volume.
+
+ :param dict attrs:
+ A dictionary with all attributes of volume
+ :return:
+ A FakeResource object with id, name, status, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ volume_info = {
+ 'id': 'volume-id' + uuid.uuid4().hex,
+ 'name': 'volume-name' + uuid.uuid4().hex,
+ 'description': 'description' + uuid.uuid4().hex,
+ 'status': random.choice(['available', 'in_use']),
+ 'size': random.randint(1, 20),
+ 'volume_type': random.choice(['fake_lvmdriver-1', 'fake_lvmdriver-2']),
+ 'bootable': random.randint(0, 1),
+ 'metadata': {
+ 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
+ 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
+ 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
+ },
+ 'snapshot_id': random.randint(1, 5),
+ 'availability_zone': 'zone' + uuid.uuid4().hex,
+ 'attachments': [
+ {
+ 'device': '/dev/' + uuid.uuid4().hex,
+ 'server_id': uuid.uuid4().hex,
+ },
+ ],
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ volume_info.update(attrs)
+
+ volume = fakes.FakeResource(None, volume_info, loaded=True)
+ return volume
+
+
+def create_volumes(attrs=None, count=2):
+ """Create multiple fake volumes.
+
+ :param dict attrs:
+ A dictionary with all attributes of volume
+ :param Integer count:
+ The number of volumes to be faked
+ :return:
+ A list of FakeResource objects
+ """
+ volumes = []
+ for n in range(0, count):
+ volumes.append(create_one_volume(attrs))
+
+ return volumes
+
+
+def create_one_sdk_volume(attrs=None):
+ """Create a fake volume.
+
+ :param dict attrs:
+ A dictionary with all attributes of volume
+ :return:
+ A FakeResource object with id, name, status, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ volume_info = {
+ 'id': 'volume-id' + uuid.uuid4().hex,
+ 'name': 'volume-name' + uuid.uuid4().hex,
+ 'description': 'description' + uuid.uuid4().hex,
+ 'status': random.choice(['available', 'in_use']),
+ 'size': random.randint(1, 20),
+ 'volume_type': random.choice(['fake_lvmdriver-1', 'fake_lvmdriver-2']),
+ 'bootable': random.choice(['true', 'false']),
+ 'metadata': {
+ 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
+ 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
+ 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
+ },
+ 'snapshot_id': random.randint(1, 5),
+ 'availability_zone': 'zone' + uuid.uuid4().hex,
+ 'attachments': [
+ {
+ 'device': '/dev/' + uuid.uuid4().hex,
+ 'server_id': uuid.uuid4().hex,
+ },
+ ],
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ volume_info.update(attrs)
+ return volume.Volume(**volume_info)
+
+
+def create_sdk_volumes(attrs=None, count=2):
+ """Create multiple fake volumes.
+
+ :param dict attrs:
+ A dictionary with all attributes of volume
+ :param Integer count:
+ The number of volumes to be faked
+ :return:
+ A list of FakeResource objects
+ """
+ volumes = []
+ for n in range(0, count):
+ volumes.append(create_one_sdk_volume(attrs))
+
+ return volumes
+
+
+def get_volumes(volumes=None, count=2):
+ """Get an iterable MagicMock object with a list of faked volumes.
+
+ If volumes list is provided, then initialize the Mock object with the
+ list. Otherwise create one.
+
+ :param List volumes:
+ A list of FakeResource objects faking volumes
+ :param Integer count:
+ The number of volumes to be faked
+ :return
+ An iterable Mock object with side_effect set to a list of faked
+ volumes
+ """
+ if volumes is None:
+ volumes = create_volumes(count)
+
+ return mock.Mock(side_effect=volumes)
+
+
+def get_volume_columns(volume=None):
+ """Get the volume columns from a faked volume object.
+
+ :param volume:
+ A FakeResource objects faking volume
+ :return
+ A tuple which may include the following keys:
+ ('id', 'name', 'description', 'status', 'size', 'volume_type',
+ 'metadata', 'snapshot', 'availability_zone', 'attachments')
+ """
+ if volume is not None:
+ return tuple(k for k in sorted(volume.keys()))
+ return tuple([])
+
+
+def get_volume_data(volume=None):
+ """Get the volume data from a faked volume object.
+
+ :param volume:
+ A FakeResource objects faking volume
+ :return
+ A tuple which may include the following values:
+ ('ce26708d', 'fake_volume', 'fake description', 'available',
+ 20, 'fake_lvmdriver-1', "Alpha='a', Beta='b', Gamma='g'",
+ 1, 'nova', [{'device': '/dev/ice', 'server_id': '1233'}])
+ """
+ data_list = []
+ if volume is not None:
+ for x in sorted(volume.keys()):
+ if x == 'tags':
+ # The 'tags' should be format_list
+ data_list.append(format_columns.ListColumn(volume.info.get(x)))
+ else:
+ data_list.append(volume.info.get(x))
+ return tuple(data_list)
+
+
+def create_one_availability_zone(attrs=None):
+ """Create a fake AZ.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with zoneName, zoneState, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ availability_zone = {
+ 'zoneName': uuid.uuid4().hex,
+ 'zoneState': {'available': True},
+ }
+
+ # Overwrite default attributes.
+ availability_zone.update(attrs)
+
+ availability_zone = fakes.FakeResource(
+ info=copy.deepcopy(availability_zone), loaded=True
+ )
+ return availability_zone
+
+
+def create_availability_zones(attrs=None, count=2):
+ """Create multiple fake AZs.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of AZs to fake
+ :return:
+ A list of FakeResource objects faking the AZs
+ """
+ availability_zones = []
+ for i in range(0, count):
+ availability_zone = create_one_availability_zone(attrs)
+ availability_zones.append(availability_zone)
+
+ return availability_zones
+
+
+def create_one_backup(attrs=None):
+ """Create a fake backup.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with id, name, volume_id, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ backup_info = {
+ "id": 'backup-id-' + uuid.uuid4().hex,
+ "name": 'backup-name-' + uuid.uuid4().hex,
+ "volume_id": 'volume-id-' + uuid.uuid4().hex,
+ "snapshot_id": 'snapshot-id' + uuid.uuid4().hex,
+ "description": 'description-' + uuid.uuid4().hex,
+ "object_count": None,
+ "container": 'container-' + uuid.uuid4().hex,
+ "size": random.randint(1, 20),
+ "status": "error",
+ "availability_zone": 'zone' + uuid.uuid4().hex,
+ }
+
+ # Overwrite default attributes.
+ backup_info.update(attrs)
+
+ backup = fakes.FakeResource(info=copy.deepcopy(backup_info), loaded=True)
+ return backup
+
+
+def create_backups(attrs=None, count=2):
+ """Create multiple fake backups.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of backups to fake
+ :return:
+ A list of FakeResource objects faking the backups
+ """
+ backups = []
+ for i in range(0, count):
+ backup = create_one_backup(attrs)
+ backups.append(backup)
+
+ return backups
+
+
+def get_backups(backups=None, count=2):
+ """Get an iterable MagicMock object with a list of faked backups.
+
+ If backups list is provided, then initialize the Mock object with the
+ list. Otherwise create one.
+
+ :param List backups:
+ A list of FakeResource objects faking backups
+ :param Integer count:
+ The number of backups to be faked
+ :return
+ An iterable Mock object with side_effect set to a list of faked
+ backups
+ """
+ if backups is None:
+ backups = create_backups(count)
+
+ return mock.Mock(side_effect=backups)
+
+
+def create_backup_record():
+ """Gets a fake backup record for a given backup.
+
+ :return: An "exported" backup record.
+ """
+
+ return {
+ 'backup_service': 'cinder.backup.drivers.swift.SwiftBackupDriver',
+ 'backup_url': 'eyJzdGF0dXMiOiAiYXZh',
+ }
+
+
+def import_backup_record():
+ """Creates a fake backup record import response from a backup.
+
+ :return: The fake backup object that was encoded.
+ """
+ return {
+ 'backup': {
+ 'id': 'backup.id',
+ 'name': 'backup.name',
+ 'links': [
+ {'href': 'link1', 'rel': 'self'},
+ {'href': 'link2', 'rel': 'bookmark'},
+ ],
+ },
+ }
+
+
+def create_one_consistency_group(attrs=None):
+ """Create a fake consistency group.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with id, name, description, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ consistency_group_info = {
+ "id": 'backup-id-' + uuid.uuid4().hex,
+ "name": 'backup-name-' + uuid.uuid4().hex,
+ "description": 'description-' + uuid.uuid4().hex,
+ "status": "error",
+ "availability_zone": 'zone' + uuid.uuid4().hex,
+ "created_at": 'time-' + uuid.uuid4().hex,
+ "volume_types": ['volume-type1'],
+ }
+
+ # Overwrite default attributes.
+ consistency_group_info.update(attrs)
+
+ consistency_group = fakes.FakeResource(
+ info=copy.deepcopy(consistency_group_info), loaded=True
+ )
+ return consistency_group
+
+
+def create_consistency_groups(attrs=None, count=2):
+ """Create multiple fake consistency groups.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of consistency groups to fake
+ :return:
+ A list of FakeResource objects faking the consistency groups
+ """
+ consistency_groups = []
+ for i in range(0, count):
+ consistency_group = create_one_consistency_group(attrs)
+ consistency_groups.append(consistency_group)
+
+ return consistency_groups
+
+
+def get_consistency_groups(consistency_groups=None, count=2):
+ """Note:
+
+ Get an iterable MagicMock object with a list of faked
+ consistency_groups.
+
+ If consistency_groups list is provided, then initialize
+ the Mock object with the list. Otherwise create one.
+
+ :param List consistency_groups:
+ A list of FakeResource objects faking consistency_groups
+ :param Integer count:
+ The number of consistency_groups to be faked
+ :return
+ An iterable Mock object with side_effect set to a list of faked
+ consistency_groups
+ """
+ if consistency_groups is None:
+ consistency_groups = create_consistency_groups(count)
+
+ return mock.Mock(side_effect=consistency_groups)
+
+
+def create_one_consistency_group_snapshot(attrs=None):
+ """Create a fake consistency group snapshot.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with id, name, description, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ consistency_group_snapshot_info = {
+ "id": 'id-' + uuid.uuid4().hex,
+ "name": 'backup-name-' + uuid.uuid4().hex,
+ "description": 'description-' + uuid.uuid4().hex,
+ "status": "error",
+ "consistencygroup_id": 'consistency-group-id' + uuid.uuid4().hex,
+ "created_at": 'time-' + uuid.uuid4().hex,
+ }
+
+ # Overwrite default attributes.
+ consistency_group_snapshot_info.update(attrs)
+
+ consistency_group_snapshot = fakes.FakeResource(
+ info=copy.deepcopy(consistency_group_snapshot_info), loaded=True
+ )
+ return consistency_group_snapshot
+
+
+def create_consistency_group_snapshots(attrs=None, count=2):
+ """Create multiple fake consistency group snapshots.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of consistency group snapshots to fake
+ :return:
+ A list of FakeResource objects faking the
+ consistency group snapshots
+ """
+ consistency_group_snapshots = []
+ for i in range(0, count):
+ consistency_group_snapshot = create_one_consistency_group_snapshot(
+ attrs,
+ )
+ consistency_group_snapshots.append(consistency_group_snapshot)
+
+ return consistency_group_snapshots
+
+
+def get_consistency_group_snapshots(snapshots=None, count=2):
+ """Get an iterable MagicMock object with a list of faked cgsnapshots.
+
+ If consistenct group snapshots list is provided, then initialize
+ the Mock object with the list. Otherwise create one.
+
+ :param List snapshots:
+ A list of FakeResource objects faking consistency group snapshots
+ :param Integer count:
+ The number of consistency group snapshots to be faked
+ :return
+ An iterable Mock object with side_effect set to a list of faked
+ consistency groups
+ """
+ if snapshots is None:
+ snapshots = create_consistency_group_snapshots(count)
+
+ return mock.Mock(side_effect=snapshots)
+
+
+def create_one_extension(attrs=None):
+ """Create a fake extension.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with name, namespace, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ extension_info = {
+ 'name': 'name-' + uuid.uuid4().hex,
+ 'namespace': (
+ 'http://docs.openstack.org/'
+ 'block-service/ext/scheduler-hints/api/v2'
+ ),
+ 'description': 'description-' + uuid.uuid4().hex,
+ 'updated': '2013-04-18T00:00:00+00:00',
+ 'alias': 'OS-SCH-HNT',
+ 'links': (
+ '[{"href":'
+ '"https://github.com/openstack/block-api", "type":'
+ ' "text/html", "rel": "describedby"}]'
+ ),
+ }
+
+ # Overwrite default attributes.
+ extension_info.update(attrs)
+
+ extension = fakes.FakeResource(
+ info=copy.deepcopy(extension_info), loaded=True
+ )
+ return extension
+
+
+def create_one_qos(attrs=None):
+ """Create a fake Qos specification.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with id, name, consumer, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ qos_info = {
+ "id": 'qos-id-' + uuid.uuid4().hex,
+ "name": 'qos-name-' + uuid.uuid4().hex,
+ "consumer": 'front-end',
+ "specs": {"foo": "bar", "iops": "9001"},
+ }
+
+ # Overwrite default attributes.
+ qos_info.update(attrs)
+
+ qos = fakes.FakeResource(info=copy.deepcopy(qos_info), loaded=True)
+ return qos
+
+
+def create_one_qos_association(attrs=None):
+ """Create a fake Qos specification association.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with id, name, association_type, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ qos_association_info = {
+ "id": 'type-id-' + uuid.uuid4().hex,
+ "name": 'type-name-' + uuid.uuid4().hex,
+ "association_type": 'volume_type',
+ }
+
+ # Overwrite default attributes.
+ qos_association_info.update(attrs)
+
+ qos_association = fakes.FakeResource(
+ info=copy.deepcopy(qos_association_info), loaded=True
+ )
+ return qos_association
+
+
+def create_qoses(attrs=None, count=2):
+ """Create multiple fake Qos specifications.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of Qos specifications to fake
+ :return:
+ A list of FakeResource objects faking the Qos specifications
+ """
+ qoses = []
+ for i in range(0, count):
+ qos = create_one_qos(attrs)
+ qoses.append(qos)
+
+ return qoses
+
+
+def get_qoses(qoses=None, count=2):
+ """Get an iterable MagicMock object with a list of faked qoses.
+
+ If qoses list is provided, then initialize the Mock object with the
+ list. Otherwise create one.
+
+ :param List qoses:
+ A list of FakeResource objects faking qoses
+ :param Integer count:
+ The number of qoses to be faked
+ :return
+ An iterable Mock object with side_effect set to a list of faked
+ qoses
+ """
+ if qoses is None:
+ qoses = create_qoses(count)
+
+ return mock.Mock(side_effect=qoses)
+
+
+def create_one_snapshot(attrs=None):
+ """Create a fake snapshot.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with id, name, description, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ snapshot_info = {
+ "id": 'snapshot-id-' + uuid.uuid4().hex,
+ "name": 'snapshot-name-' + uuid.uuid4().hex,
+ "description": 'snapshot-description-' + uuid.uuid4().hex,
+ "size": 10,
+ "status": "available",
+ "metadata": {"foo": "bar"},
+ "created_at": "2015-06-03T18:49:19.000000",
+ "volume_id": 'vloume-id-' + uuid.uuid4().hex,
+ }
+
+ # Overwrite default attributes.
+ snapshot_info.update(attrs)
+
+ snapshot = fakes.FakeResource(
+ info=copy.deepcopy(snapshot_info), loaded=True
+ )
+ return snapshot
+
+
+def create_snapshots(attrs=None, count=2):
+ """Create multiple fake snapshots.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of snapshots to fake
+ :return:
+ A list of FakeResource objects faking the snapshots
+ """
+ snapshots = []
+ for i in range(0, count):
+ snapshot = create_one_snapshot(attrs)
+ snapshots.append(snapshot)
+
+ return snapshots
+
+
+def get_snapshots(snapshots=None, count=2):
+ """Get an iterable MagicMock object with a list of faked snapshots.
+
+ If snapshots list is provided, then initialize the Mock object with the
+ list. Otherwise create one.
+
+ :param List snapshots:
+ A list of FakeResource objects faking snapshots
+ :param Integer count:
+ The number of snapshots to be faked
+ :return
+ An iterable Mock object with side_effect set to a list of faked
+ snapshots
+ """
+ if snapshots is None:
+ snapshots = create_snapshots(count)
+
+ return mock.Mock(side_effect=snapshots)
+
+
+def create_one_volume_type(attrs=None, methods=None):
+ """Create a fake volume type.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param dict methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object with id, name, description, etc.
+ """
+ attrs = attrs or {}
+ methods = methods or {}
+
+ # Set default attributes.
+ volume_type_info = {
+ "id": 'type-id-' + uuid.uuid4().hex,
+ "name": 'type-name-' + uuid.uuid4().hex,
+ "description": 'type-description-' + uuid.uuid4().hex,
+ "extra_specs": {"foo": "bar"},
+ "is_public": True,
+ }
+
+ # Overwrite default attributes.
+ volume_type_info.update(attrs)
+
+ volume_type = fakes.FakeResource(
+ info=copy.deepcopy(volume_type_info), methods=methods, loaded=True
+ )
+ return volume_type
+
+
+def create_volume_types(attrs=None, count=2):
+ """Create multiple fake volume_types.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of types to fake
+ :return:
+ A list of FakeResource objects faking the types
+ """
+ volume_types = []
+ for i in range(0, count):
+ volume_type = create_one_volume_type(attrs)
+ volume_types.append(volume_type)
+
+ return volume_types
+
+
+def get_volume_types(volume_types=None, count=2):
+ """Get an iterable MagicMock object with a list of faked volume types.
+
+ If volume_types list is provided, then initialize the Mock object with
+ the list. Otherwise create one.
+
+ :param List volume_types:
+ A list of FakeResource objects faking volume types
+ :param Integer count:
+ The number of volume types to be faked
+ :return
+ An iterable Mock object with side_effect set to a list of faked
+ volume types
+ """
+ if volume_types is None:
+ volume_types = create_volume_types(count)
+
+ return mock.Mock(side_effect=volume_types)
+
+
+def create_one_encryption_volume_type(attrs=None):
+ """Create a fake encryption volume type.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with volume_type_id etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ encryption_info = {
+ "volume_type_id": 'type-id-' + uuid.uuid4().hex,
+ 'provider': 'LuksEncryptor',
+ 'cipher': None,
+ 'key_size': None,
+ 'control_location': 'front-end',
+ }
+
+ # Overwrite default attributes.
+ encryption_info.update(attrs)
+
+ encryption_type = fakes.FakeResource(
+ info=copy.deepcopy(encryption_info), loaded=True
+ )
+ return encryption_type
+
+
+def create_one_vol_quota(attrs=None):
+ """Create one quota"""
+ attrs = attrs or {}
+
+ quota_attrs = {
+ 'id': 'project-id-' + uuid.uuid4().hex,
+ 'backups': 100,
+ 'backup_gigabytes': 100,
+ 'gigabytes': 10,
+ 'per_volume_gigabytes': 10,
+ 'snapshots': 0,
+ 'volumes': 10,
+ }
+
+ quota_attrs.update(attrs)
+
+ quota = fakes.FakeResource(info=copy.deepcopy(quota_attrs), loaded=True)
+ quota.project_id = quota_attrs['id']
+
+ return quota
+
+
+def create_one_default_vol_quota(attrs=None):
+ """Create one quota"""
+ attrs = attrs or {}
+
+ quota_attrs = {
+ 'id': 'project-id-' + uuid.uuid4().hex,
+ 'backups': 100,
+ 'backup_gigabytes': 100,
+ 'gigabytes': 100,
+ 'per_volume_gigabytes': 100,
+ 'snapshots': 100,
+ 'volumes': 100,
+ }
+
+ quota_attrs.update(attrs)
+
+ quota = fakes.FakeResource(info=copy.deepcopy(quota_attrs), loaded=True)
+ quota.project_id = quota_attrs['id']
+
+ return quota
+
+
+def create_one_detailed_quota(attrs=None):
+ """Create one quota"""
+ attrs = attrs or {}
- quota_attrs.update(attrs)
+ quota_attrs = {
+ 'volumes': {'limit': 3, 'in_use': 1, 'reserved': 0},
+ 'per_volume_gigabytes': {'limit': -1, 'in_use': 0, 'reserved': 0},
+ 'snapshots': {'limit': 10, 'in_use': 0, 'reserved': 0},
+ 'gigabytes': {'limit': 1000, 'in_use': 5, 'reserved': 0},
+ 'backups': {'limit': 10, 'in_use': 0, 'reserved': 0},
+ 'backup_gigabytes': {'limit': 1000, 'in_use': 0, 'reserved': 0},
+ 'volumes_lvmdriver-1': {'limit': -1, 'in_use': 1, 'reserved': 0},
+ 'gigabytes_lvmdriver-1': {'limit': -1, 'in_use': 5, 'reserved': 0},
+ 'snapshots_lvmdriver-1': {'limit': -1, 'in_use': 0, 'reserved': 0},
+ 'volumes___DEFAULT__': {'limit': -1, 'in_use': 0, 'reserved': 0},
+ 'gigabytes___DEFAULT__': {'limit': -1, 'in_use': 0, 'reserved': 0},
+ 'snapshots___DEFAULT__': {'limit': -1, 'in_use': 0, 'reserved': 0},
+ 'groups': {'limit': 10, 'in_use': 0, 'reserved': 0},
+ 'id': uuid.uuid4().hex,
+ }
+ quota_attrs.update(attrs)
- quota = fakes.FakeResource(
- info=copy.deepcopy(quota_attrs),
- loaded=True)
- quota.project_id = quota_attrs['id']
+ quota = fakes.FakeResource(info=copy.deepcopy(quota_attrs), loaded=True)
- return quota
+ return quota
class FakeLimits(object):
@@ -1208,37 +1146,39 @@ class FakeLimits(object):
'maxTotalVolumes': 10,
'totalVolumesUsed': 4,
'totalBackupsUsed': 0,
- 'totalGigabytesUsed': 35
+ 'totalGigabytesUsed': 35,
}
absolute_attrs = absolute_attrs or {}
self.absolute_limits_attrs.update(absolute_attrs)
- self.rate_limits_attrs = [{
- "uri": "*",
- "limit": [
- {
- "value": 10,
- "verb": "POST",
- "remaining": 2,
- "unit": "MINUTE",
- "next-available": "2011-12-15T22:42:45Z"
- },
- {
- "value": 10,
- "verb": "PUT",
- "remaining": 2,
- "unit": "MINUTE",
- "next-available": "2011-12-15T22:42:45Z"
- },
- {
- "value": 100,
- "verb": "DELETE",
- "remaining": 100,
- "unit": "MINUTE",
- "next-available": "2011-12-15T22:42:45Z"
- }
- ]
- }]
+ self.rate_limits_attrs = [
+ {
+ "uri": "*",
+ "limit": [
+ {
+ "value": 10,
+ "verb": "POST",
+ "remaining": 2,
+ "unit": "MINUTE",
+ "next-available": "2011-12-15T22:42:45Z",
+ },
+ {
+ "value": 10,
+ "verb": "PUT",
+ "remaining": 2,
+ "unit": "MINUTE",
+ "next-available": "2011-12-15T22:42:45Z",
+ },
+ {
+ "value": 100,
+ "verb": "DELETE",
+ "remaining": 100,
+ "unit": "MINUTE",
+ "next-available": "2011-12-15T22:42:45Z",
+ },
+ ],
+ }
+ ]
@property
def absolute(self):
@@ -1256,18 +1196,30 @@ class FakeLimits(object):
for group in self.rate_limits_attrs:
uri = group['uri']
for rate in group['limit']:
- yield FakeRateLimit(rate['verb'], uri, rate['value'],
- rate['remaining'], rate['unit'],
- rate['next-available'])
+ yield FakeRateLimit(
+ rate['verb'],
+ uri,
+ rate['value'],
+ rate['remaining'],
+ rate['unit'],
+ rate['next-available'],
+ )
def rate_limits(self):
reference_data = []
for group in self.rate_limits_attrs:
uri = group['uri']
for rate in group['limit']:
- reference_data.append((rate['verb'], uri, rate['value'],
- rate['remaining'], rate['unit'],
- rate['next-available']))
+ reference_data.append(
+ (
+ rate['verb'],
+ uri,
+ rate['value'],
+ rate['remaining'],
+ rate['unit'],
+ rate['next-available'],
+ )
+ )
return reference_data
@@ -1282,8 +1234,7 @@ class FakeAbsoluteLimit(object):
class FakeRateLimit(object):
"""Data model that represents a flattened view of a single rate limit."""
- def __init__(self, verb, uri, value, remain,
- unit, next_available):
+ def __init__(self, verb, uri, value, remain, unit, next_available):
self.verb = verb
self.uri = uri
self.value = value
diff --git a/openstackclient/tests/unit/volume/v2/test_backup_record.py b/openstackclient/tests/unit/volume/v2/test_backup_record.py
index 0e24174c..aa9a25a2 100644
--- a/openstackclient/tests/unit/volume/v2/test_backup_record.py
+++ b/openstackclient/tests/unit/volume/v2/test_backup_record.py
@@ -19,7 +19,7 @@ from openstackclient.volume.v2 import backup_record
class TestBackupRecord(volume_fakes.TestVolume):
def setUp(self):
- super(TestBackupRecord, self).setUp()
+ super().setUp()
self.backups_mock = self.app.client_manager.volume.backups
self.backups_mock.reset_mock()
@@ -27,12 +27,13 @@ class TestBackupRecord(volume_fakes.TestVolume):
class TestBackupRecordExport(TestBackupRecord):
- new_backup = volume_fakes.FakeBackup.create_one_backup(
- attrs={'volume_id': 'a54708a2-0388-4476-a909-09579f885c25'})
- new_record = volume_fakes.FakeBackup.create_backup_record()
+ new_backup = volume_fakes.create_one_backup(
+ attrs={'volume_id': 'a54708a2-0388-4476-a909-09579f885c25'},
+ )
+ new_record = volume_fakes.create_backup_record()
def setUp(self):
- super(TestBackupRecordExport, self).setUp()
+ super().setUp()
self.backups_mock.export_record.return_value = self.new_record
self.backups_mock.get.return_value = self.new_backup
@@ -81,12 +82,13 @@ class TestBackupRecordExport(TestBackupRecord):
class TestBackupRecordImport(TestBackupRecord):
- new_backup = volume_fakes.FakeBackup.create_one_backup(
- attrs={'volume_id': 'a54708a2-0388-4476-a909-09579f885c25'})
- new_import = volume_fakes.FakeBackup.import_backup_record()
+ new_backup = volume_fakes.create_one_backup(
+ attrs={'volume_id': 'a54708a2-0388-4476-a909-09579f885c25'},
+ )
+ new_import = volume_fakes.import_backup_record()
def setUp(self):
- super(TestBackupRecordImport, self).setUp()
+ super().setUp()
self.backups_mock.import_record.return_value = self.new_import
diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group.py b/openstackclient/tests/unit/volume/v2/test_consistency_group.py
index 434d0cf9..c5537ed8 100644
--- a/openstackclient/tests/unit/volume/v2/test_consistency_group.py
+++ b/openstackclient/tests/unit/volume/v2/test_consistency_group.py
@@ -26,7 +26,7 @@ from openstackclient.volume.v2 import consistency_group
class TestConsistencyGroup(volume_fakes.TestVolume):
def setUp(self):
- super(TestConsistencyGroup, self).setUp()
+ super().setUp()
# Get a shortcut to the TransferManager Mock
self.consistencygroups_mock = (
@@ -47,11 +47,10 @@ class TestConsistencyGroup(volume_fakes.TestVolume):
class TestConsistencyGroupAddVolume(TestConsistencyGroup):
- _consistency_group = (
- volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
+ _consistency_group = volume_fakes.create_one_consistency_group()
def setUp(self):
- super(TestConsistencyGroupAddVolume, self).setUp()
+ super().setUp()
self.consistencygroups_mock.get.return_value = (
self._consistency_group)
@@ -60,7 +59,7 @@ class TestConsistencyGroupAddVolume(TestConsistencyGroup):
consistency_group.AddVolumeToConsistencyGroup(self.app, None)
def test_add_one_volume_to_consistency_group(self):
- volume = volume_fakes.FakeVolume.create_one_volume()
+ volume = volume_fakes.create_one_volume()
self.volumes_mock.get.return_value = volume
arglist = [
self._consistency_group.id,
@@ -85,8 +84,8 @@ class TestConsistencyGroupAddVolume(TestConsistencyGroup):
self.assertIsNone(result)
def test_add_multiple_volumes_to_consistency_group(self):
- volumes = volume_fakes.FakeVolume.create_volumes(count=2)
- self.volumes_mock.get = volume_fakes.FakeVolume.get_volumes(volumes)
+ volumes = volume_fakes.create_volumes(count=2)
+ self.volumes_mock.get = volume_fakes.get_volumes(volumes)
arglist = [
self._consistency_group.id,
volumes[0].id,
@@ -112,8 +111,9 @@ class TestConsistencyGroupAddVolume(TestConsistencyGroup):
@mock.patch.object(consistency_group.LOG, 'error')
def test_add_multiple_volumes_to_consistency_group_with_exception(
- self, mock_error):
- volume = volume_fakes.FakeVolume.create_one_volume()
+ self, mock_error,
+ ):
+ volume = volume_fakes.create_one_volume()
arglist = [
self._consistency_group.id,
volume.id,
@@ -148,13 +148,10 @@ class TestConsistencyGroupAddVolume(TestConsistencyGroup):
class TestConsistencyGroupCreate(TestConsistencyGroup):
- volume_type = volume_fakes.FakeVolumeType.create_one_volume_type()
- new_consistency_group = (
- volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
+ volume_type = volume_fakes.create_one_volume_type()
+ new_consistency_group = volume_fakes.create_one_consistency_group()
consistency_group_snapshot = (
- volume_fakes.
- FakeConsistencyGroupSnapshot.
- create_one_consistency_group_snapshot()
+ volume_fakes.create_one_consistency_group_snapshot()
)
columns = (
@@ -177,7 +174,7 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
)
def setUp(self):
- super(TestConsistencyGroupCreate, self).setUp()
+ super().setUp()
self.consistencygroups_mock.create.return_value = (
self.new_consistency_group)
self.consistencygroups_mock.create_from_src.return_value = (
@@ -260,7 +257,7 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
self.new_consistency_group.name,
]
verifylist = [
- ('consistency_group_source', self.new_consistency_group.id),
+ ('source', self.new_consistency_group.id),
('description', self.new_consistency_group.description),
('name', self.new_consistency_group.name),
]
@@ -288,7 +285,7 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
self.new_consistency_group.name,
]
verifylist = [
- ('consistency_group_snapshot', self.consistency_group_snapshot.id),
+ ('snapshot', self.consistency_group_snapshot.id),
('description', self.new_consistency_group.description),
('name', self.new_consistency_group.name),
]
@@ -313,13 +310,14 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
class TestConsistencyGroupDelete(TestConsistencyGroup):
consistency_groups =\
- volume_fakes.FakeConsistencyGroup.create_consistency_groups(count=2)
+ volume_fakes.create_consistency_groups(count=2)
def setUp(self):
- super(TestConsistencyGroupDelete, self).setUp()
+ super().setUp()
- self.consistencygroups_mock.get = volume_fakes.FakeConsistencyGroup.\
- get_consistency_groups(self.consistency_groups)
+ self.consistencygroups_mock.get = volume_fakes.get_consistency_groups(
+ self.consistency_groups,
+ )
self.consistencygroups_mock.delete.return_value = None
# Get the command object to mock
@@ -409,8 +407,7 @@ class TestConsistencyGroupDelete(TestConsistencyGroup):
class TestConsistencyGroupList(TestConsistencyGroup):
- consistency_groups = (
- volume_fakes.FakeConsistencyGroup.create_consistency_groups(count=2))
+ consistency_groups = volume_fakes.create_consistency_groups(count=2)
columns = [
'ID',
@@ -444,7 +441,7 @@ class TestConsistencyGroupList(TestConsistencyGroup):
))
def setUp(self):
- super(TestConsistencyGroupList, self).setUp()
+ super().setUp()
self.consistencygroups_mock.list.return_value = self.consistency_groups
# Get the command to test
@@ -502,11 +499,10 @@ class TestConsistencyGroupList(TestConsistencyGroup):
class TestConsistencyGroupRemoveVolume(TestConsistencyGroup):
- _consistency_group = (
- volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
+ _consistency_group = volume_fakes.create_one_consistency_group()
def setUp(self):
- super(TestConsistencyGroupRemoveVolume, self).setUp()
+ super().setUp()
self.consistencygroups_mock.get.return_value = (
self._consistency_group)
@@ -515,7 +511,7 @@ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup):
consistency_group.RemoveVolumeFromConsistencyGroup(self.app, None)
def test_remove_one_volume_from_consistency_group(self):
- volume = volume_fakes.FakeVolume.create_one_volume()
+ volume = volume_fakes.create_one_volume()
self.volumes_mock.get.return_value = volume
arglist = [
self._consistency_group.id,
@@ -540,8 +536,8 @@ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup):
self.assertIsNone(result)
def test_remove_multi_volumes_from_consistency_group(self):
- volumes = volume_fakes.FakeVolume.create_volumes(count=2)
- self.volumes_mock.get = volume_fakes.FakeVolume.get_volumes(volumes)
+ volumes = volume_fakes.create_volumes(count=2)
+ self.volumes_mock.get = volume_fakes.get_volumes(volumes)
arglist = [
self._consistency_group.id,
volumes[0].id,
@@ -567,8 +563,10 @@ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup):
@mock.patch.object(consistency_group.LOG, 'error')
def test_remove_multiple_volumes_from_consistency_group_with_exception(
- self, mock_error):
- volume = volume_fakes.FakeVolume.create_one_volume()
+ self,
+ mock_error,
+ ):
+ volume = volume_fakes.create_one_volume()
arglist = [
self._consistency_group.id,
volume.id,
@@ -603,11 +601,10 @@ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup):
class TestConsistencyGroupSet(TestConsistencyGroup):
- consistency_group = (
- volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
+ consistency_group = volume_fakes.create_one_consistency_group()
def setUp(self):
- super(TestConsistencyGroupSet, self).setUp()
+ super().setUp()
self.consistencygroups_mock.get.return_value = (
self.consistency_group)
@@ -677,10 +674,9 @@ class TestConsistencyGroupShow(TestConsistencyGroup):
)
def setUp(self):
- super(TestConsistencyGroupShow, self).setUp()
+ super().setUp()
- self.consistency_group = (
- volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
+ self.consistency_group = volume_fakes.create_one_consistency_group()
self.data = (
self.consistency_group.availability_zone,
self.consistency_group.created_at,
diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py b/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py
index 2202b85b..e3c738c8 100644
--- a/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py
+++ b/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py
@@ -35,12 +35,9 @@ class TestConsistencyGroupSnapshot(volume_fakes.TestVolume):
class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot):
_consistency_group_snapshot = (
- volume_fakes.
- FakeConsistencyGroupSnapshot.
- create_one_consistency_group_snapshot()
+ volume_fakes.create_one_consistency_group_snapshot()
)
- consistency_group = (
- volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
+ consistency_group = volume_fakes.create_one_consistency_group()
columns = (
'consistencygroup_id',
@@ -124,16 +121,16 @@ class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot):
class TestConsistencyGroupSnapshotDelete(TestConsistencyGroupSnapshot):
consistency_group_snapshots = (
- volume_fakes.FakeConsistencyGroupSnapshot.
- create_consistency_group_snapshots(count=2)
+ volume_fakes.create_consistency_group_snapshots(count=2)
)
def setUp(self):
super(TestConsistencyGroupSnapshotDelete, self).setUp()
self.cgsnapshots_mock.get = (
- volume_fakes.FakeConsistencyGroupSnapshot.
- get_consistency_group_snapshots(self.consistency_group_snapshots)
+ volume_fakes.get_consistency_group_snapshots(
+ self.consistency_group_snapshots
+ )
)
self.cgsnapshots_mock.delete.return_value = None
@@ -178,12 +175,9 @@ class TestConsistencyGroupSnapshotDelete(TestConsistencyGroupSnapshot):
class TestConsistencyGroupSnapshotList(TestConsistencyGroupSnapshot):
consistency_group_snapshots = (
- volume_fakes.FakeConsistencyGroupSnapshot.
- create_consistency_group_snapshots(count=2)
- )
- consistency_group = (
- volume_fakes.FakeConsistencyGroup.create_one_consistency_group()
+ volume_fakes.create_consistency_group_snapshots(count=2)
)
+ consistency_group = volume_fakes.create_one_consistency_group()
columns = [
'ID',
@@ -306,9 +300,7 @@ class TestConsistencyGroupSnapshotList(TestConsistencyGroupSnapshot):
class TestConsistencyGroupSnapshotShow(TestConsistencyGroupSnapshot):
_consistency_group_snapshot = (
- volume_fakes.
- FakeConsistencyGroupSnapshot.
- create_one_consistency_group_snapshot()
+ volume_fakes.create_one_consistency_group_snapshot()
)
columns = (
diff --git a/openstackclient/tests/unit/volume/v2/test_qos_specs.py b/openstackclient/tests/unit/volume/v2/test_qos_specs.py
index 41c18014..6f258dd5 100644
--- a/openstackclient/tests/unit/volume/v2/test_qos_specs.py
+++ b/openstackclient/tests/unit/volume/v2/test_qos_specs.py
@@ -39,8 +39,8 @@ class TestQos(volume_fakes.TestVolume):
class TestQosAssociate(TestQos):
- volume_type = volume_fakes.FakeVolumeType.create_one_volume_type()
- qos_spec = volume_fakes.FakeQos.create_one_qos()
+ volume_type = volume_fakes.create_one_volume_type()
+ qos_spec = volume_fakes.create_one_qos()
def setUp(self):
super(TestQosAssociate, self).setUp()
@@ -82,7 +82,7 @@ class TestQosCreate(TestQos):
def setUp(self):
super(TestQosCreate, self).setUp()
- self.new_qos_spec = volume_fakes.FakeQos.create_one_qos()
+ self.new_qos_spec = volume_fakes.create_one_qos()
self.qos_mock.create.return_value = self.new_qos_spec
self.data = (
@@ -164,13 +164,13 @@ class TestQosCreate(TestQos):
class TestQosDelete(TestQos):
- qos_specs = volume_fakes.FakeQos.create_qoses(count=2)
+ qos_specs = volume_fakes.create_qoses(count=2)
def setUp(self):
super(TestQosDelete, self).setUp()
self.qos_mock.get = (
- volume_fakes.FakeQos.get_qoses(self.qos_specs))
+ volume_fakes.get_qoses(self.qos_specs))
# Get the command object to test
self.cmd = qos_specs.DeleteQos(self.app, None)
@@ -255,8 +255,8 @@ class TestQosDelete(TestQos):
class TestQosDisassociate(TestQos):
- volume_type = volume_fakes.FakeVolumeType.create_one_volume_type()
- qos_spec = volume_fakes.FakeQos.create_one_qos()
+ volume_type = volume_fakes.create_one_volume_type()
+ qos_spec = volume_fakes.create_one_qos()
def setUp(self):
super(TestQosDisassociate, self).setUp()
@@ -303,8 +303,8 @@ class TestQosDisassociate(TestQos):
class TestQosList(TestQos):
- qos_specs = volume_fakes.FakeQos.create_qoses(count=2)
- qos_association = volume_fakes.FakeQos.create_one_qos_association()
+ qos_specs = volume_fakes.create_qoses(count=2)
+ qos_association = volume_fakes.create_one_qos_association()
columns = (
'ID',
@@ -374,7 +374,7 @@ class TestQosList(TestQos):
class TestQosSet(TestQos):
- qos_spec = volume_fakes.FakeQos.create_one_qos()
+ qos_spec = volume_fakes.create_one_qos()
def setUp(self):
super(TestQosSet, self).setUp()
@@ -406,8 +406,8 @@ class TestQosSet(TestQos):
class TestQosShow(TestQos):
- qos_spec = volume_fakes.FakeQos.create_one_qos()
- qos_association = volume_fakes.FakeQos.create_one_qos_association()
+ qos_spec = volume_fakes.create_one_qos()
+ qos_association = volume_fakes.create_one_qos_association()
columns = (
'associations',
@@ -454,7 +454,7 @@ class TestQosShow(TestQos):
class TestQosUnset(TestQos):
- qos_spec = volume_fakes.FakeQos.create_one_qos()
+ qos_spec = volume_fakes.create_one_qos()
def setUp(self):
super(TestQosUnset, self).setUp()
diff --git a/openstackclient/tests/unit/volume/v2/test_service.py b/openstackclient/tests/unit/volume/v2/test_service.py
index 3e9b2df9..e9e39f41 100644
--- a/openstackclient/tests/unit/volume/v2/test_service.py
+++ b/openstackclient/tests/unit/volume/v2/test_service.py
@@ -14,14 +14,14 @@
from osc_lib import exceptions
-from openstackclient.tests.unit.volume.v2 import fakes as service_fakes
+from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
from openstackclient.volume.v2 import service
-class TestService(service_fakes.TestVolume):
+class TestService(volume_fakes.TestVolume):
def setUp(self):
- super(TestService, self).setUp()
+ super().setUp()
# Get a shortcut to the ServiceManager Mock
self.service_mock = self.app.client_manager.volume.services
@@ -31,10 +31,10 @@ class TestService(service_fakes.TestVolume):
class TestServiceList(TestService):
# The service to be listed
- services = service_fakes.FakeService.create_one_service()
+ services = volume_fakes.create_one_service()
def setUp(self):
- super(TestServiceList, self).setUp()
+ super().setUp()
self.service_mock.list.return_value = [self.services]
@@ -144,10 +144,10 @@ class TestServiceList(TestService):
class TestServiceSet(TestService):
- service = service_fakes.FakeService.create_one_service()
+ service = volume_fakes.create_one_service()
def setUp(self):
- super(TestServiceSet, self).setUp()
+ super().setUp()
self.service_mock.enable.return_value = self.service
self.service_mock.disable.return_value = self.service
diff --git a/openstackclient/tests/unit/volume/v2/test_type.py b/openstackclient/tests/unit/volume/v2/test_type.py
index d94dc1e0..1cb46c45 100644
--- a/openstackclient/tests/unit/volume/v2/test_type.py
+++ b/openstackclient/tests/unit/volume/v2/test_type.py
@@ -28,7 +28,7 @@ from openstackclient.volume.v2 import volume_type
class TestType(volume_fakes.TestVolume):
def setUp(self):
- super(TestType, self).setUp()
+ super().setUp()
self.types_mock = self.app.client_manager.volume.volume_types
self.types_mock.reset_mock()
@@ -56,10 +56,9 @@ class TestTypeCreate(TestType):
)
def setUp(self):
- super(TestTypeCreate, self).setUp()
+ super().setUp()
- self.new_volume_type = \
- volume_fakes.FakeVolumeType.create_one_volume_type()
+ self.new_volume_type = volume_fakes.create_one_volume_type()
self.data = (
self.new_volume_type.description,
self.new_volume_type.id,
@@ -144,12 +143,12 @@ class TestTypeCreate(TestType):
'key_size': '128',
'control_location': 'front-end',
}
- encryption_type = \
- volume_fakes.FakeVolumeType.create_one_encryption_volume_type(
- attrs=encryption_info)
- self.new_volume_type = \
- volume_fakes.FakeVolumeType.create_one_volume_type(
- attrs={'encryption': encryption_info})
+ encryption_type = volume_fakes.create_one_encryption_volume_type(
+ attrs=encryption_info,
+ )
+ self.new_volume_type = volume_fakes.create_one_volume_type(
+ attrs={'encryption': encryption_info},
+ )
self.types_mock.create.return_value = self.new_volume_type
self.encryption_types_mock.create.return_value = encryption_type
encryption_columns = (
@@ -203,13 +202,14 @@ class TestTypeCreate(TestType):
class TestTypeDelete(TestType):
- volume_types = volume_fakes.FakeVolumeType.create_volume_types(count=2)
+ volume_types = volume_fakes.create_volume_types(count=2)
def setUp(self):
- super(TestTypeDelete, self).setUp()
+ super().setUp()
- self.types_mock.get = volume_fakes.FakeVolumeType.get_volume_types(
- self.volume_types)
+ self.types_mock.get = volume_fakes.get_volume_types(
+ self.volume_types,
+ )
self.types_mock.delete.return_value = None
# Get the command object to mock
@@ -278,7 +278,7 @@ class TestTypeDelete(TestType):
class TestTypeList(TestType):
- volume_types = volume_fakes.FakeVolumeType.create_volume_types()
+ volume_types = volume_fakes.create_volume_types()
columns = [
"ID",
@@ -312,7 +312,7 @@ class TestTypeList(TestType):
))
def setUp(self):
- super(TestTypeList, self).setUp()
+ super().setUp()
self.types_mock.list.return_value = self.volume_types
self.types_mock.default.return_value = self.volume_types[0]
@@ -388,9 +388,9 @@ class TestTypeList(TestType):
self.assertCountEqual(self.data_with_default_type, list(data))
def test_type_list_with_encryption(self):
- encryption_type = \
- volume_fakes.FakeVolumeType.create_one_encryption_volume_type(
- attrs={'volume_type_id': self.volume_types[0].id})
+ encryption_type = volume_fakes.create_one_encryption_volume_type(
+ attrs={'volume_type_id': self.volume_types[0].id},
+ )
encryption_info = {
'provider': 'LuksEncryptor',
'cipher': None,
@@ -436,11 +436,12 @@ class TestTypeList(TestType):
class TestTypeSet(TestType):
project = identity_fakes.FakeProject.create_one_project()
- volume_type = volume_fakes.FakeVolumeType.create_one_volume_type(
- methods={'set_keys': None})
+ volume_type = volume_fakes.create_one_volume_type(
+ methods={'set_keys': None},
+ )
def setUp(self):
- super(TestTypeSet, self).setUp()
+ super().setUp()
self.types_mock.get.return_value = self.volume_type
@@ -685,9 +686,9 @@ class TestTypeShow(TestType):
)
def setUp(self):
- super(TestTypeShow, self).setUp()
+ super().setUp()
- self.volume_type = volume_fakes.FakeVolumeType.create_one_volume_type()
+ self.volume_type = volume_fakes.create_one_volume_type()
self.data = (
None,
self.volume_type.description,
@@ -727,13 +728,20 @@ class TestTypeShow(TestType):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- private_type = volume_fakes.FakeVolumeType.create_one_volume_type(
- attrs={'is_public': False})
- type_access_list = volume_fakes.FakeTypeAccess.create_one_type_access()
- with mock.patch.object(self.types_mock, 'get',
- return_value=private_type):
- with mock.patch.object(self.types_access_mock, 'list',
- return_value=[type_access_list]):
+ private_type = volume_fakes.create_one_volume_type(
+ attrs={'is_public': False},
+ )
+ type_access_list = volume_fakes.create_one_type_access()
+ with mock.patch.object(
+ self.types_mock,
+ 'get',
+ return_value=private_type,
+ ):
+ with mock.patch.object(
+ self.types_access_mock,
+ 'list',
+ return_value=[type_access_list],
+ ):
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.get.assert_called_once_with(
self.volume_type.id)
@@ -760,8 +768,9 @@ class TestTypeShow(TestType):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- private_type = volume_fakes.FakeVolumeType.create_one_volume_type(
- attrs={'is_public': False})
+ private_type = volume_fakes.create_one_volume_type(
+ attrs={'is_public': False},
+ )
with mock.patch.object(self.types_mock, 'get',
return_value=private_type):
with mock.patch.object(self.types_access_mock, 'list',
@@ -784,16 +793,16 @@ class TestTypeShow(TestType):
self.assertCountEqual(private_type_data, data)
def test_type_show_with_encryption(self):
- encryption_type = \
- volume_fakes.FakeVolumeType.create_one_encryption_volume_type()
+ encryption_type = volume_fakes.create_one_encryption_volume_type()
encryption_info = {
'provider': 'LuksEncryptor',
'cipher': None,
'key_size': None,
'control_location': 'front-end',
}
- self.volume_type = volume_fakes.FakeVolumeType.create_one_volume_type(
- attrs={'encryption': encryption_info})
+ self.volume_type = volume_fakes.create_one_volume_type(
+ attrs={'encryption': encryption_info},
+ )
self.types_mock.get.return_value = self.volume_type
self.encryption_types_mock.get.return_value = encryption_type
encryption_columns = (
@@ -834,11 +843,12 @@ class TestTypeShow(TestType):
class TestTypeUnset(TestType):
project = identity_fakes.FakeProject.create_one_project()
- volume_type = volume_fakes.FakeVolumeType.create_one_volume_type(
- methods={'unset_keys': None})
+ volume_type = volume_fakes.create_one_volume_type(
+ methods={'unset_keys': None},
+ )
def setUp(self):
- super(TestTypeUnset, self).setUp()
+ super().setUp()
self.types_mock.get.return_value = self.volume_type
@@ -936,7 +946,7 @@ class TestTypeUnset(TestType):
class TestColumns(TestType):
def test_encryption_info_column_with_info(self):
- fake_volume_type = volume_fakes.FakeVolumeType.create_one_volume_type()
+ fake_volume_type = volume_fakes.create_one_volume_type()
type_id = fake_volume_type.id
encryption_info = {
@@ -952,7 +962,7 @@ class TestColumns(TestType):
self.assertEqual(encryption_info, col.machine_readable())
def test_encryption_info_column_without_info(self):
- fake_volume_type = volume_fakes.FakeVolumeType.create_one_volume_type()
+ fake_volume_type = volume_fakes.create_one_volume_type()
type_id = fake_volume_type.id
col = volume_type.EncryptionInfoColumn(type_id, {})
diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py
index ec82e674..c930002f 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume.py
@@ -16,6 +16,7 @@ import argparse
from unittest import mock
from unittest.mock import call
+from cinderclient import api_versions
from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -30,7 +31,7 @@ from openstackclient.volume.v2 import volume
class TestVolume(volume_fakes.TestVolume):
def setUp(self):
- super(TestVolume, self).setUp()
+ super().setUp()
self.volumes_mock = self.app.client_manager.volume.volumes
self.volumes_mock.reset_mock()
@@ -47,6 +48,9 @@ class TestVolume(volume_fakes.TestVolume):
self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
self.snapshots_mock.reset_mock()
+ self.backups_mock = self.app.client_manager.volume.backups
+ self.backups_mock.reset_mock()
+
self.types_mock = self.app.client_manager.volume.volume_types
self.types_mock.reset_mock()
@@ -55,11 +59,9 @@ class TestVolume(volume_fakes.TestVolume):
self.consistencygroups_mock.reset_mock()
def setup_volumes_mock(self, count):
- volumes = volume_fakes.FakeVolume.create_volumes(count=count)
+ volumes = volume_fakes.create_volumes(count=count)
- self.volumes_mock.get = volume_fakes.FakeVolume.get_volumes(
- volumes,
- 0)
+ self.volumes_mock.get = volume_fakes.get_volumes(volumes, 0)
return volumes
@@ -83,9 +85,9 @@ class TestVolumeCreate(TestVolume):
)
def setUp(self):
- super(TestVolumeCreate, self).setUp()
+ super().setUp()
- self.new_volume = volume_fakes.FakeVolume.create_one_volume()
+ self.new_volume = volume_fakes.create_one_volume()
self.volumes_mock.create.return_value = self.new_volume
self.datalist = (
@@ -108,11 +110,9 @@ class TestVolumeCreate(TestVolume):
def test_volume_create_min_options(self):
arglist = [
'--size', str(self.new_volume.size),
- self.new_volume.name,
]
verifylist = [
('size', self.new_volume.size),
- ('name', self.new_volume.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -124,7 +124,7 @@ class TestVolumeCreate(TestVolume):
self.volumes_mock.create.assert_called_with(
size=self.new_volume.size,
snapshot_id=None,
- name=self.new_volume.name,
+ name=None,
description=None,
volume_type=None,
availability_zone=None,
@@ -133,14 +133,14 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=None,
scheduler_hints=None,
+ backup_id=None,
)
self.assertEqual(self.columns, columns)
self.assertCountEqual(self.datalist, data)
def test_volume_create_options(self):
- consistency_group = (
- volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
+ consistency_group = volume_fakes.create_one_consistency_group()
self.consistencygroups_mock.get.return_value = consistency_group
arglist = [
'--size', str(self.new_volume.size),
@@ -179,6 +179,7 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=consistency_group.id,
scheduler_hints={'k': 'v'},
+ backup_id=None,
)
self.assertEqual(self.columns, columns)
@@ -215,6 +216,7 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=None,
scheduler_hints=None,
+ backup_id=None,
)
self.assertEqual(self.columns, columns)
@@ -253,6 +255,7 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=None,
scheduler_hints=None,
+ backup_id=None,
)
self.assertEqual(self.columns, columns)
@@ -291,13 +294,14 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=None,
scheduler_hints=None,
+ backup_id=None,
)
self.assertEqual(self.columns, columns)
self.assertCountEqual(self.datalist, data)
def test_volume_create_with_snapshot(self):
- snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
+ snapshot = volume_fakes.create_one_snapshot()
self.new_volume.snapshot_id = snapshot.id
arglist = [
'--snapshot', self.new_volume.snapshot_id,
@@ -328,6 +332,104 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=None,
scheduler_hints=None,
+ backup_id=None,
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertCountEqual(self.datalist, data)
+
+ def test_volume_create_with_backup(self):
+ backup = volume_fakes.create_one_backup()
+ self.new_volume.backup_id = backup.id
+ arglist = [
+ '--backup', self.new_volume.backup_id,
+ self.new_volume.name,
+ ]
+ verifylist = [
+ ('backup', self.new_volume.backup_id),
+ ('name', self.new_volume.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.backups_mock.get.return_value = backup
+
+ self.app.client_manager.volume.api_version = \
+ api_versions.APIVersion('3.47')
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.volumes_mock.create.assert_called_once_with(
+ size=backup.size,
+ snapshot_id=None,
+ name=self.new_volume.name,
+ description=None,
+ volume_type=None,
+ availability_zone=None,
+ metadata=None,
+ imageRef=None,
+ source_volid=None,
+ consistencygroup_id=None,
+ scheduler_hints=None,
+ backup_id=backup.id,
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertCountEqual(self.datalist, data)
+
+ def test_volume_create_with_backup_pre_347(self):
+ backup = volume_fakes.create_one_backup()
+ self.new_volume.backup_id = backup.id
+ arglist = [
+ '--backup', self.new_volume.backup_id,
+ self.new_volume.name,
+ ]
+ verifylist = [
+ ('backup', self.new_volume.backup_id),
+ ('name', self.new_volume.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.backups_mock.get.return_value = backup
+
+ exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+ self.assertIn("--os-volume-api-version 3.47 or greater", str(exc))
+
+ def test_volume_create_with_source_volume(self):
+ source_vol = "source_vol"
+ arglist = [
+ '--source', self.new_volume.id,
+ source_vol,
+ ]
+ verifylist = [
+ ('source', self.new_volume.id),
+ ('name', source_vol),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.volumes_mock.get.return_value = self.new_volume
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.volumes_mock.create.assert_called_once_with(
+ size=self.new_volume.size,
+ snapshot_id=None,
+ name=source_vol,
+ description=None,
+ volume_type=None,
+ availability_zone=None,
+ metadata=None,
+ imageRef=None,
+ source_volid=self.new_volume.id,
+ consistencygroup_id=None,
+ scheduler_hints=None,
+ backup_id=None,
)
self.assertEqual(self.columns, columns)
@@ -366,6 +468,7 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=None,
scheduler_hints=None,
+ backup_id=None,
)
self.assertEqual(self.columns, columns)
@@ -408,6 +511,7 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=None,
scheduler_hints=None,
+ backup_id=None,
)
self.assertEqual(self.columns, columns)
@@ -459,6 +563,7 @@ class TestVolumeCreate(TestVolume):
source_volid=None,
consistencygroup_id=None,
scheduler_hints=None,
+ backup_id=None,
)
self.assertEqual(2, mock_error.call_count)
@@ -504,7 +609,7 @@ class TestVolumeCreate(TestVolume):
class TestVolumeDelete(TestVolume):
def setUp(self):
- super(TestVolumeDelete, self).setUp()
+ super().setUp()
self.volumes_mock.delete.return_value = None
@@ -632,9 +737,9 @@ class TestVolumeList(TestVolume):
]
def setUp(self):
- super(TestVolumeList, self).setUp()
+ super().setUp()
- self.mock_volume = volume_fakes.FakeVolume.create_one_volume()
+ self.mock_volume = volume_fakes.create_one_volume()
self.volumes_mock.list.return_value = [self.mock_volume]
self.users_mock.get.return_value = self.user
@@ -1107,10 +1212,10 @@ class TestVolumeList(TestVolume):
class TestVolumeMigrate(TestVolume):
- _volume = volume_fakes.FakeVolume.create_one_volume()
+ _volume = volume_fakes.create_one_volume()
def setUp(self):
- super(TestVolumeMigrate, self).setUp()
+ super().setUp()
self.volumes_mock.get.return_value = self._volume
self.volumes_mock.migrate_volume.return_value = None
@@ -1173,12 +1278,12 @@ class TestVolumeMigrate(TestVolume):
class TestVolumeSet(TestVolume):
- volume_type = volume_fakes.FakeVolumeType.create_one_volume_type()
+ volume_type = volume_fakes.create_one_volume_type()
def setUp(self):
- super(TestVolumeSet, self).setUp()
+ super().setUp()
- self.new_volume = volume_fakes.FakeVolume.create_one_volume()
+ self.new_volume = volume_fakes.create_one_volume()
self.volumes_mock.get.return_value = self.new_volume
self.types_mock.get.return_value = self.volume_type
@@ -1427,9 +1532,9 @@ class TestVolumeSet(TestVolume):
class TestVolumeShow(TestVolume):
def setUp(self):
- super(TestVolumeShow, self).setUp()
+ super().setUp()
- self._volume = volume_fakes.FakeVolume.create_one_volume()
+ self._volume = volume_fakes.create_one_volume()
self.volumes_mock.get.return_value = self._volume
# Get the command object to test
self.cmd = volume.ShowVolume(self.app, None)
@@ -1447,20 +1552,21 @@ class TestVolumeShow(TestVolume):
self.volumes_mock.get.assert_called_with(self._volume.id)
self.assertEqual(
- volume_fakes.FakeVolume.get_volume_columns(self._volume),
- columns)
-
+ volume_fakes.get_volume_columns(self._volume),
+ columns,
+ )
self.assertCountEqual(
- volume_fakes.FakeVolume.get_volume_data(self._volume),
- data)
+ volume_fakes.get_volume_data(self._volume),
+ data,
+ )
class TestVolumeUnset(TestVolume):
def setUp(self):
- super(TestVolumeUnset, self).setUp()
+ super().setUp()
- self.new_volume = volume_fakes.FakeVolume.create_one_volume()
+ self.new_volume = volume_fakes.create_one_volume()
self.volumes_mock.get.return_value = self.new_volume
# Get the command object to set property
@@ -1538,7 +1644,7 @@ class TestVolumeUnset(TestVolume):
class TestColumns(TestVolume):
def test_attachments_column_without_server_cache(self):
- _volume = volume_fakes.FakeVolume.create_one_volume()
+ _volume = volume_fakes.create_one_volume()
server_id = _volume.attachments[0]['server_id']
device = _volume.attachments[0]['device']
@@ -1548,7 +1654,7 @@ class TestColumns(TestVolume):
self.assertEqual(_volume.attachments, col.machine_readable())
def test_attachments_column_with_server_cache(self):
- _volume = volume_fakes.FakeVolume.create_one_volume()
+ _volume = volume_fakes.create_one_volume()
server_id = _volume.attachments[0]['server_id']
device = _volume.attachments[0]['device']
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_backend.py b/openstackclient/tests/unit/volume/v2/test_volume_backend.py
index d9ac2c96..6c64f645 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume_backend.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_backend.py
@@ -20,10 +20,10 @@ class TestShowVolumeCapability(volume_fakes.TestVolume):
"""Test backend capability functionality."""
# The capability to be listed
- capability = volume_fakes.FakeCapability.create_one_capability()
+ capability = volume_fakes.create_one_capability()
def setUp(self):
- super(TestShowVolumeCapability, self).setUp()
+ super().setUp()
# Get a shortcut to the capability Mock
self.capability_mock = self.app.client_manager.volume.capabilities
@@ -77,10 +77,10 @@ class TestListVolumePool(volume_fakes.TestVolume):
"""Tests for volume backend pool listing."""
# The pool to be listed
- pools = volume_fakes.FakePool.create_one_pool()
+ pools = volume_fakes.create_one_pool()
def setUp(self):
- super(TestListVolumePool, self).setUp()
+ super().setUp()
self.pool_mock = self.app.client_manager.volume.pools
self.pool_mock.list.return_value = [self.pools]
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_backup.py b/openstackclient/tests/unit/volume/v2/test_volume_backup.py
index 4b9212d0..7d00b8bf 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume_backup.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_backup.py
@@ -26,7 +26,7 @@ from openstackclient.volume.v2 import volume_backup
class TestBackup(volume_fakes.TestVolume):
def setUp(self):
- super(TestBackup, self).setUp()
+ super().setUp()
self.backups_mock = self.app.client_manager.volume.backups
self.backups_mock.reset_mock()
@@ -40,9 +40,9 @@ class TestBackup(volume_fakes.TestVolume):
class TestBackupCreate(TestBackup):
- volume = volume_fakes.FakeVolume.create_one_volume()
- snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
- new_backup = volume_fakes.FakeBackup.create_one_backup(
+ volume = volume_fakes.create_one_volume()
+ snapshot = volume_fakes.create_one_snapshot()
+ new_backup = volume_fakes.create_one_backup(
attrs={'volume_id': volume.id, 'snapshot_id': snapshot.id})
columns = (
@@ -71,7 +71,7 @@ class TestBackupCreate(TestBackup):
)
def setUp(self):
- super(TestBackupCreate, self).setUp()
+ super().setUp()
self.volumes_mock.get.return_value = self.volume
self.snapshots_mock.get.return_value = self.snapshot
@@ -242,13 +242,13 @@ class TestBackupCreate(TestBackup):
class TestBackupDelete(TestBackup):
- backups = volume_fakes.FakeBackup.create_backups(count=2)
+ backups = volume_fakes.create_backups(count=2)
def setUp(self):
- super(TestBackupDelete, self).setUp()
+ super().setUp()
self.backups_mock.get = (
- volume_fakes.FakeBackup.get_backups(self.backups))
+ volume_fakes.get_backups(self.backups))
self.backups_mock.delete.return_value = None
# Get the command object to mock
@@ -334,8 +334,8 @@ class TestBackupDelete(TestBackup):
class TestBackupList(TestBackup):
- volume = volume_fakes.FakeVolume.create_one_volume()
- backups = volume_fakes.FakeBackup.create_backups(
+ volume = volume_fakes.create_one_volume()
+ backups = volume_fakes.create_backups(
attrs={'volume_id': volume.name}, count=3)
columns = (
@@ -374,7 +374,7 @@ class TestBackupList(TestBackup):
))
def setUp(self):
- super(TestBackupList, self).setUp()
+ super().setUp()
self.volumes_mock.list.return_value = [self.volume]
self.backups_mock.list.return_value = self.backups
@@ -456,46 +456,106 @@ class TestBackupList(TestBackup):
class TestBackupRestore(TestBackup):
- volume = volume_fakes.FakeVolume.create_one_volume()
- backup = volume_fakes.FakeBackup.create_one_backup(
- attrs={'volume_id': volume.id})
+ volume = volume_fakes.create_one_volume()
+ backup = volume_fakes.create_one_backup(
+ attrs={'volume_id': volume.id},
+ )
def setUp(self):
- super(TestBackupRestore, self).setUp()
+ super().setUp()
self.backups_mock.get.return_value = self.backup
self.volumes_mock.get.return_value = self.volume
self.restores_mock.restore.return_value = (
- volume_fakes.FakeVolume.create_one_volume(
- {'id': self.volume['id']}))
+ volume_fakes.create_one_volume(
+ {'id': self.volume['id']},
+ )
+ )
# Get the command object to mock
self.cmd = volume_backup.RestoreVolumeBackup(self.app, None)
def test_backup_restore(self):
+ self.volumes_mock.get.side_effect = exceptions.CommandError()
+ self.volumes_mock.find.side_effect = exceptions.CommandError()
+ arglist = [
+ self.backup.id
+ ]
+ verifylist = [
+ ("backup", self.backup.id),
+ ("volume", None),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ self.restores_mock.restore.assert_called_with(
+ self.backup.id, None, None,
+ )
+ self.assertIsNotNone(result)
+
+ def test_backup_restore_with_volume(self):
+ self.volumes_mock.get.side_effect = exceptions.CommandError()
+ self.volumes_mock.find.side_effect = exceptions.CommandError()
+ arglist = [
+ self.backup.id,
+ self.backup.volume_id,
+ ]
+ verifylist = [
+ ("backup", self.backup.id),
+ ("volume", self.backup.volume_id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ self.restores_mock.restore.assert_called_with(
+ self.backup.id, None, self.backup.volume_id,
+ )
+ self.assertIsNotNone(result)
+
+ def test_backup_restore_with_volume_force(self):
arglist = [
+ "--force",
self.backup.id,
- self.backup.volume_id
+ self.volume.name,
]
verifylist = [
+ ("force", True),
("backup", self.backup.id),
- ("volume", self.backup.volume_id)
+ ("volume", self.volume.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
- self.restores_mock.restore.assert_called_with(self.backup.id,
- self.backup.volume_id)
+ self.restores_mock.restore.assert_called_with(
+ self.backup.id, self.volume.id, None,
+ )
self.assertIsNotNone(result)
+ def test_backup_restore_with_volume_existing(self):
+ arglist = [
+ self.backup.id,
+ self.volume.name,
+ ]
+ verifylist = [
+ ("backup", self.backup.id),
+ ("volume", self.volume.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.assertRaises(
+ exceptions.CommandError,
+ self.cmd.take_action,
+ parsed_args,
+ )
+
class TestBackupSet(TestBackup):
- backup = volume_fakes.FakeBackup.create_one_backup(
+ backup = volume_fakes.create_one_backup(
attrs={'metadata': {'wow': 'cool'}},
)
def setUp(self):
- super(TestBackupSet, self).setUp()
+ super().setUp()
self.backups_mock.get.return_value = self.backup
@@ -724,7 +784,7 @@ class TestBackupSet(TestBackup):
class TestBackupUnset(TestBackup):
- backup = volume_fakes.FakeBackup.create_one_backup(
+ backup = volume_fakes.create_one_backup(
attrs={'metadata': {'foo': 'bar'}},
)
@@ -785,7 +845,7 @@ class TestBackupUnset(TestBackup):
class TestBackupShow(TestBackup):
- backup = volume_fakes.FakeBackup.create_one_backup()
+ backup = volume_fakes.create_one_backup()
columns = (
'availability_zone',
@@ -813,7 +873,7 @@ class TestBackupShow(TestBackup):
)
def setUp(self):
- super(TestBackupShow, self).setUp()
+ super().setUp()
self.backups_mock.get.return_value = self.backup
# Get the command object to test
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_host.py b/openstackclient/tests/unit/volume/v2/test_volume_host.py
index b024329a..730085a3 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume_host.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_host.py
@@ -12,14 +12,14 @@
# under the License.
#
-from openstackclient.tests.unit.volume.v2 import fakes as host_fakes
+from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
from openstackclient.volume.v2 import volume_host
-class TestVolumeHost(host_fakes.TestVolume):
+class TestVolumeHost(volume_fakes.TestVolume):
def setUp(self):
- super(TestVolumeHost, self).setUp()
+ super().setUp()
self.host_mock = self.app.client_manager.volume.services
self.host_mock.reset_mock()
@@ -27,10 +27,10 @@ class TestVolumeHost(host_fakes.TestVolume):
class TestVolumeHostSet(TestVolumeHost):
- service = host_fakes.FakeService.create_one_service()
+ service = volume_fakes.create_one_service()
def setUp(self):
- super(TestVolumeHostSet, self).setUp()
+ super().setUp()
self.host_mock.freeze_host.return_value = None
self.host_mock.thaw_host.return_value = None
@@ -89,10 +89,10 @@ class TestVolumeHostSet(TestVolumeHost):
class TestVolumeHostFailover(TestVolumeHost):
- service = host_fakes.FakeService.create_one_service()
+ service = volume_fakes.create_one_service()
def setUp(self):
- super(TestVolumeHostFailover, self).setUp()
+ super().setUp()
self.host_mock.failover_host.return_value = None
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_snapshot.py b/openstackclient/tests/unit/volume/v2/test_volume_snapshot.py
index 33a5a98a..6cffcaac 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume_snapshot.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_snapshot.py
@@ -54,8 +54,8 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot):
def setUp(self):
super().setUp()
- self.volume = volume_fakes.FakeVolume.create_one_volume()
- self.new_snapshot = volume_fakes.FakeSnapshot.create_one_snapshot(
+ self.volume = volume_fakes.create_one_volume()
+ self.new_snapshot = volume_fakes.create_one_snapshot(
attrs={'volume_id': self.volume.id})
self.data = (
@@ -179,13 +179,13 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot):
class TestVolumeSnapshotDelete(TestVolumeSnapshot):
- snapshots = volume_fakes.FakeSnapshot.create_snapshots(count=2)
+ snapshots = volume_fakes.create_snapshots(count=2)
def setUp(self):
super().setUp()
self.snapshots_mock.get = (
- volume_fakes.FakeSnapshot.get_snapshots(self.snapshots))
+ volume_fakes.get_snapshots(self.snapshots))
self.snapshots_mock.delete.return_value = None
# Get the command object to mock
@@ -273,9 +273,9 @@ class TestVolumeSnapshotDelete(TestVolumeSnapshot):
class TestVolumeSnapshotList(TestVolumeSnapshot):
- volume = volume_fakes.FakeVolume.create_one_volume()
+ volume = volume_fakes.create_one_volume()
project = project_fakes.FakeProject.create_one_project()
- snapshots = volume_fakes.FakeSnapshot.create_snapshots(
+ snapshots = volume_fakes.create_snapshots(
attrs={'volume_id': volume.name}, count=3)
columns = [
@@ -495,7 +495,7 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
class TestVolumeSnapshotSet(TestVolumeSnapshot):
- snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
+ snapshot = volume_fakes.create_one_snapshot()
def setUp(self):
super().setUp()
@@ -677,7 +677,7 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot):
def setUp(self):
super().setUp()
- self.snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
+ self.snapshot = volume_fakes.create_one_snapshot()
self.data = (
self.snapshot.created_at,
@@ -712,7 +712,7 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot):
class TestVolumeSnapshotUnset(TestVolumeSnapshot):
- snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
+ snapshot = volume_fakes.create_one_snapshot()
def setUp(self):
super().setUp()
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py b/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py
index 1a1f220f..c8c6fac9 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py
@@ -20,14 +20,14 @@ from osc_lib import exceptions
from osc_lib import utils
from openstackclient.tests.unit import utils as test_utils
-from openstackclient.tests.unit.volume.v2 import fakes as transfer_fakes
+from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
from openstackclient.volume.v2 import volume_transfer_request
-class TestTransfer(transfer_fakes.TestVolume):
+class TestTransfer(volume_fakes.TestVolume):
def setUp(self):
- super(TestTransfer, self).setUp()
+ super().setUp()
# Get a shortcut to the TransferManager Mock
self.transfer_mock = self.app.client_manager.volume.transfers
@@ -47,10 +47,9 @@ class TestTransferAccept(TestTransfer):
)
def setUp(self):
- super(TestTransferAccept, self).setUp()
+ super().setUp()
- self.volume_transfer = (
- transfer_fakes.FakeTransfer.create_one_transfer())
+ self.volume_transfer = volume_fakes.create_one_transfer()
self.data = (
self.volume_transfer.id,
self.volume_transfer.name,
@@ -106,7 +105,7 @@ class TestTransferAccept(TestTransfer):
class TestTransferCreate(TestTransfer):
- volume = transfer_fakes.FakeVolume.create_one_volume()
+ volume = volume_fakes.create_one_volume()
columns = (
'auth_key',
@@ -117,12 +116,14 @@ class TestTransferCreate(TestTransfer):
)
def setUp(self):
- super(TestTransferCreate, self).setUp()
-
- self.volume_transfer = transfer_fakes.FakeTransfer.create_one_transfer(
- attrs={'volume_id': self.volume.id,
- 'auth_key': 'key',
- 'created_at': 'time'}
+ super().setUp()
+
+ self.volume_transfer = volume_fakes.create_one_transfer(
+ attrs={
+ 'volume_id': self.volume.id,
+ 'auth_key': 'key',
+ 'created_at': 'time',
+ },
)
self.data = (
self.volume_transfer.auth_key,
@@ -221,13 +222,14 @@ class TestTransferCreate(TestTransfer):
class TestTransferDelete(TestTransfer):
- volume_transfers = transfer_fakes.FakeTransfer.create_transfers(count=2)
+ volume_transfers = volume_fakes.create_transfers(count=2)
def setUp(self):
- super(TestTransferDelete, self).setUp()
+ super().setUp()
- self.transfer_mock.get = (
- transfer_fakes.FakeTransfer.get_transfers(self.volume_transfers))
+ self.transfer_mock.get = volume_fakes.get_transfers(
+ self.volume_transfers,
+ )
self.transfer_mock.delete.return_value = None
# Get the command object to mock
@@ -300,10 +302,10 @@ class TestTransferDelete(TestTransfer):
class TestTransferList(TestTransfer):
# The Transfers to be listed
- volume_transfers = transfer_fakes.FakeTransfer.create_one_transfer()
+ volume_transfers = volume_fakes.create_one_transfer()
def setUp(self):
- super(TestTransferList, self).setUp()
+ super().setUp()
self.transfer_mock.list.return_value = [self.volume_transfers]
@@ -394,11 +396,10 @@ class TestTransferShow(TestTransfer):
)
def setUp(self):
- super(TestTransferShow, self).setUp()
+ super().setUp()
- self.volume_transfer = (
- transfer_fakes.FakeTransfer.create_one_transfer(
- attrs={'created_at': 'time'})
+ self.volume_transfer = volume_fakes.create_one_transfer(
+ attrs={'created_at': 'time'},
)
self.data = (
self.volume_transfer.created_at,