This handles the case where users set `global.fqdn.domain = ""`, which would result incorrect parsing and finally resulting in the FQDN of the target machine being set to `<productname>.example.invalid`.
Reported on the community forum [0]. [0] https://forum.proxmox.com/threads/auto-install-fetching-fqdn-through-dhcp-does-not-set-search-domain-correctly.168369/ Fixes: a37e044 ("fix #5811: auto: add option to retrieve FQDN from DHCP configuration") Signed-off-by: Christoph Heiss <c.he...@proxmox.com> --- proxmox-auto-installer/src/answer.rs | 13 +++++++++++++ proxmox-auto-installer/tests/parse-answer.rs | 1 + ...n_from_dhcp_empty_dhcp_domain_setting.json | 19 +++++++++++++++++++ ...n_from_dhcp_empty_dhcp_domain_setting.toml | 17 +++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.toml diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs index b461976..88f4c87 100644 --- a/proxmox-auto-installer/src/answer.rs +++ b/proxmox-auto-installer/src/answer.rs @@ -90,6 +90,7 @@ pub struct FqdnExtendedConfig { #[serde(default)] pub source: FqdnSourceMode, /// Domain to use if none is received via DHCP. + #[serde(default, deserialize_with = "deserialize_non_empty_string_maybe")] pub domain: Option<String>, } @@ -444,3 +445,15 @@ pub enum KeyboardLayout { } serde_plain::derive_display_from_serialize!(KeyboardLayout); + +fn deserialize_non_empty_string_maybe<'de, D>(deserializer: D) -> Result<Option<String>, D::Error> +where + D: serde::Deserializer<'de>, +{ + let val: Option<String> = Deserialize::deserialize(deserializer)?; + + match val { + Some(s) if !s.is_empty() => Ok(Some(s)), + _ => Ok(None), + } +} diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs index 88f30aa..a354f21 100644 --- a/proxmox-auto-installer/tests/parse-answer.rs +++ b/proxmox-auto-installer/tests/parse-answer.rs @@ -124,6 +124,7 @@ mod tests { disk_match_any, first_boot, fqdn_from_dhcp, + fqdn_from_dhcp_empty_dhcp_domain_setting, fqdn_from_dhcp_no_dhcp_domain_with_default_domain, full_fqdn_from_dhcp_with_default_domain, hashed_root_password, diff --git a/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.json b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.json new file mode 100644 index 0000000..5ec6656 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.json @@ -0,0 +1,19 @@ +{ + "autoreboot": 1, + "cidr": "192.168.1.114/24", + "country": "at", + "dns": "192.168.1.254", + "domain": "test.local", + "filesys": "ext4", + "gateway": "192.168.1.1", + "hdsize": 223.57088470458984, + "existing_storage_auto_rename": 1, + "hostname": "pveauto", + "keymap": "de", + "mailto": "mail@no.invalid", + "mngmt_nic": "eno1", + "root_password": { "plain": "12345678" }, + "target_hd": "/dev/sda", + "timezone": "Europe/Vienna", + "first_boot": { "enabled": 0 } +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.toml b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.toml new file mode 100644 index 0000000..a19e342 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.toml @@ -0,0 +1,17 @@ +[global] +keyboard = "de" +country = "at" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root-password = "12345678" + +[global.fqdn] +source = "from-dhcp" +domain = "" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk-list = ["sda"] -- 2.49.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel