ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 2 | # 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 Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 16 | from tempest import clients |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 17 | from tempest.openstack.common import log as logging |
Chris Yeoh | 01cb279 | 2013-02-09 22:25:37 +1030 | [diff] [blame] | 18 | from tempest.test import attr |
Sean Dague | 09761f6 | 2013-05-13 15:20:40 -0400 | [diff] [blame] | 19 | from tempest.thirdparty.boto.test import BotoTestCase |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 20 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 21 | LOG = logging.getLogger(__name__) |
| 22 | |
| 23 | |
| 24 | def compare_volumes(a, b): |
| 25 | return (a.id == b.id and |
| 26 | a.size == b.size) |
| 27 | |
| 28 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 29 | class EC2VolumesTest(BotoTestCase): |
| 30 | |
| 31 | @classmethod |
| 32 | def setUpClass(cls): |
| 33 | super(EC2VolumesTest, cls).setUpClass() |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 34 | cls.os = clients.Manager() |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 35 | cls.client = cls.os.ec2api_client |
| 36 | cls.zone = cls.client.get_good_zone() |
| 37 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 38 | @attr(type='smoke') |
| 39 | def test_create_get_delete(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 40 | # EC2 Create, get, delete Volume |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 41 | 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 Fazekas | 40aa361 | 2013-01-19 22:16:38 +0100 | [diff] [blame] | 47 | self.assertVolumeStatusWait(volume, "available") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 48 | self.client.delete_volume(volume.id) |
| 49 | self.cancelResourceCleanUp(cuk) |
| 50 | |
Attila Fazekas | ec6d20f | 2012-12-06 19:47:11 +0100 | [diff] [blame] | 51 | @attr(type='smoke') |
Ashish Chandra | 0f7a30a | 2013-01-23 01:38:51 -0800 | [diff] [blame] | 52 | def test_create_volume_from_snapshot(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 53 | # EC2 Create volume from snapshot |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 54 | volume = self.client.create_volume(1, self.zone) |
| 55 | self.addResourceCleanUp(self.client.delete_volume, volume.id) |
Attila Fazekas | 40aa361 | 2013-01-19 22:16:38 +0100 | [diff] [blame] | 56 | self.assertVolumeStatusWait(volume, "available") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 57 | snap = self.client.create_snapshot(volume.id) |
| 58 | self.addResourceCleanUp(self.destroy_snapshot_wait, snap) |
Attila Fazekas | 40aa361 | 2013-01-19 22:16:38 +0100 | [diff] [blame] | 59 | self.assertSnapshotStatusWait(snap, "completed") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 60 | |
| 61 | svol = self.client.create_volume(1, self.zone, snapshot=snap) |
| 62 | cuk = self.addResourceCleanUp(svol.delete) |
Attila Fazekas | 40aa361 | 2013-01-19 22:16:38 +0100 | [diff] [blame] | 63 | self.assertVolumeStatusWait(svol, "available") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 64 | svol.delete() |
| 65 | self.cancelResourceCleanUp(cuk) |