Add test for update/reset_snapshot_status API

Add some tests fot update/reset_snapshot_status API

Change-Id: I5131ab1bdf3541bb139efd4ef4be5cd37e8f2774
diff --git a/tempest/api/volume/admin/test_snapshots_actions.py b/tempest/api/volume/admin/test_snapshots_actions.py
new file mode 100644
index 0000000..5e838e5
--- /dev/null
+++ b/tempest/api/volume/admin/test_snapshots_actions.py
@@ -0,0 +1,110 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 Huawei Technologies Co.,LTD
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+from tempest.api.volume.base import BaseVolumeAdminTest
+from tempest.common.utils import data_utils
+from tempest.test import attr
+
+
+class SnapshotsActionsTest(BaseVolumeAdminTest):
+    _interface = "json"
+
+    @classmethod
+    def setUpClass(cls):
+        super(SnapshotsActionsTest, cls).setUpClass()
+        cls.client = cls.snapshots_client
+
+        # Create admin volume client
+        cls.admin_snapshots_client = cls.os_adm.snapshots_client
+
+        # Create a test shared volume for tests
+        vol_name = data_utils.rand_name(cls.__name__ + '-Volume-')
+        resp_vol, cls.volume = \
+            cls.volumes_client.create_volume(size=1, display_name=vol_name)
+        cls.volumes_client.wait_for_volume_status(cls.volume['id'],
+                                                  'available')
+
+        # Create a test shared snapshot for tests
+        snap_name = data_utils.rand_name(cls.__name__ + '-Snapshot-')
+        resp_snap, cls.snapshot = \
+            cls.client.create_snapshot(cls.volume['id'],
+                                       display_name=snap_name)
+        cls.client.wait_for_snapshot_status(cls.snapshot['id'],
+                                            'available')
+
+    @classmethod
+    def tearDownClass(cls):
+        # Delete the test snapshot
+        cls.client.delete_snapshot(cls.snapshot['id'])
+        cls.client.wait_for_resource_deletion(cls.snapshot['id'])
+
+        # Delete the test volume
+        cls.volumes_client.delete_volume(cls.volume['id'])
+        cls.volumes_client.wait_for_resource_deletion(cls.volume['id'])
+
+        super(SnapshotsActionsTest, cls).tearDownClass()
+
+    def tearDown(self):
+        # Set snapshot's status to available after test
+        status = 'available'
+        snapshot_id = self.snapshot['id']
+        self.admin_snapshots_client.reset_snapshot_status(snapshot_id,
+                                                          status)
+        super(SnapshotsActionsTest, self).tearDown()
+
+    def _get_progress_alias(self):
+        return 'os-extended-snapshot-attributes:progress'
+
+    @attr(type='gate')
+    def test_reset_snapshot_status(self):
+        # Reset snapshot status to creating
+        status = 'creating'
+        resp, body = self.admin_snapshots_client.\
+            reset_snapshot_status(self.snapshot['id'], status)
+        self.assertEqual(202, resp.status)
+        resp_get, snapshot_get \
+            = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
+        self.assertEqual(200, resp_get.status)
+        self.assertEqual(status, snapshot_get['status'])
+
+    @attr(type='gate')
+    def test_update_snapshot_status(self):
+        # Reset snapshot status to creating
+        status = 'creating'
+        self.admin_snapshots_client.\
+            reset_snapshot_status(self.snapshot['id'], status)
+
+        # Update snapshot status to error
+        progress = '80%'
+        status = 'error'
+        progress_alias = self._get_progress_alias()
+        resp, body = self.client.update_snapshot_status(self.snapshot['id'],
+                                                        status, progress)
+        self.assertEqual(202, resp.status)
+        resp_get, snapshot_get \
+            = self.admin_snapshots_client.get_snapshot(self.snapshot['id'])
+        self.assertEqual(200, resp_get.status)
+        self.assertEqual(status, snapshot_get['status'])
+        self.assertEqual(progress, snapshot_get[progress_alias])
+
+
+class SnapshotsActionsTestXML(SnapshotsActionsTest):
+    _interface = "xml"
+
+    def _get_progress_alias(self):
+        return '{http://docs.openstack.org/volume/ext' \
+               '/extended_snapshot_attributes/api/v1}progress'
diff --git a/tempest/services/volume/json/snapshots_client.py b/tempest/services/volume/json/snapshots_client.py
index 10ba3fd..5d980eb 100644
--- a/tempest/services/volume/json/snapshots_client.py
+++ b/tempest/services/volume/json/snapshots_client.py
@@ -131,3 +131,21 @@
         except exceptions.NotFound:
             return True
         return False
+
+    def reset_snapshot_status(self, snapshot_id, status):
+        """Reset the specified snapshot's status."""
+        post_body = json.dumps({'os-reset_status': {"status": status}})
+        resp, body = self.post('snapshots/%s/action' % snapshot_id, post_body,
+                               self.headers)
+        return resp, body
+
+    def update_snapshot_status(self, snapshot_id, status, progress):
+        """Update the specified snapshot's status."""
+        post_body = {
+            'status': status,
+            'progress': progress
+        }
+        post_body = json.dumps({'os-update_snapshot_status': post_body})
+        url = 'snapshots/%s/action' % str(snapshot_id)
+        resp, body = self.post(url, post_body, self.headers)
+        return resp, body
diff --git a/tempest/services/volume/xml/snapshots_client.py b/tempest/services/volume/xml/snapshots_client.py
index b7ba56b..5d59b07 100644
--- a/tempest/services/volume/xml/snapshots_client.py
+++ b/tempest/services/volume/xml/snapshots_client.py
@@ -147,3 +147,26 @@
         except exceptions.NotFound:
             return True
         return False
+
+    def reset_snapshot_status(self, snapshot_id, status):
+        """Reset the specified snapshot's status."""
+        post_body = Element("os-reset_status",
+                            status=status
+                            )
+        url = 'snapshots/%s/action' % str(snapshot_id)
+        resp, body = self.post(url, str(Document(post_body)), self.headers)
+        if body:
+            body = xml_to_json(etree.fromstring(body))
+        return resp, body
+
+    def update_snapshot_status(self, snapshot_id, status, progress):
+        """Update the specified snapshot's status."""
+        post_body = Element("os-update_snapshot_status",
+                            status=status,
+                            progress=progress
+                            )
+        url = 'snapshots/%s/action' % str(snapshot_id)
+        resp, body = self.post(url, str(Document(post_body)), self.headers)
+        if body:
+            body = xml_to_json(etree.fromstring(body))
+        return resp, body