adrahon / vagrant-kvm

This project is dead, please use vagrant-libvirt instead! A Vagrant 1.4+ plugin that adds a KVM provider to Vagrant, allowing Vagrant to control and provision KVM/QEMU VM.
MIT License
366 stars 60 forks source link

'existing dhcp host entry' error when doing 'vagrant up' on existing vm #257

Closed vdloo closed 9 years ago

vdloo commented 10 years ago

The following error happens when running vagrant up again after shutting down a vagrant-kvm box for the first time.

/home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/driver/driver.rb:201:in `update': Call to virNetworkUpdate failed: Requested operation is not valid: there is an existing dhcp host entry in network 'vagrant-8' that matches "<host mac='00:16:3e:20:51:9c' name='nic-1410683881' ip='172.17.8.101'/>" (Libvirt::Error)
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/driver/driver.rb:201:in `create_network'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/network.rb:91:in `add_private_network_host'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/network.rb:50:in `block in create_or_update_private_network!'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/network.rb:47:in `each'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/network.rb:47:in `each_with_index'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/network.rb:47:in `create_or_update_private_network!'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/network.rb:20:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/match_mac_address.rb:16:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/import.rb:106:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/init_storage_pool.rb:17:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/customize.rb:39:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/set_name.rb:49:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/handle_box.rb:56:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/call.rb:53:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/init_storage_pool.rb:17:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/vdloo/.vagrant.d/gems/gems/vagrant-kvm-0.1.8/lib/vagrant-kvm/action/check_kvm.rb:18:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:196:in `action_raw'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:173:in `block in action'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/environment.rb:434:in `lock'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:161:in `call'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:161:in `action'
        from /home/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/batch_action.rb:82:in `block (2 levels) in run'

Here is the vagrant up --debug log and looking through the code in driver.rb it seems that for some reason old_def.already_exist_hosts? is never positively evaluated. This is a workaround that seems to fix it but I'm pretty sure it breaks other things because it will never run NETWORK_UPDATE_COMMAND_ADD_LAST. Seems related to issue #204.

adrahon commented 10 years ago

Thanks for the detailed report.

I've just pushed v0.1.9 which changes the way we handle MAC addresses, but it doesn't seem to be related to you issue. Updating networks (vs. destroy and recreate) is a recent feature in libvirt, could it be failing silently because it's not supported?

What distro are you using?

vdloo commented 10 years ago

I'm running a fresh install of Debian "jessie"

vdloo@hypervisor2:~$ cat /proc/version
Linux version 3.14-2-amd64 (debian-kernel@lists.debian.org) (gcc version 4.8.3 (Debian 4.8.3-7) ) #1 SMP Debian 3.14.15-2 (2014-08-09)
vdloo@hypervisor2:/usr/sbin$ ./libvirtd --version
./libvirtd (libvirt) 1.2.7
craigwatson commented 10 years ago

FWIW, I also have this issue using Mint 17, which is based on Ubuntu 14.04 (Trusty) and vagrant-kvm 0.1.9:

$ uname -a
Linux cwatson-desktop 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

$ libvirtd --version
libvirtd (libvirt) 1.2.

$ vagrant plugin list
vagrant-hostsupdater (0.0.11)
vagrant-kvm (0.1.9)
vagrant-mutate (0.3.1)
adrahon commented 10 years ago

Thanks guys, it seems that it's not issue.

@vdloo I'll go through your workaround and see if it could cause problems, else I'll merge it.

adrahon commented 9 years ago

This is solved now, there were two issues, first we didn't clean up the network of DHCP entries on vagrant destroy, this was fixed by https://github.com/adrahon/vagrant-kvm/commit/fea85417f11260728f465fb46def1b164b35119a

Second, the MAC addresses we generated weren't random enough and there were collisions, fixed in https://github.com/adrahon/vagrant-kvm/commit/a767774f87bdfbffa55d58e2a020b44ec483965a

vdloo commented 9 years ago

Thanks