blob: 4063eef697beef27165b750a0272ab31a9c5ef22 [file] [log] [blame]
wanghaoaa1f2f92013-10-10 11:30:37 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 Huawei Technologies Co.,LTD
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18from tempest.api.volume.base import BaseVolumeAdminTest
19from tempest.common.utils import data_utils as utils
20from tempest.test import attr
21
22
23class VolumesActionsTest(BaseVolumeAdminTest):
24 _interface = "json"
25
26 @classmethod
27 def setUpClass(cls):
28 super(VolumesActionsTest, cls).setUpClass()
29 cls.client = cls.volumes_client
30
31 # Create admin volume client
32 cls.admin_volume_client = cls.os_adm.volumes_client
33
34 # Create a test shared volume for tests
35 vol_name = utils.rand_name(cls.__name__ + '-Volume-')
36
37 resp, cls.volume = cls.client.create_volume(size=1,
38 display_name=vol_name)
39 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
40
41 @classmethod
42 def tearDownClass(cls):
43 # Delete the test volume
44 cls.client.delete_volume(cls.volume['id'])
45 cls.client.wait_for_resource_deletion(cls.volume['id'])
46
47 super(VolumesActionsTest, cls).tearDownClass()
48
49 def _reset_volume_status(self, volume_id, status):
50 #Reset the volume status
51 resp, body = self.admin_volume_client.reset_volume_status(volume_id,
52 status)
53 return resp, body
54
55 def tearDown(self):
56 # Set volume's status to available after test
57 self._reset_volume_status(self.volume['id'], 'available')
58 super(VolumesActionsTest, self).tearDown()
59
60 @attr(type='gate')
61 def test_volume_reset_status(self):
62 # test volume reset status : available->error->available
63 resp, body = self._reset_volume_status(self.volume['id'], 'error')
64 self.assertEqual(202, resp.status)
65 resp_get, volume_get = self.admin_volume_client.get_volume(
66 self.volume['id'])
67 self.assertEqual('error', volume_get['status'])
68
69 @attr(type='gate')
70 def test_volume_begin_detaching(self):
71 # test volume begin detaching : available -> detaching -> available
72 resp, body = self.client.volume_begin_detaching(self.volume['id'])
73 self.assertEqual(202, resp.status)
74 resp_get, volume_get = self.client.get_volume(self.volume['id'])
75 self.assertEqual('detaching', volume_get['status'])
76
77 @attr(type='gate')
78 def test_volume_roll_detaching(self):
79 # test volume roll detaching : detaching -> in-use -> available
80 resp, body = self.client.volume_begin_detaching(self.volume['id'])
81 self.assertEqual(202, resp.status)
82 resp, body = self.client.volume_roll_detaching(self.volume['id'])
83 self.assertEqual(202, resp.status)
84 resp_get, volume_get = self.client.get_volume(self.volume['id'])
85 self.assertEqual('in-use', volume_get['status'])
86
87
88class VolumesActionsTestXML(VolumesActionsTest):
89 _interface = "xml"