ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 2 | # 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 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 16 | from tempest.api.compute import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Chris Yeoh | 9465b0b | 2013-02-09 22:19:15 +1030 | [diff] [blame] | 18 | from tempest.test import attr |
Jerry Cai | c3c49ad | 2014-01-10 15:38:45 +0800 | [diff] [blame] | 19 | from testtools.matchers import ContainsAll |
rajalakshmi-ganesan | d3b43f6 | 2012-04-03 17:39:23 +0530 | [diff] [blame] | 20 | |
| 21 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 22 | class VolumesGetTestJSON(base.BaseV2ComputeTest): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 23 | |
| 24 | _interface = 'json' |
| 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(VolumesGetTestJSON, cls).setUpClass() |
| 29 | cls.client = cls.volumes_extensions_client |
Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 30 | if not cls.config.service_available.cinder: |
| 31 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 32 | raise cls.skipException(skip_msg) |
rajalakshmi-ganesan | d3b43f6 | 2012-04-03 17:39:23 +0530 | [diff] [blame] | 33 | |
| 34 | @attr(type='smoke') |
| 35 | def test_volume_create_get_delete(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 36 | # CREATE, GET, DELETE Volume |
Dan Prince | 9821fde | 2012-11-30 10:54:12 -0500 | [diff] [blame] | 37 | volume = None |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 38 | v_name = data_utils.rand_name('Volume-%s-') % self._interface |
Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 39 | metadata = {'Type': 'work'} |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 40 | # Create volume |
Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 41 | resp, volume = self.client.create_volume(size=1, |
| 42 | display_name=v_name, |
| 43 | metadata=metadata) |
| 44 | self.addCleanup(self._delete_volume, volume) |
| 45 | self.assertEqual(200, resp.status) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 46 | self.assertIn('id', volume) |
| 47 | self.assertIn('displayName', volume) |
Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 48 | self.assertEqual(volume['displayName'], v_name, |
| 49 | "The created volume name is not equal " |
| 50 | "to the requested name") |
| 51 | self.assertTrue(volume['id'] is not None, |
| 52 | "Field volume id is empty or not found.") |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 53 | # Wait for Volume status to become ACTIVE |
Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 54 | self.client.wait_for_volume_status(volume['id'], 'available') |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 55 | # GET Volume |
Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 56 | resp, fetched_volume = self.client.get_volume(volume['id']) |
| 57 | self.assertEqual(200, resp.status) |
nayna-patel | c07f77d | 2014-01-15 12:39:25 +0000 | [diff] [blame] | 58 | # Verification of details of fetched Volume |
Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 59 | self.assertEqual(v_name, |
| 60 | fetched_volume['displayName'], |
| 61 | 'The fetched Volume is different ' |
| 62 | 'from the created Volume') |
| 63 | self.assertEqual(volume['id'], |
| 64 | fetched_volume['id'], |
| 65 | 'The fetched Volume is different ' |
| 66 | 'from the created Volume') |
Jerry Cai | c3c49ad | 2014-01-10 15:38:45 +0800 | [diff] [blame] | 67 | self.assertThat(fetched_volume['metadata'].items(), |
| 68 | ContainsAll(metadata.items()), |
| 69 | 'The fetched Volume metadata misses data ' |
| 70 | 'from the created Volume') |
Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 71 | |
| 72 | def _delete_volume(self, volume): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 73 | # Delete the Volume created in this method |
rajalakshmi-ganesan | d3b43f6 | 2012-04-03 17:39:23 +0530 | [diff] [blame] | 74 | try: |
rajalakshmi-ganesan | d3b43f6 | 2012-04-03 17:39:23 +0530 | [diff] [blame] | 75 | resp, _ = self.client.delete_volume(volume['id']) |
| 76 | self.assertEqual(202, resp.status) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 77 | # Checking if the deleted Volume still exists |
Matthew Treinish | 9e1eb97 | 2012-08-17 17:53:41 -0400 | [diff] [blame] | 78 | self.client.wait_for_resource_deletion(volume['id']) |
Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 79 | except KeyError: |
| 80 | return |
Matthew Treinish | 9e1eb97 | 2012-08-17 17:53:41 -0400 | [diff] [blame] | 81 | |
| 82 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 83 | class VolumesGetTestXML(VolumesGetTestJSON): |
| 84 | _interface = "xml" |