summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandy Walsh <sandy@sandywalsh.com>2013-01-08 16:20:12 -0600
committerSandy Walsh <sandy.walsh@rackspace.com>2013-01-14 10:53:29 -0500
commitd1f121265badfffd097ee983d14989b885375a0e (patch)
tree8e08762772a1afdebc5aa0521111b474e0ffcf4b
parentca4b1303804e94f10f0e4e6c4a9e09c049efd1ee (diff)
Keep self and context out of error notification payload.
Back in the day, having self and context in the error notifications was handy for debugging. Now, there is a lot of confidential stuff stored in these objects (especially when self = ComputeManager) ... like passwords, etc. This patch strips it out. Also removes dead wrap_exception calls (which did nothing since they did not specify a notifier). Change-Id: Ieab7bd79b64e01c7bca18dbce97455e50094871c
-rw-r--r--nova/console/manager.py2
-rw-r--r--nova/console/vmrc_manager.py2
-rw-r--r--nova/exception.py27
-rw-r--r--nova/tests/test_exception.py12
-rw-r--r--nova/virt/baremetal/driver.py5
-rw-r--r--nova/virt/baremetal/volume_driver.py1
-rw-r--r--nova/virt/libvirt/driver.py20
7 files changed, 12 insertions, 57 deletions
diff --git a/nova/console/manager.py b/nova/console/manager.py
index 243c028d9..2045f824d 100644
--- a/nova/console/manager.py
+++ b/nova/console/manager.py
@@ -65,7 +65,6 @@ class ConsoleProxyManager(manager.Manager):
def init_host(self):
self.driver.init_host()
- @exception.wrap_exception()
def add_console(self, context, instance_id, password=None,
port=None, **kwargs):
instance = self.db.instance_get(context, instance_id)
@@ -93,7 +92,6 @@ class ConsoleProxyManager(manager.Manager):
return console['id']
- @exception.wrap_exception()
def remove_console(self, context, console_id, **_kwargs):
try:
console = self.db.console_get(context, console_id)
diff --git a/nova/console/vmrc_manager.py b/nova/console/vmrc_manager.py
index e8eab4db2..64d2a472f 100644
--- a/nova/console/vmrc_manager.py
+++ b/nova/console/vmrc_manager.py
@@ -75,7 +75,6 @@ class ConsoleVMRCManager(manager.Manager):
self.driver.setup_console(context, console)
return console
- @exception.wrap_exception()
def add_console(self, context, instance_id, password=None,
port=None, **kwargs):
"""Adds a console for the instance.
@@ -105,7 +104,6 @@ class ConsoleVMRCManager(manager.Manager):
instance)
return console['id']
- @exception.wrap_exception()
def remove_console(self, context, console_id, **_kwargs):
"""Removes a console entry."""
try:
diff --git a/nova/exception.py b/nova/exception.py
index 7ec23d32d..f96b1eaf3 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -82,9 +82,11 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None,
# to pass it in as a parameter. Otherwise we get a cyclic import of
# nova.notifier.api -> nova.utils -> nova.exception :(
def inner(f):
- def wrapped(*args, **kw):
+ def wrapped(self, context, *args, **kw):
+ # Don't store self or context in the payload, it now seems to
+ # contain confidential information.
try:
- return f(*args, **kw)
+ return f(self, context, *args, **kw)
except Exception, e:
with excutils.save_and_reraise_exception():
if notifier:
@@ -104,10 +106,6 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None,
# propagated.
temp_type = f.__name__
- context = get_context_from_function_and_args(f,
- args,
- kw)
-
notifier.notify(context, publisher_id, temp_type,
temp_level, payload)
@@ -1089,20 +1087,3 @@ class CryptoCAFileNotFound(FileNotFound):
class CryptoCRLFileNotFound(FileNotFound):
message = _("The CRL file for %(project)s could not be found")
-
-
-def get_context_from_function_and_args(function, args, kwargs):
- """Find an arg of type RequestContext and return it.
-
- This is useful in a couple of decorators where we don't
- know much about the function we're wrapping.
- """
-
- # import here to avoid circularity:
- from nova import context
-
- for arg in itertools.chain(kwargs.values(), args):
- if isinstance(arg, context.RequestContext):
- return arg
-
- return None
diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py
index 9e34f287c..ad67cff26 100644
--- a/nova/tests/test_exception.py
+++ b/nova/tests/test_exception.py
@@ -52,23 +52,23 @@ class FakeNotifier(object):
self.provided_context = context
-def good_function():
+def good_function(self, context):
return 99
-def bad_function_exception(blah="a", boo="b", context=None):
+def bad_function_exception(self, context, extra, blah="a", boo="b", zoo=None):
raise test.TestingException()
class WrapExceptionTestCase(test.TestCase):
def test_wrap_exception_good_return(self):
wrapped = exception.wrap_exception()
- self.assertEquals(99, wrapped(good_function)())
+ self.assertEquals(99, wrapped(good_function)(1, 2))
def test_wrap_exception_throws_exception(self):
wrapped = exception.wrap_exception()
self.assertRaises(test.TestingException,
- wrapped(bad_function_exception))
+ wrapped(bad_function_exception), 1, 2, 3)
def test_wrap_exception_with_notifier(self):
notifier = FakeNotifier()
@@ -76,7 +76,7 @@ class WrapExceptionTestCase(test.TestCase):
"level")
ctxt = context.get_admin_context()
self.assertRaises(test.TestingException,
- wrapped(bad_function_exception), context=ctxt)
+ wrapped(bad_function_exception), 1, ctxt, 3, zoo=3)
self.assertEquals(notifier.provided_publisher, "publisher")
self.assertEquals(notifier.provided_event, "event")
self.assertEquals(notifier.provided_priority, "level")
@@ -88,7 +88,7 @@ class WrapExceptionTestCase(test.TestCase):
notifier = FakeNotifier()
wrapped = exception.wrap_exception(notifier)
self.assertRaises(test.TestingException,
- wrapped(bad_function_exception))
+ wrapped(bad_function_exception), 1, 2, 3)
self.assertEquals(notifier.provided_publisher, None)
self.assertEquals(notifier.provided_event, "bad_function_exception")
self.assertEquals(notifier.provided_priority, notifier.ERROR)
diff --git a/nova/virt/baremetal/driver.py b/nova/virt/baremetal/driver.py
index 462e0c444..f66864127 100644
--- a/nova/virt/baremetal/driver.py
+++ b/nova/virt/baremetal/driver.py
@@ -324,10 +324,9 @@ class BareMetalDriver(driver.ComputeDriver):
return self.volume_driver.attach_volume(connection_info,
instance, mountpoint)
- @exception.wrap_exception()
- def detach_volume(self, connection_info, instance, mountpoint):
+ def detach_volume(self, connection_info, instance_name, mountpoint):
return self.volume_driver.detach_volume(connection_info,
- instance, mountpoint)
+ instance_name, mountpoint)
def get_info(self, instance):
# NOTE(deva): compute/manager.py expects to get NotFound exception
diff --git a/nova/virt/baremetal/volume_driver.py b/nova/virt/baremetal/volume_driver.py
index 570cea1d8..2e6f82b93 100644
--- a/nova/virt/baremetal/volume_driver.py
+++ b/nova/virt/baremetal/volume_driver.py
@@ -246,7 +246,6 @@ class LibvirtVolumeDriver(VolumeDriver):
# TODO(NTTdocomo): support CHAP
_allow_iscsi_tgtadm(tid, 'ALL')
- @exception.wrap_exception()
def detach_volume(self, connection_info, instance, mountpoint):
mount_device = mountpoint.rpartition("/")[2]
try:
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 42d9dd99b..a06cbdb78 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -661,7 +661,6 @@ class LibvirtDriver(driver.ComputeDriver):
method = getattr(driver, method_name)
return method(connection_info, *args, **kwargs)
- @exception.wrap_exception()
def attach_volume(self, connection_info, instance, mountpoint):
instance_name = instance['name']
virt_dom = self._lookup_by_name(instance_name)
@@ -716,7 +715,6 @@ class LibvirtDriver(driver.ComputeDriver):
block_device_info=block_device_info)
return xml
- @exception.wrap_exception()
def detach_volume(self, connection_info, instance, mountpoint):
instance_name = instance['name']
mount_device = mountpoint.rpartition("/")[2]
@@ -749,7 +747,6 @@ class LibvirtDriver(driver.ComputeDriver):
connection_info,
mount_device)
- @exception.wrap_exception()
def snapshot(self, context, instance, image_href, update_task_state):
"""Create snapshot from a running VM instance.
@@ -845,7 +842,6 @@ class LibvirtDriver(driver.ComputeDriver):
metadata,
image_file)
- @exception.wrap_exception()
def reboot(self, instance, network_info, reboot_type='SOFT',
block_device_info=None):
"""Reboot a virtual machine, given an instance reference."""
@@ -932,24 +928,20 @@ class LibvirtDriver(driver.ComputeDriver):
timer = utils.FixedIntervalLoopingCall(_wait_for_reboot)
timer.start(interval=0.5).wait()
- @exception.wrap_exception()
def pause(self, instance):
"""Pause VM instance."""
dom = self._lookup_by_name(instance['name'])
dom.suspend()
- @exception.wrap_exception()
def unpause(self, instance):
"""Unpause paused VM instance."""
dom = self._lookup_by_name(instance['name'])
dom.resume()
- @exception.wrap_exception()
def power_off(self, instance):
"""Power off the specified instance."""
self._destroy(instance)
- @exception.wrap_exception()
def power_on(self, instance):
"""Power on the specified instance."""
dom = self._lookup_by_name(instance['name'])
@@ -958,20 +950,17 @@ class LibvirtDriver(driver.ComputeDriver):
instance)
timer.start(interval=0.5).wait()
- @exception.wrap_exception()
def suspend(self, instance):
"""Suspend the specified instance."""
dom = self._lookup_by_name(instance['name'])
dom.managedSave(0)
- @exception.wrap_exception()
def resume(self, instance, network_info, block_device_info=None):
"""resume the specified instance."""
xml = self._get_domain_xml(instance, network_info, block_device_info)
self._create_domain_and_network(xml, instance, network_info,
block_device_info)
- @exception.wrap_exception()
def resume_state_on_host_boot(self, context, instance, network_info,
block_device_info=None):
"""resume guest state when a host is booted."""
@@ -979,7 +968,6 @@ class LibvirtDriver(driver.ComputeDriver):
self._create_domain_and_network(xml, instance, network_info,
block_device_info)
- @exception.wrap_exception()
def rescue(self, context, instance, network_info, image_meta,
rescue_password):
"""Loads a VM using rescue images.
@@ -1010,7 +998,6 @@ class LibvirtDriver(driver.ComputeDriver):
self._destroy(instance)
self._create_domain(xml)
- @exception.wrap_exception()
def unrescue(self, instance, network_info):
"""Reboot the VM which is being rescued back into primary images.
"""
@@ -1027,7 +1014,6 @@ class LibvirtDriver(driver.ComputeDriver):
for rescue_file in glob.iglob(rescue_files):
libvirt_utils.file_delete(rescue_file)
- @exception.wrap_exception()
def poll_rebooting_instances(self, timeout, instances):
pass
@@ -1042,7 +1028,6 @@ class LibvirtDriver(driver.ComputeDriver):
# NOTE(ilyaalekseyev): Implementation like in multinics
# for xenapi(tr3buchet)
- @exception.wrap_exception()
def spawn(self, context, instance, image_meta, injected_files,
admin_password, network_info=None, block_device_info=None):
xml = self.to_xml(instance, network_info, image_meta,
@@ -1083,7 +1068,6 @@ class LibvirtDriver(driver.ComputeDriver):
fp.write(data)
return fpath
- @exception.wrap_exception()
def get_console_output(self, instance):
virt_dom = self._lookup_by_name(instance['name'])
xml = virt_dom.XMLDesc(0)
@@ -1150,7 +1134,6 @@ class LibvirtDriver(driver.ComputeDriver):
def get_host_ip_addr():
return CONF.my_ip
- @exception.wrap_exception()
def get_vnc_console(self, instance):
def get_vnc_port_for_instance(instance_name):
virt_dom = self._lookup_by_name(instance_name)
@@ -2891,7 +2874,6 @@ class LibvirtDriver(driver.ComputeDriver):
except Exception:
pass
- @exception.wrap_exception()
def migrate_disk_and_power_off(self, context, instance, dest,
instance_type, network_info,
block_device_info=None):
@@ -2957,7 +2939,6 @@ class LibvirtDriver(driver.ComputeDriver):
LOG.info(_("Instance running successfully."), instance=instance)
raise utils.LoopingCallDone()
- @exception.wrap_exception()
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance,
block_device_info=None):
@@ -3010,7 +2991,6 @@ class LibvirtDriver(driver.ComputeDriver):
instance)
timer.start(interval=0.5).wait()
- @exception.wrap_exception()
def finish_revert_migration(self, instance, network_info,
block_device_info=None):
LOG.debug(_("Starting finish_revert_migration"),