diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-12-11 17:58:16 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-12-11 17:58:16 +0000 |
| commit | 5a2f8cbe52d4ec07ccf9867d567b217cdb4d11c2 (patch) | |
| tree | 50ece40116d4bfc84207c7f88b437ebdeed7009f | |
| parent | 0111ac1dd1deb76187a13e32e20765c7bcc54bc6 (diff) | |
| parent | eed626753c23bb82453bc5176193831fbb9e538c (diff) | |
| download | nova-5a2f8cbe52d4ec07ccf9867d567b217cdb4d11c2.tar.gz nova-5a2f8cbe52d4ec07ccf9867d567b217cdb4d11c2.tar.xz nova-5a2f8cbe52d4ec07ccf9867d567b217cdb4d11c2.zip | |
Merge "Map cinder snapshot statuses to ec2."
| -rw-r--r-- | nova/api/ec2/cloud.py | 26 | ||||
| -rw-r--r-- | nova/tests/api/ec2/test_cinder_cloud.py | 49 |
2 files changed, 72 insertions, 3 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 8155efb10..796505b57 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -345,14 +345,34 @@ class CloudController(object): snapshots.append(snapshot) else: snapshots = self.volume_api.get_all_snapshots(context) - snapshots = [self._format_snapshot(context, s) for s in snapshots] - return {'snapshotSet': snapshots} + + formatted_snapshots = [] + for s in snapshots: + formatted = self._format_snapshot(context, s) + if formatted: + formatted_snapshots.append(formatted) + return {'snapshotSet': formatted_snapshots} def _format_snapshot(self, context, snapshot): + # NOTE(mikal): this is just a set of strings in cinder. If they + # implement an enum, then we should move this code to use it. The + # valid ec2 statuses are "pending", "completed", and "error". + status_map = {'new': 'pending', + 'creating': 'pending', + 'available': 'completed', + 'active': 'completed', + 'deleting': 'pending', + 'deleted': None, + 'error': 'error'} + + mapped_status = status_map.get(snapshot['status'], snapshot['status']) + if not mapped_status: + return None + s = {} s['snapshotId'] = ec2utils.id_to_ec2_snap_id(snapshot['id']) s['volumeId'] = ec2utils.id_to_ec2_vol_id(snapshot['volume_id']) - s['status'] = snapshot['status'] + s['status'] = mapped_status s['startTime'] = snapshot['created_at'] s['progress'] = snapshot['progress'] s['ownerId'] = snapshot['project_id'] diff --git a/nova/tests/api/ec2/test_cinder_cloud.py b/nova/tests/api/ec2/test_cinder_cloud.py index e0d9aa8a8..3c119a2c2 100644 --- a/nova/tests/api/ec2/test_cinder_cloud.py +++ b/nova/tests/api/ec2/test_cinder_cloud.py @@ -19,6 +19,7 @@ import copy import tempfile +import uuid from nova.api.ec2 import cloud from nova.api.ec2 import ec2utils @@ -257,6 +258,54 @@ class CinderCloudTestCase(test.TestCase): self.cloud.delete_snapshot(self.context, snap2['snapshotId']) self.cloud.delete_volume(self.context, vol1['volumeId']) + def test_format_snapshot_maps_status(self): + fake_snapshot = {'status': 'new', + 'id': 1, + 'volume_id': 1, + 'created_at': 1353560191.08117, + 'progress': 90, + 'project_id': str(uuid.uuid4()), + 'volume_size': 10000, + 'display_description': 'desc'} + + self.assertEqual(self.cloud._format_snapshot(self.context, + fake_snapshot)['status'], + 'pending') + + fake_snapshot['status'] = 'creating' + self.assertEqual(self.cloud._format_snapshot(self.context, + fake_snapshot)['status'], + 'pending') + + fake_snapshot['status'] = 'available' + self.assertEqual(self.cloud._format_snapshot(self.context, + fake_snapshot)['status'], + 'completed') + + fake_snapshot['status'] = 'active' + self.assertEqual(self.cloud._format_snapshot(self.context, + fake_snapshot)['status'], + 'completed') + + fake_snapshot['status'] = 'deleting' + self.assertEqual(self.cloud._format_snapshot(self.context, + fake_snapshot)['status'], + 'pending') + + fake_snapshot['status'] = 'deleted' + self.assertEqual(self.cloud._format_snapshot(self.context, + fake_snapshot), None) + + fake_snapshot['status'] = 'error' + self.assertEqual(self.cloud._format_snapshot(self.context, + fake_snapshot)['status'], + 'error') + + fake_snapshot['status'] = 'banana' + self.assertEqual(self.cloud._format_snapshot(self.context, + fake_snapshot)['status'], + 'banana') + def test_create_snapshot(self): """Makes sure create_snapshot works.""" availability_zone = 'zone1:host1' |
