From ac15af4fa54adb94eba915dc52dbf9a47ecc5e8d Mon Sep 17 00:00:00 2001 From: Jonathan Woollett-Light Date: Wed, 18 Oct 2023 13:10:24 +0100 Subject: [PATCH] fix: Pass through no-API shutdown exit code Without passing through the exit code a non-zero exit code was returned on a successful no-API shutdown. Signed-off-by: Jonathan Woollett-Light --- CHANGELOG.md | 3 +++ src/firecracker/src/main.rs | 1 + .../functional/test_cmd_line_start.py | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b2d7b244d32..0445db3e3929 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ - Fixed a bug that ignored the `--show-log-origin` option, preventing it from printing the source code file of the log messages. +- [#4178](https://github.com/firecracker-microvm/firecracker/pull/4178): + Fixed a bug reporting a non-zero exit code on successful shutdown when + starting Firecracker with `--no-api`. ## [1.5.0] diff --git a/src/firecracker/src/main.rs b/src/firecracker/src/main.rs index 8c62461c2f31..af8c92ee7f0d 100644 --- a/src/firecracker/src/main.rs +++ b/src/firecracker/src/main.rs @@ -83,6 +83,7 @@ impl From for ExitCode { MainError::InvalidLogLevel(_) => FcExitCode::BadConfiguration, MainError::RunWithApi(ApiServerError::MicroVMStoppedWithoutError(code)) => code, MainError::RunWithApi(ApiServerError::MicroVMStoppedWithError(code)) => code, + MainError::RunWithoutApiError(RunWithoutApiError::Shutdown(code)) => code, _ => FcExitCode::GenericError, }; diff --git a/tests/integration_tests/functional/test_cmd_line_start.py b/tests/integration_tests/functional/test_cmd_line_start.py index 3c2a3750a763..f06d4a226780 100644 --- a/tests/integration_tests/functional/test_cmd_line_start.py +++ b/tests/integration_tests/functional/test_cmd_line_start.py @@ -7,6 +7,7 @@ import platform import re import shutil +import time from pathlib import Path import pytest @@ -156,6 +157,27 @@ def test_config_start_no_api(uvm_plain, vm_config_file): ) +@pytest.mark.parametrize("vm_config_file", ["framework/vm_config_network.json"]) +def test_config_start_no_api_exit(uvm_plain, vm_config_file): + """ + Test microvm exit when API server is disabled. + """ + test_microvm = uvm_plain + _configure_vm_from_json(test_microvm, vm_config_file) + _configure_network_interface(test_microvm) + test_microvm.jailer.extra_args.update({"no-api": None}) + + test_microvm.spawn() # Start Firecracker and MicroVM + time.sleep(3) # Wait for startup + test_microvm.ssh.run("reboot") # Exit + time.sleep(3) # Wait for shutdown + + # Check error log + test_microvm.check_log_message( + "RunWithoutApiError error: MicroVMStopped without an error: Ok" + ) + + @pytest.mark.parametrize( "vm_config_file", [