vatesfr / xen-orchestra

The global orchestration solution to manage and backup XCP-ng and XenServer.
https://xen-orchestra.com
Other
767 stars 262 forks source link

Error on vm.start on 507e9 #6748

Closed josuemotte closed 1 year ago

josuemotte commented 1 year ago

Hello,

All machines created via TF are failing at start, while deploying manually is working correctly.

It was working on commit : https://github.com/vatesfr/xen-orchestra/commit/c8b29da67718f8d8b891a7df6474d83534d65978

here is the log output :

vm.start
{
  "id": "833f68c2-a8b9-6682-4f17-94ad98dec153",
  "bypassMacAddressesCheck": false,
  "force": false
}
{
  "code": "HANDLE_INVALID",
  "params": [
    "host",
    "OpaqueRef:171c29cc-17c4-43ae-8fdb-1f0c40b49293"
  ],
  "call": {
    "method": "VM.start",
    "params": [
      "OpaqueRef:f114762a-5507-421c-873d-3725fad083d2",
      false,
      false
    ]
  },
  "message": "HANDLE_INVALID(host, OpaqueRef:171c29cc-17c4-43ae-8fdb-1f0c40b49293)",
  "name": "XapiError",
  "stack": "XapiError: HANDLE_INVALID(host, OpaqueRef:171c29cc-17c4-43ae-8fdb-1f0c40b49293)
    at Function.wrap (/opt/xo/xo-builds/xen-orchestra-202303222329/packages/xen-api/src/_XapiError.js:16:12)
    at /opt/xo/xo-builds/xen-orchestra-202303222329/packages/xen-api/src/transports/json-rpc.js:35:21
    at runNextTicks (node:internal/process/task_queues:60:5)
    at processImmediate (node:internal/timers:447:9)
    at process.callbackTrampoline (node:internal/async_hooks:130:17)"
}

What else can I provide in order to help ?

olivierlambert commented 1 year ago

Hi,

By TF you mean the TerraForm plugin for XO? If yes, have you reported first to the XO TF Github? Also, could you reproduce the issue and find the exact broken commit?

Thanks!

josuemotte commented 1 year ago

Hello,

This TF : https://github.com/terra-farm/terraform-provider-xenorchestra , I'll open an issue there as well.

I found the commit : https://github.com/vatesfr/xen-orchestra/commit/d6a3492e90d9ae6135cd43510ce963d08bcf3b8c , this commit bring also another side effect which is that , users are forced to add a MAC Address when creating a VM.

Cheers

olivierlambert commented 1 year ago

Ah indeed good catch. Let me ping @julien-f for this :)

josuemotte commented 1 year ago

after more testing, the issue seems to be related to the argument : affinity_host of the resource xenorchestra_vm, if the value is not correct you won't receive any error just a broken VM.

The argument was previously optional but since https://github.com/vatesfr/xen-orchestra/commit/d6a3492e90d9ae6135cd43510ce963d08bcf3b8c it is now mandatory.

An issue is open on the TF project : https://github.com/terra-farm/terraform-provider-xenorchestra/issues/231

olivierlambert commented 1 year ago

Perfect, thanks for your investigation. We'll fix this :)

julien-f commented 1 year ago

@josuemotte I cannot reproduce the problem in XO itself, the issue may be in the TerraForm provider instead. If you can reproduce directly in XO, let me know.

@pdonias Can you check that VM creation in xo-web does not send an empty MAC address param? The parameter is optional but must not be empty.

josuemotte commented 1 year ago

hello @julien-f,

To reproduce the issue, you need to set affinity_host to a wrong value such as the pool id instead of the host id, the TF provider won't see it as an error since the formatting is correct.

The machine will be create in XO but the start will give the above error message, can the affinity_host parameter become optional like before ?

Here is how we ended with the error message :

resource "xenorchestra_vm" "vm" {
  for_each     = local.vm
  name_label   = each.key
  name_description = each.value.description
  memory_max   = (1073741824 * each.value.memory)
  cpus         = each.value.cpu
  cloud_config = templatefile("linux.tftpl",{
   name = each.key
  })
  cloud_network_config = templatefile("network.tftpl",{
   ipaddress = each.value.ipaddress
  })
  template     = "d627d80d-027a-3993-ad48-2b59b621f40e"
  affinity_host = "wrongid"
  network {
    network_id = "bb873991-36c0-a596-d25a-87e87e17b853"
    mac_address = each.value.mac_address
  }

  disk {
    sr_id = "5f7ae541-c9be-fae5-51d1-6fc830b1ffe7"
    name_label = each.key
    size = (1073741824 * each.value.disk_size)
  }

  tags = [
    "Linux",
    each.value.tags
  ]

  // Override the default create timeout from 5 mins to 20.
  timeouts {
    create = "5m"
  }
}
julien-f commented 1 year ago

This looks like an TerraForm plugin issue and is not something to handle on XO's side.

Anyway, it's perfectly normal for vm.start to not work if it is passed an invalid host.

pdonias commented 1 year ago

@julien-f Yes, the MAC addresses may be empty, let's fix it.

julien-f commented 1 year ago

Closing, feel free to re-open if reproduced in XO itself.

josuemotte commented 1 year ago

@julien-f can't find the commit https://github.com/vatesfr/xen-orchestra/commit/7a999b460e847546122f152180f08b64b27badc9 in the master branch

julien-f commented 1 year ago

@josuemotte The commit you are looking for is https://github.com/vatesfr/xen-orchestra/commit/954b29cb61d8090438513b288d21a30e57a8a41e