Project

General

Profile

Bug #15154

Libvirt compute resource - unclear error on VM creation failure

Added by Shimon Shtein over 4 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Compute resources - libvirt
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1332652
Description of problem:

in the below example i provide environment-id="122" which does not exist:

# hammer -v -u admin -p changeme --output=csv host create --medium-id="9" --root-pass="changeme" --organization-id="1" --location-id="2" --architecture-id="1" --puppet-proxy-id="1" --name="foo4" --environment-id="122" --compute-resource-id="1" --domain-id="1" --operatingsystem-id="3" --partition-table-id="61" 
[ERROR 2016-05-03 18:14:15 Exception] ERROR:  insert or update on table "hosts" violates foreign key constraint "hosts_environment_id_fk" 
DETAIL:  Key (environment_id)=(122) is not present in table "environments".

Could not create the host:
  ERROR:  insert or update on table "hosts" violates foreign key constraint "hosts_environment_id_fk" 
  DETAIL:  Key (environment_id)=(122) is not present in table "environments".

after retrigerring the same command with the correct environment id, I'm no longer able to use the same name for the host (ending up with different error):

# hammer -v -u admin -p changeme --output=csv host create --medium-id="9" --root-pass="changeme" --organization-id="1" --location-id="2" --architecture-id="1" --puppet-proxy-id="1" --name="foo4" --environment-id="1" --compute-resource-id="1" --domain-id="1" --operatingsystem-id="3" --partition-table-id="61" 
[ERROR 2016-05-03 18:17:48 Exception] Failed to create a compute my_libvirt_cr_1 (Libvirt) instance foo4.domain.com: no implicit conversion of nil into String

Could not create the host:
  Failed to create a compute my_libvirt_cr_1 (Libvirt) instance foo4.domain.com: no implicit conversion of nil into String

Version-Release number of selected component (if applicable):
6.2.0 BETA

How reproducible:
always

Steps to Reproduce:
1. create all the prerequisites for creating a host (OS, arch, partition table, ...)
2. try to create the host with providing invalid environment-id
[3. optionally, try to create the host again with using the same name]

Actual results:
ERROR: insert or update on table "hosts" violates foreign key constraint "hosts_environment_id_fk"

Expected results:
user friendly message displayed, nothing is being created on the satellite side.

Additional info:

Associated revisions

Revision 169ac7b3 (diff)
Added by Shimon Shtein over 4 years ago

Fixes #15154 - Added more safety measures to libvirt

History

#1 Updated by Shimon Shtein over 4 years ago

  • Subject changed from CLI - host create produces ISE on providing invalid environment-id to Libvirt compute resource - unclear error on VM creation failure

#2 Updated by Dominic Cleal over 4 years ago

  • Category changed from Inventory to Compute resources - libvirt
  • Status changed from New to Assigned

Could you put the server logs in this bug report? It's clearly a server side error but no indication of the source.

#3 Updated by Shimon Shtein over 4 years ago

I was on it, you are fast :)

After a small investigation, the problem is in #create_vm function of app/models/compute_resources/foreman/model/libvirt.rb

In my case, the VM could not be created, so it has thrown an exception (Fog::Errors::Error: Error saving the server: Call to virDomainDefineXML failed: invalid argument: could not find capabilities for arch=x86_64 domaintype=kvm). This error is not important - this libvirt instance is unstable.
The rescue block took place, but vm.id was still nil, so destroy_vm also threw an exception:

... snip ...
 | TypeError: no implicit conversion of nil into String
 | /opt/theforeman/tfm/root/usr/share/gems/gems/fog-libvirt-0.0.2/lib/fog/libvirt/requests/compute/list_domains.rb:9:in `lookup_domain_by_uuid'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/fog-libvirt-0.0.2/lib/fog/libvirt/requests/compute/list_domains.rb:9:in `list_domains'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/fog-libvirt-0.0.2/lib/fog/libvirt/models/compute/servers.rb:15:in `get'
 | /usr/share/foreman/app/models/compute_resource.rb:156:in `find_vm_by_uuid'
 | /usr/share/foreman/app/models/compute_resources/foreman/model/libvirt.rb:38:in `find_vm_by_uuid'
 | /usr/share/foreman/app/models/compute_resources/foreman/model/libvirt.rb:46:in `destroy_vm'
 | /usr/share/foreman/app/models/compute_resources/foreman/model/libvirt.rb:146:in `rescue in create_vm'
 | /usr/share/foreman/app/models/compute_resources/foreman/model/libvirt.rb:141:in `create_vm'
... snip ...

#4 Updated by The Foreman Bot over 4 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3547 added

#5 Updated by Shimon Shtein over 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#6 Updated by Dominic Cleal over 4 years ago

  • Legacy Backlogs Release (now unused) set to 136

Also available in: Atom PDF