Beispiel #1
0
    def call(self, context, method, args):
        node_func = getattr(self.proxy, method)
        node_args = dict((str(k), v) for k, v in args.iteritems())

        ctxt = RpcContext.from_dict(context.to_dict())
        try:
            rval = node_func(context=ctxt, **node_args)
            # Caller might have called ctxt.reply() manually
            for (reply, failure) in ctxt._response:
                if failure:
                    raise failure[0], failure[1], failure[2]
                yield reply
            # if ending not 'sent'...we might have more data to
            # return from the function itself
            if not ctxt._done:
                if isinstance(rval, types.GeneratorType):
                    for val in rval:
                        yield val
                else:
                    yield rval
        except Exception:
            exc_info = sys.exc_info()
            raise rpc_common.RemoteError(
                exc_info[0].__name__, str(exc_info[1]),
                ''.join(traceback.format_exception(*exc_info)))
Beispiel #2
0
 def _inner():
     ctxt = RpcContext.from_dict(context.to_dict())
     try:
         rval = node_func(context=ctxt, **node_args)
         res = []
         # Caller might have called ctxt.reply() manually
         for (reply, failure) in ctxt._response:
             if failure:
                 raise failure[0], failure[1], failure[2]
             res.append(reply)
         # if ending not 'sent'...we might have more data to
         # return from the function itself
         if not ctxt._done:
             if inspect.isgenerator(rval):
                 for val in rval:
                     res.append(val)
             else:
                 res.append(rval)
         done.send(res)
     except Exception:
         exc_info = sys.exc_info()
         done.send_exception(
             rpc_common.RemoteError(
                 exc_info[0].__name__, str(exc_info[1]),
                 ''.join(traceback.format_exception(*exc_info))))
Beispiel #3
0
 def __call__(self, data):
     """The consume() callback will call this.  Store the result."""
     if data['failure']:
         self._result = rpc_common.RemoteError(*data['failure'])
     elif data.get('ending', False):
         self._got_ending = True
     else:
         self._result = data['result']
Beispiel #4
0
 def __call__(self, data, message):
     """Acks message and sets result."""
     message.ack()
     if data['failure']:
         self._results.put(rpc_common.RemoteError(*data['failure']))
     elif data.get('ending', False):
         self._got_ending = True
     else:
         self._results.put(data['result'])
    def test_live_migration_dest_host_incompatable_cpu_raises(self):
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
        self.mox.StubOutWithMock(self.driver, '_live_migration_dest_check')
        self.mox.StubOutWithMock(rpc, 'queue_get_for')
        self.mox.StubOutWithMock(rpc, 'call')
        self.mox.StubOutWithMock(rpc, 'cast')
        self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')

        dest = 'fake_host2'
        block_migration = False
        disk_over_commit = False
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance['id']).AndReturn(instance)

        self.driver._live_migration_src_check(self.context, instance)
        self.driver._live_migration_dest_check(self.context, instance,
                dest, block_migration, disk_over_commit)

        self._check_shared_storage(dest, instance, True)

        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
                [{'compute_node': [{'hypervisor_type': 'xen',
                                    'hypervisor_version': 1}]}])
        db.service_get_all_compute_by_host(self.context,
            instance['host']).AndReturn(
                    [{'compute_node': [{'hypervisor_type': 'xen',
                                        'hypervisor_version': 1,
                                        'cpu_info': 'fake_cpu_info'}]}])
        rpc.queue_get_for(self.context, FLAGS.compute_topic,
                dest).AndReturn('dest_queue')
        rpc.call(self.context, 'dest_queue',
                {'method': 'compare_cpu',
                 'args': {'cpu_info': 'fake_cpu_info'},
                 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None
                ).AndRaise(rpc_common.RemoteError())

        self.mox.ReplayAll()
        self.assertRaises(rpc_common.RemoteError,
                self.driver.schedule_live_migration, self.context,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration)
Beispiel #6
0
 def disassociate(self, context, network_id):
     for i, network in enumerate(self.networks):
         if network.get('uuid') == network_id:
             return True
     raise common.RemoteError(type(exception.NetworkNotFound()).__name__)
Beispiel #7
0
 def fake_call(*args, **kwargs):
     raise(rpc_common.RemoteError('NoMoreFloatingIps', '', ''))
Beispiel #8
0
 def fail(req):
     raise rpc_common.RemoteError('UnknownError', 'whatevs')
Beispiel #9
0
 def test_remote_quota_error_mapping(self):
     exception_value = rpc_common.RemoteError('QuotaError', 'too many used')
     self._do_test_exception_mapping(exception_value, exception.QuotaError)