diff options
| author | Anthony Young <sleepsonthefloor@gmail.com> | 2012-01-16 13:41:48 -0800 |
|---|---|---|
| committer | Anthony Young <sleepsonthefloor@gmail.com> | 2012-01-16 13:48:41 -0800 |
| commit | c1cf917bceeabdddf6f14bc0e51663e1df382677 (patch) | |
| tree | 37d055d53dcddc54e49100a0cb3c12dafce577e3 | |
| parent | f673db9b2c21d4709db467a633f1279796b6d085 (diff) | |
| download | nova-c1cf917bceeabdddf6f14bc0e51663e1df382677.tar.gz nova-c1cf917bceeabdddf6f14bc0e51663e1df382677.tar.xz nova-c1cf917bceeabdddf6f14bc0e51663e1df382677.zip | |
Add tests for volume list and detail through new volume api, and fix error that the tests caught
Change-Id: I6c706e4681cf079caab614b0870315b275339028
| -rw-r--r-- | nova/api/openstack/volume/volumes.py | 28 | ||||
| -rw-r--r-- | nova/tests/api/openstack/volume/test_volumes.py | 83 |
2 files changed, 110 insertions, 1 deletions
diff --git a/nova/api/openstack/volume/volumes.py b/nova/api/openstack/volume/volumes.py index 6783244d6..b37a56374 100644 --- a/nova/api/openstack/volume/volumes.py +++ b/nova/api/openstack/volume/volumes.py @@ -34,6 +34,34 @@ LOG = logging.getLogger("nova.api.openstack.volume.volumes") FLAGS = flags.FLAGS +def _translate_attachment_detail_view(_context, vol): + """Maps keys for attachment details view.""" + + d = _translate_attachment_summary_view(_context, vol) + + # No additional data / lookups at the moment + + return d + + +def _translate_attachment_summary_view(_context, vol): + """Maps keys for attachment summary view.""" + d = {} + + volume_id = vol['id'] + + # NOTE(justinsb): We use the volume id as the id of the attachment object + d['id'] = volume_id + + d['volumeId'] = volume_id + if vol.get('instance'): + d['serverId'] = vol['instance']['uuid'] + if vol.get('mountpoint'): + d['device'] = vol['mountpoint'] + + return d + + def _translate_volume_detail_view(context, vol): """Maps keys for volumes details view.""" diff --git a/nova/tests/api/openstack/volume/test_volumes.py b/nova/tests/api/openstack/volume/test_volumes.py index d2738b531..8e936fd56 100644 --- a/nova/tests/api/openstack/volume/test_volumes.py +++ b/nova/tests/api/openstack/volume/test_volumes.py @@ -16,15 +16,96 @@ import datetime from lxml import etree +import webob -from nova.api.openstack.volume import volumes from nova import flags from nova import test +from nova.api.openstack.volume import volumes +from nova.tests.api.openstack import fakes +from nova.volume import api as volume_api FLAGS = flags.FLAGS +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', + 'display_name': 'displayname', + 'display_description': 'displaydesc', + 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'snapshot_id': None, + 'volume_type_id': 'fakevoltype', + 'volume_type': {'name': 'vol_type_name'}} + + +def stub_volume_get_all(context, search_opts=None): + return [stub_volume(1)] + + +class VolumeTest(test.TestCase): + def setUp(self): + super(VolumeTest, self).setUp() + self.controller = volumes.VolumeController() + + def tearDown(self): + super(VolumeTest, self).tearDown() + + def test_volume_list(self): + self.stubs.Set(volume_api.API, 'get_all', + stub_volume_get_all) + + req = fakes.HTTPRequest.blank('/v1/volumes') + res_dict = self.controller.index(req) + expected = {'volumes': [{'status': 'fakestatus', + 'displayDescription': 'displaydesc', + 'availabilityZone': 'fakeaz', + 'displayName': 'displayname', + 'attachments': [{'device': '/', + 'serverId': 'fakeuuid', + 'id': 1, + 'volumeId': 1}], + '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_list_detail(self): + self.stubs.Set(volume_api.API, 'get_all', + stub_volume_get_all) + + req = fakes.HTTPRequest.blank('/v1/volumes/detail') + res_dict = self.controller.index(req) + expected = {'volumes': [{'status': 'fakestatus', + 'displayDescription': 'displaydesc', + 'availabilityZone': 'fakeaz', + 'displayName': 'displayname', + 'attachments': [{'device': '/', + 'serverId': 'fakeuuid', + 'id': 1, + 'volumeId': 1}], + '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) + + class VolumeSerializerTest(test.TestCase): def _verify_volume_attachment(self, attach, tree): for attr in ('id', 'volumeId', 'serverId', 'device'): |
