From 6ee525dd7df17b7da7361d9d8e9573983fdae873 Mon Sep 17 00:00:00 2001 From: Chris Yeoh Date: Fri, 26 Jul 2013 13:12:26 +0930 Subject: [PATCH] Adds infra for v3 API sample creation Adds the required infrastructure for the v3 API sample creation. - v3 API samples and the test cases are in their own v3 directory - API samples from "core" are now put in their own (per plugin) directory rather than in the root directory - Testcases to create api samples are now placed in individual files rather than one giant one. I think it makes it clearer what testcases we do have and avoids merge conflict pain Adds API samples for basic servers interaction Fix for bug in servers.py where if no extension was loaded which extends create xml deserialization an exception would occur (fixed here because it causes the api sample tests ported to fail). Partially implements blueprint v3-api-unittests Change-Id: I653af49dcc499c18f14b6e1764711a9922354069 --- .../api_samples/servers/server-get-resp.json | 56 +++++++++++++ .../api_samples/servers/server-get-resp.xml | 19 +++++ .../api_samples/servers/server-post-req.json | 16 ++++ .../api_samples/servers/server-post-req.xml | 19 +++++ .../api_samples/servers/server-post-resp.json | 16 ++++ .../api_samples/servers/server-post-resp.xml | 6 ++ .../servers/servers-details-resp.json | 58 ++++++++++++++ .../servers/servers-details-resp.xml | 21 +++++ .../servers/servers-list-resp.json | 18 +++++ .../api_samples/servers/servers-list-resp.xml | 7 ++ .../openstack/compute/plugins/v3/servers.py | 7 +- nova/tests/integrated/v3/__init__.py | 0 nova/tests/integrated/v3/api_sample_base.py | 80 +++++++++++++++++++ .../servers/server-get-resp.json.tpl | 56 +++++++++++++ .../servers/server-get-resp.xml.tpl | 19 +++++ .../servers/server-post-req.json.tpl | 16 ++++ .../servers/server-post-req.xml.tpl | 19 +++++ .../servers/server-post-resp.json.tpl | 16 ++++ .../servers/server-post-resp.xml.tpl | 6 ++ .../servers/servers-details-resp.json.tpl | 58 ++++++++++++++ .../servers/servers-details-resp.xml.tpl | 21 +++++ .../servers/servers-list-resp.json.tpl | 18 +++++ .../servers/servers-list-resp.xml.tpl | 7 ++ nova/tests/integrated/v3/test_servers.py | 67 ++++++++++++++++ 24 files changed, 623 insertions(+), 3 deletions(-) create mode 100644 doc/v3/api_samples/servers/server-get-resp.json create mode 100644 doc/v3/api_samples/servers/server-get-resp.xml create mode 100644 doc/v3/api_samples/servers/server-post-req.json create mode 100644 doc/v3/api_samples/servers/server-post-req.xml create mode 100644 doc/v3/api_samples/servers/server-post-resp.json create mode 100644 doc/v3/api_samples/servers/server-post-resp.xml create mode 100644 doc/v3/api_samples/servers/servers-details-resp.json create mode 100644 doc/v3/api_samples/servers/servers-details-resp.xml create mode 100644 doc/v3/api_samples/servers/servers-list-resp.json create mode 100644 doc/v3/api_samples/servers/servers-list-resp.xml create mode 100644 nova/tests/integrated/v3/__init__.py create mode 100644 nova/tests/integrated/v3/api_sample_base.py create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-get-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-get-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-post-req.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-post-req.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-post-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-post-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/servers-details-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/servers-details-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/servers-list-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/servers-list-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/test_servers.py diff --git a/doc/v3/api_samples/servers/server-get-resp.json b/doc/v3/api_samples/servers/server-get-resp.json new file mode 100644 index 000000000000..074ec35f7b98 --- /dev/null +++ b/doc/v3/api_samples/servers/server-get-resp.json @@ -0,0 +1,56 @@ +{ + "server": { + "access_ip_v4": "", + "access_ip_v6": "", + "addresses": { + "private": [ + { + "addr": "192.168.0.3", + "mac_addr": "aa:bb:cc:dd:ee:ff", + "type": "fixed", + "version": 4 + } + ] + }, + "created": "2013-08-09T05:47:55Z", + "flavor": { + "id": "1", + "links": [ + { + "href": "http://openstack.example.com/flavors/1", + "rel": "bookmark" + } + ] + }, + "host_id": "9bc5b8424de645fd39f9edd242992c6be364eddefc936296fad0c582", + "id": "4fc3ceca-91ec-47e7-85ee-ce9834e8ddbb", + "image": { + "id": "70a599e0-31e7-49b7-b260-868f441e862b", + "links": [ + { + "href": "http://openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "http://openstack.example.com/v3/servers/4fc3ceca-91ec-47e7-85ee-ce9834e8ddbb", + "rel": "self" + }, + { + "href": "http://openstack.example.com/servers/4fc3ceca-91ec-47e7-85ee-ce9834e8ddbb", + "rel": "bookmark" + } + ], + "metadata": { + "My Server Name": "Apache1" + }, + "name": "new-server-test", + "progress": 0, + "status": "ACTIVE", + "tenant_id": "openstack", + "updated": "2013-08-09T05:47:55Z", + "user_id": "fake" + } +} \ No newline at end of file diff --git a/doc/v3/api_samples/servers/server-get-resp.xml b/doc/v3/api_samples/servers/server-get-resp.xml new file mode 100644 index 000000000000..d4b56ffc1352 --- /dev/null +++ b/doc/v3/api_samples/servers/server-get-resp.xml @@ -0,0 +1,19 @@ + + + + + + + + + + Apache1 + + + + + + + + + \ No newline at end of file diff --git a/doc/v3/api_samples/servers/server-post-req.json b/doc/v3/api_samples/servers/server-post-req.json new file mode 100644 index 000000000000..d41985a1bc39 --- /dev/null +++ b/doc/v3/api_samples/servers/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/servers/server-post-req.xml b/doc/v3/api_samples/servers/server-post-req.xml new file mode 100644 index 000000000000..598839cf6a3a --- /dev/null +++ b/doc/v3/api_samples/servers/server-post-req.xml @@ -0,0 +1,19 @@ + + + + Apache1 + + + + ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp + dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k + IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs + c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g + QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo + ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv + dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy + c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 + b25zLiINCg0KLVJpY2hhcmQgQmFjaA== + + + \ No newline at end of file diff --git a/doc/v3/api_samples/servers/server-post-resp.json b/doc/v3/api_samples/servers/server-post-resp.json new file mode 100644 index 000000000000..7be48ad56c69 --- /dev/null +++ b/doc/v3/api_samples/servers/server-post-resp.json @@ -0,0 +1,16 @@ +{ + "server": { + "admin_pass": "2pXrV3mMFkxH", + "id": "f85df75c-cf69-4723-b861-deff54b7cf70", + "links": [ + { + "href": "http://openstack.example.com/v3/servers/f85df75c-cf69-4723-b861-deff54b7cf70", + "rel": "self" + }, + { + "href": "http://openstack.example.com/servers/f85df75c-cf69-4723-b861-deff54b7cf70", + "rel": "bookmark" + } + ] + } +} \ No newline at end of file diff --git a/doc/v3/api_samples/servers/server-post-resp.xml b/doc/v3/api_samples/servers/server-post-resp.xml new file mode 100644 index 000000000000..f5c7a8713cd0 --- /dev/null +++ b/doc/v3/api_samples/servers/server-post-resp.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/doc/v3/api_samples/servers/servers-details-resp.json b/doc/v3/api_samples/servers/servers-details-resp.json new file mode 100644 index 000000000000..436fa6ff8db1 --- /dev/null +++ b/doc/v3/api_samples/servers/servers-details-resp.json @@ -0,0 +1,58 @@ +{ + "servers": [ + { + "access_ip_v4": "", + "access_ip_v6": "", + "addresses": { + "private": [ + { + "addr": "192.168.0.3", + "mac_addr": "aa:bb:cc:dd:ee:ff", + "type": "fixed", + "version": 4 + } + ] + }, + "created": "2013-08-09T05:47:55Z", + "flavor": { + "id": "1", + "links": [ + { + "href": "http://openstack.example.com/flavors/1", + "rel": "bookmark" + } + ] + }, + "host_id": "c977254e8fbf1c2dd83f283dce24dfdba6f1388d05c9972342472a6f", + "id": "b327644d-d61d-49f9-86fd-d56f166e98a8", + "image": { + "id": "70a599e0-31e7-49b7-b260-868f441e862b", + "links": [ + { + "href": "http://openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "http://openstack.example.com/v3/servers/b327644d-d61d-49f9-86fd-d56f166e98a8", + "rel": "self" + }, + { + "href": "http://openstack.example.com/servers/b327644d-d61d-49f9-86fd-d56f166e98a8", + "rel": "bookmark" + } + ], + "metadata": { + "My Server Name": "Apache1" + }, + "name": "new-server-test", + "progress": 0, + "status": "ACTIVE", + "tenant_id": "openstack", + "updated": "2013-08-09T05:47:55Z", + "user_id": "fake" + } + ] +} \ No newline at end of file diff --git a/doc/v3/api_samples/servers/servers-details-resp.xml b/doc/v3/api_samples/servers/servers-details-resp.xml new file mode 100644 index 000000000000..9ae3d6e8107e --- /dev/null +++ b/doc/v3/api_samples/servers/servers-details-resp.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + Apache1 + + + + + + + + + + \ No newline at end of file diff --git a/doc/v3/api_samples/servers/servers-list-resp.json b/doc/v3/api_samples/servers/servers-list-resp.json new file mode 100644 index 000000000000..dcef4422f7b9 --- /dev/null +++ b/doc/v3/api_samples/servers/servers-list-resp.json @@ -0,0 +1,18 @@ +{ + "servers": [ + { + "id": "204da46b-4fc9-4761-9bab-aa28add417e6", + "links": [ + { + "href": "http://openstack.example.com/v3/servers/204da46b-4fc9-4761-9bab-aa28add417e6", + "rel": "self" + }, + { + "href": "http://openstack.example.com/servers/204da46b-4fc9-4761-9bab-aa28add417e6", + "rel": "bookmark" + } + ], + "name": "new-server-test" + } + ] +} \ No newline at end of file diff --git a/doc/v3/api_samples/servers/servers-list-resp.xml b/doc/v3/api_samples/servers/servers-list-resp.xml new file mode 100644 index 000000000000..1c9d40634740 --- /dev/null +++ b/doc/v3/api_samples/servers/servers-list-resp.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/nova/api/openstack/compute/plugins/v3/servers.py b/nova/api/openstack/compute/plugins/v3/servers.py index 4748139001bb..36fab6d17a44 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -1446,9 +1446,10 @@ class ServersController(wsgi.Controller): handler.server_xml_extract_server_deserialize(server_node, server_dict) def server_create_xml_deserialize(self, server_node, server): - self.create_xml_deserialize_manager.map( - self._server_create_xml_deserialize_extension_point, - server_node, server) + if list(self.create_xml_deserialize_manager): + self.create_xml_deserialize_manager.map( + self._server_create_xml_deserialize_extension_point, + server_node, server) def _get_instance(self, context, instance_uuid): try: diff --git a/nova/tests/integrated/v3/__init__.py b/nova/tests/integrated/v3/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/tests/integrated/v3/api_sample_base.py b/nova/tests/integrated/v3/api_sample_base.py new file mode 100644 index 000000000000..851c84010851 --- /dev/null +++ b/nova/tests/integrated/v3/api_sample_base.py @@ -0,0 +1,80 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# 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. + +import os + +from oslo.config import cfg + +from nova.api.openstack import API_V3_CORE_EXTENSIONS +from nova import test +from nova.tests import fake_network +from nova.tests import fake_utils +from nova.tests.integrated import api_samples_test_base + +CONF = cfg.CONF + + +class ApiSampleTestBaseV3(api_samples_test_base.ApiSampleTestBase): + _api_version = 'v3' + sample_dir = None + extra_extensions_to_load = None + + def setUp(self): + extends = [] + self.flags(use_ipv6=False, + osapi_compute_link_prefix=self._get_host(), + osapi_glance_link_prefix=self._get_glance_host()) + if not self.all_extensions: + # Set the whitelist to ensure only the extensions we are + # interested in are loaded so the api samples don't include + # data from extensions we are not interested in + whitelist = API_V3_CORE_EXTENSIONS.copy() + if self.extension_name: + whitelist.add(self.extension_name) + if self.extra_extensions_to_load: + whitelist.update(set(self.extra_extensions_to_load)) + + CONF.set_override('extensions_whitelist', whitelist, + 'osapi_v3') + + super(ApiSampleTestBaseV3, self).setUp() + self.useFixture(test.SampleNetworks()) + fake_network.stub_compute_with_ips(self.stubs) + fake_utils.stub_out_utils_spawn_n(self.stubs) + self.generate_samples = os.getenv('GENERATE_SAMPLES') is not None + + @classmethod + def _get_sample_path(cls, name, dirname, suffix=''): + parts = [dirname] + parts.append('api_samples') + if cls.all_extensions: + parts.append('all_extensions') + elif cls.sample_dir: + parts.append(cls.sample_dir) + elif cls.extension_name: + parts.append(cls.extension_name) + parts.append(name + "." + cls.ctype + suffix) + return os.path.join(*parts) + + @classmethod + def _get_sample(cls, name): + dirname = os.path.dirname(os.path.abspath(__file__)) + dirname = os.path.normpath(os.path.join(dirname, "../../../../doc/v3")) + return cls._get_sample_path(name, dirname) + + @classmethod + def _get_template(cls, name): + dirname = os.path.dirname(os.path.abspath(__file__)) + return cls._get_sample_path(name, dirname, suffix='.tpl') diff --git a/nova/tests/integrated/v3/api_samples/servers/server-get-resp.json.tpl b/nova/tests/integrated/v3/api_samples/servers/server-get-resp.json.tpl new file mode 100644 index 000000000000..b8b65d750f86 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-get-resp.json.tpl @@ -0,0 +1,56 @@ +{ + "server": { + "access_ip_v4": "", + "access_ip_v6": "", + "addresses": { + "private": [ + { + "addr": "%(ip)s", + "mac_addr": "aa:bb:cc:dd:ee:ff", + "type": "fixed", + "version": 4 + } + ] + }, + "created": "%(timestamp)s", + "flavor": { + "id": "1", + "links": [ + { + "href": "%(host)s/flavors/1", + "rel": "bookmark" + } + ] + }, + "host_id": "%(hostid)s", + "id": "%(id)s", + "image": { + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/images/%(uuid)s", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "%(host)s/v3/servers/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/servers/%(uuid)s", + "rel": "bookmark" + } + ], + "metadata": { + "My Server Name": "Apache1" + }, + "name": "new-server-test", + "progress": 0, + "status": "ACTIVE", + "tenant_id": "openstack", + "updated": "%(timestamp)s", + "user_id": "fake" + } +} diff --git a/nova/tests/integrated/v3/api_samples/servers/server-get-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/servers/server-get-resp.xml.tpl new file mode 100644 index 000000000000..557c5f610769 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-get-resp.xml.tpl @@ -0,0 +1,19 @@ + + + + + + + + + + Apache1 + + + + + + + + + diff --git a/nova/tests/integrated/v3/api_samples/servers/server-post-req.json.tpl b/nova/tests/integrated/v3/api_samples/servers/server-post-req.json.tpl new file mode 100644 index 000000000000..1dcb63e3b2ae --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/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/servers/server-post-req.xml.tpl b/nova/tests/integrated/v3/api_samples/servers/server-post-req.xml.tpl new file mode 100644 index 000000000000..ddb5ea78c4b5 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-post-req.xml.tpl @@ -0,0 +1,19 @@ + + + + Apache1 + + + + ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp + dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k + IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs + c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g + QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo + ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv + dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy + c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 + b25zLiINCg0KLVJpY2hhcmQgQmFjaA== + + + diff --git a/nova/tests/integrated/v3/api_samples/servers/server-post-resp.json.tpl b/nova/tests/integrated/v3/api_samples/servers/server-post-resp.json.tpl new file mode 100644 index 000000000000..6c3100fbec86 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/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/servers/server-post-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/servers/server-post-resp.xml.tpl new file mode 100644 index 000000000000..3470373e171f --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-post-resp.xml.tpl @@ -0,0 +1,6 @@ + + + + + + diff --git a/nova/tests/integrated/v3/api_samples/servers/servers-details-resp.json.tpl b/nova/tests/integrated/v3/api_samples/servers/servers-details-resp.json.tpl new file mode 100644 index 000000000000..305b914da4d8 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/servers-details-resp.json.tpl @@ -0,0 +1,58 @@ +{ + "servers": [ + { + "access_ip_v4": "", + "access_ip_v6": "", + "addresses": { + "private": [ + { + "addr": "%(ip)s", + "mac_addr": "aa:bb:cc:dd:ee:ff", + "type": "fixed", + "version": 4 + } + ] + }, + "created": "%(timestamp)s", + "flavor": { + "id": "1", + "links": [ + { + "href": "%(host)s/flavors/1", + "rel": "bookmark" + } + ] + }, + "host_id": "%(hostid)s", + "id": "%(id)s", + "image": { + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/images/%(uuid)s", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "%(host)s/v3/servers/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/servers/%(id)s", + "rel": "bookmark" + } + ], + "metadata": { + "My Server Name": "Apache1" + }, + "name": "new-server-test", + "progress": 0, + "status": "ACTIVE", + "tenant_id": "openstack", + "updated": "%(timestamp)s", + "user_id": "fake" + } + ] +} diff --git a/nova/tests/integrated/v3/api_samples/servers/servers-details-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/servers/servers-details-resp.xml.tpl new file mode 100644 index 000000000000..f1395d9cced4 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/servers-details-resp.xml.tpl @@ -0,0 +1,21 @@ + + + + + + + + + + + Apache1 + + + + + + + + + + diff --git a/nova/tests/integrated/v3/api_samples/servers/servers-list-resp.json.tpl b/nova/tests/integrated/v3/api_samples/servers/servers-list-resp.json.tpl new file mode 100644 index 000000000000..8797266b68f9 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/servers-list-resp.json.tpl @@ -0,0 +1,18 @@ +{ + "servers": [ + { + "id": "%(id)s", + "links": [ + { + "href": "%(host)s/v3/servers/%(id)s", + "rel": "self" + }, + { + "href": "%(host)s/servers/%(id)s", + "rel": "bookmark" + } + ], + "name": "new-server-test" + } + ] +} diff --git a/nova/tests/integrated/v3/api_samples/servers/servers-list-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/servers/servers-list-resp.xml.tpl new file mode 100644 index 000000000000..421eb28d5321 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/servers-list-resp.xml.tpl @@ -0,0 +1,7 @@ + + + + + + + diff --git a/nova/tests/integrated/v3/test_servers.py b/nova/tests/integrated/v3/test_servers.py new file mode 100644 index 000000000000..fd6bcc8afe20 --- /dev/null +++ b/nova/tests/integrated/v3/test_servers.py @@ -0,0 +1,67 @@ +# 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.tests.image import fake +from nova.tests.integrated.v3 import api_sample_base + + +class ServersSampleBase(api_sample_base.ApiSampleTestBaseV3): + def _post_server(self): + subs = { + 'image_id': fake.get_valid_image_id(), + 'host': self._get_host(), + } + response = self._do_post('servers', 'server-post-req', subs) + subs = self._get_regexes() + return self._verify_response('server-post-resp', subs, response, 202) + + +class ServersSampleJsonTest(ServersSampleBase): + sample_dir = 'servers' + + def test_servers_post(self): + return self._post_server() + + def test_servers_get(self): + uuid = self.test_servers_post() + response = self._do_get('servers/%s' % uuid) + subs = self._get_regexes() + subs['hostid'] = '[a-f0-9]+' + subs['id'] = uuid + subs['hypervisor_hostname'] = r'[\w\.\-]+' + subs['mac_addr'] = '(?:[a-f0-9]{2}:){5}[a-f0-9]{2}' + self._verify_response('server-get-resp', subs, response, 200) + + def test_servers_list(self): + uuid = self._post_server() + response = self._do_get('servers') + subs = self._get_regexes() + subs['id'] = uuid + self._verify_response('servers-list-resp', subs, response, 200) + + def test_servers_details(self): + uuid = self._post_server() + response = self._do_get('servers/detail') + subs = self._get_regexes() + subs['hostid'] = '[a-f0-9]+' + subs['id'] = uuid + subs['hypervisor_hostname'] = r'[\w\.\-]+' + subs['mac_addr'] = '(?:[a-f0-9]{2}:){5}[a-f0-9]{2}' + self._verify_response('servers-details-resp', subs, response, 200) + + +class ServersSampleXmlTest(ServersSampleJsonTest): + ctype = 'xml'