]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Implementation of rados_ioctx_snapshot_rollback 6878/head
authorFlorent Manens <florent@manens.org>
Wed, 9 Dec 2015 21:37:56 +0000 (22:37 +0100)
committerFlorent Manens <florent@manens.org>
Thu, 10 Dec 2015 11:09:07 +0000 (12:09 +0100)
Signed-off-by: Florent Manens <florent@beezim.fr>
src/pybind/rados.py
src/test/pybind/test_rados.py

index 4c7dabd3eb1164d6898d7e0b5e92b0d04aad7723..2d4022f96fe42f5e707ee6525808a7f438345ab8 100644 (file)
@@ -1984,6 +1984,25 @@ returned %d, but should return zero on success." % (self.name, ret))
             raise make_ex(ret, "Failed to lookup snap %s" % snap_name)
         return Snap(self, snap_name, snap_id)
 
+    @requires(('oid', str_type), ('snap_name', str_type))
+    def snap_rollback(self, oid, snap_name):
+        """
+        Rollback an object to a snapshot
+
+        :param oid: the name of the object
+        :type oid: str
+        :param snap_name: the name of the snapshot
+        :type snap_name: str
+
+        :raises: :class:`TypeError`
+        :raises: :class:`Error`
+        """
+        self.require_ioctx_open()
+        ret = run_in_thread(self.librados.rados_ioctx_snap_rollback,
+                            (self.io, cstr(oid), cstr(snap_name)))
+        if (ret != 0):
+            raise make_ex(ret, "Failed to rollback %s" % oid)
+
     def get_last_version(self):
         """
         Return the version of the last object read or written to.
index 24ca2b46e9b7905f3fb630b7c323a9af04fa674e..9c1d86fddf5c2dff0941bc307136c098433d0051 100644 (file)
@@ -359,6 +359,15 @@ class TestIoctx(object):
         self.ioctx.remove_snap('foo')
         eq(list(self.ioctx.list_snaps()), [])
 
+    def test_snap_rollback(self):
+        self.ioctx.write("insnap", b"contents1")
+        self.ioctx.create_snap("snap1")
+        self.ioctx.remove_object("insnap")
+        self.ioctx.snap_rollback("insnap", "snap1")
+        eq(self.ioctx.read("insnap"), b"contents1")
+        self.ioctx.remove_snap("snap1")
+        self.ioctx.remove_object("insnap")
+
     def test_set_omap(self):
         keys = ("1", "2", "3", "4")
         values = (b"aaa", b"bbb", b"ccc", b"\x04\x04\x04\x04")