From dde1b9bd4391f8e6923de9b7827c629aa8880de4 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Mon, 25 Jan 2016 19:11:54 +0000 Subject: [PATCH] Raise correct exception on domain not found Update spec to check the actually exception raised and fix the code to raise the correct one instead of throwing constant not defined. --- lib/vagrant-libvirt/action/wait_till_up.rb | 8 ++++++-- spec/vagrant-libvirt/action/wait_till_up_spec.rb | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/wait_till_up.rb b/lib/vagrant-libvirt/action/wait_till_up.rb index 431a35f..08f5c70 100644 --- a/lib/vagrant-libvirt/action/wait_till_up.rb +++ b/lib/vagrant-libvirt/action/wait_till_up.rb @@ -1,4 +1,5 @@ require 'log4r' +require 'vagrant-libvirt/errors' require 'vagrant-libvirt/util/timer' require 'vagrant/util/retryable' @@ -21,8 +22,11 @@ module VagrantPlugins env[:metrics] ||= {} # Get domain object - domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) - raise NoDomainError if domain == nil + domain = env[:machine].provider.driver.get_domain(env[:machine].id.to_s) + if domain == nil + raise Errors::NoDomainError, + :error_message => "Domain #{env[:machine].id} not found" + end # Wait for domain to obtain an ip address. Ip address is searched # from arp table, either localy or remotely via ssh, if libvirt diff --git a/spec/vagrant-libvirt/action/wait_till_up_spec.rb b/spec/vagrant-libvirt/action/wait_till_up_spec.rb index fad564f..a8997ce 100644 --- a/spec/vagrant-libvirt/action/wait_till_up_spec.rb +++ b/spec/vagrant-libvirt/action/wait_till_up_spec.rb @@ -23,7 +23,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do it "raises exception" do expect(app).to_not receive(:call) - expect{subject.call(env)}.to raise_error + expect{subject.call(env)}.to raise_error(::VagrantPlugins::ProviderLibvirt::Errors::NoDomainError, + /No domain found. Domain dummy-vagrant_dummy not found/) end end end