add positive tests for volume
- create a new file in admin directory
- test_volume_reset_status
- test_volume_begin_detaching
- test_volume_roll_detaching
Change-Id: I204705b2b430b86577b784a3610b5b6ba1f90592
diff --git a/tempest/api/volume/admin/test_volumes_actions.py b/tempest/api/volume/admin/test_volumes_actions.py
new file mode 100644
index 0000000..4063eef
--- /dev/null
+++ b/tempest/api/volume/admin/test_volumes_actions.py
@@ -0,0 +1,89 @@
+# 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 as utils
+from tempest.test import attr
+
+
+class VolumesActionsTest(BaseVolumeAdminTest):
+ _interface = "json"
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumesActionsTest, cls).setUpClass()
+ cls.client = cls.volumes_client
+
+ # Create admin volume client
+ cls.admin_volume_client = cls.os_adm.volumes_client
+
+ # Create a test shared volume for tests
+ vol_name = utils.rand_name(cls.__name__ + '-Volume-')
+
+ resp, cls.volume = cls.client.create_volume(size=1,
+ display_name=vol_name)
+ cls.client.wait_for_volume_status(cls.volume['id'], 'available')
+
+ @classmethod
+ def tearDownClass(cls):
+ # Delete the test volume
+ cls.client.delete_volume(cls.volume['id'])
+ cls.client.wait_for_resource_deletion(cls.volume['id'])
+
+ super(VolumesActionsTest, cls).tearDownClass()
+
+ def _reset_volume_status(self, volume_id, status):
+ #Reset the volume status
+ resp, body = self.admin_volume_client.reset_volume_status(volume_id,
+ status)
+ return resp, body
+
+ def tearDown(self):
+ # Set volume's status to available after test
+ self._reset_volume_status(self.volume['id'], 'available')
+ super(VolumesActionsTest, self).tearDown()
+
+ @attr(type='gate')
+ def test_volume_reset_status(self):
+ # test volume reset status : available->error->available
+ resp, body = self._reset_volume_status(self.volume['id'], 'error')
+ self.assertEqual(202, resp.status)
+ resp_get, volume_get = self.admin_volume_client.get_volume(
+ self.volume['id'])
+ self.assertEqual('error', volume_get['status'])
+
+ @attr(type='gate')
+ def test_volume_begin_detaching(self):
+ # test volume begin detaching : available -> detaching -> available
+ resp, body = self.client.volume_begin_detaching(self.volume['id'])
+ self.assertEqual(202, resp.status)
+ resp_get, volume_get = self.client.get_volume(self.volume['id'])
+ self.assertEqual('detaching', volume_get['status'])
+
+ @attr(type='gate')
+ def test_volume_roll_detaching(self):
+ # test volume roll detaching : detaching -> in-use -> available
+ resp, body = self.client.volume_begin_detaching(self.volume['id'])
+ self.assertEqual(202, resp.status)
+ resp, body = self.client.volume_roll_detaching(self.volume['id'])
+ self.assertEqual(202, resp.status)
+ resp_get, volume_get = self.client.get_volume(self.volume['id'])
+ self.assertEqual('in-use', volume_get['status'])
+
+
+class VolumesActionsTestXML(VolumesActionsTest):
+ _interface = "xml"
diff --git a/tempest/services/volume/json/volumes_client.py b/tempest/services/volume/json/volumes_client.py
index f054a2b..eb87cbe 100644
--- a/tempest/services/volume/json/volumes_client.py
+++ b/tempest/services/volume/json/volumes_client.py
@@ -164,3 +164,24 @@
url = 'volumes/%s/action' % (volume_id)
resp, body = self.post(url, post_body, self.headers)
return resp, body
+
+ def reset_volume_status(self, volume_id, status):
+ """Reset the Specified Volume's Status."""
+ post_body = json.dumps({'os-reset_status': {"status": status}})
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body,
+ self.headers)
+ return resp, body
+
+ def volume_begin_detaching(self, volume_id):
+ """Volume Begin Detaching."""
+ post_body = json.dumps({'os-begin_detaching': {}})
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body,
+ self.headers)
+ return resp, body
+
+ def volume_roll_detaching(self, volume_id):
+ """Volume Roll Detaching."""
+ post_body = json.dumps({'os-roll_detaching': {}})
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body,
+ self.headers)
+ return resp, body
diff --git a/tempest/services/volume/xml/volumes_client.py b/tempest/services/volume/xml/volumes_client.py
index f5d8beb..be292a2 100644
--- a/tempest/services/volume/xml/volumes_client.py
+++ b/tempest/services/volume/xml/volumes_client.py
@@ -237,3 +237,32 @@
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
+
+ def reset_volume_status(self, volume_id, status):
+ """Reset the Specified Volume's Status."""
+ post_body = Element("os-reset_status",
+ status=status
+ )
+ url = 'volumes/%s/action' % str(volume_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 volume_begin_detaching(self, volume_id):
+ """Volume Begin Detaching."""
+ post_body = Element("os-begin_detaching")
+ url = 'volumes/%s/action' % str(volume_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 volume_roll_detaching(self, volume_id):
+ """Volume Roll Detaching."""
+ post_body = Element("os-roll_detaching")
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body