diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-06-27 16:29:23 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-06-27 16:29:23 +0000 |
commit | c7b4a3513c21474d163b3487fa417ebb80212881 (patch) | |
tree | a9b99c744e7a2266c107aa732a210345f92165cc /nova | |
parent | 1020137af149f3abc85e83964cdd863eb4f486a7 (diff) | |
parent | e387e7bd34d6389c8c9dc599b93b4b1d8197a38a (diff) | |
download | nova-c7b4a3513c21474d163b3487fa417ebb80212881.tar.gz nova-c7b4a3513c21474d163b3487fa417ebb80212881.tar.xz nova-c7b4a3513c21474d163b3487fa417ebb80212881.zip |
Merge "Log xml in libvirt _create_domain failures"
Diffstat (limited to 'nova')
-rw-r--r-- | nova/tests/virt/libvirt/test_libvirt.py | 83 | ||||
-rwxr-xr-x | nova/virt/libvirt/driver.py | 24 |
2 files changed, 104 insertions, 3 deletions
diff --git a/nova/tests/virt/libvirt/test_libvirt.py b/nova/tests/virt/libvirt/test_libvirt.py index 000910c4c..2a6884483 100644 --- a/nova/tests/virt/libvirt/test_libvirt.py +++ b/nova/tests/virt/libvirt/test_libvirt.py @@ -44,6 +44,7 @@ from nova.openstack.common import fileutils from nova.openstack.common import importutils from nova.openstack.common import jsonutils from nova.openstack.common import loopingcall +from nova.openstack.common import processutils from nova.openstack.common import uuidutils from nova import test from nova.tests import fake_network @@ -4022,6 +4023,88 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() self.assertTrue(conn._is_storage_shared_with('foo', '/path')) + def test_create_domain_define_xml_fails(self): + """ + Tests that the xml is logged when defining the domain fails. + """ + fake_xml = "<test>this is a test</test>" + + def fake_defineXML(xml): + self.assertEquals(fake_xml, xml) + raise libvirt.libvirtError('virDomainDefineXML() failed') + + self.log_error_called = False + + def fake_error(msg): + self.log_error_called = True + self.assertTrue(fake_xml in msg) + + self.stubs.Set(nova.virt.libvirt.driver.LOG, 'error', fake_error) + + self.create_fake_libvirt_mock(defineXML=fake_defineXML) + self.mox.ReplayAll() + conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + + self.assertRaises(libvirt.libvirtError, conn._create_domain, fake_xml) + self.assertTrue(self.log_error_called) + + def test_create_domain_with_flags_fails(self): + """ + Tests that the xml is logged when creating the domain with flags fails. + """ + fake_xml = "<test>this is a test</test>" + fake_domain = FakeVirtDomain(fake_xml) + + def fake_createWithFlags(launch_flags): + raise libvirt.libvirtError('virDomainCreateWithFlags() failed') + + self.log_error_called = False + + def fake_error(msg): + self.log_error_called = True + self.assertTrue(fake_xml in msg) + + self.stubs.Set(fake_domain, 'createWithFlags', fake_createWithFlags) + self.stubs.Set(nova.virt.libvirt.driver.LOG, 'error', fake_error) + + self.create_fake_libvirt_mock() + self.mox.ReplayAll() + conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + + self.assertRaises(libvirt.libvirtError, conn._create_domain, + domain=fake_domain) + self.assertTrue(self.log_error_called) + + def test_create_domain_enable_hairpin_fails(self): + """ + Tests that the xml is logged when enabling hairpin mode for the domain + fails. + """ + fake_xml = "<test>this is a test</test>" + fake_domain = FakeVirtDomain(fake_xml) + + def fake_enable_hairpin(launch_flags): + raise processutils.ProcessExecutionError('error') + + self.log_error_called = False + + def fake_error(msg): + self.log_error_called = True + self.assertTrue(fake_xml in msg) + + self.stubs.Set(nova.virt.libvirt.driver.LOG, 'error', fake_error) + + self.create_fake_libvirt_mock() + self.mox.ReplayAll() + conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + self.stubs.Set(conn, '_enable_hairpin', fake_enable_hairpin) + + self.assertRaises(processutils.ProcessExecutionError, + conn._create_domain, + domain=fake_domain, + power_on=False) + self.assertTrue(self.log_error_called) + class HostStateTestCase(test.TestCase): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 104965d49..4544d35fb 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -2506,10 +2506,28 @@ class LibvirtDriver(driver.ComputeDriver): use_cow=CONF.use_cow_images) if xml: - domain = self._conn.defineXML(xml) + try: + domain = self._conn.defineXML(xml) + except Exception as e: + LOG.error(_("An error occurred while trying to define a domain" + " with xml: %s") % xml) + raise e + if power_on: - domain.createWithFlags(launch_flags) - self._enable_hairpin(domain.XMLDesc(0)) + try: + domain.createWithFlags(launch_flags) + except Exception as e: + with excutils.save_and_reraise_exception(): + LOG.error(_("An error occurred while trying to launch a " + "defined domain with xml: %s") % + domain.XMLDesc(0)) + + try: + self._enable_hairpin(domain.XMLDesc(0)) + except Exception: + with excutils.save_and_reraise_exception(): + LOG.error(_("An error occurred while enabling hairpin mode on " + "domain with xml: %s") % domain.XMLDesc(0)) # NOTE(uni): Now the container is running with its own private mount # namespace and so there is no need to keep the container rootfs |