Commit 5e34123e authored by Michele Tartara's avatar Michele Tartara
Browse files

Make QmpMessage a proper container

Newer pylint versions complain that QmpMessage is not a proper container because
it does not implement the __len__() and __delitem__() methods. This commit
implements them.

Also, tests are added.
Signed-off-by: default avatarMichele Tartara <>
Reviewed-by: default avatarHelga Velroyen <>
parent a9688b61
......@@ -194,6 +194,18 @@ class QmpMessage:
"""[field_name] = field_value
def __len__(self):
"""Return the number of fields stored in this QmpMessage.
return len(
def __delitem__(self, key):
"""Delete the specified element from the QmpMessage.
def BuildFromJsonString(json_string):
"""Build a QmpMessage from a JSON encoded string.
......@@ -135,6 +135,20 @@ class TestQmpMessage(testutils.GanetiTestCase):
rebuilt_message = hv_kvm.QmpMessage.BuildFromJsonString(serialized)
self.assertEqual(rebuilt_message, message)
self.assertEqual(len(rebuilt_message), len(test_data))
def testDelete(self):
toDelete = "execute"
test_data = {
toDelete: "command",
"arguments": ["a", "b", "c"],
message = hv_kvm.QmpMessage(test_data)
oldLen = len(message)
newLen = len(message)
self.assertEqual(oldLen - 1, newLen)
class TestQmp(testutils.GanetiTestCase):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment