|
| 1 | +from test.integration.conftest import get_region |
| 2 | +from test.integration.helpers import ( |
| 3 | + get_test_label, |
| 4 | + send_request_when_resource_available, |
| 5 | +) |
| 6 | + |
1 | 7 | import pytest |
2 | 8 |
|
3 | | -from linode_api4 import PlacementGroup |
| 9 | +from linode_api4 import ( |
| 10 | + MigratedInstance, |
| 11 | + MigrationType, |
| 12 | + PlacementGroup, |
| 13 | + PlacementGroupPolicy, |
| 14 | + PlacementGroupType, |
| 15 | +) |
4 | 16 |
|
5 | 17 |
|
6 | 18 | @pytest.mark.smoke |
@@ -48,3 +60,52 @@ def test_pg_assignment(test_linode_client, create_placement_group_with_linode): |
48 | 60 |
|
49 | 61 | assert pg.members[0].linode_id == inst.id |
50 | 62 | assert inst.placement_group.id == pg.id |
| 63 | + |
| 64 | + |
| 65 | +def test_pg_migration( |
| 66 | + test_linode_client, e2e_test_firewall, create_placement_group |
| 67 | +): |
| 68 | + """ |
| 69 | + Tests that an instance can be migrated into and our of PGs successfully. |
| 70 | + """ |
| 71 | + client = test_linode_client |
| 72 | + |
| 73 | + label = get_test_label(10) |
| 74 | + |
| 75 | + pg_outbound = client.placement.group_create( |
| 76 | + label, |
| 77 | + get_region(test_linode_client, {"Placement Group"}), |
| 78 | + PlacementGroupType.anti_affinity_local, |
| 79 | + PlacementGroupPolicy.flexible, |
| 80 | + ) |
| 81 | + |
| 82 | + linode = client.linode.instance_create( |
| 83 | + "g6-nanode-1", |
| 84 | + pg_outbound.region, |
| 85 | + label=create_placement_group.label, |
| 86 | + placement_group=pg_outbound, |
| 87 | + ) |
| 88 | + |
| 89 | + pg_inbound = create_placement_group |
| 90 | + |
| 91 | + # Says it could take up to ~6 hrs for migration to fully complete |
| 92 | + send_request_when_resource_available( |
| 93 | + 300, |
| 94 | + linode.initiate_migration, |
| 95 | + placement_group=pg_inbound.id, |
| 96 | + migration_type=MigrationType.COLD, |
| 97 | + region=pg_inbound.region, |
| 98 | + ) |
| 99 | + |
| 100 | + pg_inbound = test_linode_client.load(PlacementGroup, pg_inbound.id) |
| 101 | + pg_outbound = test_linode_client.load(PlacementGroup, pg_outbound.id) |
| 102 | + |
| 103 | + assert pg_inbound.migrations.inbound[0] == MigratedInstance( |
| 104 | + linode_id=linode.id |
| 105 | + ) |
| 106 | + assert pg_outbound.migrations.outbound[0] == MigratedInstance( |
| 107 | + linode_id=linode.id |
| 108 | + ) |
| 109 | + |
| 110 | + linode.delete() |
| 111 | + pg_outbound.delete() |
0 commit comments