blob: ce29b82871423cb95e42c1ce0ebbfa96633dda5d [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Giulio Fidente5ed48ce2014-01-09 18:28:28 +010016from testtools.matchers import ContainsAll
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.volume import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
Matthew Treinish4d352bc2014-01-29 18:29:18 +000020from tempest import config
Chris Yeoh01cb2792013-02-09 22:25:37 +103021from tempest.test import attr
Matthew Treinish660a4c12013-09-09 20:06:12 +000022from tempest.test import services
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070023
Matthew Treinish4d352bc2014-01-29 18:29:18 +000024CONF = config.CONF
25
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070026
Zhi Kun Liubb363a22013-11-28 18:47:39 +080027class VolumesGetTest(base.BaseVolumeV1Test):
Attila Fazekas3dcdae12013-02-14 12:50:04 +010028 _interface = "json"
29
30 @classmethod
31 def setUpClass(cls):
32 super(VolumesGetTest, cls).setUpClass()
33 cls.client = cls.volumes_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070034
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070035 def _delete_volume(self, volume_id):
36 resp, _ = self.client.delete_volume(volume_id)
37 self.assertEqual(202, resp.status)
38 self.client.wait_for_resource_deletion(volume_id)
39
John Griffithd1fefd52013-09-23 20:40:37 +000040 def _is_true(self, val):
41 # NOTE(jdg): Temporary conversion method to get cinder patch
42 # merged. Then we'll make this strict again and
43 #specifically check "true" or "false"
44 if val in ['true', 'True', True]:
45 return True
46 else:
47 return False
48
QingXin Meng611768a2013-09-18 00:51:33 -070049 def _volume_create_get_update_delete(self, **kwargs):
Sean Dague72a00382013-01-03 17:53:38 -050050 # Create a volume, Get it's details and Delete the volume
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070051 volume = {}
Masayuki Igawa259c1132013-10-31 17:48:44 +090052 v_name = data_utils.rand_name('Volume')
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070053 metadata = {'Type': 'Test'}
54 # Create a volume
55 resp, volume = self.client.create_volume(size=1,
56 display_name=v_name,
57 metadata=metadata,
58 **kwargs)
59 self.assertEqual(200, resp.status)
60 self.assertIn('id', volume)
61 self.addCleanup(self._delete_volume, volume['id'])
62 self.assertIn('display_name', volume)
63 self.assertEqual(volume['display_name'], v_name,
64 "The created volume name is not equal "
65 "to the requested name")
66 self.assertTrue(volume['id'] is not None,
67 "Field volume id is empty or not found.")
68 self.client.wait_for_volume_status(volume['id'], 'available')
69 # Get Volume information
70 resp, fetched_volume = self.client.get_volume(volume['id'])
71 self.assertEqual(200, resp.status)
72 self.assertEqual(v_name,
73 fetched_volume['display_name'],
Giulio Fidente5ed48ce2014-01-09 18:28:28 +010074 'The fetched Volume name is different '
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070075 'from the created Volume')
76 self.assertEqual(volume['id'],
77 fetched_volume['id'],
Giulio Fidente5ed48ce2014-01-09 18:28:28 +010078 'The fetched Volume id is different '
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070079 'from the created Volume')
Giulio Fidente5ed48ce2014-01-09 18:28:28 +010080 self.assertThat(fetched_volume['metadata'].items(),
81 ContainsAll(metadata.items()),
82 'The fetched Volume metadata misses data '
83 'from the created Volume')
John Griffithd1fefd52013-09-23 20:40:37 +000084
85 # NOTE(jdg): Revert back to strict true/false checking
86 # after fix for bug #1227837 merges
87 boot_flag = self._is_true(fetched_volume['bootable'])
Nayna Patel5e76be12013-08-19 12:10:16 +000088 if 'imageRef' in kwargs:
John Griffithd1fefd52013-09-23 20:40:37 +000089 self.assertEqual(boot_flag, True)
Nayna Patel5e76be12013-08-19 12:10:16 +000090 if 'imageRef' not in kwargs:
John Griffithd1fefd52013-09-23 20:40:37 +000091 self.assertEqual(boot_flag, False)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070092
QingXin Meng611768a2013-09-18 00:51:33 -070093 # Update Volume
Xiao Chen1ea93672014-01-09 10:10:47 +080094 # Test volume update when display_name is same with original value
95 resp, update_volume = \
96 self.client.update_volume(volume['id'],
97 display_name=v_name)
98 self.assertEqual(200, resp.status)
99 # Test volume update when display_name is new
Masayuki Igawa259c1132013-10-31 17:48:44 +0900100 new_v_name = data_utils.rand_name('new-Volume')
QingXin Meng611768a2013-09-18 00:51:33 -0700101 new_desc = 'This is the new description of volume'
102 resp, update_volume = \
103 self.client.update_volume(volume['id'],
104 display_name=new_v_name,
105 display_description=new_desc)
106 # Assert response body for update_volume method
107 self.assertEqual(200, resp.status)
108 self.assertEqual(new_v_name, update_volume['display_name'])
109 self.assertEqual(new_desc, update_volume['display_description'])
110 # Assert response body for get_volume method
111 resp, updated_volume = self.client.get_volume(volume['id'])
112 self.assertEqual(200, resp.status)
113 self.assertEqual(volume['id'], updated_volume['id'])
114 self.assertEqual(new_v_name, updated_volume['display_name'])
115 self.assertEqual(new_desc, updated_volume['display_description'])
Giulio Fidente5ed48ce2014-01-09 18:28:28 +0100116 self.assertThat(updated_volume['metadata'].items(),
117 ContainsAll(metadata.items()),
118 'The fetched Volume metadata misses data '
119 'from the created Volume')
Xiao Chen1ea93672014-01-09 10:10:47 +0800120 # Test volume create when display_name is none and display_description
121 # contains specific characters,
122 # then test volume update if display_name is duplicated
123 new_volume = {}
124 new_v_desc = data_utils.rand_name('@#$%^* description')
125 resp, new_volume = \
126 self.client.create_volume(size=1,
127 display_description=new_v_desc,
128 availability_zone=volume[
129 'availability_zone'])
130 self.assertEqual(200, resp.status)
131 self.assertIn('id', new_volume)
132 self.addCleanup(self._delete_volume, new_volume['id'])
133 self.client.wait_for_volume_status(new_volume['id'], 'available')
134 resp, update_volume = \
135 self.client.update_volume(new_volume['id'],
136 display_name=volume['display_name'],
137 display_description=volume[
138 'display_description'])
139 self.assertEqual(200, resp.status)
John Griffithd1fefd52013-09-23 20:40:37 +0000140
141 # NOTE(jdg): Revert back to strict true/false checking
142 # after fix for bug #1227837 merges
143 boot_flag = self._is_true(updated_volume['bootable'])
QingXin Meng611768a2013-09-18 00:51:33 -0700144 if 'imageRef' in kwargs:
John Griffithd1fefd52013-09-23 20:40:37 +0000145 self.assertEqual(boot_flag, True)
QingXin Meng611768a2013-09-18 00:51:33 -0700146 if 'imageRef' not in kwargs:
John Griffithd1fefd52013-09-23 20:40:37 +0000147 self.assertEqual(boot_flag, False)
QingXin Meng611768a2013-09-18 00:51:33 -0700148
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200149 @attr(type='smoke')
QingXin Meng611768a2013-09-18 00:51:33 -0700150 def test_volume_create_get_update_delete(self):
151 self._volume_create_get_update_delete()
Giulio Fidente36836c42013-04-05 15:43:51 +0200152
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200153 @attr(type='smoke')
Matthew Treinish660a4c12013-09-09 20:06:12 +0000154 @services('image')
QingXin Meng611768a2013-09-18 00:51:33 -0700155 def test_volume_create_get_update_delete_from_image(self):
Matthew Treinish4d352bc2014-01-29 18:29:18 +0000156 self._volume_create_get_update_delete(imageRef=CONF.compute.image_ref)
Giulio Fidente02f42982013-06-17 16:25:56 +0200157
158 @attr(type='gate')
QingXin Meng611768a2013-09-18 00:51:33 -0700159 def test_volume_create_get_update_delete_as_clone(self):
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +0900160 origin = self.create_volume()
QingXin Meng611768a2013-09-18 00:51:33 -0700161 self._volume_create_get_update_delete(source_volid=origin['id'])
Giulio Fidente36836c42013-04-05 15:43:51 +0200162
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400163
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100164class VolumesGetTestXML(VolumesGetTest):
165 _interface = "xml"