diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-02-28 21:51:55 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-02-28 21:51:55 +0000 |
commit | 5ecbb78c338ad3320b33256d51f874657b93b8ff (patch) | |
tree | 36903a3a2d9a6108b2b7821207aadea050e69d64 | |
parent | 05aaea1e1c104579c9d324fb767d18f021fb9496 (diff) | |
parent | 4a1d27c4ade3c40bc28455a49eeef5a199b5098c (diff) | |
download | nova-5ecbb78c338ad3320b33256d51f874657b93b8ff.tar.gz nova-5ecbb78c338ad3320b33256d51f874657b93b8ff.tar.xz nova-5ecbb78c338ad3320b33256d51f874657b93b8ff.zip |
Merge "Adds API Sample tests for Volume Attachments"
25 files changed, 304 insertions, 0 deletions
diff --git a/doc/api_samples/os-volumes/attach-volume-to-server-req.json b/doc/api_samples/os-volumes/attach-volume-to-server-req.json new file mode 100644 index 000000000..4062687fc --- /dev/null +++ b/doc/api_samples/os-volumes/attach-volume-to-server-req.json @@ -0,0 +1,6 @@ +{ + "volumeAttachment": { + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "device": "/dev/vdd" + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/attach-volume-to-server-req.xml b/doc/api_samples/os-volumes/attach-volume-to-server-req.xml new file mode 100644 index 000000000..eedfc329a --- /dev/null +++ b/doc/api_samples/os-volumes/attach-volume-to-server-req.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<volumeAttachment volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803" device="/dev/vdd" />
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/attach-volume-to-server-resp.json b/doc/api_samples/os-volumes/attach-volume-to-server-resp.json new file mode 100644 index 000000000..2e512ac99 --- /dev/null +++ b/doc/api_samples/os-volumes/attach-volume-to-server-resp.json @@ -0,0 +1,8 @@ +{ + "volumeAttachment": { + "device": "/dev/vdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "0c92f3f6-c253-4c9b-bd43-e880a8d2eb0a", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/attach-volume-to-server-resp.xml b/doc/api_samples/os-volumes/attach-volume-to-server-resp.xml new file mode 100644 index 000000000..aaa85dd43 --- /dev/null +++ b/doc/api_samples/os-volumes/attach-volume-to-server-resp.xml @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumeAttachment device="/dev/vdd" serverId="20f0cb44-7b00-4019-a612-364777cd2931" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/>
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/list-volume-attachments-resp.json b/doc/api_samples/os-volumes/list-volume-attachments-resp.json new file mode 100644 index 000000000..9ae9b4a2a --- /dev/null +++ b/doc/api_samples/os-volumes/list-volume-attachments-resp.json @@ -0,0 +1,16 @@ +{ + "volumeAttachments": [ + { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + }, + { + "device": "/dev/sdc", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", + "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804" + } + ] +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/list-volume-attachments-resp.xml b/doc/api_samples/os-volumes/list-volume-attachments-resp.xml new file mode 100644 index 000000000..7d70882c0 --- /dev/null +++ b/doc/api_samples/os-volumes/list-volume-attachments-resp.xml @@ -0,0 +1,5 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumeAttachments> + <volumeAttachment device="/dev/sdd" serverId="4335bab6-6086-4247-8274-8b8b048edaaa" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/> + <volumeAttachment device="/dev/sdc" serverId="4335bab6-6086-4247-8274-8b8b048edaaa" id="a26887c6-c47b-4654-abb5-dfadf7d3f804" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f804"/> +</volumeAttachments>
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/server-post-req.json b/doc/api_samples/os-volumes/server-post-req.json new file mode 100644 index 000000000..d88eb4122 --- /dev/null +++ b/doc/api_samples/os-volumes/server-post-req.json @@ -0,0 +1,16 @@ +{ + "server" : { + "name" : "new-server-test", + "imageRef" : "http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b", + "flavorRef" : "http://openstack.example.com/openstack/flavors/1", + "metadata" : { + "My Server Name" : "Apache1" + }, + "personality" : [ + { + "path" : "/etc/banner.txt", + "contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==" + } + ] + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/server-post-req.xml b/doc/api_samples/os-volumes/server-post-req.xml new file mode 100644 index 000000000..0a3c8bb53 --- /dev/null +++ b/doc/api_samples/os-volumes/server-post-req.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<server xmlns="http://docs.openstack.org/compute/api/v1.1" imageRef="http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b" flavorRef="http://openstack.example.com/openstack/flavors/1" name="new-server-test"> + <metadata> + <meta key="My Server Name">Apache1</meta> + </metadata> + <personality> + <file path="/etc/banner.txt"> + ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp + dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k + IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs + c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g + QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo + ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv + dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy + c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 + b25zLiINCg0KLVJpY2hhcmQgQmFjaA== + </file> + </personality> +</server>
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/server-post-resp.json b/doc/api_samples/os-volumes/server-post-resp.json new file mode 100644 index 000000000..6ae553403 --- /dev/null +++ b/doc/api_samples/os-volumes/server-post-resp.json @@ -0,0 +1,16 @@ +{ + "server": { + "adminPass": "8VqALQcVB9MT", + "id": "a80b9477-84c1-4242-9731-14a3c2a04241", + "links": [ + { + "href": "http://openstack.example.com/v2/openstack/servers/a80b9477-84c1-4242-9731-14a3c2a04241", + "rel": "self" + }, + { + "href": "http://openstack.example.com/openstack/servers/a80b9477-84c1-4242-9731-14a3c2a04241", + "rel": "bookmark" + } + ] + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/server-post-resp.xml b/doc/api_samples/os-volumes/server-post-resp.xml new file mode 100644 index 000000000..b2474027d --- /dev/null +++ b/doc/api_samples/os-volumes/server-post-resp.xml @@ -0,0 +1,6 @@ +<?xml version='1.0' encoding='UTF-8'?> +<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="b11339a0-3a3e-496d-ade0-4539dbb5d816" adminPass="J3qyiuLMEWV3"> + <metadata/> + <atom:link href="http://openstack.example.com/v2/openstack/servers/b11339a0-3a3e-496d-ade0-4539dbb5d816" rel="self"/> + <atom:link href="http://openstack.example.com/openstack/servers/b11339a0-3a3e-496d-ade0-4539dbb5d816" rel="bookmark"/> +</server>
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/volume-attachment-detail-resp.json b/doc/api_samples/os-volumes/volume-attachment-detail-resp.json new file mode 100644 index 000000000..5375033bb --- /dev/null +++ b/doc/api_samples/os-volumes/volume-attachment-detail-resp.json @@ -0,0 +1,8 @@ +{ + "volumeAttachment": { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "2390fb4d-1693-45d7-b309-e29c4af16538", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/volume-attachment-detail-resp.xml b/doc/api_samples/os-volumes/volume-attachment-detail-resp.xml new file mode 100644 index 000000000..dea235292 --- /dev/null +++ b/doc/api_samples/os-volumes/volume-attachment-detail-resp.xml @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumeAttachment device="/dev/sdd" serverId="20f12907-3993-44f7-a680-d51e2ceedbd9" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/>
\ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-req.json.tpl b/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-req.json.tpl new file mode 100644 index 000000000..3d360a57b --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-req.json.tpl @@ -0,0 +1,6 @@ +{ + "volumeAttachment": { + "volumeId": "%(volume_id)s", + "device": "%(device)s" + } +} diff --git a/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-req.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-req.xml.tpl new file mode 100644 index 000000000..ffb20ad1e --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-req.xml.tpl @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<volumeAttachment volumeId="%(volume_id)s" device="%(device)s" /> diff --git a/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-resp.json.tpl new file mode 100644 index 000000000..4730b3c19 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-resp.json.tpl @@ -0,0 +1,8 @@ +{ + "volumeAttachment": { + "device": "%(device)s", + "id": "%(volume_id)s", + "serverId": "%(uuid)s", + "volumeId": "%(volume_id)s" + } +} diff --git a/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-resp.xml.tpl new file mode 100644 index 000000000..efad2fd02 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/attach-volume-to-server-resp.xml.tpl @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumeAttachment device="%(device)s" serverId="%(uuid)s" id="%(volume_id)s" volumeId="%(volume_id)s"/> diff --git a/nova/tests/integrated/api_samples/os-volumes/list-volume-attachments-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/list-volume-attachments-resp.json.tpl new file mode 100644 index 000000000..6c1da07ef --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/list-volume-attachments-resp.json.tpl @@ -0,0 +1,16 @@ +{ + "volumeAttachments": [ + { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "%(uuid)s", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + }, + { + "device": "/dev/sdc", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", + "serverId": "%(uuid)s", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804" + } + ] +} diff --git a/nova/tests/integrated/api_samples/os-volumes/list-volume-attachments-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/list-volume-attachments-resp.xml.tpl new file mode 100644 index 000000000..351646d81 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/list-volume-attachments-resp.xml.tpl @@ -0,0 +1,5 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumeAttachments> + <volumeAttachment device="/dev/sdd" serverId="%(uuid)s" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/> + <volumeAttachment device="/dev/sdc" serverId="%(uuid)s" id="a26887c6-c47b-4654-abb5-dfadf7d3f804" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f804"/> +</volumeAttachments> diff --git a/nova/tests/integrated/api_samples/os-volumes/server-post-req.json.tpl b/nova/tests/integrated/api_samples/os-volumes/server-post-req.json.tpl new file mode 100644 index 000000000..d3916d1aa --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/server-post-req.json.tpl @@ -0,0 +1,16 @@ +{ + "server" : { + "name" : "new-server-test", + "imageRef" : "%(host)s/openstack/images/%(image_id)s", + "flavorRef" : "%(host)s/openstack/flavors/1", + "metadata" : { + "My Server Name" : "Apache1" + }, + "personality" : [ + { + "path" : "/etc/banner.txt", + "contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==" + } + ] + } +} diff --git a/nova/tests/integrated/api_samples/os-volumes/server-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/server-post-req.xml.tpl new file mode 100644 index 000000000..f92614984 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/server-post-req.xml.tpl @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<server xmlns="http://docs.openstack.org/compute/api/v1.1" imageRef="%(host)s/openstack/images/%(image_id)s" flavorRef="%(host)s/openstack/flavors/1" name="new-server-test"> + <metadata> + <meta key="My Server Name">Apache1</meta> + </metadata> + <personality> + <file path="/etc/banner.txt"> + ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp + dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k + IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs + c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g + QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo + ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv + dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy + c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 + b25zLiINCg0KLVJpY2hhcmQgQmFjaA== + </file> + </personality> +</server> diff --git a/nova/tests/integrated/api_samples/os-volumes/server-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/server-post-resp.json.tpl new file mode 100644 index 000000000..d5f030c87 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/server-post-resp.json.tpl @@ -0,0 +1,16 @@ +{ + "server": { + "adminPass": "%(password)s", + "id": "%(id)s", + "links": [ + { + "href": "%(host)s/v2/openstack/servers/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/openstack/servers/%(uuid)s", + "rel": "bookmark" + } + ] + } +} diff --git a/nova/tests/integrated/api_samples/os-volumes/server-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/server-post-resp.xml.tpl new file mode 100644 index 000000000..3bb13e69b --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/server-post-resp.xml.tpl @@ -0,0 +1,6 @@ +<?xml version='1.0' encoding='UTF-8'?> +<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="%(id)s" adminPass="%(password)s"> + <metadata/> + <atom:link href="%(host)s/v2/openstack/servers/%(uuid)s" rel="self"/> + <atom:link href="%(host)s/openstack/servers/%(uuid)s" rel="bookmark"/> +</server> diff --git a/nova/tests/integrated/api_samples/os-volumes/volume-attachment-detail-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/volume-attachment-detail-resp.json.tpl new file mode 100644 index 000000000..86099eeb8 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/volume-attachment-detail-resp.json.tpl @@ -0,0 +1,8 @@ +{ + "volumeAttachment": { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "%(uuid)s", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } +} diff --git a/nova/tests/integrated/api_samples/os-volumes/volume-attachment-detail-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/volume-attachment-detail-resp.xml.tpl new file mode 100644 index 000000000..45fd19979 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-volumes/volume-attachment-detail-resp.xml.tpl @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<volumeAttachment device="/dev/sdd" serverId="%(uuid)s" id="a26887c6-c47b-4654-abb5-dfadf7d3f803" volumeId="a26887c6-c47b-4654-abb5-dfadf7d3f803"/> diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index be17c020c..8469e7bb4 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -33,6 +33,7 @@ from nova.api.openstack.compute.contrib import fping # Import extensions to pull in osapi_compute_extension CONF option used below. from nova.cloudpipe import pipelib from nova.compute import api as compute_api +from nova.compute import manager as compute_manager from nova import context from nova import db from nova.db.sqlalchemy import models @@ -3660,3 +3661,94 @@ class SnapshotsSampleJsonTests(ApiSampleTestBase): class SnapshotsSampleXmlTests(SnapshotsSampleJsonTests): ctype = "xml" + + +class VolumeAttachmentsSampleJsonTest(ServersSampleBase): + extension_name = ("nova.api.openstack.compute.contrib.volumes.Volumes") + + def test_attach_volume_to_server(self): + device_name = '/dev/vdd' + self.stubs.Set(cinder.API, 'get', fakes.stub_volume_get) + self.stubs.Set(cinder.API, 'check_attach', lambda *a, **k: None) + self.stubs.Set(cinder.API, 'reserve_volume', lambda *a, **k: None) + self.stubs.Set(compute_manager.ComputeManager, + "reserve_block_device_name", + lambda *a, **k: device_name) + + volume = fakes.stub_volume_get(None, context.get_admin_context(), + 'a26887c6-c47b-4654-abb5-dfadf7d3f803') + subs = { + 'volume_id': volume['id'], + 'device': device_name + } + server_id = self._post_server() + response = self._do_post('servers/%s/os-volume_attachments' + % server_id, + 'attach-volume-to-server-req', subs) + + self.assertEqual(response.status, 200) + subs.update(self._get_regexes()) + self._verify_response('attach-volume-to-server-resp', + subs, response) + + def _stub_compute_api_get_instance_bdms(self, server_id): + + def fake_compute_api_get_instance_bdms(self, context, instance): + bdms = [ + {'volume_id': 'a26887c6-c47b-4654-abb5-dfadf7d3f803', + 'instance_uuid': server_id, + 'device_name': '/dev/sdd'}, + {'volume_id': 'a26887c6-c47b-4654-abb5-dfadf7d3f804', + 'instance_uuid': server_id, + 'device_name': '/dev/sdc'} + ] + return bdms + + self.stubs.Set(compute_api.API, "get_instance_bdms", + fake_compute_api_get_instance_bdms) + + def _stub_compute_api_get(self): + + def fake_compute_api_get(self, context, instance_id): + return {'uuid': instance_id} + + self.stubs.Set(compute_api.API, 'get', fake_compute_api_get) + + def test_list_volume_attachments(self): + server_id = self._post_server() + + self._stub_compute_api_get_instance_bdms(server_id) + + response = self._do_get('servers/%s/os-volume_attachments' + % server_id) + self.assertEqual(response.status, 200) + subs = self._get_regexes() + self._verify_response('list-volume-attachments-resp', + subs, response) + + def test_volume_attachment_detail(self): + server_id = self._post_server() + attach_id = "a26887c6-c47b-4654-abb5-dfadf7d3f803" + self._stub_compute_api_get_instance_bdms(server_id) + self._stub_compute_api_get() + response = self._do_get('servers/%s/os-volume_attachments/%s' + % (server_id, attach_id)) + self.assertEqual(response.status, 200) + subs = self._get_regexes() + self._verify_response('volume-attachment-detail-resp', + subs, response) + + def test_volume_attachment_delete(self): + server_id = self._post_server() + attach_id = "a26887c6-c47b-4654-abb5-dfadf7d3f803" + self._stub_compute_api_get_instance_bdms(server_id) + self._stub_compute_api_get() + self.stubs.Set(compute_api.API, 'detach_volume', lambda *a, **k: None) + response = self._do_delete('servers/%s/os-volume_attachments/%s' + % (server_id, attach_id)) + self.assertEqual(response.status, 202) + self.assertEqual(response.read(), '') + + +class VolumeAttachmentsSampleXmlTest(VolumeAttachmentsSampleJsonTest): + ctype = 'xml' |