hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.11k stars 3.33k forks source link

Packer sends empty API request #9712

Open paginabianca opened 4 years ago

paginabianca commented 4 years ago

Overview of the Issue

When trying to build a VM template with Packer version 1.6.1-dev (build based on the current master branch) I get the following error

Build 'proxmox' errored: Error updating template: 500 no options specified

I think this is caused by a PUT request without any options sent to the Proxmox REST API. During the finalize_template_step the changes that have to be applied to the VM are stored inside the changes map. Using the same template as provided below, the only thing in that map should be the description.

I'm not sure how to fix this since I'm pretty much new to golang and don't understand every piece of code.

Reproduction Steps

This should work with any template file as long as cloud_init, template_name and template_description are not set.

Packer version

1.6.1-dev based on the current master branch

Simplified Packer Buildfile

The error occurred with this buildfile but it should be reproducible with any buildfile as long as cloud_init, template_name and template_description are not set.

Operating system and Environment details

This was tested on an Archlinux LXC running Kernel: 5.4.44-2-pve OS, Architecture, and any other information you can provide about the environment.

Log Fragments and crash.log files

Here is the important part of the log

==> proxmox: Stopping VM
==> proxmox: Converting VM to template
2020/08/05 11:00:05 packer-builder-proxmox plugin: template_id: 110
==> proxmox: Error updating template: 500 no options specified
==> proxmox: Provisioning step had errors: Running the cleanup provisioner, if present...
==> proxmox: Stopping VM
==> proxmox: Deleting VM
Build 'proxmox' errored: Error updating template: 500 no options specified

==> Some builds didn't complete successfully and had errors:
--> proxmox: Error updating template: 500 no options specified

==> Builds finished but no artifacts were created.
2020/08/05 11:00:09 [INFO] (telemetry) ending proxmox
2020/08/05 11:00:09 machine readable: error-count []string{"1"}
==> Some builds didn't complete successfully and had errors:
2020/08/05 11:00:09 machine readable: proxmox,error []string{"Error updating template: 500 no options specified"}
==> Builds finished but no artifacts were created.
2020/08/05 11:00:09 [INFO] (telemetry) Finalizing.
2020/08/05 11:00:09 Cancelling builder after context cancellation context canceled
2020/08/05 11:00:09 waiting for all plugin processes to complete...
2020/08/05 11:00:09 /root/packer: plugin process exited
2020/08/05 11:00:09 /root/packer: plugin process exited
paginabianca commented 4 years ago

I had the time to look around a bit and found that the code that causes this error is in proxmox-api-go/proxmox/session.go and was merged in #9587. This code sends an empty API request when the only change that is applied to the VM template in step_finalize_template.go is to set the VM template description to "". I am not sure what would be the best way to fix this since the two lines

if v != "" {
    vals.Set(k, v)
}

are probably there for a reason. I could just delete the if statement or set the template description to " " in step_finalize_template.go when template_description is not set but neither option seems like a good solution.

carlpett commented 4 years ago

Nice find! I'd say that is a bug. It is only correct to ignore empty values if it was previously not empty. I added a comment on the upstream PR: https://github.com/Telmate/proxmox-api-go/pull/76 I think the appropriate thing here would be to roll back that change upstream.