Add operation logger
Add logging of user type operations. These ease debug since it dumps the VM information and 'Operation:' that can be grep'd. Also fixed 'raise' in the snapshot method that should have been 'return'. Change-Id: I63d7280baed72f5b7b237af99b22d4d72b711fad
This commit is contained in:
parent
27b7bff1e6
commit
538683d7c1
|
@ -38,7 +38,9 @@ logging.basicConfig()
|
|||
class FakeInstance(object):
|
||||
def __init__(self):
|
||||
self.name = 'fake_instance'
|
||||
self.display_name = 'fake_display_name'
|
||||
self.instance_type_id = 'instance_type_id'
|
||||
self.uuid = 'fake_uuid'
|
||||
|
||||
|
||||
class FakeFlavor(object):
|
||||
|
@ -122,6 +124,17 @@ class TestPowerVMDriver(test.TestCase):
|
|||
mock_crt.assert_called_with(mock_apt, drv.host_uuid,
|
||||
inst, my_flavor)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.driver.LOG')
|
||||
def test_log_op(self, mock_log):
|
||||
"""Validates the log_operations."""
|
||||
drv = driver.PowerVMDriver(fake.FakeVirtAPI())
|
||||
inst = FakeInstance()
|
||||
|
||||
drv._log_operation('fake_op', inst)
|
||||
entry = ('Operation: fake_op. Virtual machine display name: '
|
||||
'fake_display_name, name: fake_instance, UUID: fake_uuid')
|
||||
mock_log.info.assert_called_with(entry)
|
||||
|
||||
def test_host_resources(self):
|
||||
stats = pvm_host.build_host_resource_from_entry(self.wrapper)
|
||||
self.assertIsNotNone(stats)
|
||||
|
|
|
@ -81,6 +81,14 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
self.host_uuid = self.host_wrapper.get_uuid()
|
||||
LOG.info(_LI("Host UUID is:%s") % self.host_uuid)
|
||||
|
||||
def _log_operation(self, op, instance):
|
||||
"""Log entry point of driver operations
|
||||
"""
|
||||
LOG.info(_LI('Operation: %(op)s. Virtual machine display name: '
|
||||
'%(display_name)s, name: %(name)s, UUID: %(uuid)s') %
|
||||
{'op': op, 'display_name': instance.display_name,
|
||||
'name': instance.name, 'uuid': instance.uuid})
|
||||
|
||||
def get_info(self, instance):
|
||||
"""Get the current status of an instance, by name (not ID!)
|
||||
|
||||
|
@ -135,6 +143,7 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
:param flavor: The flavor for the instance to be spawned.
|
||||
"""
|
||||
|
||||
self._log_operation('spawn', instance)
|
||||
if not flavor:
|
||||
admin_ctx = ctx.get_admin_context(read_deleted='yes')
|
||||
flavor = (
|
||||
|
@ -162,6 +171,7 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
|
||||
"""
|
||||
|
||||
self._log_operation('destroy', instance)
|
||||
# For now, weed out the fake instances
|
||||
if instance.name in self._fake.list_instances():
|
||||
self._fake.destroy(instance, network_info,
|
||||
|
@ -172,10 +182,12 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Attach the disk to the instance at mountpoint using info."""
|
||||
self._log_operation('attach_volume', instance)
|
||||
return self._fake.attach_volume(connection_info, instance, mountpoint)
|
||||
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Detach the disk attached to the instance."""
|
||||
self._log_operation('detach_volume', instance)
|
||||
return self._fake.detach_volume(connection_info, instance, mountpoint)
|
||||
|
||||
def snapshot(self, context, instance, image_id, update_task_state):
|
||||
|
@ -186,8 +198,9 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
:param image_id: Reference to a pre-created image that will
|
||||
hold the snapshot.
|
||||
"""
|
||||
raise self._fake.snapshot(context, instance, image_id,
|
||||
update_task_state)
|
||||
self._log_operation('snapshot', instance)
|
||||
return self._fake.snapshot(context, instance, image_id,
|
||||
update_task_state)
|
||||
|
||||
def power_off(self, instance, timeout=0, retry_interval=0):
|
||||
"""Power off the specified instance.
|
||||
|
@ -198,6 +211,7 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
waiting for it to shutdown
|
||||
"""
|
||||
|
||||
self._log_operation('power_off', instance)
|
||||
"""Power off the specified instance."""
|
||||
power.power_off(self.adapter,
|
||||
vm.get_instance_wrapper(self.adapter,
|
||||
|
@ -212,6 +226,7 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
|
||||
:param instance: nova.objects.instance.Instance
|
||||
"""
|
||||
self._log_operation('power_on', instance)
|
||||
power.power_on(self.adapter,
|
||||
vm.get_instance_wrapper(self.adapter,
|
||||
instance,
|
||||
|
@ -243,10 +258,12 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
|
||||
def plug_vifs(self, instance, network_info):
|
||||
"""Plug VIFs into networks."""
|
||||
self._log_operation('plug_vifs', instance)
|
||||
pass
|
||||
|
||||
def unplug_vifs(self, instance, network_info):
|
||||
"""Unplug VIFs from networks."""
|
||||
self._log_operation('unplug_vifs', instance)
|
||||
pass
|
||||
|
||||
def get_available_nodes(self):
|
||||
|
@ -335,6 +352,7 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
:params block_migration: if true, migrate VM disk.
|
||||
:params migrate_data: implementation specific data dictionary.
|
||||
"""
|
||||
self._log_operation('live_migration', instance_ref)
|
||||
self._fake.live_migration(ctxt, instance_ref, dest,
|
||||
post_method, recover_method,
|
||||
migrate_data, block_migration=False)
|
||||
|
|
|
@ -131,8 +131,8 @@ class FakePowerVMDriver(driver.ComputeDriver):
|
|||
:param image_id: Reference to a pre-created image that will
|
||||
hold the snapshot.
|
||||
"""
|
||||
raise self._fake.snapshot(context, instance, image_id,
|
||||
update_task_state)
|
||||
return self._fake.snapshot(context, instance, image_id,
|
||||
update_task_state)
|
||||
|
||||
def power_off(self, instance, timeout=0, retry_interval=0):
|
||||
"""Power off the specified instance.
|
||||
|
|
Loading…
Reference in New Issue