Преглед на файлове

config: merge home_assistant from cluster_sources

power on/off from other cwds failed: the global config only has
cluster_sources, and ClusterSource merged clusters/nccl/before_serve/
ssh-creds but not [home_assistant] — so outside the repo dir the
binary had no HA endpoint and 'power on' (HA-only) could not work.
Same merge rule as ssh creds: main wins, first source wins.

Verified live: 'sm121 power on --cluster 1node-3' from /tmp now
resolves HA and issues turn_on (no-op: switch.dgx3 already on).
Alexander Korolev преди 2 месеца
родител
ревизия
7b687e86ae
променени са 2 файла, в които са добавени 28 реда и са изтрити 1 реда
  1. 7 0
      src/config.rs
  2. 21 1
      src/config/tests.rs

+ 7 - 0
src/config.rs

@@ -116,6 +116,10 @@ pub struct ClusterSource {
     pub nccl: HashMap<String, NcclConfig>,
     #[serde(default)]
     pub before_serve: HashMap<String, BeforeServeTable>,
+    /// HA endpoint for `power on`/`power off` from other cwds; merged only
+    /// when the main config has none.
+    #[serde(default)]
+    pub home_assistant: Option<HomeAssistantConfig>,
 }
 
 /// Merge each `Config.cluster_sources` file into `config`: extra clusters
@@ -135,6 +139,9 @@ pub async fn merge_cluster_sources(config: &mut Config) -> Result<()> {
         if config.ssh_key_path.as_os_str().is_empty() {
             config.ssh_key_path = src.ssh_key_path.clone().unwrap_or_default();
         }
+        if config.home_assistant.is_none() {
+            config.home_assistant = src.home_assistant.clone();
+        }
         for c in src.clusters {
             if !config.clusters.iter().any(|x| x.name == c.name) {
                 config.clusters.push(c);

+ 21 - 1
src/config/tests.rs

@@ -351,6 +351,11 @@ ib_disable = 0
 
 [before_serve."extra"]
 commands = ["echo hi"]
+
+[home_assistant]
+url = "http://ha.lan:8123"
+token = "sufficiently-long-test-token"
+shutdown_delay_seconds = 30
 "#,
     )
     .unwrap();
@@ -378,11 +383,26 @@ commands = ["echo hi"]
     assert!(cfg.clusters.iter().any(|c| c.name == "extra"));
     assert!(cfg.nccl.contains_key("extra"));
     assert!(cfg.before_serve.contains_key("extra"));
-    // A main-config ssh_user is never overridden by a source.
+    // HA config merges from the source when main has none (power on from
+    // other cwds depends on this).
+    assert!(cfg.home_assistant.is_some(), "home_assistant filled from source");
+    assert_eq!(cfg.home_assistant.as_ref().unwrap().url, "http://ha.lan:8123");
+    // A main-config ssh_user is never overridden by a source; same rule
+    // for home_assistant.
     let mut cfg2 = tcfg();
     cfg2.cluster_sources = vec![src_path.to_string_lossy().into_owned()];
+    cfg2.home_assistant = Some(crate::config::HomeAssistantConfig {
+        url: "http://main-ha:8123".into(),
+        token: "main".into(),
+        shutdown_delay_seconds: 5,
+    });
     merge_cluster_sources(&mut cfg2).await.unwrap();
     assert_eq!(cfg2.ssh_user, "u", "main ssh_user wins over source");
+    assert_eq!(
+        cfg2.home_assistant.as_ref().unwrap().url,
+        "http://main-ha:8123",
+        "main home_assistant wins over source"
+    );
 }
 
 #[tokio::test]