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 | |
Eric Windisch | ba35529 | 2014-02-20 16:47:10 -0800 | [diff] [blame] | 16 | from tempest import config |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 17 | from tempest.openstack.common import log as logging |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 18 | from tempest import test |
| 19 | from tempest.thirdparty.boto import test as boto_test |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 20 | |
Eric Windisch | ba35529 | 2014-02-20 16:47:10 -0800 | [diff] [blame] | 21 | CONF = config.CONF |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 22 | LOG = logging.getLogger(__name__) |
| 23 | |
| 24 | |
| 25 | def compare_volumes(a, b): |
| 26 | return (a.id == b.id and |
| 27 | a.size == b.size) |
| 28 | |
| 29 | |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 30 | class EC2VolumesTest(boto_test.BotoTestCase): |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 31 | |
| 32 | @classmethod |
| 33 | def setUpClass(cls): |
| 34 | super(EC2VolumesTest, cls).setUpClass() |
Eric Windisch | ba35529 | 2014-02-20 16:47:10 -0800 | [diff] [blame] | 35 | |
| 36 | if not CONF.service_available.cinder: |
| 37 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 38 | raise cls.skipException(skip_msg) |
| 39 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 40 | cls.client = cls.os.ec2api_client |
| 41 | cls.zone = cls.client.get_good_zone() |
| 42 | |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 43 | @test.attr(type='smoke') |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 44 | def test_create_get_delete(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 45 | # EC2 Create, get, delete Volume |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 46 | volume = self.client.create_volume(1, self.zone) |
| 47 | cuk = self.addResourceCleanUp(self.client.delete_volume, volume.id) |
| 48 | self.assertIn(volume.status, self.valid_volume_status) |
| 49 | retrieved = self.client.get_all_volumes((volume.id,)) |
| 50 | self.assertEqual(1, len(retrieved)) |
| 51 | self.assertTrue(compare_volumes(volume, retrieved[0])) |
Attila Fazekas | 40aa361 | 2013-01-19 22:16:38 +0100 | [diff] [blame] | 52 | self.assertVolumeStatusWait(volume, "available") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 53 | self.client.delete_volume(volume.id) |
| 54 | self.cancelResourceCleanUp(cuk) |
| 55 | |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 56 | @test.attr(type='smoke') |
Ashish Chandra | 0f7a30a | 2013-01-23 01:38:51 -0800 | [diff] [blame] | 57 | def test_create_volume_from_snapshot(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 58 | # EC2 Create volume from snapshot |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 59 | volume = self.client.create_volume(1, self.zone) |
| 60 | self.addResourceCleanUp(self.client.delete_volume, volume.id) |
Attila Fazekas | 40aa361 | 2013-01-19 22:16:38 +0100 | [diff] [blame] | 61 | self.assertVolumeStatusWait(volume, "available") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 62 | snap = self.client.create_snapshot(volume.id) |
| 63 | self.addResourceCleanUp(self.destroy_snapshot_wait, snap) |
Attila Fazekas | 40aa361 | 2013-01-19 22:16:38 +0100 | [diff] [blame] | 64 | self.assertSnapshotStatusWait(snap, "completed") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 65 | |
| 66 | svol = self.client.create_volume(1, self.zone, snapshot=snap) |
| 67 | cuk = self.addResourceCleanUp(svol.delete) |
Attila Fazekas | 40aa361 | 2013-01-19 22:16:38 +0100 | [diff] [blame] | 68 | self.assertVolumeStatusWait(svol, "available") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 69 | svol.delete() |
| 70 | self.cancelResourceCleanUp(cuk) |