public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings
@ 2024-12-09 12:45 Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 1/6] tui: options: simplify unit-test setup Christoph Heiss
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Christoph Heiss @ 2024-12-09 12:45 UTC (permalink / raw)
  To: pve-devel

Currently, the answer file is only syntax-checked, i.e. if it can be
parsed as TOML and whether it is of valid structure, but the actual
answer settings are not looked at.

Patch #2 is a refactoring of the whole locale info generation, as to
generate the final information structure at build-time - thus being able
to include it in the auto-install-assistant for verify answer file
settings.

Christoph Heiss (6):
  tui: options: simplify unit-test setup
  country.pl: generate final structure as json at build time directly
  common: setup: read locale info as shipped by the installer directly
  common: setup: include path in error message if file could not be read
  fix #5889: assistant: validate answer email & root password settings
  assistant: validate answer first-boot hook and locale settings

 .gitignore                                    |   2 +-
 Makefile                                      |  16 +--
 Proxmox/Install/ISOEnv.pm                     |  56 +--------
 country.pl                                    | 116 ++++++++++++++----
 proxmox-auto-install-assistant/src/main.rs    |  18 ++-
 proxmox-auto-installer/src/utils.rs           |   6 +-
 .../tests/resources/iso-info.json             |   2 +-
 proxmox-installer-common/src/setup.rs         |  34 +++--
 proxmox-low-level-installer                   |   3 -
 proxmox-tui-installer/src/options.rs          |  26 +---
 10 files changed, 152 insertions(+), 127 deletions(-)

-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pve-devel] [PATCH installer 1/6] tui: options: simplify unit-test setup
  2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
@ 2024-12-09 12:45 ` Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 2/6] country.pl: generate final structure as json at build time directly Christoph Heiss
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Christoph Heiss @ 2024-12-09 12:45 UTC (permalink / raw)
  To: pve-devel

We already have `SetupInfo::mocked()` since commit c3c9282 ("common: add
mocked variants for setup and ISO related info structs"), so use that.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-tui-installer/src/options.rs | 26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/proxmox-tui-installer/src/options.rs b/proxmox-tui-installer/src/options.rs
index e2116d2..8c882b7 100644
--- a/proxmox-tui-installer/src/options.rs
+++ b/proxmox-tui-installer/src/options.rs
@@ -84,35 +84,15 @@ impl InstallerOptions {
 mod tests {
     use super::*;
     use proxmox_installer_common::{
-        setup::{
-            Dns, Gateway, Interface, InterfaceState, IsoInfo, IsoLocations, NetworkInfo,
-            ProductConfig, ProxmoxProduct, Routes, SetupInfo,
-        },
+        setup::{Dns, Gateway, Interface, InterfaceState, NetworkInfo, Routes, SetupInfo},
         utils::{CidrAddress, Fqdn},
     };
+    use std::collections::BTreeMap;
     use std::net::{IpAddr, Ipv4Addr};
-    use std::{collections::BTreeMap, path::PathBuf};
-
-    fn dummy_setup_info() -> SetupInfo {
-        SetupInfo {
-            config: ProductConfig {
-                fullname: "Proxmox VE".to_owned(),
-                product: ProxmoxProduct::PVE,
-                enable_btrfs: true,
-            },
-            iso_info: IsoInfo {
-                release: String::new(),
-                isorelease: String::new(),
-            },
-            locations: IsoLocations {
-                iso: PathBuf::new(),
-            },
-        }
-    }
 
     #[test]
     fn network_options_from_setup_network_info() {
-        let setup = dummy_setup_info();
+        let setup = SetupInfo::mocked();
 
         let mut interfaces = BTreeMap::new();
         interfaces.insert(
-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pve-devel] [PATCH installer 2/6] country.pl: generate final structure as json at build time directly
  2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 1/6] tui: options: simplify unit-test setup Christoph Heiss
@ 2024-12-09 12:45 ` Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 3/6] common: setup: read locale info as shipped by the installer directly Christoph Heiss
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Christoph Heiss @ 2024-12-09 12:45 UTC (permalink / raw)
  To: pve-devel

Currently, we generate a custom-format `country.dat` at build time,
which we then ship with the installer. In the live environment, this
then gets parsed (via regexes) into another format and is finally
written out as JSON for e.g. the TUI and auto-installer to consume.

Instead, skip the intermediate format completely and just generate the
final data structure as JSON at build time.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 .gitignore                                    |   2 +-
 Makefile                                      |  16 +--
 Proxmox/Install/ISOEnv.pm                     |  56 +--------
 country.pl                                    | 116 ++++++++++++++----
 .../tests/resources/iso-info.json             |   2 +-
 5 files changed, 108 insertions(+), 84 deletions(-)

diff --git a/.gitignore b/.gitignore
index d50d191..2a3cd16 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,4 @@
 /test*.img
 /testdir/
 Cargo.lock
-country.dat
+locale-info.json
diff --git a/Makefile b/Makefile
index a17f6c5..af11cca 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ else
 CARGO_COMPILEDIR := target/debug
 endif
 
-INSTALLER_SOURCES=$(shell git ls-files) country.dat
+INSTALLER_SOURCES=$(shell git ls-files) locale-info.json
 
 PREFIX = /usr
 BINDIR = $(PREFIX)/bin
@@ -72,9 +72,9 @@ $(BUILDDIR):
 	cp -a debian $@.tmp/
 	mv $@.tmp $@
 
-country.dat: country.pl
-	./country.pl > country.dat.tmp
-	mv country.dat.tmp country.dat
+locale-info.json: country.pl
+	./country.pl > $@.tmp
+	mv $@.tmp $@
 
 deb: $(DEB)
 $(ASSISTANT_DEB): $(DEB)
@@ -100,10 +100,10 @@ sbuild: $(DSC)
 	sbuild $(DSC)
 
 .PHONY: prepare-test-env
-prepare-test-env: cd-info.test country.dat test.img
+prepare-test-env: cd-info.test locale-info.json test.img
 	rm -rf testdir
 	mkdir -p testdir/var/lib/proxmox-installer/
-	cp -v country.dat testdir/var/lib/proxmox-installer/
+	cp -v locale-info.json testdir/var/lib/proxmox-installer/
 	./proxmox-low-level-installer -t test.img dump-env
 
 .PHONY: test
@@ -124,7 +124,7 @@ install: $(INSTALLER_SOURCES) $(COMPILED_BINS)
 	install -D -m 644 interfaces $(DESTDIR)/etc/network/interfaces
 	install -D -m 755 fake-start-stop-daemon $(VARLIBDIR)/fake-start-stop-daemon
 	install -D -m 755 policy-disable-rc.d $(VARLIBDIR)/policy-disable-rc.d
-	install -D -m 644 country.dat $(VARLIBDIR)/country.dat
+	install -D -m 644 locale-info.json $(VARLIBDIR)/locale-info.json
 	install -D -m 755 unconfigured.sh $(DESTDIR)/sbin/unconfigured.sh
 	install -D -m 755 proxinstall $(DESTDIR)/usr/bin/proxinstall
 	install -D -m 755 proxmox-low-level-installer $(DESTDIR)/$(BINDIR)/proxmox-low-level-installer
@@ -226,5 +226,5 @@ check-pbs-tui: prepare-check-pbs
 clean:
 	rm -rf target build $(PACKAGE)-[0-9]* testdir
 	rm -f $(PACKAGE)*.tar* *.deb packages packages.tmp *.build *.dsc *.buildinfo *.changes
-	rm -f test*.img pve-final.pkglist country.dat final.pkglist cd-info.test
+	rm -f test*.img pve-final.pkglist locale-info.json final.pkglist cd-info.test
 	find . -name '*~' -exec rm {} ';'
diff --git a/Proxmox/Install/ISOEnv.pm b/Proxmox/Install/ISOEnv.pm
index e3b6f51..62945d8 100644
--- a/Proxmox/Install/ISOEnv.pm
+++ b/Proxmox/Install/ISOEnv.pm
@@ -5,6 +5,9 @@ use warnings;
 
 use Carp;
 use Cwd ();
+use JSON qw(from_json);
+
+use Proxmox::Sys::File qw(file_read_all);
 
 use base qw(Exporter);
 our @EXPORT = qw(is_test_mode);
@@ -33,57 +36,8 @@ my $product_cfg = {
 my sub read_locale_info {
     my ($lib_dir) = @_;
 
-    my $countryfn = "${lib_dir}/country.dat";
-    open (my $COUNTRY_MAP_FH, "<:encoding(utf8)", "$countryfn") || die "unable to open '$countryfn' - $!\n";
-
-    my ($country, $countryhash, $kmap, $kmaphash) = ({}, {}, {}, {});
-    while (defined (my $line = <$COUNTRY_MAP_FH>)) {
-	if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
-	    $kmap->{$1} = {
-		name => $2,
-		kvm => $3,
-		console => $4,
-		x11 => $5,
-		x11var => $6,
-	    };
-	    $kmaphash->{$2} = $1;
-	} elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
-	    $country->{$1} = {
-		name => $2,
-		kmap => $3,
-		mirror => $4,
-	    };
-	    $countryhash->{lc($2)} = $1;
-	} else {
-	    warn "unable to parse 'country.dat' line: $line";
-	}
-    }
-    close ($COUNTRY_MAP_FH);
-
-    my $zonefn = "/usr/share/zoneinfo/zone.tab";
-    open (my $ZONE_TAB_FH, '<', "$zonefn") || die "unable to open '$zonefn' - $!\n";
-
-    my ($zones, $cczones) = ({}, {});
-    while (defined (my $line = <$ZONE_TAB_FH>)) {
-	next if $line =~ m/^\s*(?:#|$)/;
-	if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
-	    my $cc = lc($1);
-	    $cczones->{$cc}->{$2} = 1;
-	    $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
-	    $zones->{$2} = 1;
-
-	}
-    }
-    close ($ZONE_TAB_FH);
-
-    return {
-	zones => $zones,
-	cczones => $cczones,
-	country => $country,
-	countryhash => $countryhash,
-	kmap => $kmap,
-	kmaphash => $kmaphash,
-    }
+    my $json = file_read_all("${lib_dir}/locale-info.json");
+    return from_json($json, { utf8 => 1 });
 }
 
 my sub get_cd_info {
diff --git a/country.pl b/country.pl
index b1a2d62..9e4881a 100755
--- a/country.pl
+++ b/country.pl
@@ -4,40 +4,101 @@ use strict;
 use warnings;
 
 use PVE::Tools;
-use JSON;
+use JSON qw(from_json to_json);
 
-# country codes from:
-my $country_codes_file = "/usr/share/iso-codes/json/iso_3166-1.json";
+# Generates a
+#
+#   - country code => name/kmap/mirror
+#   - name => country code
+#
+# mapping for each defined country
+my sub generate_country_mappings {
+    my ($country_codes, $defmap, $mirrors) = @_;
 
-my $iso_3166_codes = from_json(PVE::Tools::file_get_contents($country_codes_file, 64 * 1024));
+    my ($countries, $countryhash) = ({}, {});
+    foreach my $cc (sort keys %$country_codes) {
+	my $name = $country_codes->{$cc};
+	my $kmap = $defmap->{$cc} || '';
+	my $mirror = $mirrors->{$cc} || '';
 
-my $country = { map { lc($_->{'alpha_2'}) => $_->{'common_name'} // $_->{'name'} } @{$iso_3166_codes->{'3166-1'}} };
+	$countries->{$cc} = {
+	    name => $name,
+	    kmap => $kmap,
+	    mirror => $mirror,
+	};
+	$countryhash->{lc($name)} = $cc;
+    }
 
-# we need mappings for X11, console, and kvm vnc
+    return ($countries, $countryhash);
+}
 
+# we need mappings for X11, console, and kvm vnc
 # LC(-LC)? => [DESC, kvm, console, X11, X11variant]
-my $keymaps = PVE::Tools::kvmkeymaps();
+my sub generate_keymaps {
+    my ($country_codes) = @_;
 
-foreach my $km (sort keys %$keymaps) {
-    my ($desc, $kvm, $console, $x11, $x11var) = @{$keymaps->{$km}};
+    my ($kmap, $kmaphash) = ({}, {});
+    my $keymaps = PVE::Tools::kvmkeymaps();
+    foreach my $km (sort keys %$keymaps) {
+	my ($name, $kvm, $console, $x11, $x11var) = @{$keymaps->{$km}};
 
-    if ($km =~m/^([a-z][a-z])-([a-z][a-z])$/i) {
-	defined ($country->{$2}) || die "undefined country code '$2'";
-    } else {
-	defined ($country->{$km}) || die "undefined country code '$km'";
+	if ($km =~m/^([a-z][a-z])-([a-z][a-z])$/i) {
+	    defined ($country_codes->{$2}) || die "undefined country code '$2'";
+	} else {
+	    defined ($country_codes->{$km}) || die "undefined country code '$km'";
+	}
+
+	$x11var = '' if !defined ($x11var);
+
+	$kmap->{$km} = {
+	    name => $name,
+	    kvm => $kvm,
+	    console => $console,
+	    x11 => $x11,
+	    x11var => $x11var,
+	};
+	$kmaphash->{$name} = $km;
     }
 
-    $x11var = '' if !defined ($x11var);
-    print "map:$km:$desc:$kvm:$console:$x11:$x11var:\n";
+    return ($kmap, $kmaphash);
 }
 
+my sub parse_zoneinfo {
+    my ($countries) = @_;
+
+    my $zonefn = "/usr/share/zoneinfo/zone.tab";
+    open (my $ZONE_TAB_FH, '<', "$zonefn") || die "unable to open '$zonefn' - $!\n";
+
+    my ($zones, $cczones) = ({}, {});
+    while (defined (my $line = <$ZONE_TAB_FH>)) {
+	next if $line =~ m/^\s*(?:#|$)/;
+	if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
+	    my $cc = lc($1);
+	    $cczones->{$cc}->{$2} = 1;
+	    $countries->{$cc}->{zone} = $2 if !defined ($countries->{$cc}->{zone});
+	    $zones->{$2} = 1;
+
+	}
+    }
+    close ($ZONE_TAB_FH);
+
+    return ($zones, $cczones);
+}
+
+# country codes from:
+my $country_codes_file = "/usr/share/iso-codes/json/iso_3166-1.json";
+
+my $iso_3166_codes = from_json(PVE::Tools::file_get_contents($country_codes_file, 64 * 1024));
+
+my $country_codes = { map { lc($_->{'alpha_2'}) => $_->{'common_name'} // $_->{'name'} } @{$iso_3166_codes->{'3166-1'}} };
+
 my $defmap = {
    'us' => 'en-us',
    'be' => 'fr-be',
    'br' => 'pt-br',
    'ca' => 'en-us',
    'dk' => 'dk',
-   'nl' => 'en-us', # most Dutch people us US layout
+   'nl' => 'en-us', # most Dutch people use US layout
    'fi' => 'fi',
    'fr' => 'fr',
    'de' => 'de',
@@ -61,14 +122,23 @@ my $defmap = {
    'li' => 'de-ch',
 };
 
-
 my $mirrors = PVE::Tools::debmirrors();
 foreach my $cc (keys %$mirrors) {
-    die "undefined country code '$cc'" if !defined ($country->{$cc});
+    die "undefined country code '$cc'" if !defined ($country_codes->{$cc});
 }
 
-foreach my $cc (sort keys %$country) {
-    my $map = $defmap->{$cc} || '';
-    my $mir = $mirrors->{$cc} || '';
-    print "$cc:$country->{$cc}:$map:$mir:\n";
-}
+my ($countries, $countryhash) = generate_country_mappings($country_codes, $defmap, $mirrors);
+my ($kmap, $kmaphash) = generate_keymaps($country_codes);
+my ($zones, $cczones) = parse_zoneinfo($countries);
+
+my $locale_info = {
+    country => $countries,
+    countryhash => $countryhash,
+    kmap => $kmap,
+    kmaphash => $kmaphash,
+    zones => $zones,
+    cczones => $cczones,
+};
+
+my $json = to_json($locale_info, { utf8 => 1, canonical => 1 });
+print $json;
diff --git a/proxmox-auto-installer/tests/resources/iso-info.json b/proxmox-auto-installer/tests/resources/iso-info.json
index 33cb79b..c5fe456 100644
--- a/proxmox-auto-installer/tests/resources/iso-info.json
+++ b/proxmox-auto-installer/tests/resources/iso-info.json
@@ -1 +1 @@
-{"iso-info":{"isoname":"proxmox-ve","isorelease":"2","product":"pve","productlong":"Proxmox VE","release":"8.0"},"locations":{"iso":"/cdrom","lib":"/var/lib/proxmox-installer","pkg":"/cdrom/proxmox/packages/","run":"/run/proxmox-installer"},"product":"pve","product-cfg":{"bridged_network":1,"enable_btrfs":1,"fullname":"Proxmox VE","port":"8006","product":"pve"},"run-env-cache-file":"/run/proxmox-installer/run-env-info.json"}
+{"iso-info":{"isoname":"proxmox-ve","isorelease":"2","product":"pve","productlong":"Proxmox VE","release":"8.0"},"locations":{"iso":"../testdir","lib":"../testdir/var/lib/proxmox-installer","pkg":"../testdir/cdrom/proxmox/packages/","run":"../testdir/run/proxmox-installer"},"product":"pve","product-cfg":{"bridged_network":1,"enable_btrfs":1,"fullname":"Proxmox VE","port":"8006","product":"pve"},"run-env-cache-file":"testdir/run/proxmox-installer/run-env-info.json"}
-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pve-devel] [PATCH installer 3/6] common: setup: read locale info as shipped by the installer directly
  2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 1/6] tui: options: simplify unit-test setup Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 2/6] country.pl: generate final structure as json at build time directly Christoph Heiss
@ 2024-12-09 12:45 ` Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 4/6] common: setup: include path in error message if file could not be read Christoph Heiss
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Christoph Heiss @ 2024-12-09 12:45 UTC (permalink / raw)
  To: pve-devel

Now that we have a pre-generated `locale-info.json` available, skip
generating one on-the-fly and just read that one.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-installer-common/src/setup.rs | 20 +++++++++++++++-----
 proxmox-low-level-installer           |  3 ---
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index 4b4920e..c3004bc 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -87,13 +87,23 @@ impl IsoInfo {
 #[derive(Clone, Deserialize)]
 pub struct IsoLocations {
     pub iso: PathBuf,
+    pub lib: PathBuf,
 }
 
 impl IsoLocations {
     /// A mocked location, uses the current working directory by default
     pub fn mocked() -> Self {
+        let lib = match std::env::current_dir() {
+            Ok(mut dir) => {
+                dir.push("run");
+                dir
+            }
+            Err(_) => "/dev/null".into(),
+        };
+
         Self {
             iso: std::env::current_dir().unwrap_or("/dev/null".into()),
+            lib,
         }
     }
 }
@@ -171,24 +181,24 @@ pub fn installer_setup(in_test_mode: bool) -> Result<(SetupInfo, LocaleInfo, Run
 }
 
 pub fn load_installer_setup_files(
-    base_path: impl AsRef<Path>,
+    runtime_dir: impl AsRef<Path>,
 ) -> Result<(SetupInfo, LocaleInfo, RuntimeInfo), String> {
     let installer_info: SetupInfo = {
-        let mut path = base_path.as_ref().to_path_buf();
+        let mut path = runtime_dir.as_ref().to_path_buf();
         path.push("iso-info.json");
 
         read_json(&path).map_err(|err| format!("Failed to retrieve setup info: {err}"))?
     };
 
     let locale_info = {
-        let mut path = base_path.as_ref().to_path_buf();
-        path.push("locales.json");
+        let mut path = installer_info.locations.lib.clone();
+        path.push("locale-info.json");
 
         read_json(&path).map_err(|err| format!("Failed to retrieve locale info: {err}"))?
     };
 
     let mut runtime_info: RuntimeInfo = {
-        let mut path = base_path.as_ref().to_path_buf();
+        let mut path = runtime_dir.as_ref().to_path_buf();
         path.push("run-env-info.json");
 
         read_json(&path)
diff --git a/proxmox-low-level-installer b/proxmox-low-level-installer
index e5c2908..bcfe60e 100755
--- a/proxmox-low-level-installer
+++ b/proxmox-low-level-installer
@@ -100,9 +100,6 @@ if ($cmd eq 'dump-env') {
     make_path($out_dir);
     die "failed to create output directory '$out_dir'\n" if !-d $out_dir;
 
-    my $locales_serialized = to_json($env->{locales}, {canonical => 1, utf8 => 1}) ."\n";
-    file_write_all("$out_dir/locales.json", $locales_serialized);
-
     my $iso_info = {
 	'iso-info' => $env->{iso},
 	'product' => $env->{product},
-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pve-devel] [PATCH installer 4/6] common: setup: include path in error message if file could not be read
  2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
                   ` (2 preceding siblings ...)
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 3/6] common: setup: read locale info as shipped by the installer directly Christoph Heiss
@ 2024-12-09 12:45 ` Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 5/6] fix #5889: assistant: validate answer email & root password settings Christoph Heiss
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Christoph Heiss @ 2024-12-09 12:45 UTC (permalink / raw)
  To: pve-devel

Makes it a bit easier to figure out what went wrong in the error case.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-installer-common/src/setup.rs | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index c3004bc..0ef47d2 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -187,22 +187,28 @@ pub fn load_installer_setup_files(
         let mut path = runtime_dir.as_ref().to_path_buf();
         path.push("iso-info.json");
 
-        read_json(&path).map_err(|err| format!("Failed to retrieve setup info: {err}"))?
+        read_json(&path)
+            .map_err(|err| format!("Failed to retrieve setup info: {}: {err}", path.display()))?
     };
 
     let locale_info = {
         let mut path = installer_info.locations.lib.clone();
         path.push("locale-info.json");
 
-        read_json(&path).map_err(|err| format!("Failed to retrieve locale info: {err}"))?
+        read_json(&path)
+            .map_err(|err| format!("Failed to retrieve locale info: {}: {err}", path.display()))?
     };
 
     let mut runtime_info: RuntimeInfo = {
         let mut path = runtime_dir.as_ref().to_path_buf();
         path.push("run-env-info.json");
 
-        read_json(&path)
-            .map_err(|err| format!("Failed to retrieve runtime environment info: {err}"))?
+        read_json(&path).map_err(|err| {
+            format!(
+                "Failed to retrieve runtime environment info: {}: {err}",
+                path.display()
+            )
+        })?
     };
 
     runtime_info.disks.sort();
-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pve-devel] [PATCH installer 5/6] fix #5889: assistant: validate answer email & root password settings
  2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
                   ` (3 preceding siblings ...)
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 4/6] common: setup: include path in error message if file could not be read Christoph Heiss
@ 2024-12-09 12:45 ` Christoph Heiss
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 6/6] assistant: validate answer first-boot hook and locale settings Christoph Heiss
  2024-12-10 17:37 ` [pve-devel] applied-series: [PATCH installer 0/6] assistant: properly validate answer file settings Thomas Lamprecht
  6 siblings, 0 replies; 8+ messages in thread
From: Christoph Heiss @ 2024-12-09 12:45 UTC (permalink / raw)
  To: pve-devel

These checks are basically "free" and can be re-used from the
auto-installer 1:1.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-auto-install-assistant/src/main.rs | 9 +++++----
 proxmox-auto-installer/src/utils.rs        | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/proxmox-auto-install-assistant/src/main.rs b/proxmox-auto-install-assistant/src/main.rs
index c837cba..6796c06 100644
--- a/proxmox-auto-install-assistant/src/main.rs
+++ b/proxmox-auto-install-assistant/src/main.rs
@@ -11,11 +11,11 @@ use std::{
 };
 
 use proxmox_auto_installer::{
-    answer::Answer,
-    answer::FilterMatch,
+    answer::{Answer, FilterMatch},
     sysinfo::SysInfo,
     utils::{
-        get_matched_udev_indexes, get_nic_list, get_single_udev_index, AutoInstSettings,
+        get_matched_udev_indexes, get_nic_list, get_single_udev_index,
+        verify_email_and_root_password_settings, AutoInstSettings,
         FetchAnswerFrom, HttpOptions,
     },
 };
@@ -591,7 +591,8 @@ fn parse_answer(path: impl AsRef<Path> + fmt::Debug) -> Result<Answer> {
     }
     match toml::from_str(&contents) {
         Ok(answer) => {
-            println!("The file was parsed successfully, no syntax errors found!");
+            verify_email_and_root_password_settings(&answer)?;
+            println!("The answer file was parsed successfully, no errors found!");
             Ok(answer)
         }
         Err(err) => bail!("Error parsing answer file: {err}"),
diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs
index 27bbc3b..c26b33c 100644
--- a/proxmox-auto-installer/src/utils.rs
+++ b/proxmox-auto-installer/src/utils.rs
@@ -320,7 +320,7 @@ fn verify_locale_settings(answer: &Answer, locales: &LocaleInfo) -> Result<()> {
     Ok(())
 }
 
-fn verify_email_and_root_password_settings(answer: &Answer) -> Result<()> {
+pub fn verify_email_and_root_password_settings(answer: &Answer) -> Result<()> {
     info!("Verifying email and root password settings");
 
     email_validate(&answer.global.mailto).with_context(|| answer.global.mailto.clone())?;
-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pve-devel] [PATCH installer 6/6] assistant: validate answer first-boot hook and locale settings
  2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
                   ` (4 preceding siblings ...)
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 5/6] fix #5889: assistant: validate answer email & root password settings Christoph Heiss
@ 2024-12-09 12:45 ` Christoph Heiss
  2024-12-10 17:37 ` [pve-devel] applied-series: [PATCH installer 0/6] assistant: properly validate answer file settings Thomas Lamprecht
  6 siblings, 0 replies; 8+ messages in thread
From: Christoph Heiss @ 2024-12-09 12:45 UTC (permalink / raw)
  To: pve-devel

For the first-boot hook, the check from the auto-installer can be easily
re-used.

For the locale, as we now have that information available as JSON,
include that file in the assistant and use it to verify the answer file
settings.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-auto-install-assistant/src/main.rs | 11 +++++++++--
 proxmox-auto-installer/src/utils.rs        |  4 ++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/proxmox-auto-install-assistant/src/main.rs b/proxmox-auto-install-assistant/src/main.rs
index 6796c06..969922c 100644
--- a/proxmox-auto-install-assistant/src/main.rs
+++ b/proxmox-auto-install-assistant/src/main.rs
@@ -15,14 +15,18 @@ use proxmox_auto_installer::{
     sysinfo::SysInfo,
     utils::{
         get_matched_udev_indexes, get_nic_list, get_single_udev_index,
-        verify_email_and_root_password_settings, AutoInstSettings,
-        FetchAnswerFrom, HttpOptions,
+        verify_email_and_root_password_settings, verify_first_boot_settings,
+        verify_locale_settings, AutoInstSettings, FetchAnswerFrom, HttpOptions,
     },
 };
 use proxmox_installer_common::{FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME};
 
 static PROXMOX_ISO_FLAG: &str = "/auto-installer-capable";
 
+/// Locale information as raw JSON, can be parsed into a
+/// [LocaleInfo](`proxmox_installer_common::setup::LocaleInfo`) struct.
+const LOCALE_INFO: &str = include_str!("../../locale-info.json");
+
 /// This tool can be used to prepare a Proxmox installation ISO for automated installations.
 /// Additional uses are to validate the format of an answer file or to test match filters and
 /// print information on the properties to match against for the current hardware.
@@ -589,8 +593,11 @@ fn parse_answer(path: impl AsRef<Path> + fmt::Debug) -> Result<Answer> {
     if let Err(err) = file.read_to_string(&mut contents) {
         bail!("Reading from file {path:?} failed: {err}");
     }
+
     match toml::from_str(&contents) {
         Ok(answer) => {
+            verify_locale_settings(&answer, &serde_json::from_str(LOCALE_INFO)?)?;
+            verify_first_boot_settings(&answer)?;
             verify_email_and_root_password_settings(&answer)?;
             println!("The answer file was parsed successfully, no errors found!");
             Ok(answer)
diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs
index c26b33c..fbf874e 100644
--- a/proxmox-auto-installer/src/utils.rs
+++ b/proxmox-auto-installer/src/utils.rs
@@ -291,7 +291,7 @@ fn verify_filesystem_settings(answer: &Answer, setup_info: &SetupInfo) -> Result
     Ok(())
 }
 
-fn verify_locale_settings(answer: &Answer, locales: &LocaleInfo) -> Result<()> {
+pub fn verify_locale_settings(answer: &Answer, locales: &LocaleInfo) -> Result<()> {
     info!("Verifying locale settings");
     if !locales
         .countries
@@ -335,7 +335,7 @@ pub fn verify_email_and_root_password_settings(answer: &Answer) -> Result<()> {
     }
 }
 
-fn verify_first_boot_settings(answer: &Answer) -> Result<()> {
+pub fn verify_first_boot_settings(answer: &Answer) -> Result<()> {
     info!("Verifying first boot settings");
 
     if let Some(first_boot) = &answer.first_boot {
-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pve-devel] applied-series: [PATCH installer 0/6] assistant: properly validate answer file settings
  2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
                   ` (5 preceding siblings ...)
  2024-12-09 12:45 ` [pve-devel] [PATCH installer 6/6] assistant: validate answer first-boot hook and locale settings Christoph Heiss
@ 2024-12-10 17:37 ` Thomas Lamprecht
  6 siblings, 0 replies; 8+ messages in thread
From: Thomas Lamprecht @ 2024-12-10 17:37 UTC (permalink / raw)
  To: Proxmox VE development discussion, Christoph Heiss

Am 09.12.24 um 13:45 schrieb Christoph Heiss:
> Currently, the answer file is only syntax-checked, i.e. if it can be
> parsed as TOML and whether it is of valid structure, but the actual
> answer settings are not looked at.
> 
> Patch #2 is a refactoring of the whole locale info generation, as to
> generate the final information structure at build-time - thus being able
> to include it in the auto-install-assistant for verify answer file
> settings.
> 
> Christoph Heiss (6):
>   tui: options: simplify unit-test setup
>   country.pl: generate final structure as json at build time directly
>   common: setup: read locale info as shipped by the installer directly
>   common: setup: include path in error message if file could not be read
>   fix #5889: assistant: validate answer email & root password settings
>   assistant: validate answer first-boot hook and locale settings
> 
>  .gitignore                                    |   2 +-
>  Makefile                                      |  16 +--
>  Proxmox/Install/ISOEnv.pm                     |  56 +--------
>  country.pl                                    | 116 ++++++++++++++----
>  proxmox-auto-install-assistant/src/main.rs    |  18 ++-
>  proxmox-auto-installer/src/utils.rs           |   6 +-
>  .../tests/resources/iso-info.json             |   2 +-
>  proxmox-installer-common/src/setup.rs         |  34 +++--
>  proxmox-low-level-installer                   |   3 -
>  proxmox-tui-installer/src/options.rs          |  26 +---
>  10 files changed, 152 insertions(+), 127 deletions(-)
> 


applied series, 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] 8+ messages in thread

end of thread, other threads:[~2024-12-10 17:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 1/6] tui: options: simplify unit-test setup Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 2/6] country.pl: generate final structure as json at build time directly Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 3/6] common: setup: read locale info as shipped by the installer directly Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 4/6] common: setup: include path in error message if file could not be read Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 5/6] fix #5889: assistant: validate answer email & root password settings Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 6/6] assistant: validate answer first-boot hook and locale settings Christoph Heiss
2024-12-10 17:37 ` [pve-devel] applied-series: [PATCH installer 0/6] assistant: properly validate answer file settings Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal