Skip to content

Commit

Permalink
fix: QemuGuestAgentType can be unset
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Apr 15, 2024
1 parent 1a18758 commit ff84c23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion proxmox/config_qemu_guestagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (newSetting QemuGuestAgent) mapToAPI(currentSettings *QemuGuestAgent) strin
params += ",fstrim_cloned_disks=" + boolToIntString(*currentSettings.FsTrim)
}
if newSetting.Type != nil {
params += ",type=" + strings.ToLower(string(*newSetting.Type))
if *newSetting.Type != QemuGuestAgentType_None {
params += ",type=" + strings.ToLower(string(*newSetting.Type))
}
} else if currentSettings != nil && currentSettings.Type != nil {
params += ",type=" + strings.ToLower(string(*currentSettings.Type))
}
Expand Down
13 changes: 12 additions & 1 deletion proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
{name: `Create Agent.Enable`,
config: &ConfigQemu{Agent: &QemuGuestAgent{Enable: util.Pointer(true)}},
output: map[string]interface{}{"agent": "1"}},
{name: `Create Agent.Type`,
{name: `Create Agent.Type=""`,
config: &ConfigQemu{Agent: &QemuGuestAgent{Type: util.Pointer(QemuGuestAgentType_None)}},
output: map[string]interface{}{"agent": "0"}},
{name: `Create Agent.Type="virtio"`,
config: &ConfigQemu{Agent: &QemuGuestAgent{Type: util.Pointer(QemuGuestAgentType_VirtIO)}},
output: map[string]interface{}{"agent": "0,type=virtio"}},
{name: `Create Agent.Freeze`,
Expand Down Expand Up @@ -1346,6 +1349,14 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
config: &ConfigQemu{Agent: &QemuGuestAgent{Type: util.Pointer(QemuGuestAgentType_VirtIO)}},
currentConfig: ConfigQemu{Agent: &QemuGuestAgent{}},
output: map[string]interface{}{"agent": "0,type=virtio"}},
{name: `Update Agent.Type "" !nil`,
config: &ConfigQemu{Agent: &QemuGuestAgent{Type: util.Pointer(QemuGuestAgentType_None)}},
currentConfig: ConfigQemu{Agent: &QemuGuestAgent{}},
output: map[string]interface{}{"agent": "0"}},
{name: `Update Agent.Type "" nil`,
config: &ConfigQemu{Agent: &QemuGuestAgent{Type: util.Pointer(QemuGuestAgentType_None)}},
currentConfig: ConfigQemu{Agent: &QemuGuestAgent{Type: util.Pointer(QemuGuestAgentType_VirtIO)}},
output: map[string]interface{}{"agent": "0"}},
{name: `Update Agent.Type nil !nil`,
config: &ConfigQemu{Agent: &QemuGuestAgent{}},
currentConfig: ConfigQemu{Agent: &QemuGuestAgent{Type: util.Pointer(QemuGuestAgentType_VirtIO)}},
Expand Down

0 comments on commit ff84c23

Please sign in to comment.