blob: efacbda49617b9677293e56fbabce24f4a9c6311 [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 Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
Matthew Treinish96e9e882014-06-09 18:37:19 -040017from testtools import matchers
18
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.compute import base
Matthew Treinishbc0e03e2014-01-30 16:51:06 +000020from tempest import config
Masayuki Igawa209fd502014-02-17 14:46:43 +090021from tempest import test
Matthew Treinish96e9e882014-06-09 18:37:19 -040022
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053023
Matthew Treinishbc0e03e2014-01-30 16:51:06 +000024CONF = config.CONF
25
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053026
ivan-zhuf2b00502013-10-18 10:06:52 +080027class VolumesGetTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010028
Attila Fazekas19044d52013-02-16 07:35:06 +010029 @classmethod
Emily Hugenbruch8284a342014-12-11 22:04:55 +000030 def skip_checks(cls):
31 super(VolumesGetTestJSON, cls).skip_checks()
Matthew Treinishbc0e03e2014-01-30 16:51:06 +000032 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040033 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
34 raise cls.skipException(skip_msg)
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053035
Emily Hugenbruch8284a342014-12-11 22:04:55 +000036 @classmethod
37 def setup_clients(cls):
38 super(VolumesGetTestJSON, cls).setup_clients()
39 cls.client = cls.volumes_extensions_client
40
Chris Hoge7579c1a2015-02-26 14:12:15 -080041 @test.idempotent_id('f10f25eb-9775-4d9d-9cbe-1cf54dae9d5f')
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053042 def test_volume_create_get_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050043 # CREATE, GET, DELETE Volume
Dan Prince9821fde2012-11-30 10:54:12 -050044 volume = None
Andrea Frittolic0978352015-02-06 15:57:40 +000045 v_name = data_utils.rand_name('Volume')
Matthew Treinisha2a82182013-06-19 17:03:04 -040046 metadata = {'Type': 'work'}
Attila Fazekasf7f34f92013-08-01 17:01:44 +020047 # Create volume
Markus Zoeller3d2a21c2015-02-27 12:04:22 +010048 volume = self.client.create_volume(display_name=v_name,
David Kranz3ebc7212015-02-10 12:19:19 -050049 metadata=metadata)
Matt Riedemann5dc594c2014-01-27 11:40:28 -080050 self.addCleanup(self.delete_volume, volume['id'])
Chris Yeohc266b282014-03-13 18:19:00 +103051 self.assertIn('id', volume)
52 self.assertIn('displayName', volume)
Matthew Treinisha2a82182013-06-19 17:03:04 -040053 self.assertEqual(volume['displayName'], v_name,
54 "The created volume name is not equal "
55 "to the requested name")
56 self.assertTrue(volume['id'] is not None,
57 "Field volume id is empty or not found.")
Attila Fazekasf7f34f92013-08-01 17:01:44 +020058 # Wait for Volume status to become ACTIVE
Matthew Treinisha2a82182013-06-19 17:03:04 -040059 self.client.wait_for_volume_status(volume['id'], 'available')
Attila Fazekasf7f34f92013-08-01 17:01:44 +020060 # GET Volume
Ken'ichi Ohmichi5f448a52015-07-01 06:26:30 +000061 fetched_volume = self.client.show_volume(volume['id'])
nayna-patelc07f77d2014-01-15 12:39:25 +000062 # Verification of details of fetched Volume
Matthew Treinisha2a82182013-06-19 17:03:04 -040063 self.assertEqual(v_name,
64 fetched_volume['displayName'],
65 'The fetched Volume is different '
66 'from the created Volume')
67 self.assertEqual(volume['id'],
68 fetched_volume['id'],
69 'The fetched Volume is different '
70 'from the created Volume')
Jerry Caic3c49ad2014-01-10 15:38:45 +080071 self.assertThat(fetched_volume['metadata'].items(),
Masayuki Igawa209fd502014-02-17 14:46:43 +090072 matchers.ContainsAll(metadata.items()),
Jerry Caic3c49ad2014-01-10 15:38:45 +080073 'The fetched Volume metadata misses data '
74 'from the created Volume')