def test_exception(self):
     e = None
     try:
         try:
             raise ValueError()
         except Exception:
             raise oslo_messaging.ExpectedException()
     except oslo_messaging.ExpectedException as e:
         self.assertIsInstance(e, oslo_messaging.ExpectedException)
         self.assertTrue(hasattr(e, 'exc_info'))
         self.assertIsInstance(e.exc_info[1], ValueError)
Exemple #2
0
    def _object_dispatch(self, target, method, args, kwargs):
        """Dispatch a call to an object method.

        This ensures that object methods get called and any exception
        that is raised gets wrapped in an ExpectedException for forwarding
        back to the caller (without spamming the conductor logs).
        """
        try:
            # NOTE(danms): Keep the getattr inside the try block since
            # a missing method is really a client problem
            return getattr(target, method)(*args, **kwargs)
        except Exception:
            raise messaging.ExpectedException()