* [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration @ 2025-03-27 15:17 Christoph Heiss 2025-03-27 15:17 ` [pve-devel] [PATCH installer 1/6] auto: utils: avoid a force unwrap() Christoph Heiss ` (6 more replies) 0 siblings, 7 replies; 18+ messages in thread From: Christoph Heiss @ 2025-03-27 15:17 UTC (permalink / raw) To: pve-devel Fixes #5811 [0]. Adds a new option to the answer file for specifying to use the DHCP-provided hostname and domain. For the domain, an additional fallback/default can be specified, in case the DHCP server only provides hostnames. The hostname is always required in this mode. The addition to the answer file format is done in a backwards-compatible way. Users can now specify the following to use the DHCP-provided domain: ``` [global] fqdn.source = "from-dhcp" ``` or additionally with a custom domain: ``` [global.fqdn] source = "from-dhcp" domain = "custom.domain.local" ``` Patches #1 through #4 can all be applied independently, #1 & #4 are pure cleanups. [0] https://bugzilla.proxmox.com/show_bug.cgi?id=5811 Diffstat ======== Christoph Heiss (6): auto: utils: avoid a force unwrap() auto: tests: parse-answer: allow per-test runtime env auto: tests: allow testing for serde parse errors of answer files tui, common: move network option tests to correct crate common: options: allow user-supplied domain for network options fix #5811: auto: add option to retrieve FQDN from DHCP configuration proxmox-auto-installer/src/answer.rs | 36 +++- proxmox-auto-installer/src/utils.rs | 43 ++++- proxmox-auto-installer/tests/parse-answer.rs | 43 +++-- .../parse_answer/fqdn_from_dhcp.json | 19 ++ .../parse_answer/fqdn_from_dhcp.toml | 14 ++ ...cp_no_dhcp_domain_with_default_domain.json | 19 ++ ...cp_no_dhcp_domain_with_default_domain.toml | 17 ++ ...ll_fqdn_from_dhcp_with_default_domain.json | 19 ++ ...ll_fqdn_from_dhcp_with_default_domain.toml | 17 ++ .../fqdn_from_dhcp_no_default_domain.json | 3 + ...n_from_dhcp_no_default_domain.run-env.json | 1 + .../fqdn_from_dhcp_no_default_domain.toml | 14 ++ .../parse_answer_fail/fqdn_hostname_only.json | 3 + .../parse_answer_fail/fqdn_hostname_only.toml | 14 ++ .../parse_answer_fail/no_fqdn_from_dhcp.json | 3 + .../no_fqdn_from_dhcp.run-env.json | 1 + .../parse_answer_fail/no_fqdn_from_dhcp.toml | 14 ++ .../tests/resources/run-env-info.json | 2 +- proxmox-installer-common/Cargo.toml | 3 + proxmox-installer-common/src/options.rs | 165 +++++++++++++++++- proxmox-post-hook/src/main.rs | 19 +- proxmox-tui-installer/Cargo.toml | 3 - proxmox-tui-installer/src/main.rs | 2 +- proxmox-tui-installer/src/options.rs | 93 ---------- 24 files changed, 440 insertions(+), 127 deletions(-) create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.run-env.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.run-env.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.toml -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] [PATCH installer 1/6] auto: utils: avoid a force unwrap() 2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss @ 2025-03-27 15:17 ` Christoph Heiss 2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht 2025-03-27 15:17 ` [pve-devel] [PATCH installer 2/6] auto: tests: parse-answer: allow per-test runtime env Christoph Heiss ` (5 subsequent siblings) 6 siblings, 1 reply; 18+ messages in thread From: Christoph Heiss @ 2025-03-27 15:17 UTC (permalink / raw) To: pve-devel At this point, this value will definitely be set & valid and *should* never be `None`. Still, better be safe than sorry and just unwrap_or() with a sane default value instead. Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> --- proxmox-auto-installer/src/utils.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index 1789fd8..655fecb 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -424,7 +424,11 @@ pub fn parse_answer( mngmt_nic: network_settings.ifname, - hostname: network_settings.fqdn.host().unwrap().to_string(), + hostname: network_settings + .fqdn + .host() + .unwrap_or(setup_info.config.product.default_hostname()) + .to_string(), domain: network_settings.fqdn.domain(), cidr: network_settings.address, gateway: network_settings.gateway, -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] applied: [PATCH installer 1/6] auto: utils: avoid a force unwrap() 2025-03-27 15:17 ` [pve-devel] [PATCH installer 1/6] auto: utils: avoid a force unwrap() Christoph Heiss @ 2025-04-04 12:51 ` Thomas Lamprecht 0 siblings, 0 replies; 18+ messages in thread From: Thomas Lamprecht @ 2025-04-04 12:51 UTC (permalink / raw) To: Proxmox VE development discussion, Christoph Heiss Am 27.03.25 um 16:17 schrieb Christoph Heiss: > At this point, this value will definitely be set & valid and *should* > never be `None`. Still, better be safe than sorry and just unwrap_or() > with a sane default value instead. > > Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> > --- > proxmox-auto-installer/src/utils.rs | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > applied, thanks! _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] [PATCH installer 2/6] auto: tests: parse-answer: allow per-test runtime env 2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss 2025-03-27 15:17 ` [pve-devel] [PATCH installer 1/6] auto: utils: avoid a force unwrap() Christoph Heiss @ 2025-03-27 15:17 ` Christoph Heiss 2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht 2025-03-27 15:17 ` [pve-devel] [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files Christoph Heiss ` (4 subsequent siblings) 6 siblings, 1 reply; 18+ messages in thread From: Christoph Heiss @ 2025-03-27 15:17 UTC (permalink / raw) To: pve-devel This allows to create custom runtime environment files for tests to use instead of the common one, to allow testing codepaths which depend on certain runtime-gathered values. Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> --- proxmox-auto-installer/tests/parse-answer.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs index 39b9401..6d5f228 100644 --- a/proxmox-auto-installer/tests/parse-answer.rs +++ b/proxmox-auto-installer/tests/parse-answer.rs @@ -47,7 +47,12 @@ fn setup_test_basic(path: impl AsRef<Path>) -> (SetupInfo, LocaleInfo, RuntimeIn fn run_named_test(name: &str) { let resource_path = get_test_resource_path().unwrap(); - let (setup_info, locales, runtime_info, udev_info) = setup_test_basic(&resource_path); + let (setup_info, locales, mut runtime_info, udev_info) = setup_test_basic(&resource_path); + + let test_run_env_path = resource_path.join(format!("parse_answer/{name}.run-env.json")); + if test_run_env_path.exists() { + runtime_info = read_json(test_run_env_path).unwrap() + } let answer_path = resource_path.join(format!("parse_answer/{name}.toml")); @@ -65,7 +70,12 @@ fn run_named_test(name: &str) { fn run_named_fail_parse_test(name: &str) { let resource_path = get_test_resource_path().unwrap(); - let (setup_info, locales, runtime_info, udev_info) = setup_test_basic(&resource_path); + let (setup_info, locales, mut runtime_info, udev_info) = setup_test_basic(&resource_path); + + let test_run_env_path = resource_path.join(format!("parse_answer_fail/{name}.run-env.json")); + if test_run_env_path.exists() { + runtime_info = read_json(test_run_env_path).unwrap() + } let answer_path = resource_path.join(format!("parse_answer_fail/{name}.toml")); -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] applied: [PATCH installer 2/6] auto: tests: parse-answer: allow per-test runtime env 2025-03-27 15:17 ` [pve-devel] [PATCH installer 2/6] auto: tests: parse-answer: allow per-test runtime env Christoph Heiss @ 2025-04-04 12:51 ` Thomas Lamprecht 0 siblings, 0 replies; 18+ messages in thread From: Thomas Lamprecht @ 2025-04-04 12:51 UTC (permalink / raw) To: Proxmox VE development discussion, Christoph Heiss Am 27.03.25 um 16:17 schrieb Christoph Heiss: > This allows to create custom runtime environment files for tests to use > instead of the common one, to allow testing codepaths which depend on > certain runtime-gathered values. > > Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> > --- > proxmox-auto-installer/tests/parse-answer.rs | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > applied, thanks! _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files 2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss 2025-03-27 15:17 ` [pve-devel] [PATCH installer 1/6] auto: utils: avoid a force unwrap() Christoph Heiss 2025-03-27 15:17 ` [pve-devel] [PATCH installer 2/6] auto: tests: parse-answer: allow per-test runtime env Christoph Heiss @ 2025-03-27 15:17 ` Christoph Heiss 2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht 2025-03-27 15:17 ` [pve-devel] [PATCH installer 4/6] tui, common: move network option tests to correct crate Christoph Heiss ` (3 subsequent siblings) 6 siblings, 1 reply; 18+ messages in thread From: Christoph Heiss @ 2025-03-27 15:17 UTC (permalink / raw) To: pve-devel In certain cases, it can be useful for (expected) parse failures, where the error message then also comes directly from serde. Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> --- proxmox-auto-installer/tests/parse-answer.rs | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs index 6d5f228..57e20b3 100644 --- a/proxmox-auto-installer/tests/parse-answer.rs +++ b/proxmox-auto-installer/tests/parse-answer.rs @@ -2,7 +2,6 @@ use serde_json::Value; use std::fs; use std::path::{Path, PathBuf}; -use proxmox_auto_installer::answer; use proxmox_auto_installer::answer::Answer; use proxmox_auto_installer::udevinfo::UdevInfo; use proxmox_auto_installer::utils::parse_answer; @@ -19,11 +18,8 @@ fn get_test_resource_path() -> Result<PathBuf, String> { fn get_answer(path: impl AsRef<Path>) -> Result<Answer, String> { let answer_raw = fs::read_to_string(path).unwrap(); - let answer: answer::Answer = toml::from_str(&answer_raw) - .map_err(|err| format!("error parsing answer.toml: {err}")) - .unwrap(); - - Ok(answer) + toml::from_str(&answer_raw) + .map_err(|err| format!("error parsing answer.toml: {}", err.message())) } fn setup_test_basic(path: impl AsRef<Path>) -> (SetupInfo, LocaleInfo, RuntimeInfo, UdevInfo) { @@ -79,14 +75,21 @@ fn run_named_fail_parse_test(name: &str) { let answer_path = resource_path.join(format!("parse_answer_fail/{name}.toml")); - let answer = get_answer(&answer_path).unwrap(); - let config = parse_answer(&answer, &udev_info, &runtime_info, &locales, &setup_info); - let err_json: Value = { let path = resource_path.join(format!("parse_answer_fail/{name}.json")); read_json(path).unwrap() }; + let answer = match get_answer(&answer_path) { + Ok(answer) => answer, + Err(err) => { + assert_eq!(err, err_json.get("parse-error").unwrap().as_str().unwrap()); + return; + } + }; + + let config = parse_answer(&answer, &udev_info, &runtime_info, &locales, &setup_info); + assert!(config.is_err()); assert_eq!( config.unwrap_err().to_string(), -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] applied: [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files 2025-03-27 15:17 ` [pve-devel] [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files Christoph Heiss @ 2025-04-04 12:51 ` Thomas Lamprecht 0 siblings, 0 replies; 18+ messages in thread From: Thomas Lamprecht @ 2025-04-04 12:51 UTC (permalink / raw) To: Proxmox VE development discussion, Christoph Heiss Am 27.03.25 um 16:17 schrieb Christoph Heiss: > In certain cases, it can be useful for (expected) parse failures, where > the error message then also comes directly from serde. > > Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> > --- > proxmox-auto-installer/tests/parse-answer.rs | 21 +++++++++++--------- > 1 file changed, 12 insertions(+), 9 deletions(-) > > applied, thanks! _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] [PATCH installer 4/6] tui, common: move network option tests to correct crate 2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss ` (2 preceding siblings ...) 2025-03-27 15:17 ` [pve-devel] [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files Christoph Heiss @ 2025-03-27 15:17 ` Christoph Heiss 2025-04-04 12:54 ` Thomas Lamprecht 2025-03-27 15:17 ` [pve-devel] [PATCH installer 5/6] common: options: allow user-supplied domain for network options Christoph Heiss ` (2 subsequent siblings) 6 siblings, 1 reply; 18+ messages in thread From: Christoph Heiss @ 2025-03-27 15:17 UTC (permalink / raw) To: pve-devel The `NetworkOptions` struct was moved here in 5362c05cd ("common: copy common code from tui-installer") and 86c48f76f ("tui: switch to common crate") but the tests were forgotten at the original place. No functional changes. Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> --- proxmox-installer-common/Cargo.toml | 3 + proxmox-installer-common/src/options.rs | 88 +++++++++++++++++++++++ proxmox-tui-installer/Cargo.toml | 3 - proxmox-tui-installer/src/options.rs | 93 ------------------------- 4 files changed, 91 insertions(+), 96 deletions(-) diff --git a/proxmox-installer-common/Cargo.toml b/proxmox-installer-common/Cargo.toml index c220f01..4bdb2b0 100644 --- a/proxmox-installer-common/Cargo.toml +++ b/proxmox-installer-common/Cargo.toml @@ -31,3 +31,6 @@ http = [ "dep:sha2", "dep:ureq" ] + +[dev-dependencies] +pretty_assertions = "1.4" diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index 6ebf64c..28f2971 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -497,6 +497,12 @@ pub fn email_validate(email: &str) -> Result<()> { #[cfg(test)] mod tests { use super::*; + use crate::{ + setup::{Dns, Gateway, Interface, InterfaceState, NetworkInfo, Routes, SetupInfo}, + utils::CidrAddress, + }; + use std::collections::BTreeMap; + use std::net::{IpAddr, Ipv4Addr}; #[test] fn zfs_arc_limit() { @@ -520,4 +526,86 @@ mod tests { assert_eq!(default_zfs_arc_max(ProxmoxProduct::PDM, *total_memory), 0); } } + + #[test] + fn network_options_from_setup_network_info() { + let setup = SetupInfo::mocked(); + + let mut interfaces = BTreeMap::new(); + interfaces.insert( + "eth0".to_owned(), + Interface { + name: "eth0".to_owned(), + index: 0, + state: InterfaceState::Up, + mac: "01:23:45:67:89:ab".to_owned(), + addresses: Some(vec![ + CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), + ]), + }, + ); + + let mut info = NetworkInfo { + dns: Dns { + domain: Some("bar.com".to_owned()), + dns: Vec::new(), + }, + routes: Some(Routes { + gateway4: Some(Gateway { + dev: "eth0".to_owned(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), + }), + gateway6: None, + }), + interfaces, + hostname: Some("foo".to_owned()), + }; + + pretty_assertions::assert_eq!( + NetworkOptions::defaults_from(&setup, &info), + NetworkOptions { + ifname: "eth0".to_owned(), + fqdn: Fqdn::from("foo.bar.com").unwrap(), + address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), + dns_server: Ipv4Addr::UNSPECIFIED.into(), + } + ); + + info.hostname = None; + pretty_assertions::assert_eq!( + NetworkOptions::defaults_from(&setup, &info), + NetworkOptions { + ifname: "eth0".to_owned(), + fqdn: Fqdn::from("pve.bar.com").unwrap(), + address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), + dns_server: Ipv4Addr::UNSPECIFIED.into(), + } + ); + + info.dns.domain = None; + pretty_assertions::assert_eq!( + NetworkOptions::defaults_from(&setup, &info), + NetworkOptions { + ifname: "eth0".to_owned(), + fqdn: Fqdn::from("pve.example.invalid").unwrap(), + address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), + dns_server: Ipv4Addr::UNSPECIFIED.into(), + } + ); + + info.hostname = Some("foo".to_owned()); + pretty_assertions::assert_eq!( + NetworkOptions::defaults_from(&setup, &info), + NetworkOptions { + ifname: "eth0".to_owned(), + fqdn: Fqdn::from("foo.example.invalid").unwrap(), + address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), + dns_server: Ipv4Addr::UNSPECIFIED.into(), + } + ); + } } diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml index 0e9c940..403d1ef 100644 --- a/proxmox-tui-installer/Cargo.toml +++ b/proxmox-tui-installer/Cargo.toml @@ -14,6 +14,3 @@ serde_json.workspace = true regex.workspace = true cursive = { version = "0.21", default-features = false, features = ["crossterm-backend"] } - -[dev-dependencies] -pretty_assertions = "1.4" diff --git a/proxmox-tui-installer/src/options.rs b/proxmox-tui-installer/src/options.rs index 8dcd697..c80877f 100644 --- a/proxmox-tui-installer/src/options.rs +++ b/proxmox-tui-installer/src/options.rs @@ -79,96 +79,3 @@ impl InstallerOptions { ] } } - -#[cfg(test)] -mod tests { - use super::*; - use proxmox_installer_common::{ - setup::{Dns, Gateway, Interface, InterfaceState, NetworkInfo, Routes, SetupInfo}, - utils::{CidrAddress, Fqdn}, - }; - use std::collections::BTreeMap; - use std::net::{IpAddr, Ipv4Addr}; - - #[test] - fn network_options_from_setup_network_info() { - let setup = SetupInfo::mocked(); - - let mut interfaces = BTreeMap::new(); - interfaces.insert( - "eth0".to_owned(), - Interface { - name: "eth0".to_owned(), - index: 0, - state: InterfaceState::Up, - mac: "01:23:45:67:89:ab".to_owned(), - addresses: Some(vec![ - CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), - ]), - }, - ); - - let mut info = NetworkInfo { - dns: Dns { - domain: Some("bar.com".to_owned()), - dns: Vec::new(), - }, - routes: Some(Routes { - gateway4: Some(Gateway { - dev: "eth0".to_owned(), - gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - }), - gateway6: None, - }), - interfaces, - hostname: Some("foo".to_owned()), - }; - - pretty_assertions::assert_eq!( - NetworkOptions::defaults_from(&setup, &info), - NetworkOptions { - ifname: "eth0".to_owned(), - fqdn: Fqdn::from("foo.bar.com").unwrap(), - address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), - gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), - } - ); - - info.hostname = None; - pretty_assertions::assert_eq!( - NetworkOptions::defaults_from(&setup, &info), - NetworkOptions { - ifname: "eth0".to_owned(), - fqdn: Fqdn::from("pve.bar.com").unwrap(), - address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), - gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), - } - ); - - info.dns.domain = None; - pretty_assertions::assert_eq!( - NetworkOptions::defaults_from(&setup, &info), - NetworkOptions { - ifname: "eth0".to_owned(), - fqdn: Fqdn::from("pve.example.invalid").unwrap(), - address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), - gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), - } - ); - - info.hostname = Some("foo".to_owned()); - pretty_assertions::assert_eq!( - NetworkOptions::defaults_from(&setup, &info), - NetworkOptions { - ifname: "eth0".to_owned(), - fqdn: Fqdn::from("foo.example.invalid").unwrap(), - address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), - gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), - } - ); - } -} -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [pve-devel] [PATCH installer 4/6] tui, common: move network option tests to correct crate 2025-03-27 15:17 ` [pve-devel] [PATCH installer 4/6] tui, common: move network option tests to correct crate Christoph Heiss @ 2025-04-04 12:54 ` Thomas Lamprecht 0 siblings, 0 replies; 18+ messages in thread From: Thomas Lamprecht @ 2025-04-04 12:54 UTC (permalink / raw) To: Proxmox VE development discussion, Christoph Heiss Am 27.03.25 um 16:17 schrieb Christoph Heiss: > The `NetworkOptions` struct was moved here in > > 5362c05cd ("common: copy common code from tui-installer") > > and > > 86c48f76f ("tui: switch to common crate") > > but the tests were forgotten at the original place. > > No functional changes. > > Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> > --- > proxmox-installer-common/Cargo.toml | 3 + > proxmox-installer-common/src/options.rs | 88 +++++++++++++++++++++++ > proxmox-tui-installer/Cargo.toml | 3 - > proxmox-tui-installer/src/options.rs | 93 ------------------------- > 4 files changed, 91 insertions(+), 96 deletions(-) > this one needs to be rebased due to changes in the context, a quick resolution caused a compile failure, probably just due to a error on my side on resolution. Then you could also re-send patch 6/6 as base64 encoded (git send-email --transfer-encoding=base64 ..) _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] [PATCH installer 5/6] common: options: allow user-supplied domain for network options 2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss ` (3 preceding siblings ...) 2025-03-27 15:17 ` [pve-devel] [PATCH installer 4/6] tui, common: move network option tests to correct crate Christoph Heiss @ 2025-03-27 15:17 ` Christoph Heiss 2025-03-27 15:17 ` [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration Christoph Heiss 2025-04-01 13:45 ` [pve-devel] [PATCH installer 0/6] fix #5811: " Daniel Kral 6 siblings, 0 replies; 18+ messages in thread From: Christoph Heiss @ 2025-03-27 15:17 UTC (permalink / raw) To: pve-devel Add an optional parameter to allow specifying a domain, which will take precedence over both the DHCP-supplied domain (if any) and the hardcoded default domain. Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> --- proxmox-auto-installer/src/utils.rs | 2 +- proxmox-installer-common/src/options.rs | 95 ++++++++++++++++++++----- proxmox-tui-installer/src/main.rs | 2 +- 3 files changed, 80 insertions(+), 19 deletions(-) diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index 655fecb..cf072b8 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -24,7 +24,7 @@ fn get_network_settings( runtime_info: &RuntimeInfo, setup_info: &SetupInfo, ) -> Result<NetworkOptions> { - let mut network_options = NetworkOptions::defaults_from(setup_info, &runtime_info.network); + let mut network_options = NetworkOptions::defaults_from(setup_info, &runtime_info.network, None); info!("Setting network configuration"); diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index 28f2971..562d285 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -408,10 +408,18 @@ pub struct NetworkOptions { impl NetworkOptions { const DEFAULT_DOMAIN: &'static str = "example.invalid"; - pub fn defaults_from(setup: &SetupInfo, network: &NetworkInfo) -> Self { + pub fn defaults_from( + setup: &SetupInfo, + network: &NetworkInfo, + default_domain: Option<&str>, + ) -> Self { let mut this = Self { ifname: String::new(), - fqdn: Self::construct_fqdn(network, setup.config.product.default_hostname()), + fqdn: Self::construct_fqdn( + network, + setup.config.product.default_hostname(), + default_domain, + ), // Safety: The provided mask will always be valid. address: CidrAddress::new(Ipv4Addr::UNSPECIFIED, 0).unwrap(), gateway: Ipv4Addr::UNSPECIFIED.into(), @@ -454,14 +462,23 @@ impl NetworkOptions { this } - fn construct_fqdn(network: &NetworkInfo, default_hostname: &str) -> Fqdn { + pub fn construct_fqdn( + network: &NetworkInfo, + default_hostname: &str, + default_domain: Option<&str>, + ) -> Fqdn { let hostname = network.hostname.as_deref().unwrap_or(default_hostname); - let domain = network - .dns - .domain - .as_deref() - .unwrap_or(Self::DEFAULT_DOMAIN); + // First, use the provided default domain if provided. If that is unset, + // use the one from the host network configuration, i.e. as and if provided by DHCP. + // As last fallback, use [`Self::DEFAULT_DOMAIN`]. + let domain = default_domain.unwrap_or_else(|| { + network + .dns + .domain + .as_deref() + .unwrap_or(Self::DEFAULT_DOMAIN) + }); Fqdn::from(&format!("{hostname}.{domain}")).unwrap_or_else(|_| { // Safety: This will always result in a valid FQDN, as we control & know @@ -527,10 +544,7 @@ mod tests { } } - #[test] - fn network_options_from_setup_network_info() { - let setup = SetupInfo::mocked(); - + fn mock_setup_network() -> (SetupInfo, NetworkInfo) { let mut interfaces = BTreeMap::new(); interfaces.insert( "eth0".to_owned(), @@ -545,7 +559,7 @@ mod tests { }, ); - let mut info = NetworkInfo { + let info = NetworkInfo { dns: Dns { domain: Some("bar.com".to_owned()), dns: Vec::new(), @@ -561,8 +575,15 @@ mod tests { hostname: Some("foo".to_owned()), }; + (SetupInfo::mocked(), info) + } + + #[test] + fn network_options_from_setup_network_info() { + let (setup, mut info) = mock_setup_network(); + pretty_assertions::assert_eq!( - NetworkOptions::defaults_from(&setup, &info), + NetworkOptions::defaults_from(&setup, &info, None), NetworkOptions { ifname: "eth0".to_owned(), fqdn: Fqdn::from("foo.bar.com").unwrap(), @@ -574,7 +595,7 @@ mod tests { info.hostname = None; pretty_assertions::assert_eq!( - NetworkOptions::defaults_from(&setup, &info), + NetworkOptions::defaults_from(&setup, &info, None), NetworkOptions { ifname: "eth0".to_owned(), fqdn: Fqdn::from("pve.bar.com").unwrap(), @@ -586,7 +607,7 @@ mod tests { info.dns.domain = None; pretty_assertions::assert_eq!( - NetworkOptions::defaults_from(&setup, &info), + NetworkOptions::defaults_from(&setup, &info, None), NetworkOptions { ifname: "eth0".to_owned(), fqdn: Fqdn::from("pve.example.invalid").unwrap(), @@ -598,7 +619,7 @@ mod tests { info.hostname = Some("foo".to_owned()); pretty_assertions::assert_eq!( - NetworkOptions::defaults_from(&setup, &info), + NetworkOptions::defaults_from(&setup, &info, None), NetworkOptions { ifname: "eth0".to_owned(), fqdn: Fqdn::from("foo.example.invalid").unwrap(), @@ -608,4 +629,44 @@ mod tests { } ); } + + #[test] + fn network_options_correctly_handles_user_supplied_default_domain() { + let (setup, mut info) = mock_setup_network(); + + pretty_assertions::assert_eq!( + NetworkOptions::defaults_from(&setup, &info, None), + NetworkOptions { + ifname: "eth0".to_owned(), + fqdn: Fqdn::from("foo.bar.com").unwrap(), + address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), + dns_server: Ipv4Addr::UNSPECIFIED.into(), + } + ); + + info.dns.domain = None; + pretty_assertions::assert_eq!( + NetworkOptions::defaults_from(&setup, &info, Some("custom.local")), + NetworkOptions { + ifname: "eth0".to_owned(), + fqdn: Fqdn::from("foo.custom.local").unwrap(), + address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), + dns_server: Ipv4Addr::UNSPECIFIED.into(), + } + ); + + info.dns.domain = Some("some.domain.local".to_owned()); + pretty_assertions::assert_eq!( + NetworkOptions::defaults_from(&setup, &info, Some("custom.local")), + NetworkOptions { + ifname: "eth0".to_owned(), + fqdn: Fqdn::from("foo.custom.local").unwrap(), + address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), + dns_server: Ipv4Addr::UNSPECIFIED.into(), + } + ); + } } diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs index 341e60c..57a334f 100644 --- a/proxmox-tui-installer/src/main.rs +++ b/proxmox-tui-installer/src/main.rs @@ -169,7 +169,7 @@ fn main() { bootdisk: BootdiskOptions::defaults_from(&runtime_info.disks[0]), timezone: TimezoneOptions::defaults_from(&runtime_info, &locales), password: Default::default(), - network: NetworkOptions::defaults_from(&setup_info, &runtime_info.network), + network: NetworkOptions::defaults_from(&setup_info, &runtime_info.network, None), autoreboot: true, }, setup_info, -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration 2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss ` (4 preceding siblings ...) 2025-03-27 15:17 ` [pve-devel] [PATCH installer 5/6] common: options: allow user-supplied domain for network options Christoph Heiss @ 2025-03-27 15:17 ` Christoph Heiss 2025-04-01 13:15 ` Daniel Kral 2025-04-01 13:45 ` [pve-devel] [PATCH installer 0/6] fix #5811: " Daniel Kral 6 siblings, 1 reply; 18+ messages in thread From: Christoph Heiss @ 2025-03-27 15:17 UTC (permalink / raw) To: pve-devel Fixes #5811 [0]. Adds a new option to the answer file for specifying to use the DHCP-provided hostname and domain. For the domain, an additional fallback/default can be specified, in case the DHCP server only provides hostnames. The hostname is always required in this mode. The addition to the answer file format is done in a backwards-compatible way. Users can now either directly specify the desired FQDN in the answer file as before through ``` [global] fqdn = "node.example.local" ``` or, with the new mechanism, if the DHCP server provides all the information already: ``` [global] fqdn.source = "from-dhcp" ``` or additionally with a custom domain: ``` [global.fqdn] source = "from-dhcp" domain = "custom.domain.local" ``` The DHCP-provided hostname and domain are already provided to the auto-installer through the runtime environment, so its just a matter of using them. The test suite is extended quite a bit, to cover all the different cases. [0] https://bugzilla.proxmox.com/show_bug.cgi?id=5811 Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> --- proxmox-auto-installer/src/answer.rs | 36 +++++++++++++++++- proxmox-auto-installer/src/utils.rs | 37 ++++++++++++++++--- proxmox-auto-installer/tests/parse-answer.rs | 8 ++++ .../parse_answer/fqdn_from_dhcp.json | 19 ++++++++++ .../parse_answer/fqdn_from_dhcp.toml | 14 +++++++ ...cp_no_dhcp_domain_with_default_domain.json | 19 ++++++++++ ...cp_no_dhcp_domain_with_default_domain.toml | 17 +++++++++ ...ll_fqdn_from_dhcp_with_default_domain.json | 19 ++++++++++ ...ll_fqdn_from_dhcp_with_default_domain.toml | 17 +++++++++ .../fqdn_from_dhcp_no_default_domain.json | 3 ++ ...n_from_dhcp_no_default_domain.run-env.json | 1 + .../fqdn_from_dhcp_no_default_domain.toml | 14 +++++++ .../parse_answer_fail/fqdn_hostname_only.json | 3 ++ .../parse_answer_fail/fqdn_hostname_only.toml | 14 +++++++ .../parse_answer_fail/no_fqdn_from_dhcp.json | 3 ++ .../no_fqdn_from_dhcp.run-env.json | 1 + .../parse_answer_fail/no_fqdn_from_dhcp.toml | 14 +++++++ .../tests/resources/run-env-info.json | 2 +- proxmox-post-hook/src/main.rs | 19 ++++++++-- 19 files changed, 250 insertions(+), 10 deletions(-) create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.run-env.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.run-env.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.toml diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs index c11818e..dd7fa06 100644 --- a/proxmox-auto-installer/src/answer.rs +++ b/proxmox-auto-installer/src/answer.rs @@ -46,7 +46,8 @@ impl Answer { #[serde(rename_all = "kebab-case", deny_unknown_fields)] pub struct Global { pub country: String, - pub fqdn: Fqdn, + /// FQDN to set for the installed system. + pub fqdn: FqdnConfig, pub keyboard: KeyboardLayout, pub mailto: String, pub timezone: String, @@ -60,6 +61,39 @@ pub struct Global { pub root_ssh_keys: Vec<String>, } +/// Allow the user to either set the FQDN of the installation to either some +/// fixed value or retrieve it dynamically via e.g.DHCP. +#[derive(Clone, Deserialize, Debug)] +#[serde( + untagged, + expecting = "either a fully-qualified domain name or extendend configuration for usage with DHCP must be specified" +)] +pub enum FqdnConfig { + /// Sets the FQDN to the exact value. + Simple(Fqdn), + /// Extended configuration, e.g. to use hostname and domain from DHCP. + Extended(FqdnExtendedConfig), +} + +/// Extended configuration for retrieving the FQDN from external sources. +#[derive(Clone, Deserialize, Debug)] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] +pub struct FqdnExtendedConfig { + /// Source to gather the FQDN from. + #[serde(default)] + pub source: FqdnSourceMode, + /// Domain to use if none is received via DHCP. + pub domain: Option<String>, +} + +/// Describes the source to retrieve the FQDN of the installation. +#[derive(Clone, Deserialize, Debug, Default, PartialEq)] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] +pub enum FqdnSourceMode { + #[default] + FromDhcp, +} + #[derive(Clone, Deserialize, Debug)] #[serde(rename_all = "kebab-case", deny_unknown_fields)] pub struct PostNotificationHookInfo { diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index cf072b8..5bff8b2 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -5,7 +5,9 @@ use log::info; use std::{collections::BTreeMap, process::Command}; use crate::{ - answer::{self, Answer, FirstBootHookSourceMode}, + answer::{ + self, Answer, FirstBootHookSourceMode, FqdnConfig, FqdnExtendedConfig, FqdnSourceMode, + }, udevinfo::UdevInfo, }; use proxmox_installer_common::{ @@ -24,12 +26,37 @@ fn get_network_settings( runtime_info: &RuntimeInfo, setup_info: &SetupInfo, ) -> Result<NetworkOptions> { - let mut network_options = NetworkOptions::defaults_from(setup_info, &runtime_info.network, None); + info!("Setting up network configuration"); - info!("Setting network configuration"); + let mut network_options = match &answer.global.fqdn { + // If the user set a static FQDN in the answer file, override it + FqdnConfig::Simple(name) => { + let mut opts = NetworkOptions::defaults_from(setup_info, &runtime_info.network, None); + opts.fqdn = name.to_owned(); + opts + } + FqdnConfig::Extended(FqdnExtendedConfig { + source: FqdnSourceMode::FromDhcp, + domain, + }) => { + // A FQDN from DHCP information and/or defaults is constructed in + // `NetworkOptions::defaults_from()` below, just check that the DHCP server actually + // provided a hostname. + if runtime_info.network.hostname.is_none() { + bail!( + "`global.fqdn.source` set to \"from-dhcp\", but DHCP server did not provide a hostname!" + ); + } - // Always use the FQDN from the answer file - network_options.fqdn = answer.global.fqdn.clone(); + // Either a domain must be received from the DHCP server or it must be set manually + // (even just as fallback) in the answer file. + if runtime_info.network.dns.domain.is_none() && domain.is_none() { + bail!("no domain received from DHCP server and `global.fqdn.domain` is unset!"); + } + + NetworkOptions::defaults_from(setup_info, &runtime_info.network, domain.as_deref()) + } + }; if let answer::NetworkSettings::Manual(settings) = &answer.network.network_settings { network_options.address = settings.cidr.clone(); diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs index 57e20b3..34bc969 100644 --- a/proxmox-auto-installer/tests/parse-answer.rs +++ b/proxmox-auto-installer/tests/parse-answer.rs @@ -116,12 +116,16 @@ mod tests { declare_tests!( run_named_test, + // Keep below entries alphabetically sorted btrfs, btrfs_raid_level_uppercase, disk_match, disk_match_all, disk_match_any, first_boot, + fqdn_from_dhcp, + fqdn_from_dhcp_no_dhcp_domain_with_default_domain, + full_fqdn_from_dhcp_with_default_domain, hashed_root_password, minimal, nic_matching, @@ -136,7 +140,11 @@ mod tests { declare_tests!( run_named_fail_parse_test, + // Keep below entries alphabetically sorted both_password_and_hashed_set, + fqdn_from_dhcp_no_default_domain, + fqdn_hostname_only, + no_fqdn_from_dhcp, no_root_password_set, short_password ); diff --git a/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.json b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.json new file mode 100644 index 0000000..5ec6656 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.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.toml b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.toml new file mode 100644 index 0000000..9d13a5f --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp.toml @@ -0,0 +1,14 @@ +[global] +keyboard = "de" +country = "at" +fqdn.source = "from-dhcp" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root_password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk_list = ["sda"] diff --git a/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.json b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.json new file mode 100644 index 0000000..7ed46a2 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.json @@ -0,0 +1,19 @@ +{ + "autoreboot": 1, + "cidr": "192.168.1.114/24", + "country": "at", + "dns": "192.168.1.254", + "domain": "custom.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_no_dhcp_domain_with_default_domain.toml b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.toml new file mode 100644 index 0000000..8fbbede --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_no_dhcp_domain_with_default_domain.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 = "custom.local" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk_list = ["sda"] diff --git a/proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.json b/proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.json new file mode 100644 index 0000000..7ed46a2 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.json @@ -0,0 +1,19 @@ +{ + "autoreboot": 1, + "cidr": "192.168.1.114/24", + "country": "at", + "dns": "192.168.1.254", + "domain": "custom.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/full_fqdn_from_dhcp_with_default_domain.toml b/proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.toml new file mode 100644 index 0000000..8fbbede --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/full_fqdn_from_dhcp_with_default_domain.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 = "custom.local" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk_list = ["sda"] diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.json new file mode 100644 index 0000000..da7850f --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.json @@ -0,0 +1,3 @@ +{ + "error": "no domain received from DHCP server and `global.fqdn.domain` is unset!" +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.run-env.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.run-env.json new file mode 100644 index 0000000..eb17092 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.run-env.json @@ -0,0 +1 @@ +{"boot_type":"efi","country":"at","disks":[[0,"/dev/nvme0n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme0n1"],[1,"/dev/nvme1n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme1n1"],[2,"/dev/nvme2n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme2n1"],[3,"/dev/nvme3n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme3n1"],[4,"/dev/nvme4n1",976773168,"Samsung SSD 970 EVO Plus 500GB",512,"/sys/block/nvme4n1"],[5,"/dev/nvme5n1",732585168,"INTEL SSDPED1K375GA",512,"/sys/block/nvme5n1"],[6,"/dev/sda",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sda"],[7,"/dev/sdb",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdb"],[8,"/dev/sdc",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdc"],[9,"/dev/sdd",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdd"]],"hvm_supported":1,"ipconf":{"default":"4","dnsserver":"192.168.1.254","domain":null,"gateway":"192.168.1.1","ifaces":{"10":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac" :"24:8a:07:1e:05:bd","name":"enp193s0f1np1","state":"DOWN"},"2":{"driver":"igb","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"a0:36:9f:0a:b3:82","name":"enp65s0f0","state":"DOWN"},"3":{"driver":"igb","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"a0:36:9f:0a:b3:83","name":"enp65s0f1","state":"DOWN"},"4":{"driver":"igb","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","inet":{"addr":"192.168.1.114","mask":"255.255.240.0","prefix":20},"mac":"b4:2e:99:ac:ad:b4","name":"eno1","state":"UP"},"5":{"driver":"cdc_ether","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"5a:47:32:dd:c7:47","name":"enx5a4732ddc747","state":"UNKNOWN"},"6":{"driver":"igb","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"b4:2e:99:ac:ad:b5","name":"eno2","state":"UP"},"7":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"1c:34:da:5c:5e:24","name":"enp129s0f0np0","state":"DOWN"},"8":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"1c:34:da:5c:5e:25","name":"enp129s0f1n p1","state":"DOWN"},"9":{"driver":"mlx5_core","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"24:8a:07:1e:05:bc","name":"enp193s0f0np0","state":"UP"}}},"kernel_cmdline":"BOOT_IMAGE=/boot/linux26 ro ramdisk_size=16777216 rw splash=verbose proxdebug vga=788","network":{"hostname":"pveauto","dns":{"dns":["192.168.1.254"],"domain":null},"interfaces":{"eno1":{"addresses":[{"address":"192.168.1.114","family":"inet","prefix":24}],"index":4,"mac":"b4:2e:99:ac:ad:b4","name":"eno1","state":"UP"},"eno2":{"index":6,"mac":"b4:2e:99:ac:ad:b5","name":"eno2","state":"UP"},"enp129s0f0np0":{"index":7,"mac":"1c:34:da:5c:5e:24","name":"enp129s0f0np0","state":"DOWN"},"enp129s0f1np1":{"index":8,"mac":"1c:34:da:5c:5e:25","name":"enp129s0f1np1","state":"DOWN"},"enp193s0f0np0":{"index":9,"mac":"24:8a:07:1e:05:bc","name":"enp193s0f0np0","state":"UP"},"enp193s0f1np1":{"index":10,"mac":"24:8a:07:1e:05:bd","name":"enp193s0f1np1","state":"DOWN"},"enp65s0f0":{"index":2,"mac":"a0:36:9f:0a:b3:82","name":"enp65s0f0 ","state":"DOWN"},"enp65s0f1":{"index":3,"mac":"a0:36:9f:0a:b3:83","name":"enp65s0f1","state":"DOWN"},"enx5a4732ddc747":{"index":5,"mac":"5a:47:32:dd:c7:47","name":"enx5a4732ddc747","state":"UNKNOWN"}},"routes":{"gateway4":{"dev":"eno1","gateway":"192.168.1.1"}}},"total_memory":257597} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.toml b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.toml new file mode 100644 index 0000000..9d13a5f --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_from_dhcp_no_default_domain.toml @@ -0,0 +1,14 @@ +[global] +keyboard = "de" +country = "at" +fqdn.source = "from-dhcp" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root_password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk_list = ["sda"] diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.json new file mode 100644 index 0000000..5293b40 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.json @@ -0,0 +1,3 @@ +{ + "parse-error": "error parsing answer.toml: either a fully-qualified domain name or extendend configuration for usage with DHCP must be specified" +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.toml b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.toml new file mode 100644 index 0000000..a0a22ef --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/fqdn_hostname_only.toml @@ -0,0 +1,14 @@ +[global] +keyboard = "de" +country = "at" +fqdn = "foobar" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root_password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk_list = ["sda"] diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.json new file mode 100644 index 0000000..49a64e5 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.json @@ -0,0 +1,3 @@ +{ + "error": "`global.fqdn.source` set to \"from-dhcp\", but DHCP server did not provide a hostname!" +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.run-env.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.run-env.json new file mode 100644 index 0000000..6762470 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.run-env.json @@ -0,0 +1 @@ +{"boot_type":"efi","country":"at","disks":[[0,"/dev/nvme0n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme0n1"],[1,"/dev/nvme1n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme1n1"],[2,"/dev/nvme2n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme2n1"],[3,"/dev/nvme3n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme3n1"],[4,"/dev/nvme4n1",976773168,"Samsung SSD 970 EVO Plus 500GB",512,"/sys/block/nvme4n1"],[5,"/dev/nvme5n1",732585168,"INTEL SSDPED1K375GA",512,"/sys/block/nvme5n1"],[6,"/dev/sda",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sda"],[7,"/dev/sdb",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdb"],[8,"/dev/sdc",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdc"],[9,"/dev/sdd",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdd"]],"hvm_supported":1,"ipconf":{"default":"4","dnsserver":"192.168.1.254","domain":null,"gateway":"192.168.1.1","ifaces":{"10":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac" :"24:8a:07:1e:05:bd","name":"enp193s0f1np1","state":"DOWN"},"2":{"driver":"igb","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"a0:36:9f:0a:b3:82","name":"enp65s0f0","state":"DOWN"},"3":{"driver":"igb","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"a0:36:9f:0a:b3:83","name":"enp65s0f1","state":"DOWN"},"4":{"driver":"igb","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","inet":{"addr":"192.168.1.114","mask":"255.255.240.0","prefix":20},"mac":"b4:2e:99:ac:ad:b4","name":"eno1","state":"UP"},"5":{"driver":"cdc_ether","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"5a:47:32:dd:c7:47","name":"enx5a4732ddc747","state":"UNKNOWN"},"6":{"driver":"igb","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"b4:2e:99:ac:ad:b5","name":"eno2","state":"UP"},"7":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"1c:34:da:5c:5e:24","name":"enp129s0f0np0","state":"DOWN"},"8":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"1c:34:da:5c:5e:25","name":"enp129s0f1n p1","state":"DOWN"},"9":{"driver":"mlx5_core","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"24:8a:07:1e:05:bc","name":"enp193s0f0np0","state":"UP"}}},"kernel_cmdline":"BOOT_IMAGE=/boot/linux26 ro ramdisk_size=16777216 rw splash=verbose proxdebug vga=788","network":{"dns":{"dns":["192.168.1.254"],"domain":null},"interfaces":{"eno1":{"addresses":[{"address":"192.168.1.114","family":"inet","prefix":24}],"index":4,"mac":"b4:2e:99:ac:ad:b4","name":"eno1","state":"UP"},"eno2":{"index":6,"mac":"b4:2e:99:ac:ad:b5","name":"eno2","state":"UP"},"enp129s0f0np0":{"index":7,"mac":"1c:34:da:5c:5e:24","name":"enp129s0f0np0","state":"DOWN"},"enp129s0f1np1":{"index":8,"mac":"1c:34:da:5c:5e:25","name":"enp129s0f1np1","state":"DOWN"},"enp193s0f0np0":{"index":9,"mac":"24:8a:07:1e:05:bc","name":"enp193s0f0np0","state":"UP"},"enp193s0f1np1":{"index":10,"mac":"24:8a:07:1e:05:bd","name":"enp193s0f1np1","state":"DOWN"},"enp65s0f0":{"index":2,"mac":"a0:36:9f:0a:b3:82","name":"enp65s0f0","state":"DOWN"},"en p65s0f1":{"index":3,"mac":"a0:36:9f:0a:b3:83","name":"enp65s0f1","state":"DOWN"},"enx5a4732ddc747":{"index":5,"mac":"5a:47:32:dd:c7:47","name":"enx5a4732ddc747","state":"UNKNOWN"}},"routes":{"gateway4":{"dev":"eno1","gateway":"192.168.1.1"}}},"total_memory":257597} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.toml b/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.toml new file mode 100644 index 0000000..9d13a5f --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/no_fqdn_from_dhcp.toml @@ -0,0 +1,14 @@ +[global] +keyboard = "de" +country = "at" +fqdn.source = "from-dhcp" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root_password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk_list = ["sda"] diff --git a/proxmox-auto-installer/tests/resources/run-env-info.json b/proxmox-auto-installer/tests/resources/run-env-info.json index 6762470..2687a8a 100644 --- a/proxmox-auto-installer/tests/resources/run-env-info.json +++ b/proxmox-auto-installer/tests/resources/run-env-info.json @@ -1 +1 @@ -{"boot_type":"efi","country":"at","disks":[[0,"/dev/nvme0n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme0n1"],[1,"/dev/nvme1n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme1n1"],[2,"/dev/nvme2n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme2n1"],[3,"/dev/nvme3n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme3n1"],[4,"/dev/nvme4n1",976773168,"Samsung SSD 970 EVO Plus 500GB",512,"/sys/block/nvme4n1"],[5,"/dev/nvme5n1",732585168,"INTEL SSDPED1K375GA",512,"/sys/block/nvme5n1"],[6,"/dev/sda",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sda"],[7,"/dev/sdb",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdb"],[8,"/dev/sdc",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdc"],[9,"/dev/sdd",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdd"]],"hvm_supported":1,"ipconf":{"default":"4","dnsserver":"192.168.1.254","domain":null,"gateway":"192.168.1.1","ifaces":{"10":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac" :"24:8a:07:1e:05:bd","name":"enp193s0f1np1","state":"DOWN"},"2":{"driver":"igb","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"a0:36:9f:0a:b3:82","name":"enp65s0f0","state":"DOWN"},"3":{"driver":"igb","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"a0:36:9f:0a:b3:83","name":"enp65s0f1","state":"DOWN"},"4":{"driver":"igb","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","inet":{"addr":"192.168.1.114","mask":"255.255.240.0","prefix":20},"mac":"b4:2e:99:ac:ad:b4","name":"eno1","state":"UP"},"5":{"driver":"cdc_ether","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"5a:47:32:dd:c7:47","name":"enx5a4732ddc747","state":"UNKNOWN"},"6":{"driver":"igb","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"b4:2e:99:ac:ad:b5","name":"eno2","state":"UP"},"7":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"1c:34:da:5c:5e:24","name":"enp129s0f0np0","state":"DOWN"},"8":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"1c:34:da:5c:5e:25","name":"enp129s0f1n p1","state":"DOWN"},"9":{"driver":"mlx5_core","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"24:8a:07:1e:05:bc","name":"enp193s0f0np0","state":"UP"}}},"kernel_cmdline":"BOOT_IMAGE=/boot/linux26 ro ramdisk_size=16777216 rw splash=verbose proxdebug vga=788","network":{"dns":{"dns":["192.168.1.254"],"domain":null},"interfaces":{"eno1":{"addresses":[{"address":"192.168.1.114","family":"inet","prefix":24}],"index":4,"mac":"b4:2e:99:ac:ad:b4","name":"eno1","state":"UP"},"eno2":{"index":6,"mac":"b4:2e:99:ac:ad:b5","name":"eno2","state":"UP"},"enp129s0f0np0":{"index":7,"mac":"1c:34:da:5c:5e:24","name":"enp129s0f0np0","state":"DOWN"},"enp129s0f1np1":{"index":8,"mac":"1c:34:da:5c:5e:25","name":"enp129s0f1np1","state":"DOWN"},"enp193s0f0np0":{"index":9,"mac":"24:8a:07:1e:05:bc","name":"enp193s0f0np0","state":"UP"},"enp193s0f1np1":{"index":10,"mac":"24:8a:07:1e:05:bd","name":"enp193s0f1np1","state":"DOWN"},"enp65s0f0":{"index":2,"mac":"a0:36:9f:0a:b3:82","name":"enp65s0f0","state":"DOWN"},"en p65s0f1":{"index":3,"mac":"a0:36:9f:0a:b3:83","name":"enp65s0f1","state":"DOWN"},"enx5a4732ddc747":{"index":5,"mac":"5a:47:32:dd:c7:47","name":"enx5a4732ddc747","state":"UNKNOWN"}},"routes":{"gateway4":{"dev":"eno1","gateway":"192.168.1.1"}}},"total_memory":257597} +{"boot_type":"efi","country":"at","disks":[[0,"/dev/nvme0n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme0n1"],[1,"/dev/nvme1n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme1n1"],[2,"/dev/nvme2n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme2n1"],[3,"/dev/nvme3n1",6251233968,"Micron_9300_MTFDHAL3T2TDR",4096,"/sys/block/nvme3n1"],[4,"/dev/nvme4n1",976773168,"Samsung SSD 970 EVO Plus 500GB",512,"/sys/block/nvme4n1"],[5,"/dev/nvme5n1",732585168,"INTEL SSDPED1K375GA",512,"/sys/block/nvme5n1"],[6,"/dev/sda",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sda"],[7,"/dev/sdb",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdb"],[8,"/dev/sdc",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdc"],[9,"/dev/sdd",468862128,"SAMSUNG MZ7KM240",512,"/sys/block/sdd"]],"hvm_supported":1,"ipconf":{"default":"4","dnsserver":"192.168.1.254","domain":"test.local","gateway":"192.168.1.1","ifaces":{"10":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,U P","mac":"24:8a:07:1e:05:bd","name":"enp193s0f1np1","state":"DOWN"},"2":{"driver":"igb","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"a0:36:9f:0a:b3:82","name":"enp65s0f0","state":"DOWN"},"3":{"driver":"igb","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"a0:36:9f:0a:b3:83","name":"enp65s0f1","state":"DOWN"},"4":{"driver":"igb","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","inet":{"addr":"192.168.1.114","mask":"255.255.240.0","prefix":20},"mac":"b4:2e:99:ac:ad:b4","name":"eno1","state":"UP"},"5":{"driver":"cdc_ether","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"5a:47:32:dd:c7:47","name":"enx5a4732ddc747","state":"UNKNOWN"},"6":{"driver":"igb","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"b4:2e:99:ac:ad:b5","name":"eno2","state":"UP"},"7":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"1c:34:da:5c:5e:24","name":"enp129s0f0np0","state":"DOWN"},"8":{"driver":"mlx5_core","flags":"NO-CARRIER,BROADCAST,MULTICAST,UP","mac":"1c:34:da:5c:5e:25","name":"enp 129s0f1np1","state":"DOWN"},"9":{"driver":"mlx5_core","flags":"BROADCAST,MULTICAST,UP,LOWER_UP","mac":"24:8a:07:1e:05:bc","name":"enp193s0f0np0","state":"UP"}}},"kernel_cmdline":"BOOT_IMAGE=/boot/linux26 ro ramdisk_size=16777216 rw splash=verbose proxdebug vga=788","network":{"hostname":"pveauto","dns":{"dns":["192.168.1.254"],"domain":"test.local"},"interfaces":{"eno1":{"addresses":[{"address":"192.168.1.114","family":"inet","prefix":24}],"index":4,"mac":"b4:2e:99:ac:ad:b4","name":"eno1","state":"UP"},"eno2":{"index":6,"mac":"b4:2e:99:ac:ad:b5","name":"eno2","state":"UP"},"enp129s0f0np0":{"index":7,"mac":"1c:34:da:5c:5e:24","name":"enp129s0f0np0","state":"DOWN"},"enp129s0f1np1":{"index":8,"mac":"1c:34:da:5c:5e:25","name":"enp129s0f1np1","state":"DOWN"},"enp193s0f0np0":{"index":9,"mac":"24:8a:07:1e:05:bc","name":"enp193s0f0np0","state":"UP"},"enp193s0f1np1":{"index":10,"mac":"24:8a:07:1e:05:bd","name":"enp193s0f1np1","state":"DOWN"},"enp65s0f0":{"index":2,"mac":"a0:36:9f:0a:b3:82"," name":"enp65s0f0","state":"DOWN"},"enp65s0f1":{"index":3,"mac":"a0:36:9f:0a:b3:83","name":"enp65s0f1","state":"DOWN"},"enx5a4732ddc747":{"index":5,"mac":"5a:47:32:dd:c7:47","name":"enx5a4732ddc747","state":"UNKNOWN"}},"routes":{"gateway4":{"dev":"eno1","gateway":"192.168.1.1"}}},"total_memory":257597} diff --git a/proxmox-post-hook/src/main.rs b/proxmox-post-hook/src/main.rs index d03ce21..959a0d7 100644 --- a/proxmox-post-hook/src/main.rs +++ b/proxmox-post-hook/src/main.rs @@ -21,11 +21,11 @@ use std::{ use anyhow::{Context, Result, anyhow, bail}; use proxmox_auto_installer::{ - answer::{Answer, PostNotificationHookInfo}, + answer::{Answer, FqdnConfig, FqdnExtendedConfig, FqdnSourceMode, PostNotificationHookInfo}, udevinfo::{UdevInfo, UdevProperties}, }; use proxmox_installer_common::{ - options::{Disk, FsType}, + options::{Disk, FsType, NetworkOptions}, setup::{ BootType, InstallConfig, IsoInfo, ProxmoxProduct, RuntimeInfo, SetupInfo, load_installer_setup_files, @@ -247,6 +247,19 @@ impl PostHookInfo { .and_then(|r| Ok(String::from_utf8(r.stdout)?)) }; + let fqdn = match &answer.global.fqdn { + FqdnConfig::Simple(name) => name.to_string(), + FqdnConfig::Extended(FqdnExtendedConfig { + source: FqdnSourceMode::FromDhcp, + domain, + }) => NetworkOptions::construct_fqdn( + &run_env.network, + setup_info.config.product.default_hostname(), + domain.as_deref(), + ) + .to_string(), + }; + Ok(Self { schema: PostHookInfoSchema::default(), debian_version: read_file("/etc/debian_version")?, @@ -260,7 +273,7 @@ impl PostHookInfo { cpu_info: Self::gather_cpu_info(&run_env)?, dmi: SystemDMI::get()?, filesystem: answer.disks.fs_type, - fqdn: answer.global.fqdn.to_string(), + fqdn, machine_id: read_file("/etc/machine-id")?, disks: Self::gather_disks(&config, &run_env, &udev)?, network_interfaces: Self::gather_nic(&config, &run_env, &udev)?, -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration 2025-03-27 15:17 ` [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration Christoph Heiss @ 2025-04-01 13:15 ` Daniel Kral 2025-04-01 13:25 ` Christoph Heiss 0 siblings, 1 reply; 18+ messages in thread From: Daniel Kral @ 2025-04-01 13:15 UTC (permalink / raw) To: Proxmox VE development discussion, Christoph Heiss On 3/27/25 16:17, Christoph Heiss wrote: > The test suite is extended quite a bit, to cover all the different > cases. > > [0] https://bugzilla.proxmox.com/show_bug.cgi?id=5811 > > Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> > --- > proxmox-auto-installer/src/answer.rs | 36 +++++++++++++++++- > proxmox-auto-installer/src/utils.rs | 37 ++++++++++++++++--- > proxmox-auto-installer/tests/parse-answer.rs | 8 ++++ > .../parse_answer/fqdn_from_dhcp.json | 19 ++++++++++ > .../parse_answer/fqdn_from_dhcp.toml | 14 +++++++ > ...cp_no_dhcp_domain_with_default_domain.json | 19 ++++++++++ > ...cp_no_dhcp_domain_with_default_domain.toml | 17 +++++++++ > ...ll_fqdn_from_dhcp_with_default_domain.json | 19 ++++++++++ > ...ll_fqdn_from_dhcp_with_default_domain.toml | 17 +++++++++ > .../fqdn_from_dhcp_no_default_domain.json | 3 ++ > ...n_from_dhcp_no_default_domain.run-env.json | 1 + > .../fqdn_from_dhcp_no_default_domain.toml | 14 +++++++ > .../parse_answer_fail/fqdn_hostname_only.json | 3 ++ > .../parse_answer_fail/fqdn_hostname_only.toml | 14 +++++++ > .../parse_answer_fail/no_fqdn_from_dhcp.json | 3 ++ > .../no_fqdn_from_dhcp.run-env.json | 1 + > .../parse_answer_fail/no_fqdn_from_dhcp.toml | 14 +++++++ > .../tests/resources/run-env-info.json | 2 +- > proxmox-post-hook/src/main.rs | 19 ++++++++-- > 19 files changed, 250 insertions(+), 10 deletions(-) Just tried to apply this, and it seems like the diff for the JSON files is malformed as it splits the changes at roughly 1000 characters for the changes to run-env*.json files: * run-env-info.json * no_fqdn_from_dhcp.run-env.json * fqdn_from_dhcp_no_default_domain.run-env.json I'm not sure what could have caused this, but after manually fixing this, the rest of the patch applies cleanly and the tests run fine. _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration 2025-04-01 13:15 ` Daniel Kral @ 2025-04-01 13:25 ` Christoph Heiss 2025-04-01 13:29 ` Stefan Hanreich 0 siblings, 1 reply; 18+ messages in thread From: Christoph Heiss @ 2025-04-01 13:25 UTC (permalink / raw) To: Daniel Kral; +Cc: Proxmox VE development discussion Thanks for testing! On Tue Apr 1, 2025 at 3:15 PM CEST, Daniel Kral wrote: [..] > Just tried to apply this, and it seems like the diff for the JSON files > is malformed as it splits the changes at roughly 1000 characters for the > changes to run-env*.json files: > > * run-env-info.json > * no_fqdn_from_dhcp.run-env.json > * fqdn_from_dhcp_no_default_domain.run-env.json Right, thanks for noticing! That definitely is broken, unfortunately. Probably a hard-limit somewhere with 1000 characters per line along the line. The file directly from `git format-patch` looks fine, with no extra newlines. Sent the patches using `git send-email` as usual, so not sure where it went wrong. I'll see if I can reproduce it locally for me and fix it up for a v2. (Otherwise I'll just pretty-print/format these JSON files for v2.) > > I'm not sure what could have caused this, but after manually fixing > this, the rest of the patch applies cleanly and the tests run fine. _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration 2025-04-01 13:25 ` Christoph Heiss @ 2025-04-01 13:29 ` Stefan Hanreich 2025-04-01 13:44 ` Daniel Kral 0 siblings, 1 reply; 18+ messages in thread From: Stefan Hanreich @ 2025-04-01 13:29 UTC (permalink / raw) To: Proxmox VE development discussion, Christoph Heiss, Daniel Kral On 4/1/25 15:25, Christoph Heiss wrote: > The file directly from `git format-patch` looks fine, with no extra > newlines. Sent the patches using `git send-email` as usual, so not sure > where it went wrong. > I'll see if I can reproduce it locally for me and fix it up for a v2. I think this happened for me as well once with the firewall patch series and the mailing list trims / truncates overly long lines iirc. _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration 2025-04-01 13:29 ` Stefan Hanreich @ 2025-04-01 13:44 ` Daniel Kral 2025-04-01 14:58 ` Thomas Lamprecht 0 siblings, 1 reply; 18+ messages in thread From: Daniel Kral @ 2025-04-01 13:44 UTC (permalink / raw) To: Stefan Hanreich, Proxmox VE development discussion, Christoph Heiss On 4/1/25 15:29, Stefan Hanreich wrote: > On 4/1/25 15:25, Christoph Heiss wrote: >> The file directly from `git format-patch` looks fine, with no extra >> newlines. Sent the patches using `git send-email` as usual, so not sure >> where it went wrong. >> I'll see if I can reproduce it locally for me and fix it up for a v2. > > I think this happened for me as well once with the firewall patch series > and the mailing list trims / truncates overly long lines iirc. Hm, interesting! Just checked against the patch that created the JSON file [0] seems fine there, but admittedly the patch there is encoded in base64, could that be a reason for this? [0] https://lore.proxmox.com/pve-devel/20240417123108.212720-14-a.lauterer@proxmox.com/ _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration 2025-04-01 13:44 ` Daniel Kral @ 2025-04-01 14:58 ` Thomas Lamprecht 0 siblings, 0 replies; 18+ messages in thread From: Thomas Lamprecht @ 2025-04-01 14:58 UTC (permalink / raw) To: Proxmox VE development discussion, Daniel Kral, Stefan Hanreich, Christoph Heiss Am 01.04.25 um 15:44 schrieb Daniel Kral: > On 4/1/25 15:29, Stefan Hanreich wrote: >> On 4/1/25 15:25, Christoph Heiss wrote: >>> The file directly from `git format-patch` looks fine, with no extra >>> newlines. Sent the patches using `git send-email` as usual, so not sure >>> where it went wrong. >>> I'll see if I can reproduce it locally for me and fix it up for a v2. >> >> I think this happened for me as well once with the firewall patch series >> and the mailing list trims / truncates overly long lines iirc. > > Hm, interesting! Just checked against the patch that created the JSON > file [0] seems fine there, but admittedly the patch there is encoded in > base64, could that be a reason for this? > > [0] > https://lore.proxmox.com/pve-devel/20240417123108.212720-14-a.lauterer@proxmox.com/ Welcome to the world of email ;-) SMTP (RFC 2822, replaced by 5322, but same holds true) dictates: There are two limits that this specification places on the number of characters in a line. Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF. And yes, encoding a message as base64 avoids this as these can be wrapped at any point, thus avoiding long line lengths in the transport of the message while allowing longer ones in the message itself. _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration 2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss ` (5 preceding siblings ...) 2025-03-27 15:17 ` [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration Christoph Heiss @ 2025-04-01 13:45 ` Daniel Kral 2025-04-01 14:05 ` Christoph Heiss 6 siblings, 1 reply; 18+ messages in thread From: Daniel Kral @ 2025-04-01 13:45 UTC (permalink / raw) To: Proxmox VE development discussion, Christoph Heiss On 3/27/25 16:17, Christoph Heiss wrote: > Fixes #5811 [0]. > > Adds a new option to the answer file for specifying to use the > DHCP-provided hostname and domain. For the domain, an additional > fallback/default can be specified, in case the DHCP server only provides > hostnames. The hostname is always required in this mode. > > The addition to the answer file format is done in a backwards-compatible > way. > > Users can now specify the following to use the DHCP-provided domain: > > ``` > [global] > fqdn.source = "from-dhcp" > ``` > > or additionally with a custom domain: > > ``` > [global.fqdn] > source = "from-dhcp" > domain = "custom.domain.local" > ``` > > Patches #1 through #4 can all be applied independently, #1 & #4 are pure > cleanups. > > [0] https://bugzilla.proxmox.com/show_bug.cgi?id=5811 > > Diffstat > ======== > > Christoph Heiss (6): > auto: utils: avoid a force unwrap() > auto: tests: parse-answer: allow per-test runtime env > auto: tests: allow testing for serde parse errors of answer files > tui, common: move network option tests to correct crate > common: options: allow user-supplied domain for network options > fix #5811: auto: add option to retrieve FQDN from DHCP configuration Tested this patch series with setting up a DHCP server through dnsmasq, where I set up the dnsmasq with `dhcp-fqdn` and `domain=something.com` for the domain part, and `dhcp-host=<MAC>,<IPaddr>,<HOSTNAME>`. I tested `global.fqdn.source = 'from-dhcp'` with both `global.fqdn.domain` set and unset for: - not setting hostnames nor domain at all -> correctly errors for both, - setting a hostname but no domain -> correctly errors for unset domain, works as expected with fallback domain, - setting no hostname but a domain -> correctly errors for both, - setting both a hostname and a domain -> works as expected. Also tested that for the working cases these are set as the fqdn after installation, and also tested that setting `fqdn = "some.local.domain"` also still works as expected as before. Works great! Just wanted to ask: Would it make sense to also have a fallback for the hostname if the DHCP server does only provide a domain but no hostname here or should the DHCP provide the full FQDN? Else, consider this series as: Tested-by: Daniel Kral <d.kral@proxmox.com> _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration 2025-04-01 13:45 ` [pve-devel] [PATCH installer 0/6] fix #5811: " Daniel Kral @ 2025-04-01 14:05 ` Christoph Heiss 0 siblings, 0 replies; 18+ messages in thread From: Christoph Heiss @ 2025-04-01 14:05 UTC (permalink / raw) To: Daniel Kral; +Cc: Proxmox VE development discussion On Tue Apr 1, 2025 at 3:45 PM CEST, Daniel Kral wrote: [..] > Just wanted to ask: Would it make sense to also have a fallback for the > hostname if the DHCP server does only provide a domain but no hostname > here or should the DHCP provide the full FQDN? I thought about that, but it really does not make sense. Setting `global.fqdn.source = "from-dhcp"` is a option that must be actively set by the user and it just does not make sense, if the DHCP does not provide (at least) a hostname. At this point, the hostname can also be set directly in the answer file as before, instead of using this option. > > Else, consider this series as: > > Tested-by: Daniel Kral <d.kral@proxmox.com> Thanks for testing! _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2025-04-04 12:55 UTC | newest] Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss 2025-03-27 15:17 ` [pve-devel] [PATCH installer 1/6] auto: utils: avoid a force unwrap() Christoph Heiss 2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht 2025-03-27 15:17 ` [pve-devel] [PATCH installer 2/6] auto: tests: parse-answer: allow per-test runtime env Christoph Heiss 2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht 2025-03-27 15:17 ` [pve-devel] [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files Christoph Heiss 2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht 2025-03-27 15:17 ` [pve-devel] [PATCH installer 4/6] tui, common: move network option tests to correct crate Christoph Heiss 2025-04-04 12:54 ` Thomas Lamprecht 2025-03-27 15:17 ` [pve-devel] [PATCH installer 5/6] common: options: allow user-supplied domain for network options Christoph Heiss 2025-03-27 15:17 ` [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration Christoph Heiss 2025-04-01 13:15 ` Daniel Kral 2025-04-01 13:25 ` Christoph Heiss 2025-04-01 13:29 ` Stefan Hanreich 2025-04-01 13:44 ` Daniel Kral 2025-04-01 14:58 ` Thomas Lamprecht 2025-04-01 13:45 ` [pve-devel] [PATCH installer 0/6] fix #5811: " Daniel Kral 2025-04-01 14:05 ` Christoph Heiss
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inboxService provided by Proxmox Server Solutions GmbH | Privacy | Legal