blob: b50c6b09797a14b35cba454df75ba72e7062d7a7 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Attila Fazekasa23f5002012-10-23 19:32:45 +02002# 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
Eric Windischba355292014-02-20 16:47:10 -080016from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040017from tempest.openstack.common import log as logging
Masayuki Igawa224a8272014-02-17 15:07:43 +090018from tempest.thirdparty.boto import test as boto_test
Matthew Treinisha83a16e2012-12-07 13:44:02 -050019
Eric Windischba355292014-02-20 16:47:10 -080020CONF = config.CONF
Attila Fazekasa23f5002012-10-23 19:32:45 +020021LOG = logging.getLogger(__name__)
22
23
24def compare_volumes(a, b):
25 return (a.id == b.id and
26 a.size == b.size)
27
28
Masayuki Igawa224a8272014-02-17 15:07:43 +090029class EC2VolumesTest(boto_test.BotoTestCase):
Attila Fazekasa23f5002012-10-23 19:32:45 +020030
31 @classmethod
32 def setUpClass(cls):
33 super(EC2VolumesTest, cls).setUpClass()
Eric Windischba355292014-02-20 16:47:10 -080034
35 if not CONF.service_available.cinder:
36 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
37 raise cls.skipException(skip_msg)
38
Attila Fazekasa23f5002012-10-23 19:32:45 +020039 cls.client = cls.os.ec2api_client
Attila Fazekas27dd92e2014-02-21 14:49:40 +010040 cls.zone = CONF.boto.aws_zone
Attila Fazekasa23f5002012-10-23 19:32:45 +020041
Attila Fazekasa23f5002012-10-23 19:32:45 +020042 def test_create_get_delete(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050043 # EC2 Create, get, delete Volume
Attila Fazekasa23f5002012-10-23 19:32:45 +020044 volume = self.client.create_volume(1, self.zone)
45 cuk = self.addResourceCleanUp(self.client.delete_volume, volume.id)
46 self.assertIn(volume.status, self.valid_volume_status)
47 retrieved = self.client.get_all_volumes((volume.id,))
48 self.assertEqual(1, len(retrieved))
49 self.assertTrue(compare_volumes(volume, retrieved[0]))
Attila Fazekas40aa3612013-01-19 22:16:38 +010050 self.assertVolumeStatusWait(volume, "available")
Attila Fazekasa23f5002012-10-23 19:32:45 +020051 self.client.delete_volume(volume.id)
52 self.cancelResourceCleanUp(cuk)
53
Ashish Chandra0f7a30a2013-01-23 01:38:51 -080054 def test_create_volume_from_snapshot(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050055 # EC2 Create volume from snapshot
Attila Fazekasa23f5002012-10-23 19:32:45 +020056 volume = self.client.create_volume(1, self.zone)
57 self.addResourceCleanUp(self.client.delete_volume, volume.id)
Attila Fazekas40aa3612013-01-19 22:16:38 +010058 self.assertVolumeStatusWait(volume, "available")
Attila Fazekasa23f5002012-10-23 19:32:45 +020059 snap = self.client.create_snapshot(volume.id)
60 self.addResourceCleanUp(self.destroy_snapshot_wait, snap)
Attila Fazekas40aa3612013-01-19 22:16:38 +010061 self.assertSnapshotStatusWait(snap, "completed")
Attila Fazekasa23f5002012-10-23 19:32:45 +020062
63 svol = self.client.create_volume(1, self.zone, snapshot=snap)
64 cuk = self.addResourceCleanUp(svol.delete)
Attila Fazekas40aa3612013-01-19 22:16:38 +010065 self.assertVolumeStatusWait(svol, "available")
Attila Fazekasa23f5002012-10-23 19:32:45 +020066 svol.delete()
67 self.cancelResourceCleanUp(cuk)