Skip to content

Commit

Permalink
Merge pull request #290 from Tinyblargon/BugFix-Qemu-Pool2
Browse files Browse the repository at this point in the history
Bug fix: `ConfigQemu`. `Node`, `Pool`, `VmID`
  • Loading branch information
mleone87 authored Dec 21, 2023
2 parents 12edfd8 + 23f299e commit f5ef0e7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
10 changes: 8 additions & 2 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (config ConfigQemu) mapToApiValues(currentConfig ConfigQemu) (rebootRequire
return
}

func (ConfigQemu) mapToStruct(params map[string]interface{}) (*ConfigQemu, error) {
func (ConfigQemu) mapToStruct(vmr *VmRef, params map[string]interface{}) (*ConfigQemu, error) {
// vmConfig Sample: map[ cpu:host
// net0:virtio=62:DF:XX:XX:XX:XX,bridge=vmbr0
// ide2:local:iso/xxx-xx.iso,media=cdrom memory:2048
Expand All @@ -469,6 +469,12 @@ func (ConfigQemu) mapToStruct(params map[string]interface{}) (*ConfigQemu, error

config := ConfigQemu{}

if vmr != nil {
config.Node = vmr.node
config.Pool = vmr.pool
config.VmID = vmr.vmId
}

if _, isSet := params["agent"]; isSet {
switch params["agent"].(type) {
case float64:
Expand Down Expand Up @@ -1223,7 +1229,7 @@ func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err e
return nil, fmt.Errorf("vm locked, could not obtain config")
}

config, err = ConfigQemu{}.mapToStruct(vmConfig)
config, err = ConfigQemu{}.mapToStruct(vmr, vmConfig)
if err != nil {
return
}
Expand Down
39 changes: 38 additions & 1 deletion proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) {
tests := []struct {
name string
input map[string]interface{}
vmr *VmRef
output *ConfigQemu
err error
}{
Expand Down Expand Up @@ -4514,10 +4515,46 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) {
"volume": "local-lvm:vm-1000-disk-0",
}},
},
// Node
{name: "Node vmr nil",
output: &ConfigQemu{},
},
{name: "Node vmr empty",
vmr: &VmRef{node: ""},
output: &ConfigQemu{},
},
{name: "Node vmr populated",
vmr: &VmRef{node: "test"},
output: &ConfigQemu{Node: "test"},
},
// Pool
{name: "Pool vmr nil",
output: &ConfigQemu{},
},
{name: "Pool vmr empty",
vmr: &VmRef{pool: ""},
output: &ConfigQemu{},
},
{name: "Pool vmr populated",
vmr: &VmRef{pool: "test"},
output: &ConfigQemu{Pool: "test"},
},
// VmID
{name: "VmID vmr nil",
output: &ConfigQemu{},
},
{name: "VmID vmr empty",
vmr: &VmRef{vmId: 0},
output: &ConfigQemu{},
},
{name: "VmID vmr populated",
vmr: &VmRef{vmId: 100},
output: &ConfigQemu{VmID: 100},
},
}
for _, test := range tests {
t.Run(test.name, func(*testing.T) {
output, err := ConfigQemu{}.mapToStruct(test.input)
output, err := ConfigQemu{}.mapToStruct(test.vmr, test.input)
if err != nil {
require.Equal(t, test.err, err, test.name)
} else {
Expand Down

0 comments on commit f5ef0e7

Please sign in to comment.