diff --git a/actions/server.migrate.yaml b/actions/server.migrate.yaml index 2e5930b63..1cb381247 100644 --- a/actions/server.migrate.yaml +++ b/actions/server.migrate.yaml @@ -34,4 +34,9 @@ parameters: type: boolean required: true default: true + check_flavor: + description: "Check the Flavor of the Server to decide if migration is feasible. When set as True, GPUs, FPGAs, and Flavors with more than 60 CPUs will NOT be migrated." + type: boolean + required: true + default: true runner_type: python-script diff --git a/actions/workflows/hypervisor.drain.workflow.yaml b/actions/workflows/hypervisor.drain.workflow.yaml index 4028322a8..c1d0160e6 100644 --- a/actions/workflows/hypervisor.drain.workflow.yaml +++ b/actions/workflows/hypervisor.drain.workflow.yaml @@ -48,3 +48,4 @@ tasks: cloud_account: <% ctx().cloud_account %> server_id: <% item(server_id) %> snapshot: <% not item(server_name).startsWith("amphora-") %> + check_flavor: true diff --git a/lib/apis/openstack_api/openstack_server.py b/lib/apis/openstack_api/openstack_server.py index 208e1a74b..366a9d0f4 100644 --- a/lib/apis/openstack_api/openstack_server.py +++ b/lib/apis/openstack_api/openstack_server.py @@ -10,25 +10,27 @@ logger = logging.getLogger(__name__) -def can_be_migrated(server: Server): - if server.flavor.name.startswith("g-") or server.flavor.name.startswith("f-"): - raise ValueError( - f"Attempted to move GPU or FPGA flavor, {server.flavor.name}, which is not allowed!" - ) +def can_be_migrated(server: Server, check_flavor: bool): + if check_flavor: + if server.flavor.name.startswith("g-") or server.flavor.name.startswith("f-"): + raise ValueError( + f"Attempted to move GPU or FPGA flavor, {server.flavor.name}, which is not allowed!" + ) + if server.flavor.vcpus > 60: + raise ValueError( + f"Attempted to move flavor with greater than 60 cores, {server.flavor.name}, which is not allowed!" + ) if server.status not in ["ACTIVE", "SHUTOFF"]: raise ValueError( f"Server status: {server.status}. The server must be ACTIVE or SHUTOFF to be migrated" ) - if server.flavor.vcpus > 60: - raise ValueError( - f"Attempted to move flavor with greater than 60 cores, {server.flavor.name}, which is not allowed!" - ) def snapshot_and_migrate_server( conn: Connection, server_id: str, snapshot: bool, + check_flavor: bool, dest_host: Optional[str] = None, ) -> None: """ @@ -38,9 +40,10 @@ def snapshot_and_migrate_server( :param server_status: Status of machine to migrate - must be ACTIVE or SHUTOFF :param flavor_name: Server flavor name :param dest_host: Optional host to migrate to, otherwise chosen by scheduler + :param check_flavor: boolean. When value is True, GPUs, FPGAs and Flavors with many CPUs will not be migrated """ server = conn.compute.get_server(server_id) - can_be_migrated(server) + can_be_migrated(server, check_flavor) if snapshot: snapshot_server(conn=conn, server_id=server_id) time.sleep(10) # Ensure server task status has updated after snapshot diff --git a/tests/lib/apis/openstack_api/test_openstack_server.py b/tests/lib/apis/openstack_api/test_openstack_server.py index f7fd373de..3a131a7df 100644 --- a/tests/lib/apis/openstack_api/test_openstack_server.py +++ b/tests/lib/apis/openstack_api/test_openstack_server.py @@ -43,6 +43,7 @@ def test_active_migration( server_id=mock_server_id, dest_host=dest_host, snapshot=True, + check_flavor=True, ) mock_snapshot_server.assert_called_once_with( conn=mock_connection, server_id=mock_server_id @@ -79,6 +80,7 @@ def test_shutoff_migration( server_id=mock_server_id, dest_host=dest_host, snapshot=True, + check_flavor=True, ) mock_snapshot_server.assert_called_once_with( conn=mock_connection, server_id=mock_server_id @@ -119,6 +121,7 @@ def test_active_migration_failed_wait_for_status( server_id=mock_server_id, dest_host=None, snapshot=True, + check_flavor=True, ) mock_snapshot_server.assert_called_once_with( conn=mock_connection, server_id=mock_server_id @@ -150,6 +153,7 @@ def test_no_snapshot_migration(mock_wait_for_migration_status, mock_snapshot_ser conn=mock_connection, server_id=mock_server_id, snapshot=False, + check_flavor=True, ) mock_snapshot_server.assert_not_called() mock_connection.compute.live_migrate_server.assert_called_once_with( @@ -181,6 +185,7 @@ def test_migration_fail(mock_snapshot_server): conn=mock_connection, server_id=mock_server_id, snapshot=True, + check_flavor=True, ) mock_snapshot_server.assert_not_called() mock_connection.compute.live_migrate_server.assert_not_called() @@ -242,6 +247,7 @@ def test_raise_invalid_migration(flavor_name, flavor_vcpu): server_id=mock_server_id, dest_host=None, snapshot=True, + check_flavor=True, )