diff options
| author | Brian Waldon <bcwaldon@gmail.com> | 2012-02-28 17:11:05 -0800 |
|---|---|---|
| committer | Brian Waldon <bcwaldon@gmail.com> | 2012-02-28 21:32:09 -0800 |
| commit | 36100f6f99b317ef9f10f101f7cecfb1639255a8 (patch) | |
| tree | b95bf140d1c16623cf9d822a1f71ca0a0c7a81dd | |
| parent | 9a6dfec8276520a200cd7dfa4e7e2997ffeb45d6 (diff) | |
Return empty list when volume not attached
* The api used to return a list of a single empty dict
* Fixes bug 942990
Change-Id: I9926515acfcedf711e81615aa13cec0bbf968086
| -rw-r--r-- | nova/api/openstack/volume/volumes.py | 6 | ||||
| -rw-r--r-- | nova/tests/api/openstack/fakes.py | 42 | ||||
| -rw-r--r-- | nova/tests/api/openstack/volume/test_volumes.py | 22 |
3 files changed, 48 insertions, 22 deletions
diff --git a/nova/api/openstack/volume/volumes.py b/nova/api/openstack/volume/volumes.py index 45ad297a4..edad3286a 100644 --- a/nova/api/openstack/volume/volumes.py +++ b/nova/api/openstack/volume/volumes.py @@ -84,10 +84,10 @@ def _translate_volume_summary_view(context, vol): d['availabilityZone'] = vol['availability_zone'] d['createdAt'] = vol['created_at'] + d['attachments'] = [] if vol['attach_status'] == 'attached': - d['attachments'] = [_translate_attachment_detail_view(context, vol)] - else: - d['attachments'] = [{}] + attachment = _translate_attachment_detail_view(context, vol) + d['attachments'].append(attachment) d['displayName'] = vol['display_name'] d['displayDescription'] = vol['display_description'] diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 140353222..fe48dd88d 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -591,25 +591,29 @@ def stub_instance(id, user_id=None, project_id=None, host=None, return instance -def stub_volume(id): - return {'id': id, - 'user_id': 'fakeuser', - 'project_id': 'fakeproject', - 'host': 'fakehost', - 'size': 1, - 'availability_zone': 'fakeaz', - 'instance': {'uuid': 'fakeuuid'}, - 'mountpoint': '/', - 'status': 'fakestatus', - 'attach_status': 'attached', - 'name': 'vol name', - 'display_name': 'displayname', - 'display_description': 'displaydesc', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), - 'snapshot_id': None, - 'volume_type_id': 'fakevoltype', - 'volume_metadata': [], - 'volume_type': {'name': 'vol_type_name'}} +def stub_volume(id, **kwargs): + volume = { + 'id': id, + 'user_id': 'fakeuser', + 'project_id': 'fakeproject', + 'host': 'fakehost', + 'size': 1, + 'availability_zone': 'fakeaz', + 'instance': {'uuid': 'fakeuuid'}, + 'mountpoint': '/', + 'status': 'fakestatus', + 'attach_status': 'attached', + 'name': 'vol name', + 'display_name': 'displayname', + 'display_description': 'displaydesc', + 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'snapshot_id': None, + 'volume_type_id': 'fakevoltype', + 'volume_metadata': [], + 'volume_type': {'name': 'vol_type_name'}} + + volume.update(kwargs) + return volume def stub_volume_create(self, context, size, name, description, snapshot, diff --git a/nova/tests/api/openstack/volume/test_volumes.py b/nova/tests/api/openstack/volume/test_volumes.py index 9e9b5ff71..f0a21e074 100644 --- a/nova/tests/api/openstack/volume/test_volumes.py +++ b/nova/tests/api/openstack/volume/test_volumes.py @@ -135,6 +135,28 @@ class VolumeApiTest(test.TestCase): 'size': 1}} self.assertEqual(res_dict, expected) + def test_volume_show_no_attachments(self): + def stub_volume_get(self, context, volume_id): + return fakes.stub_volume(volume_id, attach_status='detached') + + self.stubs.Set(volume_api.API, 'get', stub_volume_get) + + req = fakes.HTTPRequest.blank('/v1/volumes/1') + res_dict = self.controller.show(req, 1) + expected = {'volume': {'status': 'fakestatus', + 'displayDescription': 'displaydesc', + 'availabilityZone': 'fakeaz', + 'displayName': 'displayname', + 'attachments': [], + 'volumeType': 'vol_type_name', + 'snapshotId': None, + 'metadata': {}, + 'id': '1', + 'createdAt': datetime.datetime(1, 1, 1, + 1, 1, 1), + 'size': 1}} + self.assertEqual(res_dict, expected) + def test_volume_show_no_volume(self): self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound) |
