From fccf0ca795f7c7a5991af715734de344e8be8fde Mon Sep 17 00:00:00 2001 From: Chris Yeoh <cyeoh@au1.ibm.com> Date: Thu, 5 Sep 2013 18:44:35 +0930 Subject: [PATCH] Adds V3 API samples for attach-interfaces Adds api sample tests and api samples for attach interfaces Partially implements blueprint v3-api-unittests Partially implements blueprint v3-api-specification Change-Id: I54088cca1b83a8b92620062840606f2340a528c9 --- .../attach-interfaces-create-req.json | 5 + .../attach-interfaces-create-req.xml | 4 + .../attach-interfaces-create-resp.json | 14 ++ .../attach-interfaces-create-resp.xml | 13 ++ .../attach-interfaces-list-resp.json | 16 ++ .../attach-interfaces-list-resp.xml | 15 ++ .../attach-interfaces-show-resp.json | 14 ++ .../attach-interfaces-show-resp.xml | 13 ++ .../os-attach-interfaces/server-post-req.json | 16 ++ .../os-attach-interfaces/server-post-req.xml | 19 ++ .../server-post-resp.json | 16 ++ .../os-attach-interfaces/server-post-resp.xml | 6 + .../attach-interfaces-create-req.json.tpl | 5 + .../attach-interfaces-create-req.xml.tpl | 4 + .../attach-interfaces-create-resp.json.tpl | 14 ++ .../attach-interfaces-create-resp.xml.tpl | 13 ++ .../attach-interfaces-list-resp.json.tpl | 16 ++ .../attach-interfaces-list-resp.xml.tpl | 15 ++ .../attach-interfaces-show-resp.json.tpl | 14 ++ .../attach-interfaces-show-resp.xml.tpl | 13 ++ .../server-post-req.json.tpl | 16 ++ .../server-post-req.xml.tpl | 19 ++ .../server-post-resp.json.tpl | 16 ++ .../server-post-resp.xml.tpl | 6 + .../integrated/v3/test_attach_interfaces.py | 171 ++++++++++++++++++ 25 files changed, 473 insertions(+) create mode 100644 doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.json create mode 100644 doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.xml create mode 100644 doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json create mode 100644 doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.xml create mode 100644 doc/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json create mode 100644 doc/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.xml create mode 100644 doc/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json create mode 100644 doc/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.xml create mode 100644 doc/v3/api_samples/os-attach-interfaces/server-post-req.json create mode 100644 doc/v3/api_samples/os-attach-interfaces/server-post-req.xml create mode 100644 doc/v3/api_samples/os-attach-interfaces/server-post-resp.json create mode 100644 doc/v3/api_samples/os-attach-interfaces/server-post-resp.xml create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-req.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-req.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/test_attach_interfaces.py diff --git a/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.json b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.json new file mode 100644 index 000000000000..af7bdd7af466 --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.json @@ -0,0 +1,5 @@ +{ + "interface_attachment": { + "port_id": "ce531f90-199f-48c0-816c-13e38010b442" + } +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.xml b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.xml new file mode 100644 index 000000000000..c11f5bcb4602 --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface_attachment> + <port_id>ce531f90-199f-48c0-816c-13e38010b442</port_id> +</interface_attachment> \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json new file mode 100644 index 000000000000..93b68d9c694d --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json @@ -0,0 +1,14 @@ +{ + "interface_attachment": { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE" + } +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.xml b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.xml new file mode 100644 index 000000000000..3da28042742d --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.xml @@ -0,0 +1,13 @@ +<?xml version='1.0' encoding='UTF-8'?> +<interface_attachment> + <port_state>ACTIVE</port_state> + <fixed_ips> + <fixed_ip> + <subnet_id>f8a6e8f8-c2ec-497c-9f23-da9616de54ef</subnet_id> + <ip_address>192.168.1.3</ip_address> + </fixed_ip> + </fixed_ips> + <port_id>ce531f90-199f-48c0-816c-13e38010b442</port_id> + <net_id>3cb9bc59-5699-4588-a4b1-b87f96708bc6</net_id> + <mac_addr>fa:16:3e:4c:2c:30</mac_addr> +</interface_attachment> \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json new file mode 100644 index 000000000000..9d977378b779 --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json @@ -0,0 +1,16 @@ +{ + "interface_attachments": [ + { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE" + } + ] +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.xml b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.xml new file mode 100644 index 000000000000..236f7b96a198 --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.xml @@ -0,0 +1,15 @@ +<?xml version='1.0' encoding='UTF-8'?> +<interface_attachments> + <interface_attachment> + <port_state>ACTIVE</port_state> + <fixed_ips> + <fixed_ip> + <subnet_id>f8a6e8f8-c2ec-497c-9f23-da9616de54ef</subnet_id> + <ip_address>192.168.1.3</ip_address> + </fixed_ip> + </fixed_ips> + <port_id>ce531f90-199f-48c0-816c-13e38010b442</port_id> + <net_id>3cb9bc59-5699-4588-a4b1-b87f96708bc6</net_id> + <mac_addr>fa:16:3e:4c:2c:30</mac_addr> + </interface_attachment> +</interface_attachments> \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json new file mode 100644 index 000000000000..93b68d9c694d --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json @@ -0,0 +1,14 @@ +{ + "interface_attachment": { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE" + } +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.xml b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.xml new file mode 100644 index 000000000000..3da28042742d --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.xml @@ -0,0 +1,13 @@ +<?xml version='1.0' encoding='UTF-8'?> +<interface_attachment> + <port_state>ACTIVE</port_state> + <fixed_ips> + <fixed_ip> + <subnet_id>f8a6e8f8-c2ec-497c-9f23-da9616de54ef</subnet_id> + <ip_address>192.168.1.3</ip_address> + </fixed_ip> + </fixed_ips> + <port_id>ce531f90-199f-48c0-816c-13e38010b442</port_id> + <net_id>3cb9bc59-5699-4588-a4b1-b87f96708bc6</net_id> + <mac_addr>fa:16:3e:4c:2c:30</mac_addr> +</interface_attachment> \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/server-post-req.json b/doc/v3/api_samples/os-attach-interfaces/server-post-req.json new file mode 100644 index 000000000000..d41985a1bc39 --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/server-post-req.json @@ -0,0 +1,16 @@ +{ + "server" : { + "name" : "new-server-test", + "image_ref" : "http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b", + "flavor_ref" : "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/v3/api_samples/os-attach-interfaces/server-post-req.xml b/doc/v3/api_samples/os-attach-interfaces/server-post-req.xml new file mode 100644 index 000000000000..598839cf6a3a --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/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" image_ref="http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b" flavor_ref="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/v3/api_samples/os-attach-interfaces/server-post-resp.json b/doc/v3/api_samples/os-attach-interfaces/server-post-resp.json new file mode 100644 index 000000000000..8ff309c4a481 --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/server-post-resp.json @@ -0,0 +1,16 @@ +{ + "server": { + "admin_pass": "fjPxt8d8YcSR", + "id": "c937be78-c423-495b-a99a-e590ab6f30ba", + "links": [ + { + "href": "http://openstack.example.com/v3/servers/c937be78-c423-495b-a99a-e590ab6f30ba", + "rel": "self" + }, + { + "href": "http://openstack.example.com/servers/c937be78-c423-495b-a99a-e590ab6f30ba", + "rel": "bookmark" + } + ] + } +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-attach-interfaces/server-post-resp.xml b/doc/v3/api_samples/os-attach-interfaces/server-post-resp.xml new file mode 100644 index 000000000000..ef42392064a9 --- /dev/null +++ b/doc/v3/api_samples/os-attach-interfaces/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="df8ced02-6e8e-447f-817e-eed7b4546931" admin_pass="h2kBdURmTqv4"> + <metadata/> + <atom:link href="http://openstack.example.com/v3/servers/df8ced02-6e8e-447f-817e-eed7b4546931" rel="self"/> + <atom:link href="http://openstack.example.com/servers/df8ced02-6e8e-447f-817e-eed7b4546931" rel="bookmark"/> +</server> \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.json.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.json.tpl new file mode 100644 index 000000000000..e0fcbe86a03d --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.json.tpl @@ -0,0 +1,5 @@ +{ + "interface_attachment": { + "port_id": "ce531f90-199f-48c0-816c-13e38010b442" + } +} diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.xml.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.xml.tpl new file mode 100644 index 000000000000..a4a541685086 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-req.xml.tpl @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface_attachment> + <port_id>%(port_id)s</port_id> +</interface_attachment> diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json.tpl new file mode 100644 index 000000000000..93b68d9c694d --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json.tpl @@ -0,0 +1,14 @@ +{ + "interface_attachment": { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE" + } +} \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.xml.tpl new file mode 100644 index 000000000000..3da28042742d --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-create-resp.xml.tpl @@ -0,0 +1,13 @@ +<?xml version='1.0' encoding='UTF-8'?> +<interface_attachment> + <port_state>ACTIVE</port_state> + <fixed_ips> + <fixed_ip> + <subnet_id>f8a6e8f8-c2ec-497c-9f23-da9616de54ef</subnet_id> + <ip_address>192.168.1.3</ip_address> + </fixed_ip> + </fixed_ips> + <port_id>ce531f90-199f-48c0-816c-13e38010b442</port_id> + <net_id>3cb9bc59-5699-4588-a4b1-b87f96708bc6</net_id> + <mac_addr>fa:16:3e:4c:2c:30</mac_addr> +</interface_attachment> \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json.tpl new file mode 100644 index 000000000000..9d977378b779 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json.tpl @@ -0,0 +1,16 @@ +{ + "interface_attachments": [ + { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE" + } + ] +} \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.xml.tpl new file mode 100644 index 000000000000..236f7b96a198 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-list-resp.xml.tpl @@ -0,0 +1,15 @@ +<?xml version='1.0' encoding='UTF-8'?> +<interface_attachments> + <interface_attachment> + <port_state>ACTIVE</port_state> + <fixed_ips> + <fixed_ip> + <subnet_id>f8a6e8f8-c2ec-497c-9f23-da9616de54ef</subnet_id> + <ip_address>192.168.1.3</ip_address> + </fixed_ip> + </fixed_ips> + <port_id>ce531f90-199f-48c0-816c-13e38010b442</port_id> + <net_id>3cb9bc59-5699-4588-a4b1-b87f96708bc6</net_id> + <mac_addr>fa:16:3e:4c:2c:30</mac_addr> + </interface_attachment> +</interface_attachments> \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json.tpl new file mode 100644 index 000000000000..93b68d9c694d --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json.tpl @@ -0,0 +1,14 @@ +{ + "interface_attachment": { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE" + } +} \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.xml.tpl new file mode 100644 index 000000000000..3da28042742d --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/attach-interfaces-show-resp.xml.tpl @@ -0,0 +1,13 @@ +<?xml version='1.0' encoding='UTF-8'?> +<interface_attachment> + <port_state>ACTIVE</port_state> + <fixed_ips> + <fixed_ip> + <subnet_id>f8a6e8f8-c2ec-497c-9f23-da9616de54ef</subnet_id> + <ip_address>192.168.1.3</ip_address> + </fixed_ip> + </fixed_ips> + <port_id>ce531f90-199f-48c0-816c-13e38010b442</port_id> + <net_id>3cb9bc59-5699-4588-a4b1-b87f96708bc6</net_id> + <mac_addr>fa:16:3e:4c:2c:30</mac_addr> +</interface_attachment> \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-req.json.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-req.json.tpl new file mode 100644 index 000000000000..1dcb63e3b2ae --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-req.json.tpl @@ -0,0 +1,16 @@ +{ + "server" : { + "name" : "new-server-test", + "image_ref" : "%(host)s/openstack/images/%(image_id)s", + "flavor_ref" : "%(host)s/openstack/flavors/1", + "metadata" : { + "My Server Name" : "Apache1" + }, + "personality" : [ + { + "path" : "/etc/banner.txt", + "contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==" + } + ] + } +} diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-req.xml.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-req.xml.tpl new file mode 100644 index 000000000000..ddb5ea78c4b5 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/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" image_ref="%(host)s/openstack/images/%(image_id)s" flavor_ref="%(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/v3/api_samples/os-attach-interfaces/server-post-resp.json.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-resp.json.tpl new file mode 100644 index 000000000000..6c3100fbec86 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-resp.json.tpl @@ -0,0 +1,16 @@ +{ + "server": { + "admin_pass": "%(password)s", + "id": "%(id)s", + "links": [ + { + "href": "http://openstack.example.com/v3/servers/%(uuid)s", + "rel": "self" + }, + { + "href": "http://openstack.example.com/servers/%(uuid)s", + "rel": "bookmark" + } + ] + } +} diff --git a/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/server-post-resp.xml.tpl new file mode 100644 index 000000000000..3470373e171f --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-attach-interfaces/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" admin_pass="%(password)s"> + <metadata/> + <atom:link href="%(host)s/v3/servers/%(uuid)s" rel="self"/> + <atom:link href="%(host)s/servers/%(uuid)s" rel="bookmark"/> +</server> diff --git a/nova/tests/integrated/v3/test_attach_interfaces.py b/nova/tests/integrated/v3/test_attach_interfaces.py new file mode 100644 index 000000000000..16175ba111a2 --- /dev/null +++ b/nova/tests/integrated/v3/test_attach_interfaces.py @@ -0,0 +1,171 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright 2012 Nebula, Inc. +# Copyright 2013 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from nova.compute import api as compute_api +from nova import exception +from nova.network import api as network_api +from nova.tests import fake_network_cache_model +from nova.tests.integrated.v3 import test_servers + + +class AttachInterfacesSampleJsonTest(test_servers.ServersSampleBase): + extension_name = 'os-attach-interfaces' + + def setUp(self): + super(AttachInterfacesSampleJsonTest, self).setUp() + + def fake_list_ports(self, *args, **kwargs): + uuid = kwargs.get('device_id', None) + if not uuid: + raise exception.InstanceNotFound(instance_id=None) + port_data = { + "id": "ce531f90-199f-48c0-816c-13e38010b442", + "network_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "admin_state_up": True, + "status": "ACTIVE", + "mac_address": "fa:16:3e:4c:2c:30", + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "device_id": uuid, + } + ports = {'ports': [port_data]} + return ports + + def fake_show_port(self, context, port_id=None): + if not port_id: + raise exception.PortNotFound(port_id=None) + port_data = { + "id": port_id, + "network_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "admin_state_up": True, + "status": "ACTIVE", + "mac_address": "fa:16:3e:4c:2c:30", + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "device_id": 'bece68a3-2f8b-4e66-9092-244493d6aba7', + } + port = {'port': port_data} + return port + + def fake_attach_interface(self, context, instance, + network_id, port_id, + requested_ip='192.168.1.3'): + if not network_id: + network_id = "fake_net_uuid" + if not port_id: + port_id = "fake_port_uuid" + vif = fake_network_cache_model.new_vif() + vif['id'] = port_id + vif['network']['id'] = network_id + vif['network']['subnets'][0]['ips'][0] = requested_ip + return vif + + def fake_detach_interface(self, context, instance, port_id): + pass + + self.stubs.Set(network_api.API, 'list_ports', fake_list_ports) + self.stubs.Set(network_api.API, 'show_port', fake_show_port) + self.stubs.Set(compute_api.API, 'attach_interface', + fake_attach_interface) + self.stubs.Set(compute_api.API, 'detach_interface', + fake_detach_interface) + self.flags(neutron_auth_strategy=None) + self.flags(neutron_url='http://anyhost/') + self.flags(neutron_url_timeout=30) + + def generalize_subs(self, subs, vanilla_regexes): + subs['subnet_id'] = vanilla_regexes['uuid'] + subs['net_id'] = vanilla_regexes['uuid'] + subs['port_id'] = vanilla_regexes['uuid'] + subs['mac_addr'] = '(?:[a-f0-9]{2}:){5}[a-f0-9]{2}' + subs['ip_address'] = vanilla_regexes['ip'] + return subs + + def test_list_interfaces(self): + instance_uuid = self._post_server() + response = self._do_get('servers/%s/os-attach-interfaces' + % instance_uuid) + subs = { + 'ip_address': '192.168.1.3', + 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', + 'mac_addr': 'fa:16:3e:4c:2c:30', + 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', + 'port_id': 'ce531f90-199f-48c0-816c-13e38010b442', + 'port_state': 'ACTIVE' + } + self._verify_response('attach-interfaces-list-resp', subs, + response, 200) + + def _stub_show_for_instance(self, instance_uuid, port_id): + show_port = network_api.API().show_port(None, port_id) + show_port['port']['device_id'] = instance_uuid + self.stubs.Set(network_api.API, 'show_port', lambda *a, **k: show_port) + + def test_show_interfaces(self): + instance_uuid = self._post_server() + port_id = 'ce531f90-199f-48c0-816c-13e38010b442' + self._stub_show_for_instance(instance_uuid, port_id) + response = self._do_get('servers/%s/os-attach-interfaces/%s' % + (instance_uuid, port_id)) + subs = { + 'ip_address': '192.168.1.3', + 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', + 'mac_addr': 'fa:16:3e:4c:2c:30', + 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', + 'port_id': port_id, + 'port_state': 'ACTIVE' + } + self._verify_response('attach-interfaces-show-resp', subs, + response, 200) + + def test_create_interfaces(self, instance_uuid=None): + if instance_uuid is None: + instance_uuid = self._post_server() + subs = { + 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', + 'port_id': 'ce531f90-199f-48c0-816c-13e38010b442', + 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', + 'ip_address': '192.168.1.3', + 'port_state': 'ACTIVE', + 'mac_addr': 'fa:16:3e:4c:2c:30', + } + self._stub_show_for_instance(instance_uuid, subs['port_id']) + response = self._do_post('servers/%s/os-attach-interfaces' + % instance_uuid, + 'attach-interfaces-create-req', subs) + subs.update(self._get_regexes()) + self._verify_response('attach-interfaces-create-resp', subs, + response, 200) + + def test_delete_interfaces(self): + instance_uuid = self._post_server() + port_id = 'ce531f90-199f-48c0-816c-13e38010b442' + response = self._do_delete('servers/%s/os-attach-interfaces/%s' % + (instance_uuid, port_id)) + self.assertEqual(response.status, 202) + self.assertEqual(response.read(), '') + + +class AttachInterfacesSampleXmlTest(AttachInterfacesSampleJsonTest): + ctype = 'xml'