From: Josh Durgin Date: Fri, 19 Feb 2016 07:28:25 +0000 (-0800) Subject: pybind: replace __del__ with __dealloc__ for rbd X-Git-Tag: v10.1.0~356^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0a988f95bc16fcfdd9cd9c82f9307d6ad90c019b;p=ceph.git pybind: replace __del__ with __dealloc__ for rbd Cython extension types like these don't call __del__, but use __dealloc__ instead: http://docs.cython.org/src/userguide/special_methods.html#finalization-method-dealloc Signed-off-by: Josh Durgin --- diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index c7ae45aed75..f25b3e10fce 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -661,7 +661,7 @@ cdef class Image(object): self.name,)) self.closed = True - def __del__(self): + def __dealloc__(self): self.close() def __repr__(self): @@ -1440,7 +1440,7 @@ cdef class SnapIterator(object): 'name' : decode_cstr(self.snaps[i].name), } - def __del__(self): + def __dealloc__(self): if self.snaps: rbd_snap_list_end(self.snaps) free(self.snaps) diff --git a/src/test/pybind/test_rbd.py b/src/test/pybind/test_rbd.py index 093a40dc8bc..df98dee8c09 100644 --- a/src/test/pybind/test_rbd.py +++ b/src/test/pybind/test_rbd.py @@ -327,6 +327,9 @@ class TestImage(object): flags = self.image.flags() eq(0, flags) + def test_image_auto_close(self): + image = Image(ioctx, image_name) + def test_write(self): data = rand_data(256) self.image.write(data, 0) @@ -466,6 +469,11 @@ class TestImage(object): self.image.remove_snap('snap1') self.image.remove_snap('snap2') + def test_list_snaps_iterator_auto_close(self): + self.image.create_snap('snap1') + self.image.list_snaps() + self.image.remove_snap('snap1') + def test_remove_snap(self): eq([], list(self.image.list_snaps())) self.image.create_snap('snap1')