packer-plugin-proxmox icon indicating copy to clipboard operation
packer-plugin-proxmox copied to clipboard

Race condition when creating multiple VMs with HCL2 build sources

Open itsmeow opened this issue 1 year ago • 1 comments

Overview of the Issue

It appears there's been a regression with #42, if you use the new build-level source blocks, the VM IDs will conflict.

Reproduction Steps

Create multiple build-level source blocks using the proxmox-clone source type that exist within a single source block, and run packer build on them.

Plugin and Packer version

Packer v1.11.2

packer-plugin-proxmox_v1.2.2_x5.0_linux_amd64

Simplified Packer Buildfile

source "proxmox-clone" "three-tier-cloned" {
  clone_vm = "${var.template-VMNAME}"
  username    = "${local.PROXMOX_USERNAME}"
  token       = "${local.PROXMOX_TOKEN}"
  proxmox_url = "${local.URL}"
  cpu_type  = "host"
  cores     = "${var.NUMBEROFCORES}"
  memory    = "${var.MEMORY}"
  os                       = "l26"
  insecure_skip_tls_verify = true
  qemu_agent               = true
  cloud_init               = true
  cloud_init_storage_pool  = "local"
  ssh_username             = "root"
  ssh_password             = "example"
  ssh_timeout              = "22m"
}

build {
  name = "three-tier-concurrent"
  source "source.proxmox-clone.three-tier-cloned" {
    name = "load-balancer"
  }

  source "source.proxmox-clone.three-tier-cloned" {
    name = "frontend"
  }

  source "source.proxmox-clone.three-tier-cloned" {
    name = "backend"
  }
}

Operating system and Environment details

Tested on a proxmox 8.0.3 server

Log Fragments and crash.log files

You can see here, all 3 builds picked VM ID 313, but the code to retry if they fail didn't trigger.

==> three-tier-concurrent.proxmox-clone.load-balancer: Creating VM
==> three-tier-concurrent.proxmox-clone.load-balancer: No VM ID given, getting next free from Proxmox
==> three-tier-concurrent.proxmox-clone.backend: Creating VM
==> three-tier-concurrent.proxmox-clone.backend: No VM ID given, getting next free from Proxmox
==> three-tier-concurrent.proxmox-clone.frontend: Creating VM
==> three-tier-concurrent.proxmox-clone.frontend: No VM ID given, getting next free from Proxmox
==> three-tier-concurrent.proxmox-clone.backend: Error creating VM: 500 unable to create VM 313: config file already exists
==> three-tier-concurrent.proxmox-clone.backend: Error creating VM: 500 unable to create VM 313: config file already exists
==> three-tier-concurrent.proxmox-clone.backend: Step "stepStartVM" failed
==> three-tier-concurrent.proxmox-clone.backend: [c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)? a
==> three-tier-concurrent.proxmox-clone.frontend: Error creating VM: can't lock file '/var/lock/qemu-server/lock-313.conf' - got timeout
==> three-tier-concurrent.proxmox-clone.frontend: Error creating VM: can't lock file '/var/lock/qemu-server/lock-313.conf' - got timeout
==> three-tier-concurrent.proxmox-clone.backend: Error creating VM: 500 unable to create VM 313: config file already exists

itsmeow avatar Mar 12 '25 07:03 itsmeow

It doesn't actually seem to be related to the new source blocks, I think it's just that the detection for the error is broken on whatever proxmox API version I'm running. The error is config file already exists, but the code looks for already exists on node https://github.com/hashicorp/packer-plugin-proxmox/blob/be6fae7ad701bf0e612fcbb2daf7a1d6c2e38462/builder/proxmox/common/step_start_vm.go#L781

itsmeow avatar Mar 12 '25 07:03 itsmeow