libvirt: pause mode is not supported by all drivers

Only KVM/Qemu drivers support the VIR_DOMAIN_START_PAUSED flag
Booting guests on other drivers with the above flag will make it fail.

Closes-Bug: 1301453
Change-Id: Ia98e018b686c4ec3c15fd1f6bcc78188f330fcef
This commit is contained in:
Vladik Romanovsky 2014-04-02 15:00:19 -04:00
parent 53f52b3000
commit bfb28fcf90
2 changed files with 35 additions and 5 deletions

View File

@ -6900,6 +6900,23 @@ class LibvirtConnTestCase(test.TestCase):
block_device_info=block_device_info)
self.assertTrue('fake' in self.resultXML)
def test_create_without_pause(self):
self.flags(virt_type='lxc', group='libvirt')
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
instance = instance_obj.Instance(id=1, uuid='fake-uuid')
with contextlib.nested(
mock.patch.object(conn, 'plug_vifs'),
mock.patch.object(conn, 'firewall_driver'),
mock.patch.object(conn, '_create_domain'),
mock.patch.object(conn, 'cleanup')) as (
cleanup, firewall_driver, create, plug_vifs):
domain = conn._create_domain_and_network(self.context, 'xml',
instance, None)
self.assertEqual(0, create.call_args_list[0][1]['launch_flags'])
self.assertEqual(0, domain.resume.call_count)
def _test_create_with_network_events(self, neutron_failure=None):
self.flags(vif_driver="nova.tests.fake_network.FakeVIFDriver",
group='libvirt')
@ -6940,9 +6957,12 @@ class LibvirtConnTestCase(test.TestCase):
domain = conn._create_domain_and_network(self.context, 'xml',
instance, vifs)
plug_vifs.assert_called_with(instance, vifs)
self.assertEqual(libvirt.VIR_DOMAIN_START_PAUSED,
event = utils.is_neutron() and CONF.vif_plugging_timeout
flag = event and libvirt.VIR_DOMAIN_START_PAUSED or 0
self.assertEqual(flag,
create.call_args_list[0][1]['launch_flags'])
domain.resume.assert_called_once_with()
if flag:
domain.resume.assert_called_once_with()
if neutron_failure and CONF.vif_plugging_is_fatal:
cleanup.assert_called_once_with(self.context,
instance, network_info=vifs,

View File

@ -3581,6 +3581,10 @@ class LibvirtDriver(driver.ComputeDriver):
return [('network-vif-plugged', vif['id'])
for vif in network_info if vif.get('active', True) is False]
@staticmethod
def _conn_supports_start_paused():
return CONF.libvirt.virt_type in ('kvm', 'qemu')
def _create_domain_and_network(self, context, xml, instance, network_info,
block_device_info=None, power_on=True,
reboot=False, vifs_already_plugged=False):
@ -3614,11 +3618,14 @@ class LibvirtDriver(driver.ComputeDriver):
encryptor.attach_volume(context, **encryption)
timeout = CONF.vif_plugging_timeout
if utils.is_neutron() and not vifs_already_plugged and timeout:
if (self._conn_supports_start_paused() and
utils.is_neutron() and not
vifs_already_plugged and timeout):
events = self._get_neutron_events(network_info)
else:
events = []
launch_flags = events and libvirt.VIR_DOMAIN_START_PAUSED or 0
try:
with self.virtapi.wait_for_instance_event(
instance, events, deadline=timeout,
@ -3630,7 +3637,7 @@ class LibvirtDriver(driver.ComputeDriver):
network_info)
domain = self._create_domain(
xml, instance=instance,
launch_flags=libvirt.VIR_DOMAIN_START_PAUSED,
launch_flags=launch_flags,
power_on=power_on)
self.firewall_driver.apply_instance_filter(instance,
@ -3651,7 +3658,10 @@ class LibvirtDriver(driver.ComputeDriver):
self.cleanup(context, instance, network_info=network_info,
block_device_info=block_device_info)
raise exception.VirtualInterfaceCreateException()
domain.resume()
# Resume only if domain has been paused
if launch_flags & libvirt.VIR_DOMAIN_START_PAUSED:
domain.resume()
return domain
def get_all_block_devices(self):