summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/compute/v2/fakes.py
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-10-12 16:01:52 +0000
committerGerrit Code Review <review@openstack.org>2020-10-12 16:01:52 +0000
commitad2ac13c97ab51c00a69f67b8cd5027328408bc0 (patch)
tree1e0e76201f3c5454e3f92e8804d6e8f8c2c82829 /openstackclient/tests/unit/compute/v2/fakes.py
parenta48c05b90a376ce33e2f0a2d321b8c851a6ef0b0 (diff)
parentb77c28d2954a2c5861a3a6a1df29d8de448f7c08 (diff)
downloadpython-openstackclient-ad2ac13c97ab51c00a69f67b8cd5027328408bc0.tar.gz
Merge "Add server migration list CLI"
Diffstat (limited to 'openstackclient/tests/unit/compute/v2/fakes.py')
-rw-r--r--openstackclient/tests/unit/compute/v2/fakes.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py
index 31430984..6aeb5da7 100644
--- a/openstackclient/tests/unit/compute/v2/fakes.py
+++ b/openstackclient/tests/unit/compute/v2/fakes.py
@@ -14,6 +14,7 @@
#
import copy
+import random
from unittest import mock
import uuid
@@ -198,6 +199,9 @@ class FakeComputev2Client(object):
self.instance_action = mock.Mock()
self.instance_action.resource_class = fakes.FakeResource(None, {})
+ self.migrations = mock.Mock()
+ self.migrations.resource_class = fakes.FakeResource(None, {})
+
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
@@ -1570,3 +1574,89 @@ class FakeRateLimit(object):
self.remain = remain
self.unit = unit
self.next_available = next_available
+
+
+class FakeServerMigration(object):
+ """Fake one or more server migrations."""
+
+ @staticmethod
+ def create_one_server_migration(attrs=None, methods=None):
+ """Create a fake server migration.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object, with id, type, and so on
+ """
+ attrs = attrs or {}
+ methods = methods or {}
+
+ # Set default attributes.
+ migration_info = {
+ "dest_host": "10.0.2.15",
+ "status": "migrating",
+ "type": "migration",
+ "updated_at": "2017-01-31T08:03:25.000000",
+ "created_at": "2017-01-31T08:03:21.000000",
+ "dest_compute": "compute-" + uuid.uuid4().hex,
+ "id": random.randint(1, 999),
+ "source_node": "node-" + uuid.uuid4().hex,
+ "server": uuid.uuid4().hex,
+ "dest_node": "node-" + uuid.uuid4().hex,
+ "source_compute": "compute-" + uuid.uuid4().hex,
+ "uuid": uuid.uuid4().hex,
+ "old_instance_type_id": uuid.uuid4().hex,
+ "new_instance_type_id": uuid.uuid4().hex,
+ "project": uuid.uuid4().hex,
+ "user": uuid.uuid4().hex
+ }
+
+ # Overwrite default attributes.
+ migration_info.update(attrs)
+
+ migration = fakes.FakeResource(info=copy.deepcopy(migration_info),
+ methods=methods,
+ loaded=True)
+ return migration
+
+ @staticmethod
+ def create_server_migrations(attrs=None, methods=None, count=2):
+ """Create multiple fake server migrations.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :param int count:
+ The number of server migrations to fake
+ :return:
+ A list of FakeResource objects faking the server migrations
+ """
+ migrations = []
+ for i in range(0, count):
+ migrations.append(
+ FakeServerMigration.create_one_server_migration(
+ attrs, methods))
+
+ return migrations
+
+ @staticmethod
+ def get_server_migrations(migrations=None, count=2):
+ """Get an iterable MagicMock object with a list of faked migrations.
+
+ If server migrations list is provided, then initialize the Mock object
+ with the list. Otherwise create one.
+
+ :param List migrations:
+ A list of FakeResource objects faking server migrations
+ :param int count:
+ The number of server migrations to fake
+ :return:
+ An iterable Mock object with side_effect set to a list of faked
+ server migrations
+ """
+ if migrations is None:
+ migrations = FakeServerMigration.create_server_migrations(count)
+ return mock.Mock(side_effect=migrations)