From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 5/5] fake remotes: make use of ClusterResource more resilient to changes
Date: Fri, 20 Mar 2026 10:25:42 +0100 [thread overview]
Message-ID: <20260320092702.1069143-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260320092702.1069143-1-d.csapak@proxmox.com>
since all new properties have to be optional due to backwards
compatibility, we can simply use a json object to parse from with serde.
This is less type safe, but it's more flexible and less prone to
compile errors.
note that we have to explicitly specify u64 for the values, otherwise
rust will assume i32 and overflow.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
server/src/test_support/fake_remote.rs | 223 +++++++++----------------
1 file changed, 80 insertions(+), 143 deletions(-)
diff --git a/server/src/test_support/fake_remote.rs b/server/src/test_support/fake_remote.rs
index ae367f68..d38753d5 100644
--- a/server/src/test_support/fake_remote.rs
+++ b/server/src/test_support/fake_remote.rs
@@ -1,7 +1,8 @@
use std::{sync::Arc, time::Duration};
-use anyhow::{bail, Error};
+use anyhow::{bail, format_err, Error};
use serde::Deserialize;
+use serde_json::json;
use pdm_api_types::{remotes::Remote, Authid, ConfigDigest};
use pdm_config::remotes::RemoteConfig;
@@ -10,8 +11,7 @@ use proxmox_product_config::ApiLockGuard;
use proxmox_section_config::typed::SectionConfigData;
use pve_api_types::{
ClusterMetrics, ClusterMetricsData, ClusterNodeIndexResponse, ClusterNodeIndexResponseStatus,
- ClusterResource, ClusterResourceKind, ClusterResourceType, ListTasks, ListTasksResponse,
- PveUpid, StorageContent,
+ ClusterResource, ClusterResourceKind, ListTasks, ListTasksResponse, PveUpid,
};
use crate::{
@@ -152,163 +152,100 @@ impl pve_api_types::client::PveClient for FakePveClient {
for _ in 0..self.nr_of_vms {
vmid += 1;
let jitter = ((vmid as f64).sin() * bytejitter).round() as i64;
- result.push(ClusterResource {
- cgroup_mode: None,
- content: None,
- cpu: Some(cpu),
- diskread: Some(1034),
- diskwrite: Some(1034),
- disk: Some(disk.saturating_add_signed(jitter)),
- hastate: None,
- id: format!("qemu/{vmid}"),
- level: Some("".into()),
- maxcpu: Some(maxcpu),
- maxdisk: Some(maxdisk),
- maxmem: Some(maxmem),
- mem: Some(mem.saturating_sub_signed(jitter)),
- memhost: Some(memhost.saturating_add_signed(jitter)),
- name: Some(format!("vm-{vmid}")),
- netin: Some(1034),
- netout: Some(1034),
- node: Some(format!("node-{}", vmid % self.nr_of_nodes)),
- plugintype: None,
- pool: None,
- status: Some("running".into()),
- storage: None,
- template: Some(false),
- ty: ClusterResourceType::Qemu,
- uptime: Some(1234),
- vmid: Some(vmid),
- lock: None,
- tags: None,
- sdn: None,
- network: None,
- network_type: None,
- protocol: None,
- shared: None,
- zone_type: None,
+ let val = json!({
+ "cpu": cpu,
+ "diskread": 1034,
+ "diskwrite": 1034,
+ "disk": disk.saturating_add_signed(jitter),
+ "id": format!("qemu/{vmid}"),
+ "level": "",
+ "maxcpu": maxcpu,
+ "maxdisk": maxdisk,
+ "maxmem": maxmem,
+ "mem": mem.saturating_add_signed(jitter),
+ "memhost": memhost.saturating_add_signed(jitter),
+ "name": format!("vm-{vmid}"),
+ "netin": 1034,
+ "netout": 1034,
+ "node": format!("node-{}", vmid % self.nr_of_nodes),
+ "status": "running",
+ "template": false,
+ "type": "qemu",
+ "uptime": 1234,
+ "vmid": vmid,
});
+ result.push(serde_json::from_value(val).map_err(|err| {
+ proxmox_client::Error::Anyhow(format_err!("error on vm {vmid}: {err}"))
+ })?);
}
for _ in 0..self.nr_of_cts {
vmid += 1;
let jitter = ((vmid as f64).sin() * bytejitter).round() as i64;
- result.push(ClusterResource {
- cgroup_mode: None,
- content: None,
- cpu: Some(cpu),
- disk: Some(disk.saturating_add_signed(jitter)),
- diskread: Some(1034),
- diskwrite: Some(1034),
- hastate: None,
- id: format!("lxc/{vmid}"),
- level: Some("".into()),
- maxcpu: Some(maxcpu),
- maxdisk: Some(maxdisk),
- maxmem: Some(maxmem),
- memhost: Some(memhost),
- mem: Some(mem.saturating_add_signed(jitter)),
- name: Some(format!("ct-{vmid}")),
- netin: Some(1034),
- netout: Some(1034),
- node: Some(format!("node-{}", vmid % self.nr_of_nodes)),
- plugintype: None,
- pool: None,
- status: Some("running".into()),
- storage: None,
- template: Some(false),
- ty: ClusterResourceType::Lxc,
- uptime: Some(1234),
- vmid: Some(vmid),
- lock: None,
- tags: None,
- sdn: None,
- network: None,
- network_type: None,
- protocol: None,
- shared: None,
- zone_type: None,
+ let val = json!({
+ "cpu": cpu,
+ "diskread": 1034,
+ "diskwrite": 1034,
+ "disk": disk.saturating_add_signed(jitter),
+ "id": format!("lxc/{vmid}"),
+ "level": "",
+ "maxcpu": maxcpu,
+ "maxdisk": maxdisk,
+ "maxmem": maxmem,
+ "mem": mem.saturating_add_signed(jitter),
+ "memhost": memhost.saturating_add_signed(jitter),
+ "name": format!("ct-{vmid}"),
+ "netin": 1034,
+ "netout": 1034,
+ "node": format!("node-{}", vmid % self.nr_of_nodes),
+ "status": "running",
+ "template": false,
+ "type": "lxc",
+ "uptime": 1234,
+ "vmid": vmid,
});
+ result.push(serde_json::from_value(val).map_err(|err| {
+ proxmox_client::Error::Anyhow(format_err!("error on ct {vmid}: {err}"))
+ })?);
}
for i in 0..self.nr_of_nodes {
let jitter = ((i as f64).sin() * bytejitter).round() as i64;
- result.push(ClusterResource {
- cgroup_mode: None,
- content: None,
- cpu: Some(cpu),
- disk: Some(disk.saturating_add_signed(jitter)),
- diskread: None,
- diskwrite: None,
- hastate: None,
- id: format!("node/node-{i}"),
- level: Some("".into()),
- maxcpu: Some(16.),
- maxdisk: Some(maxdisk),
- maxmem: Some(maxmem),
- mem: Some(mem.saturating_add_signed(jitter)),
- memhost: None,
- name: None,
- netin: None,
- netout: None,
- node: Some(format!("node-{i}")),
- plugintype: None,
- pool: None,
- status: Some("online".into()),
- storage: None,
- template: None,
- ty: ClusterResourceType::Node,
- uptime: Some(1234),
- vmid: Some(vmid),
- lock: None,
- tags: None,
- sdn: None,
- network: None,
- network_type: None,
- protocol: None,
- shared: None,
- zone_type: None,
+ let val = json!({
+ "cpu": cpu,
+ "disk": disk.saturating_add_signed(jitter),
+ "id": format!("node/node-{i}"),
+ "level": "",
+ "maxcpu": 16.0,
+ "maxdisk": maxdisk,
+ "maxmem": maxmem,
+ "mem": mem.saturating_add_signed(jitter),
+ "node": format!("node-{i}"),
+ "status": "online",
+ "type": "node",
+ "uptime": 1234,
});
+ result.push(serde_json::from_value(val).map_err(|err| {
+ proxmox_client::Error::Anyhow(format_err!("error on node {i}: {err}"))
+ })?);
}
for i in 0..self.nr_of_storages {
let jitter = ((i as f64).sin() * bytejitter).round() as i64;
- result.push(ClusterResource {
- cgroup_mode: None,
- content: Some(vec![StorageContent::Images, StorageContent::Rootdir]),
- cpu: None,
- disk: Some(disk.saturating_add_signed(jitter)),
- diskread: None,
- diskwrite: None,
- hastate: None,
- id: format!("storage/node-0/storage-{i}"),
- level: None,
- maxcpu: None,
- maxdisk: Some(maxdisk),
- maxmem: None,
- mem: None,
- memhost: None,
- name: None,
- netin: None,
- netout: None,
- node: Some(format!("node-{}", i % self.nr_of_nodes)),
- plugintype: Some("dir".into()),
- pool: None,
- status: Some("available".into()),
- storage: Some(format!("storage-{i}")),
- template: None,
- ty: ClusterResourceType::Storage,
- uptime: None,
- vmid: None,
- lock: None,
- tags: None,
- sdn: None,
- network: None,
- network_type: None,
- protocol: None,
- shared: None,
- zone_type: None,
+ let val = json!({
+ "content": "images,rootdir",
+ "disk": disk.saturating_add_signed(jitter),
+ "id": format!("storage/node-0/storage-{i}"),
+ "maxdisk": maxdisk,
+ "node": format!("node-{}", i % self.nr_of_nodes),
+ "plugintype": "dir",
+ "status": "available",
+ "storage": format!("storage-{i}"),
+ "type": "storage",
});
+ result.push(serde_json::from_value(val).map_err(|err| {
+ proxmox_client::Error::Anyhow(format_err!("error on storage {i}: {err}"))
+ })?);
}
tokio::time::sleep(Duration::from_millis(self.api_delay_ms as u64)).await;
--
2.47.3
next prev parent reply other threads:[~2026-03-20 9:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 9:25 [PATCH datacenter-manager 0/5] fix/improve fake-remote code Dominik Csapak
2026-03-20 9:25 ` [PATCH datacenter-manager 1/5] fake remote: update code to implement/use new interfaces Dominik Csapak
2026-03-20 9:25 ` [PATCH datacenter-manager 2/5] fake remote: fix nonsensical values Dominik Csapak
2026-03-20 9:25 ` [PATCH datacenter-manager 3/5] fake remote: factor out cpu/disk/mem values Dominik Csapak
2026-03-20 9:25 ` [PATCH datacenter-manager 4/5] fake remote: add jitter to disk/memory values Dominik Csapak
2026-03-20 9:25 ` Dominik Csapak [this message]
2026-03-20 10:48 ` applied: [PATCH datacenter-manager 0/5] fix/improve fake-remote code Lukas Wagner
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=20260320092702.1069143-6-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-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