Merge "Log xml in libvirt _create_domain failures"
This commit is contained in:
@@ -44,6 +44,7 @@ from nova.openstack.common import fileutils
|
|||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
from nova.openstack.common import jsonutils
|
from nova.openstack.common import jsonutils
|
||||||
from nova.openstack.common import loopingcall
|
from nova.openstack.common import loopingcall
|
||||||
|
from nova.openstack.common import processutils
|
||||||
from nova.openstack.common import uuidutils
|
from nova.openstack.common import uuidutils
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fake_network
|
from nova.tests import fake_network
|
||||||
@@ -4022,6 +4023,88 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
self.assertTrue(conn._is_storage_shared_with('foo', '/path'))
|
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):
|
class HostStateTestCase(test.TestCase):
|
||||||
|
|
||||||
|
|||||||
@@ -2506,10 +2506,28 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||||||
use_cow=CONF.use_cow_images)
|
use_cow=CONF.use_cow_images)
|
||||||
|
|
||||||
if xml:
|
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:
|
if power_on:
|
||||||
domain.createWithFlags(launch_flags)
|
try:
|
||||||
self._enable_hairpin(domain.XMLDesc(0))
|
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
|
# NOTE(uni): Now the container is running with its own private mount
|
||||||
# namespace and so there is no need to keep the container rootfs
|
# namespace and so there is no need to keep the container rootfs
|
||||||
|
|||||||
Reference in New Issue
Block a user