From c723745c6487e1956218259ff494c2b7686d023b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Barb=C3=A1chano?= Date: Mon, 9 Oct 2023 09:56:11 +0200 Subject: [PATCH] fix: restore the id parameter default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running Firecracker without parameters causes a panic. ``` [anonymous-instance:main] Running Firecracker v1.5.0-dev [anonymous-instance:main] Firecracker panicked at 'called `Option::unwrap()` on a `None` value', src/firecracker/src/main.rs:291:52 [1] 980007 IOT instruction ./firecracker ``` Fixes: 332f2184ae29265fbae1648469e073fc7f987378 Signed-off-by: Pablo Barbáchano --- src/firecracker/src/main.rs | 9 +++------ .../functional/test_cmd_line_parameters.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/firecracker/src/main.rs b/src/firecracker/src/main.rs index 5b237b02bae..cf95ff1f995 100644 --- a/src/firecracker/src/main.rs +++ b/src/firecracker/src/main.rs @@ -144,6 +144,7 @@ fn main_exec() -> Result<(), MainError> { .arg( Argument::new("id") .takes_value(true) + .default_value(vmm::logger::DEFAULT_INSTANCE_ID) .help("MicroVM unique identifier."), ) .arg( @@ -262,8 +263,6 @@ fn main_exec() -> Result<(), MainError> { return Ok(()); } - info!("Running Firecracker v{FIRECRACKER_VERSION}"); - register_signal_handlers().map_err(MainError::RegisterSignalHandlers)?; #[cfg(target_arch = "aarch64")] @@ -298,11 +297,9 @@ fn main_exec() -> Result<(), MainError> { app_name: "Firecracker".to_string(), }; - let id = arguments - .single_value("id") - .map(|s| s.as_str()) - .unwrap_or(vmm::logger::DEFAULT_INSTANCE_ID); + let id = arguments.single_value("id").map(|s| s.as_str()).unwrap(); vmm::logger::INSTANCE_ID.set(String::from(id)).unwrap(); + info!("Running Firecracker v{FIRECRACKER_VERSION}"); // Apply the logger configuration. let log_path = arguments.single_value("log-path").map(PathBuf::from); diff --git a/tests/integration_tests/functional/test_cmd_line_parameters.py b/tests/integration_tests/functional/test_cmd_line_parameters.py index 4b3bcb00703..55985ddea0f 100644 --- a/tests/integration_tests/functional/test_cmd_line_parameters.py +++ b/tests/integration_tests/functional/test_cmd_line_parameters.py @@ -3,6 +3,7 @@ """Tests that ensure the correctness of the command line parameters.""" import platform +import subprocess from pathlib import Path import pytest @@ -130,3 +131,18 @@ def test_cli_metrics_if_resume_no_metrics(uvm_plain, microvm_factory): # Then: the old metrics configuration does not exist metrics2 = Path(uvm2.jailer.chroot_path()) / metrics_path.name assert not metrics2.exists() + + +def test_cli_no_params(): + """ + Test running firecracker with no parameters should work + """ + + fc_binary, _ = get_firecracker_binaries() + process = subprocess.Popen(fc_binary) + try: + process.communicate(timeout=3) + assert process.returncode is None + except subprocess.TimeoutExpired: + # The good case + process.kill()