LGTM, thanks
On Tue, Sep 24, 2013 at 3:29 PM, Michele Tartara <[email protected]>wrote: > 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: Michele Tartara <[email protected]> > --- > lib/hypervisor/hv_kvm.py | 12 ++++++++++++ > test/py/ganeti.hypervisor.hv_kvm_unittest.py | 14 ++++++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py > index b4acee3..91a3b35 100644 > --- a/lib/hypervisor/hv_kvm.py > +++ b/lib/hypervisor/hv_kvm.py > @@ -194,6 +194,18 @@ class QmpMessage: > """ > self.data[field_name] = field_value > > + def __len__(self): > + """Return the number of fields stored in this QmpMessage. > + > + """ > + return len(self.data) > + > + def __delitem__(self, key): > + """Delete the specified element from the QmpMessage. > + > + """ > + del(self.data[key]) > + > @staticmethod > def BuildFromJsonString(json_string): > """Build a QmpMessage from a JSON encoded string. > diff --git a/test/py/ganeti.hypervisor.hv_kvm_unittest.py b/test/py/ > ganeti.hypervisor.hv_kvm_unittest.py > index b3d3f79..c8eaffc 100755 > --- a/test/py/ganeti.hypervisor.hv_kvm_unittest.py > +++ b/test/py/ganeti.hypervisor.hv_kvm_unittest.py > @@ -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) > + del(message[toDelete]) > + newLen = len(message) > + self.assertEqual(oldLen - 1, newLen) > > > class TestQmp(testutils.GanetiTestCase): > -- > 1.7.10.4 > > -- -- Helga Velroyen | Software Engineer | [email protected] | Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores
