• Iustin Pop's avatar
    Convert rpc results to a custom type · 781de953
    Iustin Pop authored
    For a long time we had the problem that both RPC-layer errors and
    results from the remote node share the same "valuespace". This is
    because we shouldn't raise an exception when only one node failed
    (and lose the results from the other nodes).
    
    This patch attempts to address this problem by returning a special
    object from RPC calls, which separates the rpc-layer status and the
    remote results into different attributes.
    
    All the users of rpc (mainly cmdlib, but also bootstrap and the
    HooksMaster in mcpu) have been converted to this new model. The code has
    changed from, e.g. for boolean return types:
    
      if not self.rpc.call_...
    
    to
    
      result = self.rpc.call_
      if result.failed or not result.data:
         ^ rpc-layer error    |
                              - result payload
    
    While this is slightly more complicated, it will allow cleaner checks in
    the future; right now the code is just a plain port, without
    optimizations.
    
    There's also a "result.Raise()" which raises an OpExecError if the
    rpc-layer had errors.
    
    One side-effect of the patch is that now all return types from the
    rpc.call_ functions are of either RpcResult (single-node) or dicts of
    (node name, RpcResult); previously, some functions were returning
    different object types based on error status.
    
    The code passes burnin (after many retries :).
    
    Reviewed-by: imsnah
    781de953
bootstrap.py 15.7 KB