mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-09-07 20:45:40 +00:00
NodeService.GetNodeConfig/GetNodeDns, ClusterConfigService.GetClusterConfig, BackupService.GetNotBackedUp and VmService.GetGuestExecStatus returned raw Dictionary/List<Dictionary> instead of a Pve* model, per issue #157. Each now has a typed model under Models/{Nodes,Cluster,Backup,Vms}/ with [JsonProperty] for documented fields and a [JsonExtensionData]-backed AdditionalProperties catch-all, following the PveVmConfig pattern. The five consuming cmdlets and their [OutputType] attributes are updated to match. GetClusterConfig also fixes a latent bug: GET /cluster/config returns a JSON array (a directory index), but the old code did `data is JObject obj ? ... : empty dict`, which silently always returned an empty dictionary since data was a JArray. PveClusterConfigEntry decodes the array correctly and exposes a typed Name property (the array items' schema documents no named fields, but the endpoint's "links" metadata gives the child-URL template as "{name}"). The guest-exec poll loop in InvokePveVmGuestExecCmdlet keeps its exact Stopwatch + Thread.Sleep(1000) structure (ADR 0001 accepted exception); only the type it reads from changed. A TolerantBooleanConverter was added so PveGuestExecStatus.Exited keeps accepting PVE's boolean/integer/string forms, matching what ApiValueHelper.IsExited already tolerated for the old dictionary path. Reviewed with codex-rescue, correctness-reviewer and api-compat-reviewer before commit; both real findings above (the name/subdir key and the Exited string-form regression) came from that pass and are mutation-tested. Co-authored-by: goodolclint-claude[bot] <323206664+goodolclint-claude[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9a92577794
commit
0026ef2b57
@@ -108,5 +108,62 @@ namespace PSProxmoxVE.Core.Tests.Models
|
||||
Assert.NotNull(nodes[0].LoadAverage);
|
||||
Assert.Equal(3, nodes[0].LoadAverage!.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PveNodeConfig_Deserialize_HasDocumentedFields()
|
||||
{
|
||||
var json = @"{""data"": {
|
||||
""description"": ""Primary node"",
|
||||
""wakeonlan"": ""AA:BB:CC:DD:EE:FF"",
|
||||
""ballooning-target"": 80,
|
||||
""startall-onboot-delay"": 30,
|
||||
""digest"": ""abc123""
|
||||
}}";
|
||||
var data = JObject.Parse(json)["data"];
|
||||
Assert.NotNull(data);
|
||||
var config = data.ToObject<PveNodeConfig>();
|
||||
Assert.NotNull(config);
|
||||
Assert.Equal("Primary node", config.Description);
|
||||
Assert.Equal("AA:BB:CC:DD:EE:FF", config.WakeOnLan);
|
||||
Assert.Equal(80, config.BallooningTarget);
|
||||
Assert.Equal(30, config.StartAllOnbootDelay);
|
||||
Assert.Equal("abc123", config.Digest);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PveNodeConfig_UnmappedKey_LandsInAdditionalProperties()
|
||||
{
|
||||
var json = @"{""data"": {""description"": ""n1"", ""acmedomain0"": ""example.com,plugin=dns""}}";
|
||||
var data = JObject.Parse(json)["data"];
|
||||
var config = data!.ToObject<PveNodeConfig>();
|
||||
Assert.NotNull(config);
|
||||
Assert.Equal("example.com,plugin=dns", config!.AdditionalProperties["acmedomain0"]);
|
||||
Assert.False(config.AdditionalProperties.ContainsKey("description"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PveNodeDns_Deserialize_HasDocumentedFields()
|
||||
{
|
||||
var json = @"{""data"": {""dns1"": ""8.8.8.8"", ""dns2"": ""8.8.4.4"", ""dns3"": ""1.1.1.1"", ""search"": ""example.com""}}";
|
||||
var data = JObject.Parse(json)["data"];
|
||||
Assert.NotNull(data);
|
||||
var dns = data.ToObject<PveNodeDns>();
|
||||
Assert.NotNull(dns);
|
||||
Assert.Equal("8.8.8.8", dns.Dns1);
|
||||
Assert.Equal("8.8.4.4", dns.Dns2);
|
||||
Assert.Equal("1.1.1.1", dns.Dns3);
|
||||
Assert.Equal("example.com", dns.Search);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PveNodeDns_UnmappedKey_LandsInAdditionalProperties()
|
||||
{
|
||||
var json = @"{""data"": {""dns1"": ""8.8.8.8"", ""dns4"": ""9.9.9.9""}}";
|
||||
var data = JObject.Parse(json)["data"];
|
||||
var dns = data!.ToObject<PveNodeDns>();
|
||||
Assert.NotNull(dns);
|
||||
Assert.Equal("9.9.9.9", dns!.AdditionalProperties["dns4"]);
|
||||
Assert.False(dns.AdditionalProperties.ContainsKey("dns1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user