summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/volume/v3
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2022-09-29 18:42:26 +0100
committerStephen Finucane <stephenfin@redhat.com>2022-09-30 11:42:07 +0000
commit1aaaa6f1d14ebc2498513aabe788239c9f867639 (patch)
tree6bab1ce1ca60e45a56d248e2db15b96ae00212c5 /openstackclient/tests/unit/volume/v3
parentd7f431be507f3f6904a503e5b0ce7fcc23caa326 (diff)
downloadpython-openstackclient-1aaaa6f1d14ebc2498513aabe788239c9f867639.tar.gz
tests: Remove unnecessary nesting of volume resources
Change-Id: I210ce7534d161e89115e5cb96e42ab7f27170aa1 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/tests/unit/volume/v3')
-rw-r--r--openstackclient/tests/unit/volume/v3/fakes.py780
-rw-r--r--openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py6
-rw-r--r--openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py6
-rw-r--r--openstackclient/tests/unit/volume/v3/test_volume_attachment.py20
-rw-r--r--openstackclient/tests/unit/volume/v3/test_volume_group.py19
-rw-r--r--openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py9
-rw-r--r--openstackclient/tests/unit/volume/v3/test_volume_group_type.py29
-rw-r--r--openstackclient/tests/unit/volume/v3/test_volume_message.py14
8 files changed, 407 insertions, 476 deletions
diff --git a/openstackclient/tests/unit/volume/v3/fakes.py b/openstackclient/tests/unit/volume/v3/fakes.py
index caf7d269..3e3a05fa 100644
--- a/openstackclient/tests/unit/volume/v3/fakes.py
+++ b/openstackclient/tests/unit/volume/v3/fakes.py
@@ -24,7 +24,6 @@ from openstackclient.tests.unit.volume.v2 import fakes as volume_v2_fakes
class FakeVolumeClient:
-
def __init__(self, **kwargs):
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
@@ -51,17 +50,14 @@ class FakeVolumeClient:
class TestVolume(utils.TestCommand):
-
def setUp(self):
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.compute = compute_fakes.FakeComputev2Client(
endpoint=fakes.AUTH_URL,
@@ -70,353 +66,309 @@ class TestVolume(utils.TestCommand):
# TODO(stephenfin): Check if the responses are actually the same
-FakeVolume = volume_v2_fakes.FakeVolume
-FakeVolumeType = volume_v2_fakes.FakeVolumeType
-
-
-class FakeCluster:
- """Fake one or more clusters."""
-
- @staticmethod
- def create_one_cluster(attrs=None):
- """Create a fake service cluster.
-
- :param attrs: A dictionary with all attributes of service cluster
- :return: A FakeResource object with id, name, status, etc.
- """
- attrs = attrs or {}
-
- # Set default attribute
- cluster_info = {
- 'name': f'cluster-{uuid.uuid4().hex}',
- 'binary': f'binary-{uuid.uuid4().hex}',
- 'state': random.choice(['up', 'down']),
- 'status': random.choice(['enabled', 'disabled']),
- 'disabled_reason': None,
- 'num_hosts': random.randint(1, 64),
- 'num_down_hosts': random.randint(1, 64),
- 'last_heartbeat': '2015-09-16T09:28:52.000000',
- 'created_at': '2015-09-16T09:28:52.000000',
- 'updated_at': '2015-09-16T09:28:52.000000',
- 'replication_status': None,
- 'frozen': False,
- 'active_backend_id': None,
- }
-
- # Overwrite default attributes if there are some attributes set
- cluster_info.update(attrs)
-
- return fakes.FakeResource(
- None,
- cluster_info,
- loaded=True)
-
- @staticmethod
- def create_clusters(attrs=None, count=2):
- """Create multiple fake service clusters.
-
- :param attrs: A dictionary with all attributes of service cluster
- :param count: The number of service clusters to be faked
- :return: A list of FakeResource objects
- """
- clusters = []
- for n in range(0, count):
- clusters.append(FakeCluster.create_one_cluster(attrs))
-
- return clusters
-
-
-class FakeResourceFilter:
- """Fake one or more resource filters."""
-
- @staticmethod
- def create_one_resource_filter(attrs=None):
- """Create a fake resource filter.
-
- :param attrs: A dictionary with all attributes of resource filter
- :return: A FakeResource object with id, name, status, etc.
- """
- attrs = attrs or {}
-
- # Set default attribute
-
- resource_filter_info = {
- 'filters': [
- 'name',
- 'status',
- 'image_metadata',
- 'bootable',
- 'migration_status',
- ],
- 'resource': 'volume',
- }
-
- # Overwrite default attributes if there are some attributes set
- resource_filter_info.update(attrs)
-
- return fakes.FakeResource(None, resource_filter_info, loaded=True)
-
- @staticmethod
- def create_resource_filters(attrs=None, count=2):
- """Create multiple fake resource filters.
-
- :param attrs: A dictionary with all attributes of resource filter
- :param count: The number of resource filters to be faked
- :return: A list of FakeResource objects
- """
- resource_filters = []
- for n in range(0, count):
- resource_filters.append(
- FakeResourceFilter.create_one_resource_filter(attrs)
- )
-
- return resource_filters
-
-
-class FakeVolumeGroup:
- """Fake one or more volume groups."""
-
- @staticmethod
- def create_one_volume_group(attrs=None):
- """Create a fake group.
-
- :param attrs: A dictionary with all attributes of group
- :return: A FakeResource object with id, name, status, etc.
- """
- attrs = attrs or {}
-
- group_type = attrs.pop('group_type', None) or uuid.uuid4().hex
- volume_types = attrs.pop('volume_types', None) or [uuid.uuid4().hex]
-
- # Set default attribute
- group_info = {
- 'id': uuid.uuid4().hex,
- 'status': random.choice([
+create_one_volume = volume_v2_fakes.create_one_volume
+create_one_volume_type = volume_v2_fakes.create_one_volume_type
+
+
+def create_one_cluster(attrs=None):
+ """Create a fake service cluster.
+
+ :param attrs: A dictionary with all attributes of service cluster
+ :return: A FakeResource object with id, name, status, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ cluster_info = {
+ 'name': f'cluster-{uuid.uuid4().hex}',
+ 'binary': f'binary-{uuid.uuid4().hex}',
+ 'state': random.choice(['up', 'down']),
+ 'status': random.choice(['enabled', 'disabled']),
+ 'disabled_reason': None,
+ 'num_hosts': random.randint(1, 64),
+ 'num_down_hosts': random.randint(1, 64),
+ 'last_heartbeat': '2015-09-16T09:28:52.000000',
+ 'created_at': '2015-09-16T09:28:52.000000',
+ 'updated_at': '2015-09-16T09:28:52.000000',
+ 'replication_status': None,
+ 'frozen': False,
+ 'active_backend_id': None,
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ cluster_info.update(attrs)
+
+ return fakes.FakeResource(None, cluster_info, loaded=True)
+
+
+def create_clusters(attrs=None, count=2):
+ """Create multiple fake service clusters.
+
+ :param attrs: A dictionary with all attributes of service cluster
+ :param count: The number of service clusters to be faked
+ :return: A list of FakeResource objects
+ """
+ clusters = []
+ for n in range(0, count):
+ clusters.append(create_one_cluster(attrs))
+
+ return clusters
+
+
+def create_one_resource_filter(attrs=None):
+ """Create a fake resource filter.
+
+ :param attrs: A dictionary with all attributes of resource filter
+ :return: A FakeResource object with id, name, status, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+
+ resource_filter_info = {
+ 'filters': [
+ 'name',
+ 'status',
+ 'image_metadata',
+ 'bootable',
+ 'migration_status',
+ ],
+ 'resource': 'volume',
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ resource_filter_info.update(attrs)
+
+ return fakes.FakeResource(None, resource_filter_info, loaded=True)
+
+
+def create_resource_filters(attrs=None, count=2):
+ """Create multiple fake resource filters.
+
+ :param attrs: A dictionary with all attributes of resource filter
+ :param count: The number of resource filters to be faked
+ :return: A list of FakeResource objects
+ """
+ resource_filters = []
+ for n in range(0, count):
+ resource_filters.append(create_one_resource_filter(attrs))
+
+ return resource_filters
+
+
+def create_one_volume_group(attrs=None):
+ """Create a fake group.
+
+ :param attrs: A dictionary with all attributes of group
+ :return: A FakeResource object with id, name, status, etc.
+ """
+ attrs = attrs or {}
+
+ group_type = attrs.pop('group_type', None) or uuid.uuid4().hex
+ volume_types = attrs.pop('volume_types', None) or [uuid.uuid4().hex]
+
+ # Set default attribute
+ group_info = {
+ 'id': uuid.uuid4().hex,
+ 'status': random.choice(
+ [
'available',
- ]),
- 'availability_zone': f'az-{uuid.uuid4().hex}',
- 'created_at': '2015-09-16T09:28:52.000000',
- 'name': 'first_group',
- 'description': f'description-{uuid.uuid4().hex}',
- 'group_type': group_type,
- 'volume_types': volume_types,
- 'volumes': [f'volume-{uuid.uuid4().hex}'],
- 'group_snapshot_id': None,
- 'source_group_id': None,
- 'project_id': f'project-{uuid.uuid4().hex}',
- }
-
- # Overwrite default attributes if there are some attributes set
- group_info.update(attrs)
-
- group = fakes.FakeResource(
- None,
- group_info,
- loaded=True)
- return group
-
- @staticmethod
- def create_volume_groups(attrs=None, count=2):
- """Create multiple fake groups.
-
- :param attrs: A dictionary with all attributes of group
- :param count: The number of groups to be faked
- :return: A list of FakeResource objects
- """
- groups = []
- for n in range(0, count):
- groups.append(FakeVolumeGroup.create_one_volume_group(attrs))
-
- return groups
-
-
-class FakeVolumeGroupSnapshot:
- """Fake one or more volume group snapshots."""
-
- @staticmethod
- def create_one_volume_group_snapshot(attrs=None, methods=None):
- """Create a fake group snapshot.
-
- :param attrs: A dictionary with all attributes
- :param methods: A dictionary with all methods
- :return: A FakeResource object with id, name, description, etc.
- """
- attrs = attrs or {}
-
- # Set default attribute
- group_snapshot_info = {
- 'id': uuid.uuid4().hex,
- 'name': f'group-snapshot-{uuid.uuid4().hex}',
- 'description': f'description-{uuid.uuid4().hex}',
- 'status': random.choice(['available']),
- 'group_id': uuid.uuid4().hex,
- 'group_type_id': uuid.uuid4().hex,
- 'project_id': uuid.uuid4().hex,
- }
-
- # Overwrite default attributes if there are some attributes set
- group_snapshot_info.update(attrs)
-
- group_snapshot = fakes.FakeResource(
- None,
- group_snapshot_info,
- methods=methods,
- loaded=True)
- return group_snapshot
-
- @staticmethod
- def create_volume_group_snapshots(attrs=None, count=2):
- """Create multiple fake group snapshots.
-
- :param attrs: A dictionary with all attributes of group snapshot
- :param count: The number of group snapshots to be faked
- :return: A list of FakeResource objects
- """
- group_snapshots = []
- for n in range(0, count):
- group_snapshots.append(
- FakeVolumeGroupSnapshot.create_one_volume_group_snapshot(attrs)
- )
-
- return group_snapshots
-
-
-class FakeVolumeGroupType:
- """Fake one or more volume group types."""
-
- @staticmethod
- def create_one_volume_group_type(attrs=None, methods=None):
- """Create a fake group type.
-
- :param attrs: A dictionary with all attributes of group type
- :param methods: A dictionary with all methods
- :return: A FakeResource object with id, name, description, etc.
- """
- attrs = attrs or {}
-
- # Set default attribute
- group_type_info = {
- 'id': uuid.uuid4().hex,
- 'name': f'group-type-{uuid.uuid4().hex}',
- 'description': f'description-{uuid.uuid4().hex}',
- 'is_public': random.choice([True, False]),
- 'group_specs': {},
- }
-
- # Overwrite default attributes if there are some attributes set
- group_type_info.update(attrs)
-
- group_type = fakes.FakeResource(
- None,
- group_type_info,
- methods=methods,
- loaded=True)
- return group_type
-
- @staticmethod
- def create_volume_group_types(attrs=None, count=2):
- """Create multiple fake group types.
-
- :param attrs: A dictionary with all attributes of group type
- :param count: The number of group types to be faked
- :return: A list of FakeResource objects
- """
- group_types = []
- for n in range(0, count):
- group_types.append(
- FakeVolumeGroupType.create_one_volume_group_type(attrs)
- )
-
- return group_types
-
-
-class FakeVolumeMessage:
- """Fake one or more volume messages."""
-
- @staticmethod
- def create_one_volume_message(attrs=None):
- """Create a fake message.
-
- :param attrs: A dictionary with all attributes of message
- :return: A FakeResource object with id, name, status, etc.
- """
- attrs = attrs or {}
-
- # Set default attribute
- message_info = {
- 'created_at': '2016-02-11T11:17:37.000000',
- 'event_id': f'VOLUME_{random.randint(1, 999999):06d}',
- 'guaranteed_until': '2016-02-11T11:17:37.000000',
- 'id': uuid.uuid4().hex,
- 'message_level': 'ERROR',
- 'request_id': f'req-{uuid.uuid4().hex}',
- 'resource_type': 'VOLUME',
- 'resource_uuid': uuid.uuid4().hex,
- 'user_message': f'message-{uuid.uuid4().hex}',
- }
-
- # Overwrite default attributes if there are some attributes set
- message_info.update(attrs)
-
- return fakes.FakeResource(
- None,
- message_info,
- loaded=True)
-
- @staticmethod
- def create_volume_messages(attrs=None, count=2):
- """Create multiple fake messages.
-
- :param attrs: A dictionary with all attributes of message
- :param count: The number of messages to be faked
- :return: A list of FakeResource objects
- """
- messages = []
- for n in range(0, count):
- messages.append(FakeVolumeMessage.create_one_volume_message(attrs))
-
- return messages
-
- @staticmethod
- def get_volume_messages(messages=None, count=2):
- """Get an iterable MagicMock object with a list of faked messages.
-
- If messages list is provided, then initialize the Mock object with the
- list. Otherwise create one.
-
- :param messages: A list of FakeResource objects faking messages
- :param count: The number of messages to be faked
- :return An iterable Mock object with side_effect set to a list of faked
- messages
- """
- if messages is None:
- messages = FakeVolumeMessage.create_messages(count)
-
- return mock.Mock(side_effect=messages)
-
-
-class FakeVolumeAttachment:
- """Fake one or more volume attachments."""
-
- @staticmethod
- def create_one_volume_attachment(attrs=None):
- """Create a fake volume attachment.
-
- :param attrs: A dictionary with all attributes of volume attachment
- :return: A FakeResource object with id, status, etc.
- """
- attrs = attrs or {}
-
- attachment_id = uuid.uuid4().hex
- volume_id = attrs.pop('volume_id', None) or uuid.uuid4().hex
- server_id = attrs.pop('instance', None) or uuid.uuid4().hex
-
- # Set default attribute
- attachment_info = {
- 'id': attachment_id,
- 'volume_id': volume_id,
- 'instance': server_id,
- 'status': random.choice([
+ ]
+ ),
+ 'availability_zone': f'az-{uuid.uuid4().hex}',
+ 'created_at': '2015-09-16T09:28:52.000000',
+ 'name': 'first_group',
+ 'description': f'description-{uuid.uuid4().hex}',
+ 'group_type': group_type,
+ 'volume_types': volume_types,
+ 'volumes': [f'volume-{uuid.uuid4().hex}'],
+ 'group_snapshot_id': None,
+ 'source_group_id': None,
+ 'project_id': f'project-{uuid.uuid4().hex}',
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ group_info.update(attrs)
+
+ group = fakes.FakeResource(None, group_info, loaded=True)
+ return group
+
+
+def create_volume_groups(attrs=None, count=2):
+ """Create multiple fake groups.
+
+ :param attrs: A dictionary with all attributes of group
+ :param count: The number of groups to be faked
+ :return: A list of FakeResource objects
+ """
+ groups = []
+ for n in range(0, count):
+ groups.append(create_one_volume_group(attrs))
+
+ return groups
+
+
+def create_one_volume_group_snapshot(attrs=None, methods=None):
+ """Create a fake group snapshot.
+
+ :param attrs: A dictionary with all attributes
+ :param methods: A dictionary with all methods
+ :return: A FakeResource object with id, name, description, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ group_snapshot_info = {
+ 'id': uuid.uuid4().hex,
+ 'name': f'group-snapshot-{uuid.uuid4().hex}',
+ 'description': f'description-{uuid.uuid4().hex}',
+ 'status': random.choice(['available']),
+ 'group_id': uuid.uuid4().hex,
+ 'group_type_id': uuid.uuid4().hex,
+ 'project_id': uuid.uuid4().hex,
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ group_snapshot_info.update(attrs)
+
+ group_snapshot = fakes.FakeResource(
+ None, group_snapshot_info, methods=methods, loaded=True
+ )
+ return group_snapshot
+
+
+def create_volume_group_snapshots(attrs=None, count=2):
+ """Create multiple fake group snapshots.
+
+ :param attrs: A dictionary with all attributes of group snapshot
+ :param count: The number of group snapshots to be faked
+ :return: A list of FakeResource objects
+ """
+ group_snapshots = []
+ for n in range(0, count):
+ group_snapshots.append(create_one_volume_group_snapshot(attrs))
+
+ return group_snapshots
+
+
+def create_one_volume_group_type(attrs=None, methods=None):
+ """Create a fake group type.
+
+ :param attrs: A dictionary with all attributes of group type
+ :param methods: A dictionary with all methods
+ :return: A FakeResource object with id, name, description, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ group_type_info = {
+ 'id': uuid.uuid4().hex,
+ 'name': f'group-type-{uuid.uuid4().hex}',
+ 'description': f'description-{uuid.uuid4().hex}',
+ 'is_public': random.choice([True, False]),
+ 'group_specs': {},
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ group_type_info.update(attrs)
+
+ group_type = fakes.FakeResource(
+ None, group_type_info, methods=methods, loaded=True
+ )
+ return group_type
+
+
+def create_volume_group_types(attrs=None, count=2):
+ """Create multiple fake group types.
+
+ :param attrs: A dictionary with all attributes of group type
+ :param count: The number of group types to be faked
+ :return: A list of FakeResource objects
+ """
+ group_types = []
+ for n in range(0, count):
+ group_types.append(create_one_volume_group_type(attrs))
+
+ return group_types
+
+
+def create_one_volume_message(attrs=None):
+ """Create a fake message.
+
+ :param attrs: A dictionary with all attributes of message
+ :return: A FakeResource object with id, name, status, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ message_info = {
+ 'created_at': '2016-02-11T11:17:37.000000',
+ 'event_id': f'VOLUME_{random.randint(1, 999999):06d}',
+ 'guaranteed_until': '2016-02-11T11:17:37.000000',
+ 'id': uuid.uuid4().hex,
+ 'message_level': 'ERROR',
+ 'request_id': f'req-{uuid.uuid4().hex}',
+ 'resource_type': 'VOLUME',
+ 'resource_uuid': uuid.uuid4().hex,
+ 'user_message': f'message-{uuid.uuid4().hex}',
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ message_info.update(attrs)
+
+ return fakes.FakeResource(None, message_info, loaded=True)
+
+
+def create_volume_messages(attrs=None, count=2):
+ """Create multiple fake messages.
+
+ :param attrs: A dictionary with all attributes of message
+ :param count: The number of messages to be faked
+ :return: A list of FakeResource objects
+ """
+ messages = []
+ for n in range(0, count):
+ messages.append(create_one_volume_message(attrs))
+
+ return messages
+
+
+def get_volume_messages(messages=None, count=2):
+ """Get an iterable MagicMock object with a list of faked messages.
+
+ If messages list is provided, then initialize the Mock object with the
+ list. Otherwise create one.
+
+ :param messages: A list of FakeResource objects faking messages
+ :param count: The number of messages to be faked
+ :return An iterable Mock object with side_effect set to a list of faked
+ messages
+ """
+ if messages is None:
+ messages = create_volume_messages(count)
+
+ return mock.Mock(side_effect=messages)
+
+
+def create_one_volume_attachment(attrs=None):
+ """Create a fake volume attachment.
+
+ :param attrs: A dictionary with all attributes of volume attachment
+ :return: A FakeResource object with id, status, etc.
+ """
+ attrs = attrs or {}
+
+ attachment_id = uuid.uuid4().hex
+ volume_id = attrs.pop('volume_id', None) or uuid.uuid4().hex
+ server_id = attrs.pop('instance', None) or uuid.uuid4().hex
+
+ # Set default attribute
+ attachment_info = {
+ 'id': attachment_id,
+ 'volume_id': volume_id,
+ 'instance': server_id,
+ 'status': random.choice(
+ [
'attached',
'attaching',
'detached',
@@ -424,67 +376,63 @@ class FakeVolumeAttachment:
'error_attaching',
'error_detaching',
'deleted',
- ]),
- 'attach_mode': random.choice(['ro', 'rw']),
- 'attached_at': '2015-09-16T09:28:52.000000',
- 'detached_at': None,
- 'connection_info': {
- 'access_mode': 'rw',
- 'attachment_id': attachment_id,
- 'auth_method': 'CHAP',
- 'auth_password': 'AcUZ8PpxLHwzypMC',
- 'auth_username': '7j3EZQWT3rbE6pcSGKvK',
- 'cacheable': False,
- 'driver_volume_type': 'iscsi',
- 'encrypted': False,
- 'qos_specs': None,
- 'target_discovered': False,
- 'target_iqn':
- f'iqn.2010-10.org.openstack:volume-{attachment_id}',
- 'target_lun': '1',
- 'target_portal': '192.168.122.170:3260',
- 'volume_id': volume_id,
- },
- }
-
- # Overwrite default attributes if there are some attributes set
- attachment_info.update(attrs)
-
- return fakes.FakeResource(
- None,
- attachment_info,
- loaded=True)
-
- @staticmethod
- def create_volume_attachments(attrs=None, count=2):
- """Create multiple fake volume attachments.
-
- :param attrs: A dictionary with all attributes of volume attachment
- :param count: The number of volume attachments to be faked
- :return: A list of FakeResource objects
- """
- attachments = []
-
- for n in range(0, count):
- attachments.append(
- FakeVolumeAttachment.create_one_volume_attachment(attrs))
-
- return attachments
-
- @staticmethod
- def get_volume_attachments(attachments=None, count=2):
- """Get an iterable MagicMock object with a list of faked volumes.
-
- If attachments list is provided, then initialize the Mock object with
- the list. Otherwise create one.
-
- :param attachments: A list of FakeResource objects faking volume
- attachments
- :param count: The number of volume attachments to be faked
- :return An iterable Mock object with side_effect set to a list of faked
- volume attachments
- """
- if attachments is None:
- attachments = FakeVolumeAttachment.create_volume_attachments(count)
-
- return mock.Mock(side_effect=attachments)
+ ]
+ ),
+ 'attach_mode': random.choice(['ro', 'rw']),
+ 'attached_at': '2015-09-16T09:28:52.000000',
+ 'detached_at': None,
+ 'connection_info': {
+ 'access_mode': 'rw',
+ 'attachment_id': attachment_id,
+ 'auth_method': 'CHAP',
+ 'auth_password': 'AcUZ8PpxLHwzypMC',
+ 'auth_username': '7j3EZQWT3rbE6pcSGKvK',
+ 'cacheable': False,
+ 'driver_volume_type': 'iscsi',
+ 'encrypted': False,
+ 'qos_specs': None,
+ 'target_discovered': False,
+ 'target_iqn': f'iqn.2010-10.org.openstack:volume-{attachment_id}',
+ 'target_lun': '1',
+ 'target_portal': '192.168.122.170:3260',
+ 'volume_id': volume_id,
+ },
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ attachment_info.update(attrs)
+
+ return fakes.FakeResource(None, attachment_info, loaded=True)
+
+
+def create_volume_attachments(attrs=None, count=2):
+ """Create multiple fake volume attachments.
+
+ :param attrs: A dictionary with all attributes of volume attachment
+ :param count: The number of volume attachments to be faked
+ :return: A list of FakeResource objects
+ """
+ attachments = []
+
+ for n in range(0, count):
+ attachments.append(create_one_volume_attachment(attrs))
+
+ return attachments
+
+
+def get_volume_attachments(attachments=None, count=2):
+ """Get an iterable MagicMock object with a list of faked volumes.
+
+ If attachments list is provided, then initialize the Mock object with
+ the list. Otherwise create one.
+
+ :param attachments: A list of FakeResource objects faking volume
+ attachments
+ :param count: The number of volume attachments to be faked
+ :return An iterable Mock object with side_effect set to a list of faked
+ volume attachments
+ """
+ if attachments is None:
+ attachments = create_volume_attachments(count)
+
+ return mock.Mock(side_effect=attachments)
diff --git a/openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py b/openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py
index d87a946b..fdfd1100 100644
--- a/openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py
+++ b/openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py
@@ -30,7 +30,7 @@ class TestBlockStorageCluster(volume_fakes.TestVolume):
class TestBlockStorageClusterList(TestBlockStorageCluster):
# The cluster to be listed
- fake_clusters = volume_fakes.FakeCluster.create_clusters()
+ fake_clusters = volume_fakes.create_clusters()
def setUp(self):
super().setUp()
@@ -176,7 +176,7 @@ class TestBlockStorageClusterList(TestBlockStorageCluster):
class TestBlockStorageClusterSet(TestBlockStorageCluster):
- cluster = volume_fakes.FakeCluster.create_one_cluster()
+ cluster = volume_fakes.create_one_cluster()
columns = (
'Name',
'Binary',
@@ -347,7 +347,7 @@ class TestBlockStorageClusterSet(TestBlockStorageCluster):
class TestBlockStorageClusterShow(TestBlockStorageCluster):
- cluster = volume_fakes.FakeCluster.create_one_cluster()
+ cluster = volume_fakes.create_one_cluster()
columns = (
'Name',
'Binary',
diff --git a/openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py b/openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py
index b886726d..086339ff 100644
--- a/openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py
+++ b/openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py
@@ -31,8 +31,7 @@ class TestBlockStorageResourceFilter(volume_fakes.TestVolume):
class TestBlockStorageResourceFilterList(TestBlockStorageResourceFilter):
# The resource filters to be listed
- fake_resource_filters = \
- volume_fakes.FakeResourceFilter.create_resource_filters()
+ fake_resource_filters = volume_fakes.create_resource_filters()
def setUp(self):
super().setUp()
@@ -86,8 +85,7 @@ class TestBlockStorageResourceFilterList(TestBlockStorageResourceFilter):
class TestBlockStorageResourceFilterShow(TestBlockStorageResourceFilter):
# The resource filters to be listed
- fake_resource_filter = \
- volume_fakes.FakeResourceFilter.create_one_resource_filter()
+ fake_resource_filter = volume_fakes.create_one_resource_filter()
def setUp(self):
super().setUp()
diff --git a/openstackclient/tests/unit/volume/v3/test_volume_attachment.py b/openstackclient/tests/unit/volume/v3/test_volume_attachment.py
index 44fac6c5..c0bf5ae7 100644
--- a/openstackclient/tests/unit/volume/v3/test_volume_attachment.py
+++ b/openstackclient/tests/unit/volume/v3/test_volume_attachment.py
@@ -41,11 +41,11 @@ class TestVolumeAttachment(volume_fakes.TestVolume):
class TestVolumeAttachmentCreate(TestVolumeAttachment):
- volume = volume_fakes.FakeVolume.create_one_volume()
+ volume = volume_fakes.create_one_volume()
server = compute_fakes.FakeServer.create_one_server()
- volume_attachment = \
- volume_fakes.FakeVolumeAttachment.create_one_volume_attachment(
- attrs={'instance': server.id, 'volume_id': volume.id})
+ volume_attachment = volume_fakes.create_one_volume_attachment(
+ attrs={'instance': server.id, 'volume_id': volume.id},
+ )
columns = (
'ID',
@@ -238,8 +238,7 @@ class TestVolumeAttachmentCreate(TestVolumeAttachment):
class TestVolumeAttachmentDelete(TestVolumeAttachment):
- volume_attachment = \
- volume_fakes.FakeVolumeAttachment.create_one_volume_attachment()
+ volume_attachment = volume_fakes.create_one_volume_attachment()
def setUp(self):
super().setUp()
@@ -290,8 +289,7 @@ class TestVolumeAttachmentDelete(TestVolumeAttachment):
class TestVolumeAttachmentSet(TestVolumeAttachment):
- volume_attachment = \
- volume_fakes.FakeVolumeAttachment.create_one_volume_attachment()
+ volume_attachment = volume_fakes.create_one_volume_attachment()
columns = (
'ID',
@@ -391,8 +389,7 @@ class TestVolumeAttachmentSet(TestVolumeAttachment):
class TestVolumeAttachmentComplete(TestVolumeAttachment):
- volume_attachment = \
- volume_fakes.FakeVolumeAttachment.create_one_volume_attachment()
+ volume_attachment = volume_fakes.create_one_volume_attachment()
def setUp(self):
super().setUp()
@@ -444,8 +441,7 @@ class TestVolumeAttachmentComplete(TestVolumeAttachment):
class TestVolumeAttachmentList(TestVolumeAttachment):
project = identity_fakes.FakeProject.create_one_project()
- volume_attachments = \
- volume_fakes.FakeVolumeAttachment.create_volume_attachments()
+ volume_attachments = volume_fakes.create_volume_attachments()
columns = (
'ID',
diff --git a/openstackclient/tests/unit/volume/v3/test_volume_group.py b/openstackclient/tests/unit/volume/v3/test_volume_group.py
index 13ef38d2..96079a08 100644
--- a/openstackclient/tests/unit/volume/v3/test_volume_group.py
+++ b/openstackclient/tests/unit/volume/v3/test_volume_group.py
@@ -35,10 +35,9 @@ class TestVolumeGroup(volume_fakes.TestVolume):
class TestVolumeGroupCreate(TestVolumeGroup):
- fake_volume_type = volume_fakes.FakeVolumeType.create_one_volume_type()
- fake_volume_group_type = \
- volume_fakes.FakeVolumeGroupType.create_one_volume_group_type()
- fake_volume_group = volume_fakes.FakeVolumeGroup.create_one_volume_group(
+ fake_volume_type = volume_fakes.create_one_volume_type()
+ fake_volume_group_type = volume_fakes.create_one_volume_group_type()
+ fake_volume_group = volume_fakes.create_one_volume_group(
attrs={
'group_type': fake_volume_group_type.id,
'volume_types': [fake_volume_type.id],
@@ -180,8 +179,7 @@ class TestVolumeGroupCreate(TestVolumeGroup):
class TestVolumeGroupDelete(TestVolumeGroup):
- fake_volume_group = \
- volume_fakes.FakeVolumeGroup.create_one_volume_group()
+ fake_volume_group = volume_fakes.create_one_volume_group()
def setUp(self):
super().setUp()
@@ -236,8 +234,7 @@ class TestVolumeGroupDelete(TestVolumeGroup):
class TestVolumeGroupSet(TestVolumeGroup):
- fake_volume_group = \
- volume_fakes.FakeVolumeGroup.create_one_volume_group()
+ fake_volume_group = volume_fakes.create_one_volume_group()
columns = (
'ID',
@@ -368,8 +365,7 @@ class TestVolumeGroupSet(TestVolumeGroup):
class TestVolumeGroupList(TestVolumeGroup):
- fake_volume_groups = \
- volume_fakes.FakeVolumeGroup.create_volume_groups()
+ fake_volume_groups = volume_fakes.create_volume_groups()
columns = (
'ID',
@@ -436,8 +432,7 @@ class TestVolumeGroupList(TestVolumeGroup):
class TestVolumeGroupFailover(TestVolumeGroup):
- fake_volume_group = \
- volume_fakes.FakeVolumeGroup.create_one_volume_group()
+ fake_volume_group = volume_fakes.create_one_volume_group()
def setUp(self):
super().setUp()
diff --git a/openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py b/openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py
index 509d9f08..2a5a30f0 100644
--- a/openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py
+++ b/openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py
@@ -32,9 +32,9 @@ class TestVolumeGroupSnapshot(volume_fakes.TestVolume):
class TestVolumeGroupSnapshotCreate(TestVolumeGroupSnapshot):
- fake_volume_group = volume_fakes.FakeVolumeGroup.create_one_volume_group()
+ fake_volume_group = volume_fakes.create_one_volume_group()
fake_volume_group_snapshot = \
- volume_fakes.FakeVolumeGroupSnapshot.create_one_volume_group_snapshot()
+ volume_fakes.create_one_volume_group_snapshot()
columns = (
'ID',
@@ -141,7 +141,7 @@ class TestVolumeGroupSnapshotCreate(TestVolumeGroupSnapshot):
class TestVolumeGroupSnapshotDelete(TestVolumeGroupSnapshot):
fake_volume_group_snapshot = \
- volume_fakes.FakeVolumeGroupSnapshot.create_one_volume_group_snapshot()
+ volume_fakes.create_one_volume_group_snapshot()
def setUp(self):
super().setUp()
@@ -195,8 +195,7 @@ class TestVolumeGroupSnapshotDelete(TestVolumeGroupSnapshot):
class TestVolumeGroupSnapshotList(TestVolumeGroupSnapshot):
- fake_volume_group_snapshots = \
- volume_fakes.FakeVolumeGroupSnapshot.create_volume_group_snapshots()
+ fake_volume_group_snapshots = volume_fakes.create_volume_group_snapshots()
columns = (
'ID',
diff --git a/openstackclient/tests/unit/volume/v3/test_volume_group_type.py b/openstackclient/tests/unit/volume/v3/test_volume_group_type.py
index 7e758a2c..34b4e501 100644
--- a/openstackclient/tests/unit/volume/v3/test_volume_group_type.py
+++ b/openstackclient/tests/unit/volume/v3/test_volume_group_type.py
@@ -34,8 +34,7 @@ class TestVolumeGroupTypeCreate(TestVolumeGroupType):
maxDiff = 2000
- fake_volume_group_type = \
- volume_fakes.FakeVolumeGroupType.create_one_volume_group_type()
+ fake_volume_group_type = volume_fakes.create_one_volume_group_type()
columns = (
'ID',
@@ -133,8 +132,7 @@ class TestVolumeGroupTypeCreate(TestVolumeGroupType):
class TestVolumeGroupTypeDelete(TestVolumeGroupType):
- fake_volume_group_type = \
- volume_fakes.FakeVolumeGroupType.create_one_volume_group_type()
+ fake_volume_group_type = volume_fakes.create_one_volume_group_type()
def setUp(self):
super().setUp()
@@ -187,13 +185,13 @@ class TestVolumeGroupTypeDelete(TestVolumeGroupType):
class TestVolumeGroupTypeSet(TestVolumeGroupType):
- fake_volume_group_type = \
- volume_fakes.FakeVolumeGroupType.create_one_volume_group_type(
- methods={
- 'get_keys': {'foo': 'bar'},
- 'set_keys': None,
- 'unset_keys': None,
- })
+ fake_volume_group_type = volume_fakes.create_one_volume_group_type(
+ methods={
+ 'get_keys': {'foo': 'bar'},
+ 'set_keys': None,
+ 'unset_keys': None,
+ },
+ )
columns = (
'ID',
@@ -316,9 +314,9 @@ class TestVolumeGroupTypeSet(TestVolumeGroupType):
class TestVolumeGroupTypeUnset(TestVolumeGroupType):
- fake_volume_group_type = \
- volume_fakes.FakeVolumeGroupType.create_one_volume_group_type(
- methods={'unset_keys': None})
+ fake_volume_group_type = volume_fakes.create_one_volume_group_type(
+ methods={'unset_keys': None},
+ )
columns = (
'ID',
@@ -393,8 +391,7 @@ class TestVolumeGroupTypeUnset(TestVolumeGroupType):
class TestVolumeGroupTypeList(TestVolumeGroupType):
- fake_volume_group_types = \
- volume_fakes.FakeVolumeGroupType.create_volume_group_types()
+ fake_volume_group_types = volume_fakes.create_volume_group_types()
columns = (
'ID',
diff --git a/openstackclient/tests/unit/volume/v3/test_volume_message.py b/openstackclient/tests/unit/volume/v3/test_volume_message.py
index 8cabc0c3..45b0747e 100644
--- a/openstackclient/tests/unit/volume/v3/test_volume_message.py
+++ b/openstackclient/tests/unit/volume/v3/test_volume_message.py
@@ -34,15 +34,14 @@ class TestVolumeMessage(volume_fakes.TestVolume):
class TestVolumeMessageDelete(TestVolumeMessage):
- fake_messages = volume_fakes.FakeVolumeMessage.create_volume_messages(
- count=2)
+ fake_messages = volume_fakes.create_volume_messages(count=2)
def setUp(self):
super().setUp()
- self.volume_messages_mock.get = \
- volume_fakes.FakeVolumeMessage.get_volume_messages(
- self.fake_messages)
+ self.volume_messages_mock.get = volume_fakes.get_volume_messages(
+ self.fake_messages,
+ )
self.volume_messages_mock.delete.return_value = None
# Get the command object to mock
@@ -139,8 +138,7 @@ class TestVolumeMessageDelete(TestVolumeMessage):
class TestVolumeMessageList(TestVolumeMessage):
fake_project = identity_fakes.FakeProject.create_one_project()
- fake_messages = volume_fakes.FakeVolumeMessage.create_volume_messages(
- count=3)
+ fake_messages = volume_fakes.create_volume_messages(count=3)
columns = (
'ID',
@@ -253,7 +251,7 @@ class TestVolumeMessageList(TestVolumeMessage):
class TestVolumeMessageShow(TestVolumeMessage):
- fake_message = volume_fakes.FakeVolumeMessage.create_one_volume_message()
+ fake_message = volume_fakes.create_one_volume_message()
columns = (
'created_at',