From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 7/7] tui: add tests for RAID setup checks
Date: Thu, 13 Jul 2023 11:49:31 +0200 [thread overview]
Message-ID: <20230713094941.475486-8-c.heiss@proxmox.com> (raw)
In-Reply-To: <20230713094941.475486-1-c.heiss@proxmox.com>
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
proxmox-tui-installer/src/views/bootdisk.rs | 143 ++++++++++++++++++++
1 file changed, 143 insertions(+)
diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs
index 9056323..8303cd7 100644
--- a/proxmox-tui-installer/src/views/bootdisk.rs
+++ b/proxmox-tui-installer/src/views/bootdisk.rs
@@ -714,3 +714,146 @@ fn check_btrfs_raid_config(level: BtrfsRaidLevel, disks: &[Disk]) -> Result<(),
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::HashMap;
+
+ use super::*;
+ use crate::setup::{Dns, NetworkInfo};
+
+ fn dummy_disk(index: usize) -> Disk {
+ Disk {
+ index: index.to_string(),
+ path: format!("/dev/dummy{index}"),
+ model: Some("Dummy disk".to_owned()),
+ size: 1024. * 1024. * 1024. * 8.,
+ block_size: 512,
+ }
+ }
+
+ fn dummy_disks(num: usize) -> Vec<Disk> {
+ (0..num).map(dummy_disk).collect()
+ }
+
+ fn dummy_runinfo(boot_type: BootType) -> RuntimeInfo {
+ RuntimeInfo {
+ boot_type,
+ country: Some("at".to_owned()),
+ disks: dummy_disks(4),
+ network: NetworkInfo {
+ dns: Dns {
+ domain: None,
+ dns: vec![],
+ },
+ routes: None,
+ interfaces: HashMap::new(),
+ },
+ total_memory: 1024 * 1024 * 1024 * 64,
+ }
+ }
+
+ #[test]
+ fn duplicate_disks() {
+ assert!(check_for_duplicate_disks(&dummy_disks(2)).is_ok());
+ assert_eq!(
+ check_for_duplicate_disks(&[
+ dummy_disk(0),
+ dummy_disk(1),
+ dummy_disk(2),
+ dummy_disk(2),
+ dummy_disk(3),
+ ]),
+ Err(&dummy_disk(2)),
+ );
+ }
+
+ #[test]
+ fn raid_min_disks() {
+ let disks = dummy_disks(10);
+
+ assert!(check_raid_min_disks(&disks[..1], 2).is_err());
+ assert!(check_raid_min_disks(&disks[..1], 1).is_ok());
+ assert!(check_raid_min_disks(&disks, 1).is_ok());
+ }
+
+ #[test]
+ fn btrfs_raid() {
+ let disks = dummy_disks(10);
+
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid0, &[]).is_err());
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid0, &disks[..1]).is_ok());
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid0, &disks).is_ok());
+
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid1, &[]).is_err());
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid1, &disks[..1]).is_err());
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid1, &disks[..2]).is_ok());
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid1, &disks).is_ok());
+
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid10, &[]).is_err());
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid10, &disks[..3]).is_err());
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid10, &disks[..4]).is_ok());
+ assert!(check_btrfs_raid_config(BtrfsRaidLevel::Raid10, &disks).is_ok());
+ }
+
+ #[test]
+ fn zfs_raid_bios() {
+ let disks = dummy_disks(10);
+ let runinfo = dummy_runinfo(BootType::Bios);
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid0, &[]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid0, &disks[..1]).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid0, &disks).is_ok());
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid1, &[]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid1, &disks[..2]).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid1, &disks).is_ok());
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid10, &[]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid10, &dummy_disks(4)).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid10, &disks).is_ok());
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ, &[]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ, &disks[..2]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ, &disks[..3]).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ, &disks).is_ok());
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ2, &[]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ2, &disks[..3]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ2, &disks[..4]).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ2, &disks).is_ok());
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ3, &[]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ3, &disks[..4]).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ3, &disks[..5]).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ3, &disks).is_ok());
+
+ for i in 0..10 {
+ let mut disks = dummy_disks(10);
+ disks[i].block_size = 4096;
+
+ // Must fail if /any/ of the disks are 4Kn
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid0, &disks).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid1, &disks).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid10, &disks).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ, &disks).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ2, &disks).is_err());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ3, &disks).is_err());
+ }
+ }
+
+ #[test]
+ fn zfs_raid_efi() {
+ let disks = dummy_disks(10);
+ let runinfo = dummy_runinfo(BootType::Efi);
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid0, &disks[..1]).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid0, &disks).is_ok());
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid1, &disks[..2]).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid1, &disks).is_ok());
+
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid10, &dummy_disks(4)).is_ok());
+ assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid10, &disks).is_ok());
+ }
+}
--
2.41.0
next prev parent reply other threads:[~2023-07-13 9:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-13 9:49 [pve-devel] [PATCH installer 0/7] tui: add ZFS/Btrfs " Christoph Heiss
2023-07-13 9:49 ` [pve-devel] [PATCH installer 1/7] gitignore: add cd-info.test Christoph Heiss
2023-07-13 9:49 ` [pve-devel] [PATCH installer 2/7] tui: fix small typo in error message Christoph Heiss
2023-07-13 9:49 ` [pve-devel] [PATCH installer 3/7] tui: simplify duplicate disk checking logic Christoph Heiss
2023-07-13 9:49 ` [pve-devel] [PATCH installer 4/7] tui: deserialize boot type and disk blocksize from runtime env info Christoph Heiss
2023-07-13 9:49 ` [pve-devel] [PATCH installer 5/7] tui: improve bootdisk dialog error handling Christoph Heiss
2023-07-13 9:49 ` [pve-devel] [PATCH installer 6/7] tui: add RAID setup checks for ZFS/Btrfs Christoph Heiss
2023-07-13 9:49 ` Christoph Heiss [this message]
2023-07-21 14:20 ` [pve-devel] partially-applied: [PATCH installer 0/7] tui: add ZFS/Btrfs RAID setup checks 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=20230713094941.475486-8-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