From 0f040b7df6407ae5690b0652f105416fb23aca83 Mon Sep 17 00:00:00 2001 From: Leonardo Forchini Date: Thu, 1 Oct 2026 09:41:09 +0100 Subject: [PATCH] Allow for per-test dbus sessions dbus sessions will be used to get controller status in component tests which means each test will have to have an independent bus. Allow for test-only non-system runs of the daemon. Also add VM liveness to the status response. Signed-off-by: Leonardo Forchini --- src/controller.rs | 1 + src/daemon.rs | 3 ++- src/dbus.rs | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index a89a4f9..8b14cb9 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -312,6 +312,7 @@ impl Controller { "thread_count": status.thread_count, "manual_scaling_sticky": status.manual_scaling_sticky, "scaling_allowed": status.scaling_allowed, + "alive": status.alive, "vcpu_count": status.vcpu_count, "per_thread_util": status.per_thread_util, // FIXME omit if status.perf.is_none()? diff --git a/src/daemon.rs b/src/daemon.rs index d72d8d5..2597e32 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -79,7 +79,8 @@ pub async fn run(cfg: Config, backends: Vec>) -> Result<(), Dae tracing::info!(target: "controller", added, "initial discovery"); let (dbus_tx, mut dbus_rx) = tokio::sync::mpsc::channel(1); - let _dbus_connection = dbus::serve(dbus::Service::new(dbus_tx)).await?; + let service = dbus::Service::new(dbus_tx); + let _dbus_connection = dbus::serve(service).await?; let mut inotify_events = setup_inotify(&backends)?; let mut poll = interval(Duration::from_secs_f64(cfg.scale_poll_secs)); poll.set_missed_tick_behavior(MissedTickBehavior::Skip); diff --git a/src/dbus.rs b/src/dbus.rs index fa9cbf2..1dbaa75 100644 --- a/src/dbus.rs +++ b/src/dbus.rs @@ -289,8 +289,22 @@ impl Service { /// Spin the D-Bus service on the well-known name / object path /// backed by `service` and drive replies from the controller mpsc. +/// +/// Component tests set `IO_THREAD_CONTROLLER_DBUS_ADDRESS` to use their +/// private bus; production leaves it unset and uses the system bus. pub async fn serve(service: Service) -> Result { - let conn = zbus::connection::Builder::system()? + let builder = match std::env::var("IO_THREAD_CONTROLLER_DBUS_ADDRESS") { + Ok(address) => zbus::connection::Builder::address(address.as_str())?, + Err(_) => zbus::connection::Builder::system()?, + }; + serve_with(builder, service).await +} + +async fn serve_with( + builder: zbus::connection::Builder<'_>, + service: Service, +) -> Result { + let conn = builder .name(DBUS_BUS_NAME)? .serve_at(DBUS_OBJECT_PATH, service)? .build()