Skip to content

Commit

Permalink
Implements resume_state_on_host_boot for libvirt.
Browse files Browse the repository at this point in the history
Adds a new virt driver function to help resume guest states
on host boot. This fixes a couple issue with using a reboot
(like we did previously):

 * Using reboot would clear some task states (VERIFY_RESIZE for example)
 * Provides a mechanism for hypervisor specific guest restarts.
   Reboot would not have worked for XenServer for example...
 * Updates libvirt to use a hard reboot (instead of soft)

Fixes LP Bug #985162.

Change-Id: Iaf5aad75ec9b91f44710a18ddaf3a93378573a62
(cherry picked from commit 6548c50)
  • Loading branch information
dprince authored and vishvananda committed Jun 11, 2012
1 parent 3ee026e commit 27133ee
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nova/compute/manager.py
Expand Up @@ -246,15 +246,21 @@ def init_host(self):
LOG.debug(_('Current state is %(drv_state)s, state in DB is '
'%(db_state)s.'), locals(), instance=instance)

net_info = self._get_instance_nw_info(context, instance)
if ((expect_running and FLAGS.resume_guests_state_on_host_boot) or
FLAGS.start_guests_on_host_boot):
LOG.info(_('Rebooting instance after nova-compute restart.'),
locals(), instance=instance)
self.reboot_instance(context, instance['uuid'])
try:
self.driver.resume_state_on_host_boot(context, instance,
self._legacy_nw_info(net_info))
except NotImplementedError:
LOG.warning(_('Hypervisor driver does not support '
'resume guests'), instance=instance)

elif drv_state == power_state.RUNNING:
# Hyper-V and VMWareAPI drivers will raise an exception
try:
net_info = self._get_instance_nw_info(context, instance)
self.driver.ensure_filtering_rules_for_instance(instance,
self._legacy_nw_info(net_info))
except NotImplementedError:
Expand Down
6 changes: 6 additions & 0 deletions nova/tests/test_virt_drivers.py
Expand Up @@ -142,6 +142,12 @@ def test_agent_update(self):
self.connection.agent_update(instance_ref, 'http://www.openstack.org/',
'd41d8cd98f00b204e9800998ecf8427e')

@catch_notimplementederror
def test_resume_state_on_host_boot(self):
instance_ref, network_info = self._get_running_instance()
self.connection.resume_state_on_host_boot(self.ctxt, instance_ref,
network_info)

@catch_notimplementederror
def test_rescue(self):
instance_ref, network_info = self._get_running_instance()
Expand Down
4 changes: 4 additions & 0 deletions nova/virt/driver.py
Expand Up @@ -335,6 +335,10 @@ def resume(self, instance):
# TODO(Vek): Need to pass context in for access to auth_token
raise NotImplementedError()

def resume_state_on_host_boot(self, context, instance, network_info):
"""resume guest state when a host is booted"""
raise NotImplementedError()

def rescue(self, context, instance, network_info, image_meta):
"""Rescue the specified instance"""
raise NotImplementedError()
Expand Down
3 changes: 3 additions & 0 deletions nova/virt/fake.py
Expand Up @@ -131,6 +131,9 @@ def inject_file(self, instance, b64_path, b64_contents):
def agent_update(self, instance, url, md5hash):
pass

def resume_state_on_host_boot(self, context, instance, network_info):
pass

def rescue(self, context, instance, network_info, image_meta):
pass

Expand Down
7 changes: 7 additions & 0 deletions nova/virt/libvirt/connection.py
Expand Up @@ -824,6 +824,13 @@ def resume(self, instance):
dom = self._lookup_by_name(instance.name)
dom.create()

@exception.wrap_exception()
def resume_state_on_host_boot(self, context, instance, network_info):
"""resume guest state when a host is booted"""
# NOTE(dprince): use hard reboot to ensure network and firewall
# rules are configured
self._hard_reboot(instance, network_info)

@exception.wrap_exception()
def rescue(self, context, instance, network_info, image_meta):
"""Loads a VM using rescue images.
Expand Down

0 comments on commit 27133ee

Please sign in to comment.