Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 88672d2

Browse files
committed
tests: Use fake SDK Migration object
We missed this when migrating the 'server migration list' command across. Change-Id: Ide05a0289020764829f1dbc416be5336fdf37d84 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
1 parent 5501ac7 commit 88672d2

2 files changed

Lines changed: 42 additions & 60 deletions

File tree

openstackclient/tests/unit/compute/v2/fakes.py

Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from novaclient import api_versions
2222
from openstack.compute.v2 import flavor as _flavor
2323
from openstack.compute.v2 import hypervisor as _hypervisor
24+
from openstack.compute.v2 import migration as _migration
2425
from openstack.compute.v2 import server as _server
2526
from openstack.compute.v2 import server_group as _server_group
2627
from openstack.compute.v2 import server_interface as _server_interface
@@ -1433,71 +1434,53 @@ def __init__(self, verb, uri, value, remain,
14331434
self.next_available = next_available
14341435

14351436

1436-
class FakeMigration(object):
1437-
"""Fake one or more migrations."""
1437+
def create_one_migration(attrs=None):
1438+
"""Create a fake migration.
14381439
1439-
@staticmethod
1440-
def create_one_migration(attrs=None, methods=None):
1441-
"""Create a fake migration.
1440+
:param dict attrs: A dictionary with all attributes
1441+
:return: A fake openstack.compute.v2.migration.Migration object
1442+
"""
1443+
attrs = attrs or {}
14421444

1443-
:param dict attrs:
1444-
A dictionary with all attributes
1445-
:param dict methods:
1446-
A dictionary with all methods
1447-
:return:
1448-
A FakeResource object, with id, type, and so on
1449-
"""
1450-
attrs = attrs or {}
1451-
methods = methods or {}
1445+
# Set default attributes.
1446+
migration_info = {
1447+
"created_at": "2017-01-31T08:03:21.000000",
1448+
"dest_compute": "compute-" + uuid.uuid4().hex,
1449+
"dest_host": "10.0.2.15",
1450+
"dest_node": "node-" + uuid.uuid4().hex,
1451+
"id": random.randint(1, 999),
1452+
"migration_type": "migration",
1453+
"new_flavor_id": uuid.uuid4().hex,
1454+
"old_flavor_id": uuid.uuid4().hex,
1455+
"project_id": uuid.uuid4().hex,
1456+
"server_id": uuid.uuid4().hex,
1457+
"source_compute": "compute-" + uuid.uuid4().hex,
1458+
"source_node": "node-" + uuid.uuid4().hex,
1459+
"status": "migrating",
1460+
"updated_at": "2017-01-31T08:03:25.000000",
1461+
"user_id": uuid.uuid4().hex,
1462+
"uuid": uuid.uuid4().hex,
1463+
}
14521464

1453-
# Set default attributes.
1454-
migration_info = {
1455-
"dest_host": "10.0.2.15",
1456-
"status": "migrating",
1457-
"migration_type": "migration",
1458-
"updated_at": "2017-01-31T08:03:25.000000",
1459-
"created_at": "2017-01-31T08:03:21.000000",
1460-
"dest_compute": "compute-" + uuid.uuid4().hex,
1461-
"id": random.randint(1, 999),
1462-
"source_node": "node-" + uuid.uuid4().hex,
1463-
"instance_uuid": uuid.uuid4().hex,
1464-
"dest_node": "node-" + uuid.uuid4().hex,
1465-
"source_compute": "compute-" + uuid.uuid4().hex,
1466-
"uuid": uuid.uuid4().hex,
1467-
"old_instance_type_id": uuid.uuid4().hex,
1468-
"new_instance_type_id": uuid.uuid4().hex,
1469-
"project_id": uuid.uuid4().hex,
1470-
"user_id": uuid.uuid4().hex
1471-
}
1465+
# Overwrite default attributes.
1466+
migration_info.update(attrs)
14721467

1473-
# Overwrite default attributes.
1474-
migration_info.update(attrs)
1468+
migration = _migration.Migration(**migration_info)
1469+
return migration
14751470

1476-
migration = fakes.FakeResource(info=copy.deepcopy(migration_info),
1477-
methods=methods,
1478-
loaded=True)
1479-
return migration
14801471

1481-
@staticmethod
1482-
def create_migrations(attrs=None, methods=None, count=2):
1483-
"""Create multiple fake migrations.
1472+
def create_migrations(attrs=None, count=2):
1473+
"""Create multiple fake migrations.
14841474
1485-
:param dict attrs:
1486-
A dictionary with all attributes
1487-
:param dict methods:
1488-
A dictionary with all methods
1489-
:param int count:
1490-
The number of migrations to fake
1491-
:return:
1492-
A list of FakeResource objects faking the migrations
1493-
"""
1494-
migrations = []
1495-
for i in range(0, count):
1496-
migrations.append(
1497-
FakeMigration.create_one_migration(
1498-
attrs, methods))
1475+
:param dict attrs: A dictionary with all attributes
1476+
:param int count: The number of migrations to fake
1477+
:return: A list of fake openstack.compute.v2.migration.Migration objects
1478+
"""
1479+
migrations = []
1480+
for i in range(0, count):
1481+
migrations.append(create_one_migration(attrs))
14991482

1500-
return migrations
1483+
return migrations
15011484

15021485

15031486
class FakeServerMigration(object):

openstackclient/tests/unit/compute/v2/test_server_migration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ class TestListMigration(TestServerMigration):
5959
def setUp(self):
6060
super().setUp()
6161

62-
self.server = compute_fakes.FakeServer.create_one_server()
62+
self.server = compute_fakes.FakeServer.create_one_sdk_server()
6363
self.sdk_client.find_server.return_value = self.server
6464

65-
self.migrations = compute_fakes.FakeMigration.create_migrations(
66-
count=3)
65+
self.migrations = compute_fakes.create_migrations(count=3)
6766
self.sdk_client.migrations.return_value = self.migrations
6867

6968
self.data = (common_utils.get_item_properties(

0 commit comments

Comments
 (0)