summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2010-08-12 21:27:53 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2010-08-12 21:27:53 -0700
commita679cab031ec91dd719b9ba887cdae4f595b2ca4 (patch)
treecbc8b1772582f3f8b5ab5694147580e416e0fd68 /nova/tests
parent2bbb2b86272c89b35a1042ab2866bbe4863bc3e3 (diff)
make rpc.call propogate exception info. Includes tests
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/rpc_unittest.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/nova/tests/rpc_unittest.py b/nova/tests/rpc_unittest.py
new file mode 100644
index 000000000..9c2e29344
--- /dev/null
+++ b/nova/tests/rpc_unittest.py
@@ -0,0 +1,62 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import logging
+
+from twisted.internet import defer
+
+from nova import flags
+from nova import rpc
+from nova import test
+
+
+FLAGS = flags.FLAGS
+
+
+class RpcTestCase(test.BaseTestCase):
+ def setUp(self):
+ super(RpcTestCase, self).setUp()
+ self.conn = rpc.Connection.instance()
+ self.receiver = TestReceiver()
+ self.consumer = rpc.AdapterConsumer(connection=self.conn,
+ topic='test',
+ proxy=self.receiver)
+
+ self.injected.append(self.consumer.attach_to_tornado(self.ioloop))
+
+ def test_call_succeed(self):
+ value = 42
+ result = yield rpc.call('test', {"method": "echo", "args": {"value": value}})
+ self.assertEqual(value, result)
+
+ def test_call_exception(self):
+ value = 42
+ self.assertFailure(rpc.call('test', {"method": "fail", "args": {"value": value}}), rpc.RemoteError)
+ try:
+ yield rpc.call('test', {"method": "fail", "args": {"value": value}})
+ self.fail("should have thrown rpc.RemoteError")
+ except rpc.RemoteError as exc:
+ self.assertEqual(int(exc.value), value)
+
+class TestReceiver(object):
+ def echo(self, value):
+ logging.debug("Received %s", value)
+ return defer.succeed(value)
+
+ def fail(self, value):
+ raise Exception(value)