Skip to content

Commit

Permalink
Added in functionality to disable the snapshotting.
Browse files Browse the repository at this point in the history
  • Loading branch information
lizsalmon committed Dec 20, 2024
1 parent 705b248 commit 7844eee
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions actions/server.migrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ parameters:
type: string
required: false
description: "Optional, host to migrate server to"
snapshot:
type: boolean
required: true
default: true
runner_type: python-script
6 changes: 4 additions & 2 deletions lib/openstack_api/openstack_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ def snapshot_and_migrate_server(
conn: Connection,
server_id: str,
server_status: str,
snapshot: bool,
dest_host: Optional[str] = None,
) -> None:
"""
Snapshot a server and then migrate it to a new host
Optionally snapshot a server and then migrate it to a new host
:param conn: Openstack Connection
:param server_id: Server ID to migrate
:param server_status: Status of machine to migrate - must be ACTIVE or SHUTOFF
:param dest_host: Optional host to migrate to, otherwise chosen by scheduler
"""
snapshot_server(conn=conn, server_id=server_id)
if snapshot:
snapshot_server(conn=conn, server_id=server_id)
if server_status == "ACTIVE":
live = True
elif server_status == "SHUTOFF":
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/openstack_api/test_openstack_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_active_migration(mock_snapshot_server, dest_host):
server_id=mock_server_id,
server_status=mock_server_status,
dest_host=dest_host,
snapshot=True,
)
mock_snapshot_server.assert_called_once_with(
conn=mock_connection, server_id=mock_server_id
Expand All @@ -42,6 +43,7 @@ def test_shutoff_migration(mock_snapshot_server, dest_host):
server_id=mock_server_id,
server_status=mock_server_status,
dest_host=dest_host,
snapshot=True,
)
mock_snapshot_server.assert_called_once_with(
conn=mock_connection, server_id=mock_server_id
Expand All @@ -52,8 +54,28 @@ def test_shutoff_migration(mock_snapshot_server, dest_host):
)


@patch("openstack_api.openstack_server.snapshot_server")
def test_no_snapshot_migration(mock_snapshot_server):
"""
Test migration with no snapshot
"""
mock_connection = MagicMock()
mock_server_id = "server1"
mock_server_status = "ACTIVE"
snapshot_and_migrate_server(
conn=mock_connection,
server_id=mock_server_id,
server_status=mock_server_status,
snapshot=False,
)
mock_snapshot_server.assert_not_called()


@patch("openstack_api.openstack_server.snapshot_server")
def test_migration_fail(mock_snapshot_server):
"""
Test failure of migration when the status is not ACTIVE or SHUTOFF
"""
mock_connection = MagicMock()
mock_server_id = "server1"
mock_server_status = "TEST"
Expand All @@ -65,6 +87,7 @@ def test_migration_fail(mock_snapshot_server):
conn=mock_connection,
server_id=mock_server_id,
server_status=mock_server_status,
snapshot=True,
)
mock_snapshot_server.assert_called_once_with(
conn=mock_connection, server_id=mock_server_id
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/workflows/test_search_by_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_search_by_property_all(mock_openstackquery, mock_to_webhook, output_typ
@patch("workflows.search_by_property.to_webhook")
def test_search_by_property_migrate_webhook(mock_openstackquery):
"""
Runs search_by_property with webhook as migrate-server
Tests search_by_property with webhook as migrate-server adds params to the query needed for the migrate action
"""

mock_query = MagicMock()
Expand Down

0 comments on commit 7844eee

Please sign in to comment.