summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2013-03-12 17:21:33 -0400
committerRussell Bryant <rbryant@redhat.com>2013-03-12 17:21:33 -0400
commit1df14918988ba45fc95b6925a617238af398cc50 (patch)
tree206089cc72867bcee0d2c980f10ad3b3ecc5c616
parent562b0787421b145c4a91ccbbcacfc74c340cead8 (diff)
downloadnova-1df14918988ba45fc95b6925a617238af398cc50.tar.gz
nova-1df14918988ba45fc95b6925a617238af398cc50.tar.xz
nova-1df14918988ba45fc95b6925a617238af398cc50.zip
List ConsoleTypeInvalid as a client exception.
get_vnc_console() and get_spice_console() in nova.compute.manager should list ConsoleTypeInvalid as a client exception for rpc. This prevents the rpc layer from logging a traceback for this exception when raised. It is an expected type of exception that the client should be left to handle how it would like. Fix bug 1154301. Change-Id: I3a359cbb4edbfabea1775e927b6f9947db26a284
-rwxr-xr-xnova/compute/manager.py3
-rw-r--r--nova/tests/compute/test_compute.py34
2 files changed, 37 insertions, 0 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 53ab3a2ed..3d3a094a2 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -65,6 +65,7 @@ from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
from nova.openstack.common.notifier import api as notifier
from nova.openstack.common import rpc
+from nova.openstack.common.rpc import common as rpc_common
from nova.openstack.common import timeutils
from nova import paths
from nova import quota
@@ -2579,6 +2580,7 @@ class ComputeManager(manager.SchedulerDependentManager):
else:
return '\n'.join(log.split('\n')[-int(length):])
+ @rpc_common.client_exceptions(exception.ConsoleTypeInvalid)
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@wrap_instance_fault
def get_vnc_console(self, context, console_type, instance):
@@ -2607,6 +2609,7 @@ class ComputeManager(manager.SchedulerDependentManager):
return connect_info
+ @rpc_common.client_exceptions(exception.ConsoleTypeInvalid)
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@wrap_instance_fault
def get_spice_console(self, context, console_type, instance):
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 0e41678b3..7be3cf9a0 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -172,6 +172,12 @@ class BaseTestCase(test.TestCase):
fake.restore_nodes()
super(BaseTestCase, self).tearDown()
+ def stub_out_client_exceptions(self):
+ def passthru(exceptions, func, *args, **kwargs):
+ return func(*args, **kwargs)
+
+ self.stubs.Set(rpc_common, 'catch_client_exception', passthru)
+
def _create_fake_instance(self, params=None, type_name='m1.tiny'):
"""Create a test instance."""
if not params:
@@ -1529,9 +1535,16 @@ class ComputeTestCase(BaseTestCase):
instance = jsonutils.to_primitive(self._create_fake_instance())
self.compute.run_instance(self.context, instance=instance)
+ self.assertRaises(rpc_common.ClientException,
+ self.compute.get_vnc_console,
+ self.context, 'invalid', instance=instance)
+
+ self.stub_out_client_exceptions()
+
self.assertRaises(exception.ConsoleTypeInvalid,
self.compute.get_vnc_console,
self.context, 'invalid', instance=instance)
+
self.compute.terminate_instance(self.context, instance=instance)
def test_missing_vnc_console_type(self):
@@ -1542,9 +1555,16 @@ class ComputeTestCase(BaseTestCase):
instance = jsonutils.to_primitive(self._create_fake_instance())
self.compute.run_instance(self.context, instance=instance)
+ self.assertRaises(rpc_common.ClientException,
+ self.compute.get_vnc_console,
+ self.context, None, instance=instance)
+
+ self.stub_out_client_exceptions()
+
self.assertRaises(exception.ConsoleTypeInvalid,
self.compute.get_vnc_console,
self.context, None, instance=instance)
+
self.compute.terminate_instance(self.context, instance=instance)
def test_spicehtml5_spice_console(self):
@@ -1570,9 +1590,16 @@ class ComputeTestCase(BaseTestCase):
instance = jsonutils.to_primitive(self._create_fake_instance())
self.compute.run_instance(self.context, instance=instance)
+ self.assertRaises(rpc_common.ClientException,
+ self.compute.get_spice_console,
+ self.context, 'invalid', instance=instance)
+
+ self.stub_out_client_exceptions()
+
self.assertRaises(exception.ConsoleTypeInvalid,
self.compute.get_spice_console,
self.context, 'invalid', instance=instance)
+
self.compute.terminate_instance(self.context, instance=instance)
def test_missing_spice_console_type(self):
@@ -1583,9 +1610,16 @@ class ComputeTestCase(BaseTestCase):
instance = jsonutils.to_primitive(self._create_fake_instance())
self.compute.run_instance(self.context, instance=instance)
+ self.assertRaises(rpc_common.ClientException,
+ self.compute.get_spice_console,
+ self.context, None, instance=instance)
+
+ self.stub_out_client_exceptions()
+
self.assertRaises(exception.ConsoleTypeInvalid,
self.compute.get_spice_console,
self.context, None, instance=instance)
+
self.compute.terminate_instance(self.context, instance=instance)
def test_diagnostics(self):