Hi Michael,

>> +    response = self.Execute(self._CAPABILITIES_COMMAND)
>> +    if response[self._ERROR_KEY]:
>> +      self._connected = False
>> +      raise errors.HypervisorError("kvm: qmp communication error 
>> (impossible"
>> +                                   " to execute the qmp_capabilities 
>> command)")
>
> Doesn't it return an error message in _ERROR_KEY?

It does, I will add the relevant info to the error message).

>> +    self._check_connection()
>> +    received_data = ""
>
> Use a StringIO.

Will do.

>> +    try:
>> +      while True:
>> +        data = self.sock.recv(4096)
>> +        if not data:
>> +          break
>> +        received_data += data
>> +
>> +        # To check if we received the complete JSON message, we check if the
>> +        # curly parentheses are balanced in the received message.
>> +        # The underlying assumption is that the QMP server always sends
>> +        # well-formed messages.
>> +        if received_data.count("{") == received_data.count("}"):
>
> Aren't the messages separated by a well-known character?

Yes, CRLF (spec. section 2.1.1); but I somehow missed this bit while
reading the spec. :)
Will use CRLF to detect the EOM. In the hope that the server escapes
it correctly if it is contained in the JSON message.

>> +    # Events can occur between the sending of the command and the reception
>> +    # of the response, so we need to filter out messages with the event key.
>> +    while True:
>> +      response = self._Recv()
>> +      if not response[self._EVENT_KEY]:
>> +        if response[self._ERROR_KEY]:
>
> These two conditions can be merged.

Will do.

I'll send the updated patch.

Thanks,
Andrea

Reply via email to