blob: f05a5a30273c0b00702a0d40575ad805491500e6 [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Ken'ichi Ohmichic6633232015-07-08 08:31:04 +000020from tempest.common import waiters
Matthew Treinishbc0e03e2014-01-30 16:51:06 +000021from tempest import config
Masayuki Igawa209fd502014-02-17 14:46:43 +090022from tempest import test
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
Chris Hoge7579c1a2015-02-26 14:12:15 -080042 @test.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
Dan Prince9821fde2012-11-30 10:54:12 -050045 volume = None
Andrea Frittolic0978352015-02-06 15:57:40 +000046 v_name = data_utils.rand_name('Volume')
Matthew Treinisha2a82182013-06-19 17:03:04 -040047 metadata = {'Type': 'work'}
Attila Fazekasf7f34f92013-08-01 17:01:44 +020048 # Create volume
Ken'ichi Ohmichic4921782015-08-05 08:14:42 +000049 volume = self.client.create_volume(size=CONF.volume.volume_size,
50 display_name=v_name,
David Kranz3ebc7212015-02-10 12:19:19 -050051 metadata=metadata)
Matt Riedemann5dc594c2014-01-27 11:40:28 -080052 self.addCleanup(self.delete_volume, volume['id'])
Chris Yeohc266b282014-03-13 18:19:00 +103053 self.assertIn('id', volume)
54 self.assertIn('displayName', volume)
Matthew Treinisha2a82182013-06-19 17:03:04 -040055 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 Fazekasf7f34f92013-08-01 17:01:44 +020060 # Wait for Volume status to become ACTIVE
Ken'ichi Ohmichic6633232015-07-08 08:31:04 +000061 waiters.wait_for_volume_status(self.client, volume['id'], 'available')
Attila Fazekasf7f34f92013-08-01 17:01:44 +020062 # GET Volume
Ken'ichi Ohmichi5f448a52015-07-01 06:26:30 +000063 fetched_volume = self.client.show_volume(volume['id'])
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')
69 self.assertEqual(volume['id'],
70 fetched_volume['id'],
71 'The fetched Volume is different '
72 'from the created Volume')
Jerry Caic3c49ad2014-01-10 15:38:45 +080073 self.assertThat(fetched_volume['metadata'].items(),
Masayuki Igawa209fd502014-02-17 14:46:43 +090074 matchers.ContainsAll(metadata.items()),
Jerry Caic3c49ad2014-01-10 15:38:45 +080075 'The fetched Volume metadata misses data '
76 'from the created Volume')