Change in vdsm[ovirt-3.5-gluster]: gluster: Added gluster snapshot restore verb.

dnarayan at redhat.com dnarayan at redhat.com
Thu Apr 16 10:14:08 UTC 2015


Hello Piotr Kliczewski, Dan Kenigsberg,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/39919

to review the following change.

Change subject: gluster: Added gluster snapshot restore verb.
......................................................................

gluster: Added gluster snapshot restore verb.

This patch adds verb to restore gluster volume
snapshot.

*glusterSnapshotRestore: Restores a gluster volume snapshot.
Takes snapshot name as an argunment.
Returns:
{'volumeName': 'vol1',
 'volumeUuid': 'uuid',
 'snapshotName': 'snap2',
 'snapshotUuid': 'uuid'}

Change-Id: I422fab5bc9ec9dc51d759bad46487c60051bbfc1
Signed-off-by: Darshan N <dnarayan at redhat.com>
Reviewed-on: http://gerrit.ovirt.org/34638
Reviewed-by: Piotr Kliczewski <piotr.kliczewski at gmail.com>
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
---
M client/vdsClientGluster.py
M tests/Makefile.am
A tests/glusterSnapshotRestore.xml
M tests/glusterTestData.py
M tests/gluster_cli_tests.py
M vdsm.spec.in
M vdsm/gluster/api.py
M vdsm/gluster/apiwrapper.py
M vdsm/gluster/cli.py
M vdsm/gluster/exception.py
M vdsm/rpc/vdsmapi-gluster-schema.json
11 files changed, 126 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/19/39919/1

diff --git a/client/vdsClientGluster.py b/client/vdsClientGluster.py
index 8e66ea2..d86d16d 100644
--- a/client/vdsClientGluster.py
+++ b/client/vdsClientGluster.py
@@ -605,6 +605,14 @@
         pp.pprint(status)
         return status['status']['code'], status['status']['message']
 
+    def do_glusterSnapshotRestore(self, args):
+        params = self._eqSplit(args)
+        snapName = params.get('snapName', '')
+
+        status = self.s.glusterSnapshotRestore(snapName)
+        pp.pprint(status)
+        return status['status']['code'], status['status']['message']
+
 
 def getGlusterCmdDict(serv):
     return \
@@ -1028,5 +1036,10 @@
              serv.do_glusterSnapshotDeactivate,
              ('snapName=<snap_name>',
               'de-activate snapshot'
+              )),
+         'glusterSnapshotRestore': (
+             serv.do_glusterSnapshotRestore,
+             ('snapName=snap_name',
+              'restore snapshot'
               ))
          }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d52c6f4..0395058 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -114,6 +114,7 @@
 	caps_numactl_4_nodes.out \
 	glob_1c60971a-8647-44ac-ae33-6520887f8843.out \
 	glusterGeoRepStatus.xml \
+	glusterSnapshotRestore.xml \
 	glusterVolumeGeoRepConfigList.xml \
 	glusterVolumeProfileInfo.xml \
 	glusterVolumeProfileInfoNfs.xml \
diff --git a/tests/glusterSnapshotRestore.xml b/tests/glusterSnapshotRestore.xml
new file mode 100644
index 0000000..2086038
--- /dev/null
+++ b/tests/glusterSnapshotRestore.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<cliOutput>
+  <opRet>0</opRet>
+  <opErrno>0</opErrno>
+  <opErrstr/>
+  <snapRestore>
+    <volume>
+      <name>snap-vol2</name>
+      <uuid>8558c40f-1581-414e-89d6-46854376ae3d</uuid>
+    </volume>
+    <snapshot>
+      <name>snap1</name>
+      <uuid>ef4b5442-2d6e-498b-9e42-fd0e566ac74c</uuid>
+    </snapshot>
+  </snapRestore>
+</cliOutput>
diff --git a/tests/glusterTestData.py b/tests/glusterTestData.py
index 3e52c9b..8e588da 100644
--- a/tests/glusterTestData.py
+++ b/tests/glusterTestData.py
@@ -1119,3 +1119,10 @@
         'volume_id': '67186261-91a7-4930-b681-9f127f485a0e'
     }
 }
+
+GLUSTER_SNAPSHOT_RESTORE = {
+    'snapshotName': 'snap1',
+    'snapshotUuid': 'ef4b5442-2d6e-498b-9e42-fd0e566ac74c',
+    'volumeName': 'snap-vol2',
+    'volumeUuid': '8558c40f-1581-414e-89d6-46854376ae3d'
+}
diff --git a/tests/gluster_cli_tests.py b/tests/gluster_cli_tests.py
index ea06119..eeb00d9 100644
--- a/tests/gluster_cli_tests.py
+++ b/tests/gluster_cli_tests.py
@@ -1145,3 +1145,10 @@
         tree = etree.fromstring(out)
         status = gcli._parseVolumeGeoRepConfig(tree)
         self.assertEquals(status, glusterTestData.GLUSTER_GEOREP_CONFIG_LIST)
+
+    def test_parseSnapshotRestore(self):
+        with open("glusterSnapshotRestore.xml") as f:
+            out = f.read()
+        tree = etree.fromstring(out)
+        status = gcli._parseRestoredSnapshot(tree)
+        self.assertEquals(status, glusterTestData.GLUSTER_SNAPSHOT_RESTORE)
diff --git a/vdsm.spec.in b/vdsm.spec.in
index fa471e1..c1737a7 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1303,6 +1303,7 @@
 %{_datadir}/%{vdsm_name}/tests/glusterVolumeProfileInfoNfs.xml
 %{_datadir}/%{vdsm_name}/tests/glusterVolumeRebalanceStatus.xml
 %{_datadir}/%{vdsm_name}/tests/glusterVolumeRemoveBricksStatus.xml
+%{_datadir}/%{vdsm_name}/tests/glusterSnapshotRestore.xml
 %{_datadir}/%{vdsm_name}/tests/glusterVolumeTasks.xml
 %{_datadir}/%{vdsm_name}/tests/functional/*.py*
 %{_datadir}/%{vdsm_name}/tests/functional/*.policy
diff --git a/vdsm/gluster/api.py b/vdsm/gluster/api.py
index cd74b11..6d7e139 100644
--- a/vdsm/gluster/api.py
+++ b/vdsm/gluster/api.py
@@ -440,6 +440,11 @@
     def snapshotDeactivate(self, snapName, options=None):
         self.svdsmProxy.glusterSnapshotDeactivate(snapName)
 
+    @exportAsVerb
+    def snapshotRestore(self, snapName, options=None):
+        status = self.svdsmProxy.glusterSnapshotRestore(snapName)
+        return {'snapRestore': status}
+
 
 def getGlusterMethods(gluster):
     l = []
diff --git a/vdsm/gluster/apiwrapper.py b/vdsm/gluster/apiwrapper.py
index 154613b..f4177cd 100644
--- a/vdsm/gluster/apiwrapper.py
+++ b/vdsm/gluster/apiwrapper.py
@@ -261,3 +261,6 @@
 
     def deactivate(self, snapName):
         return self._gluster.snapshotDeactivate(snapName)
+
+    def restore(self, snapName):
+        return self._gluster.snapshotRestore(snapName)
diff --git a/vdsm/gluster/cli.py b/vdsm/gluster/cli.py
index 24154e9..e60da27 100644
--- a/vdsm/gluster/cli.py
+++ b/vdsm/gluster/cli.py
@@ -1302,3 +1302,36 @@
         return True
     except ge.GlusterCmdFailedException as e:
         raise ge.GlusterSnapshotDeactivateFailedException(rc=e.rc, err=e.err)
+
+
+def _parseRestoredSnapshot(tree):
+    """
+    returns {'volumeName': 'vol1',
+             'volumeUuid': 'uuid',
+             'snapshotName': 'snap2',
+             'snapshotUuid': 'uuid'
+            }
+    """
+    snapshotRestore = {}
+    snapshotRestore['volumeName'] = tree.find('snapRestore/volume/name').text
+    snapshotRestore['volumeUuid'] = tree.find('snapRestore/volume/uuid').text
+    snapshotRestore['snapshotName'] = tree.find(
+        'snapRestore/snapshot/name').text
+    snapshotRestore['snapshotUuid'] = tree.find(
+        'snapRestore/snapshot/uuid').text
+
+    return snapshotRestore
+
+
+ at makePublic
+def snapshotRestore(snapName):
+    command = _getGlusterSnapshotCmd() + ["restore", snapName]
+
+    try:
+        xmltree = _execGlusterXml(command)
+    except ge.GlusterCmdFailedException as e:
+        raise ge.GlusterSnapshotRestoreFailedException(rc=e.rc, err=e.err)
+    try:
+        return _parseRestoredSnapshot(xmltree)
+    except _etreeExceptions:
+        raise ge.GlusterXmlErrorException(err=[etree.tostring(xmltree)])
diff --git a/vdsm/gluster/exception.py b/vdsm/gluster/exception.py
index be4dda9..e7e4533 100644
--- a/vdsm/gluster/exception.py
+++ b/vdsm/gluster/exception.py
@@ -570,3 +570,8 @@
 class GlusterSnapshotDeactivateFailedException(GlusterSnapshotException):
     code = 4704
     message = "Snapshot de-activate failed"
+
+
+class GlusterSnapshotRestoreFailedException(GlusterSnapshotException):
+    code = 4705
+    message = "Snapshot restore failed"
diff --git a/vdsm/rpc/vdsmapi-gluster-schema.json b/vdsm/rpc/vdsmapi-gluster-schema.json
index 2e610b6..5143f26 100644
--- a/vdsm/rpc/vdsmapi-gluster-schema.json
+++ b/vdsm/rpc/vdsmapi-gluster-schema.json
@@ -1689,3 +1689,38 @@
 {'command': {'class': 'GlusterSnapshot', 'name': 'deactivate'},
  'data': {'snapName': 'str'},
  'returns': 'bool'}
+
+##
+# @SnapRestoreDetail:
+#
+# Restored snapshot detail
+#
+# @volumeName:   Name and of restored volume
+#
+# @volumeUuid:   Uuid of the restored volume
+#
+# @snapshotUuid: Uuid of the restored snapshot
+#
+# @snapshotName: Name of the restored snapshot
+#
+# Since: 4.17.0
+##
+{'type': 'SnapRestoreDetail',
+ 'data': {'volumeName': 'str', 'volumeUuid': 'UUID',
+          'snapshotName': 'str', 'snapshotUuid': 'UUID'}}
+
+##
+# @GlusterSnapshot.restore:
+#
+# Restore a snapshot
+#
+# @snapName: Gluster volume snapshot name
+#
+# Returns:
+# Volume snapshot pair
+#
+# Since: 4.17.0
+##
+{'command': {'class': 'GlusterSnapshot', 'name': 'restore'},
+ 'data': {'snapName': 'str'},
+ 'returns': 'SnapRestoreDetail'}


-- 
To view, visit https://gerrit.ovirt.org/39919
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I422fab5bc9ec9dc51d759bad46487c60051bbfc1
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5-gluster
Gerrit-Owner: Darshan N <dnarayan at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski at gmail.com>


More information about the vdsm-patches mailing list