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