blob: 43c837a594ff8ce729a6ea6c078f7e52c64e36e3 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# 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 Treinish96e9e882014-06-09 18:37:19 -040016from testtools import matchers
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Ken'ichi Ohmichic6633232015-07-08 08:31:04 +000019from tempest.common import waiters
Matthew Treinishbc0e03e2014-01-30 16:51:06 +000020from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080021from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080022from tempest.lib import decorators
Matthew Treinish96e9e882014-06-09 18:37:19 -040023
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053024
Matthew Treinishbc0e03e2014-01-30 16:51:06 +000025CONF = config.CONF
26
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053027
ivan-zhuf2b00502013-10-18 10:06:52 +080028class VolumesGetTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010029
Attila Fazekas19044d52013-02-16 07:35:06 +010030 @classmethod
Emily Hugenbruch8284a342014-12-11 22:04:55 +000031 def skip_checks(cls):
32 super(VolumesGetTestJSON, cls).skip_checks()
Matthew Treinishbc0e03e2014-01-30 16:51:06 +000033 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040034 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
35 raise cls.skipException(skip_msg)
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053036
Emily Hugenbruch8284a342014-12-11 22:04:55 +000037 @classmethod
38 def setup_clients(cls):
39 super(VolumesGetTestJSON, cls).setup_clients()
40 cls.client = cls.volumes_extensions_client
41
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080042 @decorators.idempotent_id('f10f25eb-9775-4d9d-9cbe-1cf54dae9d5f')
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053043 def test_volume_create_get_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050044 # CREATE, GET, DELETE Volume
zhuflc6ce5392016-08-17 14:34:37 +080045 v_name = data_utils.rand_name(self.__class__.__name__ + '-Volume')
Matthew Treinisha2a82182013-06-19 17:03:04 -040046 metadata = {'Type': 'work'}
Attila Fazekasf7f34f92013-08-01 17:01:44 +020047 # Create volume
Ken'ichi Ohmichic4921782015-08-05 08:14:42 +000048 volume = self.client.create_volume(size=CONF.volume.volume_size,
49 display_name=v_name,
ghanshyamcb131762015-08-24 18:21:08 +090050 metadata=metadata)['volume']
Chris Yeohc266b282014-03-13 18:19:00 +103051 self.assertIn('id', volume)
guo yunxianc53b8cc2016-08-10 20:36:52 +080052 self.addCleanup(self.delete_volume, volume['id'])
Chris Yeohc266b282014-03-13 18:19:00 +103053 self.assertIn('displayName', volume)
Matthew Treinisha2a82182013-06-19 17:03:04 -040054 self.assertEqual(volume['displayName'], v_name,
55 "The created volume name is not equal "
56 "to the requested name")
Béla Vancsics64862f72016-11-08 09:12:31 +010057 self.assertIsNotNone(volume['id'],
58 "Field volume id is empty or not found.")
Attila Fazekasf7f34f92013-08-01 17:01:44 +020059 # Wait for Volume status to become ACTIVE
lkuchlan52d7b0d2016-11-07 20:53:19 +020060 waiters.wait_for_volume_resource_status(self.client, volume['id'],
61 'available')
Attila Fazekasf7f34f92013-08-01 17:01:44 +020062 # GET Volume
ghanshyamcb131762015-08-24 18:21:08 +090063 fetched_volume = self.client.show_volume(volume['id'])['volume']
nayna-patelc07f77d2014-01-15 12:39:25 +000064 # Verification of details of fetched Volume
Matthew Treinisha2a82182013-06-19 17:03:04 -040065 self.assertEqual(v_name,
66 fetched_volume['displayName'],
67 'The fetched Volume is different '
68 'from the created Volume')
guo yunxianc53b8cc2016-08-10 20:36:52 +080069 self.assertEqual(CONF.volume.volume_size,
70 fetched_volume['size'],
71 'The fetched volume size is different '
72 'from the created Volume')
Matthew Treinisha2a82182013-06-19 17:03:04 -040073 self.assertEqual(volume['id'],
74 fetched_volume['id'],
75 'The fetched Volume is different '
76 'from the created Volume')
Jerry Caic3c49ad2014-01-10 15:38:45 +080077 self.assertThat(fetched_volume['metadata'].items(),
Masayuki Igawa209fd502014-02-17 14:46:43 +090078 matchers.ContainsAll(metadata.items()),
Jerry Caic3c49ad2014-01-10 15:38:45 +080079 'The fetched Volume metadata misses data '
80 'from the created Volume')