Skip to content

Race condition when creating multiple VMs with HCL2 build sources #315

@itsmeow

Description

@itsmeow

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions