Skip to content

Commit

Permalink
[qemu] Make logging code terser
Browse files Browse the repository at this point in the history
Condense code to log mismatches between suspension snapshot and VM
state.
  • Loading branch information
ricab committed Aug 30, 2024
1 parent 1b2ae43 commit 329d131
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
22 changes: 7 additions & 15 deletions src/platform/backends/qemu/qemu_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,25 +380,17 @@ void mp::QemuVirtualMachine::shutdown(bool force)
mpl::log(mpl::Level::debug, vm_name, "No process to kill");
}

if (mp::backend::instance_image_has_snapshot(desc.image.image_path, suspend_tag))
{
if (state != State::suspended)
{
mpl::log(
mpl::Level::warning,
vm_name,
fmt::format("{} has the image suspension snapshot, but it is not in the suspended state", vm_name));
}
const auto has_suspend_snapshot = mp::backend::instance_image_has_snapshot(desc.image.image_path, suspend_tag);
if (has_suspend_snapshot != (state == State::suspended)) // clang-format off
mpl::log(mpl::Level::warning, vm_name, fmt::format("Image has {} suspension snapshot, but the state is {}",
has_suspend_snapshot ? "a" : "no",
static_cast<short>(state))); // clang-format on

if (has_suspend_snapshot)
{
mpl::log(mpl::Level::info, vm_name, "Deleting suspend image");
mp::backend::delete_instance_suspend_image(desc.image.image_path, suspend_tag);
}
else if (state == State::suspended)
{
mpl::log(mpl::Level::warning,
vm_name,
fmt::format("{} is suspended, but the image does not have the suspension snapshot", vm_name));
}

state = State::off;
}
Expand Down
6 changes: 2 additions & 4 deletions tests/qemu/test_qemu_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ TEST_F(QemuBackend, forceShutdownSuspendedStateButNoSuspensionSnapshotInImage)
logger_scope.mock_logger->screen_logs(mpl::Level::debug);
logger_scope.mock_logger->expect_log(mpl::Level::info, "Forcing shutdown");
logger_scope.mock_logger->expect_log(mpl::Level::debug, "No process to kill");
logger_scope.mock_logger->expect_log(mpl::Level::warning,
"is suspended, but the image does not have the suspension snapshot");
logger_scope.mock_logger->expect_log(mpl::Level::warning, "Image has no suspension snapshot, but the state is 7");

mpt::StubVMStatusMonitor stub_monitor;
mp::QemuVirtualMachineFactory backend{data_dir.path()};
Expand Down Expand Up @@ -577,8 +576,7 @@ TEST_F(QemuBackend, forceShutdownRunningStateButWithSuspensionSnapshotInImage)
logger_scope.mock_logger->expect_log(mpl::Level::info, "Forcing shutdown");
logger_scope.mock_logger->expect_log(mpl::Level::debug, "No process to kill");
logger_scope.mock_logger->expect_log(mpl::Level::info, "Deleting suspend image");
logger_scope.mock_logger->expect_log(mpl::Level::warning,
"has the image suspension snapshot, but it is not in the suspended state");
logger_scope.mock_logger->expect_log(mpl::Level::warning, "Image has a suspension snapshot, but the state is 4");

mpt::StubVMStatusMonitor stub_monitor;
mp::QemuVirtualMachineFactory backend{data_dir.path()};
Expand Down

0 comments on commit 329d131

Please sign in to comment.