]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: replace __del__ with __dealloc__ for rbd
authorJosh Durgin <jdurgin@redhat.com>
Fri, 19 Feb 2016 07:28:25 +0000 (23:28 -0800)
committerJosh Durgin <jdurgin@redhat.com>
Fri, 19 Feb 2016 07:47:24 +0000 (23:47 -0800)
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 <jdurgin@redhat.com>
src/pybind/rbd/rbd.pyx
src/test/pybind/test_rbd.py

index c7ae45aed751091df93bed7a70c95db78c6b53a3..f25b3e10fce6da29b4f39c305913f0a272db9408 100644 (file)
@@ -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)
index 093a40dc8bc409bd2621d0e20208c201201bf88f..df98dee8c09c9fa6135787138914c29e862c2c9d 100644 (file)
@@ -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')