vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
150 stars 32 forks source link

Resolve PV driver issues with the terraform acceptance test VM template #57

Closed ddelnano closed 3 years ago

ddelnano commented 4 years ago

When I was developing #54, I noticed that when my terraform acceptance code tried to create a second VIF for a VM I would receive the following error from the XO api.

Aug 27 20:56:03 xoa xo-server[501]: 2020-08-28T00:56:03.833Z - xo:api - [WARN] admin@admin.net | vm.createInterface(...) [75ms] =!> XapiError: VM_MISSING_PV_DRIVERS(OpaqueRef:1e3e2a3c-d2fe-45a1-a0c3-459d322bcae8)
Aug 27 20:56:44 xoa xo-server[501]: 2020-08-28T00:56:44.814Z - xo:api - [WARN] admin@admin.net | vif.connect(...) [65ms] =!> XapiError: VM_MISSING_PV_DRIVERS(OpaqueRef:1e3e2a3c-d2fe-45a1-a0c3-459d322bcae8)

What made this very confusing was that if I created a VM from the same template through the XO web UI or calling vm.create with the xo-cli I never experienced this issue. I did notice that when the terraform acceptance tests run that the VM created during the test has a kernel panic and goes into a crash loop. When the VM was created outside the test the kernel panic doesn't occur. Unfortunately I was only able to see the console output in the XO UI which isn't that helpful for copy and pasting or seeing the full log. I tried configuring xenconsoled to log the output to the filesystem (using --log=all). This created a file for each VM but the boot logs I was interested in weren't written to the file :(.

The acceptance criteria is to fix these missing pv drivers, update the following tests (will add link once #54 is merged) to not bypass returning errors and add additional assertions about VIF state during the acceptance tests.

ddelnano commented 3 years ago

I found out that this actually a race condition. If the VIF attachment, detachment code runs before the guest kernel has loaded its drivers it throws that error. The key was to add time.Sleeps into the code for now and the test mentioned above has been re-enabled.