Skip to content

Commit

Permalink
Add notification for pause/unpause instance
Browse files Browse the repository at this point in the history
When pause/unpause instance, there are no notifications, this
will cause someone cannot know when pause/unpause operation
would be finished.

All other instance operations do have notifications. We should
also add notification support for those two operations.

Change-Id: I5b8cc33a5992f5f028a3220217dcf7a0288d150d
Closes-Bug: #1043861
  • Loading branch information
Jay Lau committed Sep 27, 2013
1 parent ab5a99b commit 54f465f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nova/compute/manager.py
Expand Up @@ -3215,12 +3215,14 @@ def pause_instance(self, context, instance):
"""Pause an instance on this host."""
context = context.elevated()
LOG.audit(_('Pausing'), context=context, instance=instance)
self._notify_about_instance_usage(context, instance, 'pause.start')
self.driver.pause(instance)
current_power_state = self._get_power_state(context, instance)
instance.power_state = current_power_state
instance.vm_state = vm_states.PAUSED
instance.task_state = None
instance.save(expected_task_state=task_states.PAUSING)
self._notify_about_instance_usage(context, instance, 'pause.end')

@object_compat
@wrap_exception()
Expand All @@ -3231,12 +3233,14 @@ def unpause_instance(self, context, instance):
"""Unpause a paused instance on this host."""
context = context.elevated()
LOG.audit(_('Unpausing'), context=context, instance=instance)
self._notify_about_instance_usage(context, instance, 'unpause.start')
self.driver.unpause(instance)
current_power_state = self._get_power_state(context, instance)
instance.power_state = current_power_state
instance.vm_state = vm_states.ACTIVE
instance.task_state = None
instance.save(expected_task_state=task_states.UNPAUSING)
self._notify_about_instance_usage(context, instance, 'unpause.end')

@wrap_exception()
def host_power_action(self, context, host=None, action=None):
Expand Down
16 changes: 16 additions & 0 deletions nova/tests/compute/test_compute.py
Expand Up @@ -1845,10 +1845,26 @@ def test_pause(self):
self.compute.run_instance(self.context, instance=instance)
db.instance_update(self.context, instance['uuid'],
{"task_state": task_states.PAUSING})
fake_notifier.NOTIFICATIONS = []
self.compute.pause_instance(self.context, instance=instance)
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
msg = fake_notifier.NOTIFICATIONS[0]
self.assertEqual(msg.event_type,
'compute.instance.pause.start')
msg = fake_notifier.NOTIFICATIONS[1]
self.assertEqual(msg.event_type,
'compute.instance.pause.end')
db.instance_update(self.context, instance['uuid'],
{"task_state": task_states.UNPAUSING})
fake_notifier.NOTIFICATIONS = []
self.compute.unpause_instance(self.context, instance=instance)
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
msg = fake_notifier.NOTIFICATIONS[0]
self.assertEqual(msg.event_type,
'compute.instance.unpause.start')
msg = fake_notifier.NOTIFICATIONS[1]
self.assertEqual(msg.event_type,
'compute.instance.unpause.end')
self.compute.terminate_instance(self.context, instance=instance)

def test_suspend(self):
Expand Down

0 comments on commit 54f465f

Please sign in to comment.