diff options
author | Adalberto Medeiros <adalbas@linux.vnet.ibm.com> | 2013-02-14 19:17:57 -0200 |
---|---|---|
committer | Adalberto Medeiros <adalbas@linux.vnet.ibm.com> | 2013-03-01 11:31:25 -0300 |
commit | a94176e15bcaf9a557c4cf16bd83b6aedb6db07d (patch) | |
tree | 5c828a1f2f915dc15d5dab7c00cd2c1c49f20c99 | |
parent | 11764e5250dc2ea4a92cf7402271e7d4e407113f (diff) | |
download | nova-a94176e15bcaf9a557c4cf16bd83b6aedb6db07d.tar.gz nova-a94176e15bcaf9a557c4cf16bd83b6aedb6db07d.tar.xz nova-a94176e15bcaf9a557c4cf16bd83b6aedb6db07d.zip |
Add os-volumes extension to api samples
Add samples and templates to api samples for volumes extensions
Fixes: bug 1071338
Implements: blueprint nova-api-samples
Change-Id: Ia021cc4d6c29ccaa3e81f4c5fdbb7e88d9f02dc6
21 files changed, 383 insertions, 0 deletions
diff --git a/doc/api_samples/os-volumes/os-volumes-detail-resp.json b/doc/api_samples/os-volumes/os-volumes-detail-resp.json new file mode 100644 index 000000000..95be0419e --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-detail-resp.json @@ -0,0 +1,24 @@ +{ + "volumes": [ + { + "attachments": [ + { + "device": "/", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "3912f2b4-c5ba-4aec-9165-872876fe202e", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } + ], + "availabilityZone": "zone1:host1", + "createdAt": "1999-01-01T01:01:01", + "displayDescription": "Volume Description", + "displayName": "Volume Name", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "metadata": {}, + "size": 100, + "snapshotId": null, + "status": "in-use", + "volumeType": "Backup" + } + ] +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/os-volumes-detail-resp.xml b/doc/api_samples/os-volumes/os-volumes-detail-resp.xml new file mode 100644 index 000000000..b849c2d2e --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-detail-resp.xml @@ -0,0 +1,9 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumes> + <volume status="in-use" displayDescription="Volume Description" availabilityZone="zone1:host1" displayName="Volume Name" volumeType="Backup" snapshotId="None" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" createdAt="2008-12-01T11:01:55" size="100"> + <attachments> + <attachment device="/" serverId="3912f2b4-c5ba-4aec-9165-872876fe202e" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/> + </attachments> + <metadata/> + </volume> +</volumes>
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/os-volumes-get-resp.json b/doc/api_samples/os-volumes/os-volumes-get-resp.json new file mode 100644 index 000000000..5c8429cb1 --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-get-resp.json @@ -0,0 +1,22 @@ +{ + "volume": { + "attachments": [ + { + "device": "/", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "3912f2b4-c5ba-4aec-9165-872876fe202e", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } + ], + "availabilityZone": "zone1:host1", + "createdAt": "2013-02-18T14:51:18.528085", + "displayDescription": "Volume Description", + "displayName": "Volume Name", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "metadata": {}, + "size": 100, + "snapshotId": null, + "status": "in-use", + "volumeType": "Backup" + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/os-volumes-get-resp.xml b/doc/api_samples/os-volumes/os-volumes-get-resp.xml new file mode 100644 index 000000000..1a516d5d2 --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-get-resp.xml @@ -0,0 +1,7 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volume status="in-use" displayDescription="Volume Description" availabilityZone="zone1:host1" displayName="Volume Name" volumeType="Backup" snapshotId="None" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" createdAt="2008-12-01T11:01:55" size="100"> + <attachments> + <attachment device="/" serverId="3912f2b4-c5ba-4aec-9165-872876fe202e" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/> + </attachments> + <metadata/> +</volume>
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/os-volumes-index-resp.json b/doc/api_samples/os-volumes/os-volumes-index-resp.json new file mode 100644 index 000000000..c0fa4b891 --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-index-resp.json @@ -0,0 +1,24 @@ +{ + "volumes": [ + { + "attachments": [ + { + "device": "/", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "3912f2b4-c5ba-4aec-9165-872876fe202e", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } + ], + "availabilityZone": "zone1:host1", + "createdAt": "2013-02-19T20:01:40.274897", + "displayDescription": "Volume Description", + "displayName": "Volume Name", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "metadata": {}, + "size": 100, + "snapshotId": null, + "status": "in-use", + "volumeType": "Backup" + } + ] +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/os-volumes-index-resp.xml b/doc/api_samples/os-volumes/os-volumes-index-resp.xml new file mode 100644 index 000000000..b849c2d2e --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-index-resp.xml @@ -0,0 +1,9 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumes> + <volume status="in-use" displayDescription="Volume Description" availabilityZone="zone1:host1" displayName="Volume Name" volumeType="Backup" snapshotId="None" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" createdAt="2008-12-01T11:01:55" size="100"> + <attachments> + <attachment device="/" serverId="3912f2b4-c5ba-4aec-9165-872876fe202e" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/> + </attachments> + <metadata/> + </volume> +</volumes>
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/os-volumes-post-req.json b/doc/api_samples/os-volumes/os-volumes-post-req.json new file mode 100644 index 000000000..c8b218adb --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-post-req.json @@ -0,0 +1,9 @@ +{ + "volume": + { + "availability_zone": "zone1:host1", + "display_name": "Volume Name", + "display_description": "Volume Description", + "size": 100 + } +} diff --git a/doc/api_samples/os-volumes/os-volumes-post-req.xml b/doc/api_samples/os-volumes/os-volumes-post-req.xml new file mode 100644 index 000000000..68a0b5864 --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-post-req.xml @@ -0,0 +1,3 @@ +<?xml version='1.0' encoding='UTF-8'?> + <volume displayDescription="Volume Description" availabilityZone="zone1:host1" displayName="Volume Name" size="100"/> + diff --git a/doc/api_samples/os-volumes/os-volumes-post-resp.json b/doc/api_samples/os-volumes/os-volumes-post-resp.json new file mode 100644 index 000000000..ba3795a0b --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-post-resp.json @@ -0,0 +1,22 @@ +{ + "volume": { + "attachments": [ + { + "device": "/", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "3912f2b4-c5ba-4aec-9165-872876fe202e", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } + ], + "availabilityZone": "zone1:host1", + "createdAt": "2013-02-18T14:51:17.970024", + "displayDescription": "Volume Description", + "displayName": "Volume Name", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "metadata": {}, + "size": 100, + "snapshotId": null, + "status": "in-use", + "volumeType": "Backup" + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/os-volumes-post-resp.xml b/doc/api_samples/os-volumes/os-volumes-post-resp.xml new file mode 100644 index 000000000..1a516d5d2 --- /dev/null +++ b/doc/api_samples/os-volumes/os-volumes-post-resp.xml @@ -0,0 +1,7 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volume status="in-use" displayDescription="Volume Description" availabilityZone="zone1:host1" displayName="Volume Name" volumeType="Backup" snapshotId="None" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" createdAt="2008-12-01T11:01:55" size="100"> + <attachments> + <attachment device="/" serverId="3912f2b4-c5ba-4aec-9165-872876fe202e" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/> + </attachments> + <metadata/> +</volume>
\ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-detail-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-detail-resp.json.tpl new file mode 100644 index 000000000..eeca4489e --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-detail-resp.json.tpl @@ -0,0 +1,24 @@ +{ + "volumes": [ + { + "attachments": [ + { + "device": "/", + "id": "%(uuid)s", + "serverId": "%(uuid)s", + "volumeId": "%(uuid)s" + } + ], + "availabilityZone": "zone1:host1", + "createdAt": "%(timestamp)s", + "displayDescription": "%(volume_desc)s", + "displayName": "%(volume_name)s", + "id": "%(uuid)s", + "metadata": {}, + "size": 100, + "snapshotId": null, + "status": "in-use", + "volumeType": "Backup" + } + ] +} diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-detail-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-detail-resp.xml.tpl new file mode 100644 index 000000000..7410bed49 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-detail-resp.xml.tpl @@ -0,0 +1,9 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumes> + <volume status="in-use" displayDescription="%(volume_desc)s" availabilityZone="zone1:host1" displayName="%(volume_name)s" volumeType="Backup" snapshotId="None" id="%(uuid)s" createdAt="%(timestamp)s" size="100"> + <attachments> + <attachment device="/" serverId="%(uuid)s" id="%(uuid)s" volumeId="%(uuid)s"/> + </attachments> + <metadata/> + </volume> +</volumes> diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-get-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-get-resp.json.tpl new file mode 100644 index 000000000..4343e6c0a --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-get-resp.json.tpl @@ -0,0 +1,22 @@ +{ + "volume": { + "attachments": [ + { + "device": "/", + "id": "%(uuid)s", + "serverId": "%(uuid)s", + "volumeId": "%(uuid)s" + } + ], + "availabilityZone": "zone1:host1", + "createdAt": "%(timestamp)s", + "displayDescription": "%(volume_desc)s", + "displayName": "%(volume_name)s", + "id": "%(uuid)s", + "metadata": {}, + "size": 100, + "snapshotId": null, + "status": "in-use", + "volumeType": "Backup" + } +} diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-get-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-get-resp.xml.tpl new file mode 100644 index 000000000..6503138f0 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-get-resp.xml.tpl @@ -0,0 +1,7 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volume status="in-use" displayDescription="%(volume_desc)s" availabilityZone="zone1:host1" displayName="%(volume_name)s" volumeType="Backup" snapshotId="None" id="%(uuid)s" createdAt="%(timestamp)s" size="100"> + <attachments> + <attachment device="/" serverId="%(uuid)s" id="%(uuid)s" volumeId="%(uuid)s"/> + </attachments> + <metadata/> +</volume> diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-index-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-index-resp.json.tpl new file mode 100644 index 000000000..eeca4489e --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-index-resp.json.tpl @@ -0,0 +1,24 @@ +{ + "volumes": [ + { + "attachments": [ + { + "device": "/", + "id": "%(uuid)s", + "serverId": "%(uuid)s", + "volumeId": "%(uuid)s" + } + ], + "availabilityZone": "zone1:host1", + "createdAt": "%(timestamp)s", + "displayDescription": "%(volume_desc)s", + "displayName": "%(volume_name)s", + "id": "%(uuid)s", + "metadata": {}, + "size": 100, + "snapshotId": null, + "status": "in-use", + "volumeType": "Backup" + } + ] +} diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-index-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-index-resp.xml.tpl new file mode 100644 index 000000000..7410bed49 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-index-resp.xml.tpl @@ -0,0 +1,9 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumes> + <volume status="in-use" displayDescription="%(volume_desc)s" availabilityZone="zone1:host1" displayName="%(volume_name)s" volumeType="Backup" snapshotId="None" id="%(uuid)s" createdAt="%(timestamp)s" size="100"> + <attachments> + <attachment device="/" serverId="%(uuid)s" id="%(uuid)s" volumeId="%(uuid)s"/> + </attachments> + <metadata/> + </volume> +</volumes> diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-req.json.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-req.json.tpl new file mode 100644 index 000000000..db7fbff4d --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-req.json.tpl @@ -0,0 +1,9 @@ +{ + "volume": + { + "availability_zone": "zone1:host1", + "display_name": "%(volume_name)s", + "display_description": "%(volume_desc)s", + "size": 100 + } +} diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-req.xml.tpl new file mode 100644 index 000000000..bb115cc61 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-req.xml.tpl @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> + <volume displayDescription="%(volume_desc)s" availabilityZone="zone1:host1" displayName="%(volume_name)s" size="100"/> diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-resp.json.tpl new file mode 100644 index 000000000..f1a3d3ca3 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-resp.json.tpl @@ -0,0 +1,21 @@ +{ + "volume": { + "status": "in-use", + "displayDescription": "%(volume_desc)s", + "availabilityZone": "zone1:host1", + "displayName": "%(volume_name)s", + "attachments": [ + { "device": "/", + "serverId": "%(uuid)s", + "id": "%(uuid)s", + "volumeId": "%(uuid)s" + } + ], + "volumeType": "Backup", + "snapshotId": null, + "metadata": {}, + "id": "%(uuid)s", + "createdAt": "%(timestamp)s", + "size": 100 + } +} diff --git a/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-resp.xml.tpl new file mode 100644 index 000000000..6503138f0 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/os-volumes-post-resp.xml.tpl @@ -0,0 +1,7 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volume status="in-use" displayDescription="%(volume_desc)s" availabilityZone="zone1:host1" displayName="%(volume_name)s" volumeType="Backup" snapshotId="None" id="%(uuid)s" createdAt="%(timestamp)s" size="100"> + <attachments> + <attachment device="/" serverId="%(uuid)s" id="%(uuid)s" volumeId="%(uuid)s"/> + </attachments> + <metadata/> +</volume> diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index 8469e7bb4..27f5fba9a 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -3752,3 +3752,116 @@ class VolumeAttachmentsSampleJsonTest(ServersSampleBase): class VolumeAttachmentsSampleXmlTest(VolumeAttachmentsSampleJsonTest): ctype = 'xml' + + +class VolumesSampleJsonTest(ServersSampleBase): + extension_name = ("nova.api.openstack.compute.contrib.volumes.Volumes") + + def _get_volume_id(self): + return 'a26887c6-c47b-4654-abb5-dfadf7d3f803' + + def _stub_volume(self, id, displayname="Volume Name", + displaydesc="Volume Description", size=100): + volume = { + 'id': id, + 'size': size, + 'availability_zone': 'zone1:host1', + 'instance_uuid': '3912f2b4-c5ba-4aec-9165-872876fe202e', + 'mountpoint': '/', + 'status': 'in-use', + 'attach_status': 'attached', + 'name': 'vol name', + 'display_name': displayname, + 'display_description': displaydesc, + 'created_at': "2008-12-01T11:01:55", + 'snapshot_id': None, + 'volume_type_id': 'fakevoltype', + 'volume_metadata': [], + 'volume_type': {'name': 'Backup'} + } + return volume + + def _stub_volume_get(self, context, volume_id): + return self._stub_volume(volume_id) + + def _stub_volume_delete(self, context, *args, **param): + pass + + def _stub_volume_get_all(self, context, search_opts=None): + id = self._get_volume_id() + return [self._stub_volume(id)] + + def _stub_volume_create(self, context, size, name, description, snapshot, + **param): + id = self._get_volume_id() + return self._stub_volume(id) + + def setUp(self): + super(VolumesSampleJsonTest, self).setUp() + fakes.stub_out_networking(self.stubs) + fakes.stub_out_rate_limiting(self.stubs) + + self.stubs.Set(cinder.API, "delete", self._stub_volume_delete) + self.stubs.Set(cinder.API, "get", self._stub_volume_get) + self.stubs.Set(cinder.API, "get_all", self._stub_volume_get_all) + + def _post_volume(self): + subs_req = { + 'volume_name': "Volume Name", + 'volume_desc': "Volume Description", + } + + self.stubs.Set(cinder.API, "create", self._stub_volume_create) + response = self._do_post('os-volumes', 'os-volumes-post-req', + subs_req) + self.assertEqual(response.status, 200) + subs = self._get_regexes() + subs.update(subs_req) + return self._verify_response('os-volumes-post-resp', subs, response) + + def test_volumes_show(self): + subs = { + 'volume_name': "Volume Name", + 'volume_desc': "Volume Description", + } + vol_id = self._get_volume_id() + response = self._do_get('os-volumes/%s' % vol_id) + self.assertEqual(response.status, 200) + subs.update(self._get_regexes()) + return self._verify_response('os-volumes-get-resp', subs, response) + + def test_volumes_index(self): + subs = { + 'volume_name': "Volume Name", + 'volume_desc': "Volume Description", + } + response = self._do_get('os-volumes') + self.assertEqual(response.status, 200) + subs.update(self._get_regexes()) + return self._verify_response('os-volumes-index-resp', subs, response) + + def test_volumes_detail(self): + # For now, index and detail are the same. + # See the volumes api + subs = { + 'volume_name': "Volume Name", + 'volume_desc': "Volume Description", + } + response = self._do_get('os-volumes/detail') + self.assertEqual(response.status, 200) + subs.update(self._get_regexes()) + return self._verify_response('os-volumes-detail-resp', subs, response) + + def test_volumes_create(self): + return self._post_volume() + + def test_volumes_delete(self): + self._post_volume() + vol_id = self._get_volume_id() + response = self._do_delete('os-volumes/%s' % vol_id) + self.assertEqual(response.status, 202) + self.assertEqual(response.read(), '') + + +class VolumesSampleXmlTest(VolumesSampleJsonTest): + ctype = 'xml' |