Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/apis/openstack_api/openstack_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ def wait_for_migration_status(
"""
start_time = time.time()
while time.time() - start_time < timeout:
migration = next(conn.compute.migrations(instance_uuid=server_id))
try:
migration = next(conn.compute.migrations(instance_uuid=server_id))
except StopIteration:
logger.info("No migration details available for %s yet", server_id)
time.sleep(interval)
continue

logger.info("Status of migration of server %s: %s", server_id, migration.status)
if migration.status == status:
return migration
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/apis/openstack_api/test_openstack_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,17 @@ def test_shutoff_server_propagates_resource_failure():
shutoff_server(mock_conn, "server-123")

assert exc_info.value is expected_exception


def test_with_empty_migration_list():
"""
Tests that the code can handle an empty list of migrations e.g. when we
ask before nova gets the message we're migrating
"""
mock_conn = MagicMock()
mock_conn.compute.migrations.side_effect = [] # Return nothing intentionally

with pytest.raises(ResourceTimeout):
wait_for_migration_status(
mock_conn, "test-server-id", "should-timeout", interval=1, timeout=1
)