public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: Aaron Lauterer <a.lauterer@proxmox.com>
Cc: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH installer v6 36/36] autoinst-helper: add prepare-iso subcommand
Date: Thu, 18 Apr 2024 10:48:09 +0200	[thread overview]
Message-ID: <ngfu5db7q42yvem2in63zc2cqgakvu7grpaztvefw4qmrlfnhs@bsn6bewqmwsj> (raw)
In-Reply-To: <20240417123108.212720-37-a.lauterer@proxmox.com>

Just quick three notes inline; nits other than the crate thing.
Did not review in depth, LGTM overall tho.

On Wed, Apr 17, 2024 at 02:31:08PM +0200, Aaron Lauterer wrote:
[..]
> diff --git a/proxmox-autoinst-helper/Cargo.toml b/proxmox-autoinst-helper/Cargo.toml
> index 2a88c0f..75399e0 100644
> --- a/proxmox-autoinst-helper/Cargo.toml
> +++ b/proxmox-autoinst-helper/Cargo.toml
> @@ -19,3 +19,4 @@ serde_json = "1.0"
>  toml = "0.7"
>  log = "0.4.20"
>  regex = "1.7"
> +which = "4.2.5"

Misses the debian/control entry, but see also below.

[..]
>
> +fn prepare_iso(args: &CommandPrepareISO) -> Result<()> {
> +    check_prepare_requirements(args)?;
> +
> +    if args.install_mode == AutoInstModes::Included && args.answer_file.is_none() {
> +        bail!("Missing path to answer file needed for 'direct' install mode.");
> +    }
> +    if args.install_mode == AutoInstModes::Included && args.cert_fingerprint.is_some() {
> +        bail!("No certificate fingerprint needed for direct install mode. Drop the parameter!");
> +    }
> +    if args.install_mode == AutoInstModes::Included && args.url.is_some() {
> +        bail!("No URL needed for direct install mode. Drop the parameter!");
> +    }

  if args.install_mode == AutoInstModes::Included {
    if args.answer_file.is_none() {
        bail!("Missing path to answer file needed for 'direct' install mode.");
    }
    if args.cert_fingerprint.is_some() {
        bail!("No certificate fingerprint needed for direct install mode. Drop the parameter!");
    }
    if args.url.is_some() {
        bail!("No URL needed for direct install mode. Drop the parameter!");
    }
  } else if (args.install_mode == AutoInstModes::Partition) { .. }

.. maybe, to avoid the repeated condition? (The resulting visual
grouping is also nice)


> +    if args.answer_file.is_some() && args.install_mode != AutoInstModes::Included {
> +        bail!("Set '-i', '--install-mode' to 'included' to place the answer file directly in the ISO.");
> +    }
> +    if args.install_mode == AutoInstModes::Partition && args.cert_fingerprint.is_some() {
> +        bail!("No certificate fingerprint needed for partition install mode. Drop the parameter!");
> +    }
> +    if args.install_mode == AutoInstModes::Partition && args.url.is_some() {
> +        bail!("No URL needed for partition install mode. Drop the parameter!");
> +    }
> +
[..]
> +
>  fn get_disks() -> Result<BTreeMap<String, BTreeMap<String, String>>> {
>      let unwantend_block_devs = vec![
>          "ram[0-9]*",
> @@ -335,3 +510,53 @@ fn get_udev_properties(path: &PathBuf) -> Result<String> {
>      }
>      Ok(String::from_utf8(udev_output.stdout)?)
>  }
> +
> +fn parse_answer(path: &PathBuf) -> Result<Answer> {
> +    let mut file = match fs::File::open(path) {
> +        Ok(file) => file,
> +        Err(err) => bail!("Opening answer file '{}' failed: {err}", path.display()),
> +    };
> +    let mut contents = String::new();
> +    if let Err(err) = file.read_to_string(&mut contents) {
> +        bail!("Reading from file '{}' failed: {err}", path.display());
> +    }

There is also std::fs::read_to_string() for exactly that; and would
avoid the whole open/close dance :^)

(Seems I missed that when reviewing the patch that introduced
validate_answer())

> +    match toml::from_str(&contents) {
> +        Ok(answer) => {
> +            println!("The file was parsed successfully, no syntax errors found!");
> +            Ok(answer)
> +        }
> +        Err(err) => bail!("Error parsing answer file: {err}"),
> +    }
> +}
> +
> +fn check_prepare_requirements(args: &CommandPrepareISO) -> Result<()> {
> +    match which("xorriso") {

Do we really need _yet another_ crate dependency for that? Below is a
check / bail! anyway when running the command proper.

And if we really want a explicit check beforehand, I'd just do something
like

  fn which(name: &str) -> Result<()> {
      match Command::new(name).output() {
          Ok(_) => Ok(()),
          Err(err) => Err(err.into()),
      }
  }

> +        Ok(_) => (),
> +        Err(_) => bail!("Could not find 'xorriso'. Please install it and try again"),
> +    }
> +
> +    match Path::try_exists(&args.source) {
> +        Ok(true) => (),
> +        Ok(false) => bail!("Source file does not exist."),
> +        Err(_) => bail!("Source file does not exist."),
> +    }
> +
> +    match Command::new("xorriso")
> +        .arg("-dev")
> +        .arg(&args.source)
> +        .arg("-find")
> +        .arg(PROXMOX_ISO_FLAG)
> +        .stderr(Stdio::null())
> +        .stdout(Stdio::null())
> +        .status()
> +    {
> +        Ok(v) => {
> +            if !v.success() {
> +                bail!("The source ISO file is not able to be installed automatically. Please try a more current one.");
> +            }
> +        }
> +        Err(_) => bail!("Could not run 'xorriso'. Please install it."),
> +    };
> +
> +    Ok(())
> +}
> --
> 2.39.2
>
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
>


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


  reply	other threads:[~2024-04-18  8:48 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 12:30 [pve-devel] [PATCH installer v6 00/36] add automated/unattended installation Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 01/36] tui: common: move InstallConfig struct to common crate Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 02/36] common: make InstallZfsOption members public Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 03/36] common: tui: use BTreeMap for predictable ordering Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 04/36] common: utils: add deserializer for CidrAddress Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 05/36] common: options: add Deserialize trait Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 06/36] low-level: add dump-udev command Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 07/36] add auto-installer crate Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 08/36] auto-installer: add dependencies Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 09/36] auto-installer: add answer file definition Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 10/36] auto-installer: add struct to hold udev info Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 11/36] auto-installer: add utils Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 12/36] auto-installer: add simple logging Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 13/36] auto-installer: add tests for answer file parsing Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 14/36] auto-installer: add auto-installer binary Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 15/36] auto-installer: add fetch answer binary Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 16/36] unconfigured: add proxauto as option to start auto installer Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 17/36] auto-installer: use glob crate for pattern matching Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 18/36] auto-installer: utils: make get_udev_index functions public Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 19/36] auto-installer: add proxmox-autoinst-helper tool Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 20/36] common: add Display trait to ProxmoxProduct Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 21/36] auto-installer: fetch: add gathering of system identifiers and restructure code Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 22/36] auto-installer: helper: add subcommand to view indentifiers Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 23/36] auto-installer: fetch: add http post utility module Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 24/36] auto-installer: fetch: add http plugin to fetch answer Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 25/36] control: update build depends for auto installer Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 26/36] auto installer: factor out fetch-answer and autoinst-helper Aaron Lauterer
2024-04-17 12:30 ` [pve-devel] [PATCH installer v6 27/36] low-level: write low level config to /tmp Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 28/36] common: add deserializer for FsType Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 29/36] common: skip target_hd when deserializing InstallConfig Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 30/36] add proxmox-chroot utility Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 31/36] auto-installer: answer: deny unknown fields Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 32/36] fetch-answer: move get_answer_file to utils Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 33/36] auto-installer: utils: define ISO specified settings Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 34/36] fetch-answer: use ISO specified configurations Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 35/36] fetch-answer: dpcp: improve logging of steps taken Aaron Lauterer
2024-04-17 12:31 ` [pve-devel] [PATCH installer v6 36/36] autoinst-helper: add prepare-iso subcommand Aaron Lauterer
2024-04-18  8:48   ` Christoph Heiss [this message]
2024-04-18  9:13     ` Aaron Lauterer
2024-04-18 13:39     ` Thomas Lamprecht
2024-04-18 11:38   ` [pve-devel] [PATCH installer v6 36/36 follow-up] " Aaron Lauterer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ngfu5db7q42yvem2in63zc2cqgakvu7grpaztvefw4qmrlfnhs@bsn6bewqmwsj \
    --to=c.heiss@proxmox.com \
    --cc=a.lauterer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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