summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/compute/v2/fakes.py
diff options
context:
space:
mode:
authorDiwei Zhu <zhu.diw@northeastern.edu>2021-10-28 23:25:52 +0000
committerDiwei Zhu <zhu.diw@northeastern.edu>2021-11-22 16:01:29 +0000
commit3078a0a121743c387d83d7f27ce3d8fd8fbb4ccf (patch)
tree4fae6930917e02a95c73e3ba701e254c044b53dc /openstackclient/tests/unit/compute/v2/fakes.py
parent8b394e564120984059d6424bb870c8da51a400e7 (diff)
downloadpython-openstackclient-3078a0a121743c387d83d7f27ce3d8fd8fbb4ccf.tar.gz
Switch command server add volume to sdk.
File tests.unit.volume.v2.fakes is modified to provide sdk volume fakes. File tests.unit.compute.v2.fakes is modified to provide sdk volume attachment fakes. For test, setup_sdk_volumes_mock() method is created so that volumes are created in similar way as servers are created. Change-Id: I290ba83b6ba27a1377ab73fd0ae06ecced25efd1
Diffstat (limited to 'openstackclient/tests/unit/compute/v2/fakes.py')
-rw-r--r--openstackclient/tests/unit/compute/v2/fakes.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py
index 23468ebc..7618c229 100644
--- a/openstackclient/tests/unit/compute/v2/fakes.py
+++ b/openstackclient/tests/unit/compute/v2/fakes.py
@@ -21,6 +21,7 @@ import uuid
from novaclient import api_versions
from openstack.compute.v2 import flavor as _flavor
from openstack.compute.v2 import server
+from openstack.compute.v2 import volume_attachment
from openstackclient.api import compute_v2
from openstackclient.tests.unit import fakes
@@ -1803,3 +1804,58 @@ class FakeVolumeAttachment(object):
attrs, methods))
return volume_attachments
+
+ @staticmethod
+ def create_one_sdk_volume_attachment(attrs=None, methods=None):
+ """Create a fake sdk VolumeAttachment.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param dict methods:
+ A dictionary with all methods
+ :return:
+ A fake VolumeAttachment object, with id, device, and so on
+ """
+ attrs = attrs or {}
+ methods = methods or {}
+
+ # Set default attributes.
+ volume_attachment_info = {
+ "id": uuid.uuid4().hex,
+ "device": "/dev/sdb",
+ "server_id": uuid.uuid4().hex,
+ "volume_id": uuid.uuid4().hex,
+ # introduced in API microversion 2.70
+ "tag": "foo",
+ # introduced in API microversion 2.79
+ "delete_on_termination": True,
+ # introduced in API microversion 2.89
+ "attachment_id": uuid.uuid4().hex,
+ "bdm_uuid": uuid.uuid4().hex
+ }
+
+ # Overwrite default attributes.
+ volume_attachment_info.update(attrs)
+
+ return volume_attachment.VolumeAttachment(**volume_attachment_info)
+
+ @staticmethod
+ def create_sdk_volume_attachments(attrs=None, methods=None, count=2):
+ """Create multiple fake VolumeAttachment objects (BDMs).
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param dict methods:
+ A dictionary with all methods
+ :param int count:
+ The number of volume attachments to fake
+ :return:
+ A list of VolumeAttachment objects faking the volume attachments.
+ """
+ volume_attachments = []
+ for i in range(0, count):
+ volume_attachments.append(
+ FakeVolumeAttachment.create_one_sdk_volume_attachment(
+ attrs, methods))
+
+ return volume_attachments