blob: dbb3104a85d19dd3d3e96803700c93c6097bbeb4 [file] [log] [blame]
Attila Fazekasa23f5002012-10-23 19:32:45 +02001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# 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
Matthew Treinish481466b2012-12-20 17:16:01 -050018from tempest import clients
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040019from tempest.openstack.common import log as logging
Chris Yeoh01cb2792013-02-09 22:25:37 +103020from tempest.test import attr
Sean Dague09761f62013-05-13 15:20:40 -040021from tempest.thirdparty.boto.test import BotoTestCase
Matthew Treinisha83a16e2012-12-07 13:44:02 -050022
Attila Fazekasa23f5002012-10-23 19:32:45 +020023LOG = logging.getLogger(__name__)
24
25
26def compare_volumes(a, b):
27 return (a.id == b.id and
28 a.size == b.size)
29
30
Attila Fazekasa23f5002012-10-23 19:32:45 +020031class EC2VolumesTest(BotoTestCase):
32
33 @classmethod
34 def setUpClass(cls):
35 super(EC2VolumesTest, cls).setUpClass()
Matthew Treinish481466b2012-12-20 17:16:01 -050036 cls.os = clients.Manager()
Attila Fazekasa23f5002012-10-23 19:32:45 +020037 cls.client = cls.os.ec2api_client
38 cls.zone = cls.client.get_good_zone()
39
Attila Fazekasa23f5002012-10-23 19:32:45 +020040 @attr(type='smoke')
41 def test_create_get_delete(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050042 # EC2 Create, get, delete Volume
Attila Fazekasa23f5002012-10-23 19:32:45 +020043 volume = self.client.create_volume(1, self.zone)
44 cuk = self.addResourceCleanUp(self.client.delete_volume, volume.id)
45 self.assertIn(volume.status, self.valid_volume_status)
46 retrieved = self.client.get_all_volumes((volume.id,))
47 self.assertEqual(1, len(retrieved))
48 self.assertTrue(compare_volumes(volume, retrieved[0]))
Attila Fazekas40aa3612013-01-19 22:16:38 +010049 self.assertVolumeStatusWait(volume, "available")
Attila Fazekasa23f5002012-10-23 19:32:45 +020050 self.client.delete_volume(volume.id)
51 self.cancelResourceCleanUp(cuk)
52
Attila Fazekasec6d20f2012-12-06 19:47:11 +010053 @attr(type='smoke')
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)