blob: 3e7e2de3939b16fdabdc9f55a49c60d3e3587b09 [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
Matthew Treinish481466b2012-12-20 17:16:01 -050016from tempest import clients
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040017from tempest.openstack.common import log as logging
Chris Yeoh01cb2792013-02-09 22:25:37 +103018from tempest.test import attr
Sean Dague09761f62013-05-13 15:20:40 -040019from tempest.thirdparty.boto.test import BotoTestCase
Matthew Treinisha83a16e2012-12-07 13:44:02 -050020
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
Attila Fazekasa23f5002012-10-23 19:32:45 +020029class EC2VolumesTest(BotoTestCase):
30
31 @classmethod
32 def setUpClass(cls):
33 super(EC2VolumesTest, cls).setUpClass()
Matthew Treinish481466b2012-12-20 17:16:01 -050034 cls.os = clients.Manager()
Attila Fazekasa23f5002012-10-23 19:32:45 +020035 cls.client = cls.os.ec2api_client
36 cls.zone = cls.client.get_good_zone()
37
Attila Fazekasa23f5002012-10-23 19:32:45 +020038 @attr(type='smoke')
39 def test_create_get_delete(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050040 # EC2 Create, get, delete Volume
Attila Fazekasa23f5002012-10-23 19:32:45 +020041 volume = self.client.create_volume(1, self.zone)
42 cuk = self.addResourceCleanUp(self.client.delete_volume, volume.id)
43 self.assertIn(volume.status, self.valid_volume_status)
44 retrieved = self.client.get_all_volumes((volume.id,))
45 self.assertEqual(1, len(retrieved))
46 self.assertTrue(compare_volumes(volume, retrieved[0]))
Attila Fazekas40aa3612013-01-19 22:16:38 +010047 self.assertVolumeStatusWait(volume, "available")
Attila Fazekasa23f5002012-10-23 19:32:45 +020048 self.client.delete_volume(volume.id)
49 self.cancelResourceCleanUp(cuk)
50
Attila Fazekasec6d20f2012-12-06 19:47:11 +010051 @attr(type='smoke')
Ashish Chandra0f7a30a2013-01-23 01:38:51 -080052 def test_create_volume_from_snapshot(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050053 # EC2 Create volume from snapshot
Attila Fazekasa23f5002012-10-23 19:32:45 +020054 volume = self.client.create_volume(1, self.zone)
55 self.addResourceCleanUp(self.client.delete_volume, volume.id)
Attila Fazekas40aa3612013-01-19 22:16:38 +010056 self.assertVolumeStatusWait(volume, "available")
Attila Fazekasa23f5002012-10-23 19:32:45 +020057 snap = self.client.create_snapshot(volume.id)
58 self.addResourceCleanUp(self.destroy_snapshot_wait, snap)
Attila Fazekas40aa3612013-01-19 22:16:38 +010059 self.assertSnapshotStatusWait(snap, "completed")
Attila Fazekasa23f5002012-10-23 19:32:45 +020060
61 svol = self.client.create_volume(1, self.zone, snapshot=snap)
62 cuk = self.addResourceCleanUp(svol.delete)
Attila Fazekas40aa3612013-01-19 22:16:38 +010063 self.assertVolumeStatusWait(svol, "available")
Attila Fazekasa23f5002012-10-23 19:32:45 +020064 svol.delete()
65 self.cancelResourceCleanUp(cuk)