|
21 | 21 | from novaclient import api_versions |
22 | 22 | from openstack.compute.v2 import flavor as _flavor |
23 | 23 | from openstack.compute.v2 import hypervisor as _hypervisor |
| 24 | +from openstack.compute.v2 import migration as _migration |
24 | 25 | from openstack.compute.v2 import server as _server |
25 | 26 | from openstack.compute.v2 import server_group as _server_group |
26 | 27 | from openstack.compute.v2 import server_interface as _server_interface |
@@ -1433,71 +1434,53 @@ def __init__(self, verb, uri, value, remain, |
1433 | 1434 | self.next_available = next_available |
1434 | 1435 |
|
1435 | 1436 |
|
1436 | | -class FakeMigration(object): |
1437 | | - """Fake one or more migrations.""" |
| 1437 | +def create_one_migration(attrs=None): |
| 1438 | + """Create a fake migration. |
1438 | 1439 |
|
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 {} |
1442 | 1444 |
|
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 | + } |
1452 | 1464 |
|
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) |
1472 | 1467 |
|
1473 | | - # Overwrite default attributes. |
1474 | | - migration_info.update(attrs) |
| 1468 | + migration = _migration.Migration(**migration_info) |
| 1469 | + return migration |
1475 | 1470 |
|
1476 | | - migration = fakes.FakeResource(info=copy.deepcopy(migration_info), |
1477 | | - methods=methods, |
1478 | | - loaded=True) |
1479 | | - return migration |
1480 | 1471 |
|
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. |
1484 | 1474 |
|
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)) |
1499 | 1482 |
|
1500 | | - return migrations |
| 1483 | + return migrations |
1501 | 1484 |
|
1502 | 1485 |
|
1503 | 1486 | class FakeServerMigration(object): |
|
0 commit comments