Revision 4c4e4e1e lib/rpc.py

b/lib/rpc.py
93 93
      offline, as opposed to actual failure; offline=True will always
94 94
      imply failed=True, in order to allow simpler checking if
95 95
      the user doesn't care about the exact failure mode
96
  @ivar error: the error message if the call failed
96
  @ivar fail_msg: the error message if the call failed
97 97

  
98 98
  """
99 99
  def __init__(self, data=None, failed=False, offline=False,
......
104 104
    self.node = node
105 105
    if offline:
106 106
      self.failed = True
107
      self.error = "Node is marked offline"
107
      self.fail_msg = "Node is marked offline"
108 108
      self.data = self.payload = None
109 109
    elif failed:
110
      self.error = self._EnsureErr(data)
110
      self.fail_msg = self._EnsureErr(data)
111 111
      self.data = self.payload = None
112 112
    else:
113 113
      self.data = data
114 114
      if not isinstance(self.data, (tuple, list)):
115
        self.error = ("RPC layer error: invalid result type (%s)" %
116
                      type(self.data))
115
        self.fail_msg = ("RPC layer error: invalid result type (%s)" %
116
                         type(self.data))
117 117
      elif len(data) != 2:
118
        self.error = ("RPC layer error: invalid result length (%d), "
119
                      "expected 2" % len(self.data))
118
        self.fail_msg = ("RPC layer error: invalid result length (%d), "
119
                         "expected 2" % len(self.data))
120 120
      elif not self.data[0]:
121
        self.error = self._EnsureErr(self.data[1])
121
        self.fail_msg = self._EnsureErr(self.data[1])
122 122
      else:
123 123
        # finally success
124
        self.error = None
124
        self.fail_msg = None
125 125
        self.payload = data[1]
126 126

  
127 127
  @staticmethod
......
132 132
    else:
133 133
      return "No error information"
134 134

  
135
  def Raise(self):
135
  def Raise(self, msg, prereq=False):
136 136
    """If the result has failed, raise an OpExecError.
137 137

  
138 138
    This is used so that LU code doesn't have to check for each
139 139
    result, but instead can call this function.
140 140

  
141 141
    """
142
    if self.failed:
143
      raise errors.OpExecError("Call '%s' to node '%s' has failed: %s" %
144
                               (self.call, self.node, self.error))
142
    if not self.fail_msg:
143
      return
144

  
145
    if not msg: # one could pass None for default message
146
      msg = ("Call '%s' to node '%s' has failed: %s" %
147
             (self.call, self.node, self.fail_msg))
148
    else:
149
      msg = "%s: %s" % (msg, self.fail_msg)
150
    if prereq:
151
      ec = errors.OpPrereqError
152
    else:
153
      ec = errors.OpExecError
154
    raise ec(msg)
145 155

  
146 156
  def RemoteFailMsg(self):
147 157
    """Check if the remote procedure failed.
......
149 159
    @return: the fail_msg attribute
150 160

  
151 161
    """
152
    return self.error
162
    return self.fail_msg
153 163

  
154 164

  
155 165
class Client:

Also available in: Unified diff