Gaozexu | b9c9d6e | 2015-09-10 17:08:04 +0800 | [diff] [blame] | 1 | # Copyright 2015 Fujitsu(fnst) Corporation |
| 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 | |
| 16 | from tempest.api.compute import base |
| 17 | from tempest.common.utils import data_utils |
| 18 | from tempest.common import waiters |
| 19 | from tempest import config |
| 20 | from tempest import test |
| 21 | |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | |
| 26 | class VolumesSnapshotsTestJSON(base.BaseV2ComputeTest): |
| 27 | |
| 28 | @classmethod |
| 29 | def skip_checks(cls): |
| 30 | super(VolumesSnapshotsTestJSON, cls).skip_checks() |
| 31 | if not CONF.service_available.cinder: |
| 32 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 33 | raise cls.skipException(skip_msg) |
| 34 | |
| 35 | @classmethod |
| 36 | def setup_clients(cls): |
| 37 | super(VolumesSnapshotsTestJSON, cls).setup_clients() |
| 38 | cls.volumes_client = cls.volumes_extensions_client |
| 39 | cls.snapshots_client = cls.snapshots_extensions_client |
| 40 | |
| 41 | @test.idempotent_id('cd4ec87d-7825-450d-8040-6e2068f2da8f') |
| 42 | def test_volume_snapshot_create_get_list_delete(self): |
| 43 | v_name = data_utils.rand_name('Volume') |
| 44 | volume = self.volumes_client.create_volume( |
| 45 | size=CONF.volume.volume_size, |
| 46 | display_name=v_name)['volume'] |
| 47 | self.addCleanup(self.delete_volume, volume['id']) |
| 48 | waiters.wait_for_volume_status(self.volumes_client, volume['id'], |
| 49 | 'available') |
| 50 | s_name = data_utils.rand_name('Snapshot') |
| 51 | # Create snapshot |
| 52 | snapshot = self.snapshots_client.create_snapshot( |
Ghanshyam | 0b75b63 | 2015-12-11 15:08:28 +0900 | [diff] [blame] | 53 | volume_id=volume['id'], |
Gaozexu | b9c9d6e | 2015-09-10 17:08:04 +0800 | [diff] [blame] | 54 | display_name=s_name)['snapshot'] |
| 55 | |
| 56 | def delete_snapshot(snapshot_id): |
| 57 | waiters.wait_for_snapshot_status(self.snapshots_client, |
| 58 | snapshot_id, |
| 59 | 'available') |
| 60 | # Delete snapshot |
| 61 | self.snapshots_client.delete_snapshot(snapshot_id) |
| 62 | self.snapshots_client.wait_for_resource_deletion(snapshot_id) |
| 63 | |
| 64 | self.addCleanup(delete_snapshot, snapshot['id']) |
| 65 | self.assertEqual(volume['id'], snapshot['volumeId']) |
| 66 | # Get snapshot |
| 67 | fetched_snapshot = self.snapshots_client.show_snapshot( |
| 68 | snapshot['id'])['snapshot'] |
| 69 | self.assertEqual(s_name, fetched_snapshot['displayName']) |
| 70 | self.assertEqual(volume['id'], fetched_snapshot['volumeId']) |
| 71 | # Fetch all snapshots |
| 72 | snapshots = self.snapshots_client.list_snapshots()['snapshots'] |
| 73 | self.assertIn(snapshot['id'], map(lambda x: x['id'], snapshots)) |