Merge "tests: Use fake SDK Migration object"
This commit is contained in:
@@ -21,6 +21,7 @@ import uuid
|
|||||||
from novaclient import api_versions
|
from novaclient import api_versions
|
||||||
from openstack.compute.v2 import flavor as _flavor
|
from openstack.compute.v2 import flavor as _flavor
|
||||||
from openstack.compute.v2 import hypervisor as _hypervisor
|
from openstack.compute.v2 import hypervisor as _hypervisor
|
||||||
|
from openstack.compute.v2 import migration as _migration
|
||||||
from openstack.compute.v2 import server as _server
|
from openstack.compute.v2 import server as _server
|
||||||
from openstack.compute.v2 import server_group as _server_group
|
from openstack.compute.v2 import server_group as _server_group
|
||||||
from openstack.compute.v2 import server_interface as _server_interface
|
from openstack.compute.v2 import server_interface as _server_interface
|
||||||
@@ -1433,71 +1434,53 @@ class FakeRateLimit(object):
|
|||||||
self.next_available = next_available
|
self.next_available = next_available
|
||||||
|
|
||||||
|
|
||||||
class FakeMigration(object):
|
def create_one_migration(attrs=None):
|
||||||
"""Fake one or more migrations."""
|
"""Create a fake migration.
|
||||||
|
|
||||||
@staticmethod
|
:param dict attrs: A dictionary with all attributes
|
||||||
def create_one_migration(attrs=None, methods=None):
|
:return: A fake openstack.compute.v2.migration.Migration object
|
||||||
"""Create a fake migration.
|
"""
|
||||||
|
attrs = attrs or {}
|
||||||
|
|
||||||
:param dict attrs:
|
# Set default attributes.
|
||||||
A dictionary with all attributes
|
migration_info = {
|
||||||
:param dict methods:
|
"created_at": "2017-01-31T08:03:21.000000",
|
||||||
A dictionary with all methods
|
"dest_compute": "compute-" + uuid.uuid4().hex,
|
||||||
:return:
|
"dest_host": "10.0.2.15",
|
||||||
A FakeResource object, with id, type, and so on
|
"dest_node": "node-" + uuid.uuid4().hex,
|
||||||
"""
|
"id": random.randint(1, 999),
|
||||||
attrs = attrs or {}
|
"migration_type": "migration",
|
||||||
methods = methods or {}
|
"new_flavor_id": uuid.uuid4().hex,
|
||||||
|
"old_flavor_id": uuid.uuid4().hex,
|
||||||
|
"project_id": uuid.uuid4().hex,
|
||||||
|
"server_id": uuid.uuid4().hex,
|
||||||
|
"source_compute": "compute-" + uuid.uuid4().hex,
|
||||||
|
"source_node": "node-" + uuid.uuid4().hex,
|
||||||
|
"status": "migrating",
|
||||||
|
"updated_at": "2017-01-31T08:03:25.000000",
|
||||||
|
"user_id": uuid.uuid4().hex,
|
||||||
|
"uuid": uuid.uuid4().hex,
|
||||||
|
}
|
||||||
|
|
||||||
# Set default attributes.
|
# Overwrite default attributes.
|
||||||
migration_info = {
|
migration_info.update(attrs)
|
||||||
"dest_host": "10.0.2.15",
|
|
||||||
"status": "migrating",
|
|
||||||
"migration_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,
|
|
||||||
"instance_uuid": 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_id": uuid.uuid4().hex,
|
|
||||||
"user_id": uuid.uuid4().hex
|
|
||||||
}
|
|
||||||
|
|
||||||
# Overwrite default attributes.
|
migration = _migration.Migration(**migration_info)
|
||||||
migration_info.update(attrs)
|
return migration
|
||||||
|
|
||||||
migration = fakes.FakeResource(info=copy.deepcopy(migration_info),
|
|
||||||
methods=methods,
|
|
||||||
loaded=True)
|
|
||||||
return migration
|
|
||||||
|
|
||||||
@staticmethod
|
def create_migrations(attrs=None, count=2):
|
||||||
def create_migrations(attrs=None, methods=None, count=2):
|
"""Create multiple fake migrations.
|
||||||
"""Create multiple fake migrations.
|
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:param int count: The number of migrations to fake
|
||||||
:param dict methods:
|
:return: A list of fake openstack.compute.v2.migration.Migration objects
|
||||||
A dictionary with all methods
|
"""
|
||||||
:param int count:
|
migrations = []
|
||||||
The number of migrations to fake
|
for i in range(0, count):
|
||||||
:return:
|
migrations.append(create_one_migration(attrs))
|
||||||
A list of FakeResource objects faking the migrations
|
|
||||||
"""
|
|
||||||
migrations = []
|
|
||||||
for i in range(0, count):
|
|
||||||
migrations.append(
|
|
||||||
FakeMigration.create_one_migration(
|
|
||||||
attrs, methods))
|
|
||||||
|
|
||||||
return migrations
|
return migrations
|
||||||
|
|
||||||
|
|
||||||
class FakeServerMigration(object):
|
class FakeServerMigration(object):
|
||||||
|
@@ -59,11 +59,10 @@ class TestListMigration(TestServerMigration):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.server = compute_fakes.FakeServer.create_one_server()
|
self.server = compute_fakes.FakeServer.create_one_sdk_server()
|
||||||
self.sdk_client.find_server.return_value = self.server
|
self.sdk_client.find_server.return_value = self.server
|
||||||
|
|
||||||
self.migrations = compute_fakes.FakeMigration.create_migrations(
|
self.migrations = compute_fakes.create_migrations(count=3)
|
||||||
count=3)
|
|
||||||
self.sdk_client.migrations.return_value = self.migrations
|
self.sdk_client.migrations.return_value = self.migrations
|
||||||
|
|
||||||
self.data = (common_utils.get_item_properties(
|
self.data = (common_utils.get_item_properties(
|
||||||
|
Reference in New Issue
Block a user