From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer v2 1/6] auto, tui: move low-level installer message struct to common crate
Date: Mon, 25 Nov 2024 12:27:15 +0100 [thread overview]
Message-ID: <20241125112900.988346-2-c.heiss@proxmox.com> (raw)
In-Reply-To: <20241125112900.988346-1-c.heiss@proxmox.com>
.. effectively de-duplicating the struct, which currently is defined in
both the auto-installer and the tui-installer separately.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v1 -> v2:
* no changes
.../src/bin/proxmox-auto-installer.rs | 5 +-
proxmox-auto-installer/src/utils.rs | 23 ---------
proxmox-installer-common/src/setup.rs | 23 +++++++++
.../src/views/install_progress.rs | 50 +++++--------------
4 files changed, 39 insertions(+), 62 deletions(-)
diff --git a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
index 4b9d73d..151694f 100644
--- a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
+++ b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
@@ -10,7 +10,8 @@ use std::{
use proxmox_installer_common::{
http,
setup::{
- installer_setup, read_json, spawn_low_level_installer, LocaleInfo, RuntimeInfo, SetupInfo,
+ installer_setup, read_json, spawn_low_level_installer, LocaleInfo, LowLevelMessage,
+ RuntimeInfo, SetupInfo,
},
FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME, RUNTIME_DIR,
};
@@ -19,7 +20,7 @@ use proxmox_auto_installer::{
answer::{Answer, FirstBootHookInfo, FirstBootHookSourceMode},
log::AutoInstLogger,
udevinfo::UdevInfo,
- utils::{parse_answer, LowLevelMessage},
+ utils::parse_answer,
};
static LOGGER: AutoInstLogger = AutoInstLogger;
diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs
index ea7176a..2be81ea 100644
--- a/proxmox-auto-installer/src/utils.rs
+++ b/proxmox-auto-installer/src/utils.rs
@@ -441,26 +441,3 @@ pub fn parse_answer(
Ok(config)
}
-
-#[derive(Clone, Debug, Deserialize, PartialEq)]
-#[serde(tag = "type", rename_all = "lowercase")]
-pub enum LowLevelMessage {
- #[serde(rename = "message")]
- Info {
- message: String,
- },
- Error {
- message: String,
- },
- Prompt {
- query: String,
- },
- Finished {
- state: String,
- message: String,
- },
- Progress {
- ratio: f32,
- text: String,
- },
-}
diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index 1a9a71c..e22ce4e 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -551,3 +551,26 @@ pub struct InstallConfig {
pub first_boot: InstallFirstBootSetup,
}
+
+#[derive(Clone, Debug, Deserialize, PartialEq)]
+#[serde(tag = "type", rename_all = "lowercase")]
+pub enum LowLevelMessage {
+ #[serde(rename = "message")]
+ Info {
+ message: String,
+ },
+ Error {
+ message: String,
+ },
+ Prompt {
+ query: String,
+ },
+ Finished {
+ state: String,
+ message: String,
+ },
+ Progress {
+ ratio: f32,
+ text: String,
+ },
+}
diff --git a/proxmox-tui-installer/src/views/install_progress.rs b/proxmox-tui-installer/src/views/install_progress.rs
index 4b4a418..585877c 100644
--- a/proxmox-tui-installer/src/views/install_progress.rs
+++ b/proxmox-tui-installer/src/views/install_progress.rs
@@ -4,7 +4,6 @@ use cursive::{
views::{Dialog, DummyView, LinearLayout, PaddedView, ProgressBar, TextView},
CbSink, Cursive,
};
-use serde::Deserialize;
use std::{
fs::File,
io::{BufRead, BufReader, Write},
@@ -14,7 +13,7 @@ use std::{
};
use crate::{abort_install_button, prompt_dialog, InstallerState};
-use proxmox_installer_common::setup::{spawn_low_level_installer, InstallConfig};
+use proxmox_installer_common::setup::{spawn_low_level_installer, InstallConfig, LowLevelMessage};
pub struct InstallProgressView {
view: PaddedView<LinearLayout>,
@@ -105,7 +104,7 @@ impl InstallProgressView {
continue;
}
- let msg = match serde_json::from_str::<UiMessage>(&line) {
+ let msg = match serde_json::from_str::<LowLevelMessage>(&line) {
Ok(msg) => msg,
Err(err) => {
// Not a fatal error, so don't abort the installation by returning
@@ -116,17 +115,17 @@ impl InstallProgressView {
};
let result = match msg.clone() {
- UiMessage::Info { message } => cb_sink.send(Box::new(|siv| {
+ LowLevelMessage::Info { message } => cb_sink.send(Box::new(|siv| {
siv.add_layer(Dialog::info(message).title("Information"));
})),
- UiMessage::Error { message } => cb_sink.send(Box::new(|siv| {
+ LowLevelMessage::Error { message } => cb_sink.send(Box::new(|siv| {
siv.add_layer(Dialog::info(message).title("Error"));
})),
- UiMessage::Prompt { query } => cb_sink.send({
+ LowLevelMessage::Prompt { query } => cb_sink.send({
let writer = writer.clone();
Box::new(move |siv| Self::show_prompt(siv, &query, writer))
}),
- UiMessage::Progress { ratio, text } => {
+ LowLevelMessage::Progress { ratio, text } => {
counter.set((ratio * 100.).floor() as usize);
cb_sink.send(Box::new(move |siv| {
siv.call_on_name(Self::PROGRESS_TEXT_VIEW_ID, |v: &mut TextView| {
@@ -134,7 +133,7 @@ impl InstallProgressView {
});
}))
}
- UiMessage::Finished { state, message } => {
+ LowLevelMessage::Finished { state, message } => {
counter.set(100);
cb_sink.send(Box::new(move |siv| {
siv.call_on_name(Self::PROGRESS_TEXT_VIEW_ID, |v: &mut TextView| {
@@ -245,39 +244,16 @@ impl ViewWrapper for InstallProgressView {
cursive::wrap_impl!(self.view: PaddedView<LinearLayout>);
}
-#[derive(Clone, Debug, Deserialize, PartialEq)]
-#[serde(tag = "type", rename_all = "lowercase")]
-enum UiMessage {
- #[serde(rename = "message")]
- Info {
- message: String,
- },
- Error {
- message: String,
- },
- Prompt {
- query: String,
- },
- Finished {
- state: String,
- message: String,
- },
- Progress {
- ratio: f32,
- text: String,
- },
-}
-
#[cfg(test)]
mod tests {
use super::*;
use std::env;
- fn next_msg<R: BufRead>(reader: &mut R) -> Option<UiMessage> {
+ fn next_msg<R: BufRead>(reader: &mut R) -> Option<LowLevelMessage> {
let mut line = String::new();
reader.read_line(&mut line).expect("a line");
- match serde_json::from_str::<UiMessage>(&line) {
+ match serde_json::from_str::<LowLevelMessage>(&line) {
Ok(msg) => Some(msg),
Err(err) => {
eprintln!("invalid json: '{err}'");
@@ -310,7 +286,7 @@ mod tests {
assert_eq!(
next_msg(&mut reader),
- Some(UiMessage::Prompt {
+ Some(LowLevelMessage::Prompt {
query: "Reply anything?".to_owned()
}),
);
@@ -324,7 +300,7 @@ mod tests {
assert_eq!(
next_msg(&mut reader),
- Some(UiMessage::Info {
+ Some(LowLevelMessage::Info {
message: "Test Message - got ok".to_owned()
}),
);
@@ -332,7 +308,7 @@ mod tests {
for i in (1..=1000).step_by(3) {
assert_eq!(
next_msg(&mut reader),
- Some(UiMessage::Progress {
+ Some(LowLevelMessage::Progress {
ratio: (i as f32) / 1000.,
text: format!("foo {i}"),
}),
@@ -341,7 +317,7 @@ mod tests {
assert_eq!(
next_msg(&mut reader),
- Some(UiMessage::Finished {
+ Some(LowLevelMessage::Finished {
state: "ok".to_owned(),
message: "Installation finished - reboot now?".to_owned(),
}),
--
2.47.0
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2024-11-25 11:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 11:27 [pve-devel] [PATCH installer v2 0/6] small, overall install progress improvements Christoph Heiss
2024-11-25 11:27 ` Christoph Heiss [this message]
2024-11-25 11:27 ` [pve-devel] [PATCH installer v2 2/6] auto: log non-json low-level messages into separate file Christoph Heiss
2024-11-25 11:27 ` [pve-devel] [PATCH installer v2 3/6] low-level: stdio: fix: make progress text properly optional Christoph Heiss
2024-11-25 11:27 ` [pve-devel] [PATCH installer v2 4/6] low-level: add proper message to 100% progress ratio update Christoph Heiss
2024-11-25 11:27 ` [pve-devel] [PATCH installer v2 5/6] auto: avoid printing unnecessary progress update lines Christoph Heiss
2024-11-25 11:27 ` [pve-devel] [PATCH installer v2 6/6] tui: tests: catch EOF from proxmox-low-level-installer early Christoph Heiss
2024-11-25 22:25 ` [pve-devel] applied-series: [PATCH installer v2 0/6] small, overall install progress improvements Thomas Lamprecht
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=20241125112900.988346-2-c.heiss@proxmox.com \
--to=c.heiss@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