| 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 |  | 
| Matthew Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 16 | from testtools import matchers | 
|  | 17 |  | 
| Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.compute import base | 
| Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 19 | from tempest.common.utils import data_utils | 
| Ken'ichi Ohmichi | c663323 | 2015-07-08 08:31:04 +0000 | [diff] [blame] | 20 | from tempest.common import waiters | 
| Matthew Treinish | bc0e03e | 2014-01-30 16:51:06 +0000 | [diff] [blame] | 21 | from tempest import config | 
| Masayuki Igawa | 209fd50 | 2014-02-17 14:46:43 +0900 | [diff] [blame] | 22 | from tempest import test | 
| Matthew Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 23 |  | 
| rajalakshmi-ganesan | d3b43f6 | 2012-04-03 17:39:23 +0530 | [diff] [blame] | 24 |  | 
| Matthew Treinish | bc0e03e | 2014-01-30 16:51:06 +0000 | [diff] [blame] | 25 | CONF = config.CONF | 
|  | 26 |  | 
| rajalakshmi-ganesan | d3b43f6 | 2012-04-03 17:39:23 +0530 | [diff] [blame] | 27 |  | 
| ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 28 | class VolumesGetTestJSON(base.BaseV2ComputeTest): | 
| Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 29 |  | 
| Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 30 | @classmethod | 
| Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 31 | def skip_checks(cls): | 
|  | 32 | super(VolumesGetTestJSON, cls).skip_checks() | 
| Matthew Treinish | bc0e03e | 2014-01-30 16:51:06 +0000 | [diff] [blame] | 33 | if not CONF.service_available.cinder: | 
| Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 34 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) | 
|  | 35 | raise cls.skipException(skip_msg) | 
| rajalakshmi-ganesan | d3b43f6 | 2012-04-03 17:39:23 +0530 | [diff] [blame] | 36 |  | 
| Emily Hugenbruch | 8284a34 | 2014-12-11 22:04:55 +0000 | [diff] [blame] | 37 | @classmethod | 
|  | 38 | def setup_clients(cls): | 
|  | 39 | super(VolumesGetTestJSON, cls).setup_clients() | 
|  | 40 | cls.client = cls.volumes_extensions_client | 
|  | 41 |  | 
| Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 42 | @test.idempotent_id('f10f25eb-9775-4d9d-9cbe-1cf54dae9d5f') | 
| rajalakshmi-ganesan | d3b43f6 | 2012-04-03 17:39:23 +0530 | [diff] [blame] | 43 | def test_volume_create_get_delete(self): | 
| Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 44 | # CREATE, GET, DELETE Volume | 
| Dan Prince | 9821fde | 2012-11-30 10:54:12 -0500 | [diff] [blame] | 45 | volume = None | 
| Andrea Frittoli | c097835 | 2015-02-06 15:57:40 +0000 | [diff] [blame] | 46 | v_name = data_utils.rand_name('Volume') | 
| Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 47 | metadata = {'Type': 'work'} | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 48 | # Create volume | 
| Ken'ichi Ohmichi | c492178 | 2015-08-05 08:14:42 +0000 | [diff] [blame] | 49 | volume = self.client.create_volume(size=CONF.volume.volume_size, | 
|  | 50 | display_name=v_name, | 
| David Kranz | 3ebc721 | 2015-02-10 12:19:19 -0500 | [diff] [blame] | 51 | metadata=metadata) | 
| Matt Riedemann | 5dc594c | 2014-01-27 11:40:28 -0800 | [diff] [blame] | 52 | self.addCleanup(self.delete_volume, volume['id']) | 
| Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 53 | self.assertIn('id', volume) | 
|  | 54 | self.assertIn('displayName', volume) | 
| Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 55 | self.assertEqual(volume['displayName'], v_name, | 
|  | 56 | "The created volume name is not equal " | 
|  | 57 | "to the requested name") | 
|  | 58 | self.assertTrue(volume['id'] is not None, | 
|  | 59 | "Field volume id is empty or not found.") | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 60 | # Wait for Volume status to become ACTIVE | 
| Ken'ichi Ohmichi | c663323 | 2015-07-08 08:31:04 +0000 | [diff] [blame] | 61 | waiters.wait_for_volume_status(self.client, volume['id'], 'available') | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 62 | # GET Volume | 
| Ken'ichi Ohmichi | 5f448a5 | 2015-07-01 06:26:30 +0000 | [diff] [blame] | 63 | fetched_volume = self.client.show_volume(volume['id']) | 
| nayna-patel | c07f77d | 2014-01-15 12:39:25 +0000 | [diff] [blame] | 64 | # Verification of details of fetched Volume | 
| Matthew Treinish | a2a8218 | 2013-06-19 17:03:04 -0400 | [diff] [blame] | 65 | self.assertEqual(v_name, | 
|  | 66 | fetched_volume['displayName'], | 
|  | 67 | 'The fetched Volume is different ' | 
|  | 68 | 'from the created Volume') | 
|  | 69 | self.assertEqual(volume['id'], | 
|  | 70 | fetched_volume['id'], | 
|  | 71 | 'The fetched Volume is different ' | 
|  | 72 | 'from the created Volume') | 
| Jerry Cai | c3c49ad | 2014-01-10 15:38:45 +0800 | [diff] [blame] | 73 | self.assertThat(fetched_volume['metadata'].items(), | 
| Masayuki Igawa | 209fd50 | 2014-02-17 14:46:43 +0900 | [diff] [blame] | 74 | matchers.ContainsAll(metadata.items()), | 
| Jerry Cai | c3c49ad | 2014-01-10 15:38:45 +0800 | [diff] [blame] | 75 | 'The fetched Volume metadata misses data ' | 
|  | 76 | 'from the created Volume') |