blob: f6fed5bed1244e29a405130c15ef70a393123479 [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04004# 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 Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
Chris Yeoh9465b0b2013-02-09 22:19:15 +103020from tempest.test import attr
Jerry Caic3c49ad2014-01-10 15:38:45 +080021from testtools.matchers import ContainsAll
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053022
23
ivan-zhuf2b00502013-10-18 10:06:52 +080024class VolumesGetTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010025
26 _interface = 'json'
27
28 @classmethod
29 def setUpClass(cls):
30 super(VolumesGetTestJSON, cls).setUpClass()
31 cls.client = cls.volumes_extensions_client
Matthew Treinish4c412922013-07-16 15:27:42 -040032 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-ganesand3b43f62012-04-03 17:39:23 +053035
36 @attr(type='smoke')
37 def test_volume_create_get_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050038 # CREATE, GET, DELETE Volume
Dan Prince9821fde2012-11-30 10:54:12 -050039 volume = None
Masayuki Igawa259c1132013-10-31 17:48:44 +090040 v_name = data_utils.rand_name('Volume-%s-') % self._interface
Matthew Treinisha2a82182013-06-19 17:03:04 -040041 metadata = {'Type': 'work'}
Attila Fazekasf7f34f92013-08-01 17:01:44 +020042 # Create volume
Matthew Treinisha2a82182013-06-19 17:03:04 -040043 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 Fazekase191cb12013-07-29 06:41:52 +020048 self.assertIn('id', volume)
49 self.assertIn('displayName', volume)
Matthew Treinisha2a82182013-06-19 17:03:04 -040050 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 Fazekasf7f34f92013-08-01 17:01:44 +020055 # Wait for Volume status to become ACTIVE
Matthew Treinisha2a82182013-06-19 17:03:04 -040056 self.client.wait_for_volume_status(volume['id'], 'available')
Attila Fazekasf7f34f92013-08-01 17:01:44 +020057 # GET Volume
Matthew Treinisha2a82182013-06-19 17:03:04 -040058 resp, fetched_volume = self.client.get_volume(volume['id'])
59 self.assertEqual(200, resp.status)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020060 # Verfication of details of fetched Volume
Matthew Treinisha2a82182013-06-19 17:03:04 -040061 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 Caic3c49ad2014-01-10 15:38:45 +080069 self.assertThat(fetched_volume['metadata'].items(),
70 ContainsAll(metadata.items()),
71 'The fetched Volume metadata misses data '
72 'from the created Volume')
Matthew Treinisha2a82182013-06-19 17:03:04 -040073
74 def _delete_volume(self, volume):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020075 # Delete the Volume created in this method
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053076 try:
rajalakshmi-ganesand3b43f62012-04-03 17:39:23 +053077 resp, _ = self.client.delete_volume(volume['id'])
78 self.assertEqual(202, resp.status)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020079 # Checking if the deleted Volume still exists
Matthew Treinish9e1eb972012-08-17 17:53:41 -040080 self.client.wait_for_resource_deletion(volume['id'])
Matthew Treinisha2a82182013-06-19 17:03:04 -040081 except KeyError:
82 return
Matthew Treinish9e1eb972012-08-17 17:53:41 -040083
84
Attila Fazekas19044d52013-02-16 07:35:06 +010085class VolumesGetTestXML(VolumesGetTestJSON):
86 _interface = "xml"