From a6d641d4e98ecfc6fb7b9fff3fa2da39e9303bb5 Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Tue, 29 Oct 2013 13:12:39 +0800 Subject: [PATCH] Add v3 api samples for shelve Adds api sample tests and api samples for shelve Partially implements blueprint v3-api-unittests Partially implements blueprint v3-api-specification Change-Id: Ib485ab042a340c4672ad01fb35d065fd52889b07 --- doc/v3/api_samples/os-shelve/os-shelve.json | 3 + doc/v3/api_samples/os-shelve/os-shelve.xml | 2 + .../os-shelve/server-post-req.json | 16 ++++++ .../api_samples/os-shelve/server-post-req.xml | 19 +++++++ .../os-shelve/server-post-resp.json | 16 ++++++ .../os-shelve/server-post-resp.xml | 6 ++ .../api_samples/os-shelve/os-shelve.json.tpl | 3 + .../api_samples/os-shelve/os-shelve.xml.tpl | 2 + .../os-shelve/server-post-req.json.tpl | 16 ++++++ .../os-shelve/server-post-req.xml.tpl | 19 +++++++ .../os-shelve/server-post-resp.json.tpl | 16 ++++++ .../os-shelve/server-post-resp.xml.tpl | 6 ++ nova/tests/integrated/v3/test_shelve.py | 55 +++++++++++++++++++ 13 files changed, 179 insertions(+) create mode 100644 doc/v3/api_samples/os-shelve/os-shelve.json create mode 100644 doc/v3/api_samples/os-shelve/os-shelve.xml create mode 100644 doc/v3/api_samples/os-shelve/server-post-req.json create mode 100644 doc/v3/api_samples/os-shelve/server-post-req.xml create mode 100644 doc/v3/api_samples/os-shelve/server-post-resp.json create mode 100644 doc/v3/api_samples/os-shelve/server-post-resp.xml create mode 100644 nova/tests/integrated/v3/api_samples/os-shelve/os-shelve.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-shelve/os-shelve.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-shelve/server-post-req.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-shelve/server-post-req.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-shelve/server-post-resp.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-shelve/server-post-resp.xml.tpl create mode 100644 nova/tests/integrated/v3/test_shelve.py diff --git a/doc/v3/api_samples/os-shelve/os-shelve.json b/doc/v3/api_samples/os-shelve/os-shelve.json new file mode 100644 index 0000000000..e33b05865a --- /dev/null +++ b/doc/v3/api_samples/os-shelve/os-shelve.json @@ -0,0 +1,3 @@ +{ + "shelve": null +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-shelve/os-shelve.xml b/doc/v3/api_samples/os-shelve/os-shelve.xml new file mode 100644 index 0000000000..687b1b1f58 --- /dev/null +++ b/doc/v3/api_samples/os-shelve/os-shelve.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/doc/v3/api_samples/os-shelve/server-post-req.json b/doc/v3/api_samples/os-shelve/server-post-req.json new file mode 100644 index 0000000000..8cc0fd01df --- /dev/null +++ b/doc/v3/api_samples/os-shelve/server-post-req.json @@ -0,0 +1,16 @@ +{ + "server" : { + "name" : "new-server-test", + "image_ref" : "http://glance.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-shelve/server-post-req.xml b/doc/v3/api_samples/os-shelve/server-post-req.xml new file mode 100644 index 0000000000..25f02e3e8b --- /dev/null +++ b/doc/v3/api_samples/os-shelve/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/os-shelve/server-post-resp.json b/doc/v3/api_samples/os-shelve/server-post-resp.json new file mode 100644 index 0000000000..2d2eafa2eb --- /dev/null +++ b/doc/v3/api_samples/os-shelve/server-post-resp.json @@ -0,0 +1,16 @@ +{ + "server": { + "admin_password": "LJGRdNsvzh6z", + "id": "1d08717a-835e-4dca-9bfb-166fa18a6715", + "links": [ + { + "href": "http://openstack.example.com/v3/servers/1d08717a-835e-4dca-9bfb-166fa18a6715", + "rel": "self" + }, + { + "href": "http://openstack.example.com/servers/1d08717a-835e-4dca-9bfb-166fa18a6715", + "rel": "bookmark" + } + ] + } +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-shelve/server-post-resp.xml b/doc/v3/api_samples/os-shelve/server-post-resp.xml new file mode 100644 index 0000000000..5cdc225c89 --- /dev/null +++ b/doc/v3/api_samples/os-shelve/server-post-resp.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-shelve/os-shelve.json.tpl b/nova/tests/integrated/v3/api_samples/os-shelve/os-shelve.json.tpl new file mode 100644 index 0000000000..5a19f85cff --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-shelve/os-shelve.json.tpl @@ -0,0 +1,3 @@ +{ + "%(action)s": null +} diff --git a/nova/tests/integrated/v3/api_samples/os-shelve/os-shelve.xml.tpl b/nova/tests/integrated/v3/api_samples/os-shelve/os-shelve.xml.tpl new file mode 100644 index 0000000000..41d18bdac0 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-shelve/os-shelve.xml.tpl @@ -0,0 +1,2 @@ + + <%(action)s/> diff --git a/nova/tests/integrated/v3/api_samples/os-shelve/server-post-req.json.tpl b/nova/tests/integrated/v3/api_samples/os-shelve/server-post-req.json.tpl new file mode 100644 index 0000000000..b1013defdf --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-shelve/server-post-req.json.tpl @@ -0,0 +1,16 @@ +{ + "server" : { + "name" : "new-server-test", + "image_ref" : "%(glance_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-shelve/server-post-req.xml.tpl b/nova/tests/integrated/v3/api_samples/os-shelve/server-post-req.xml.tpl new file mode 100644 index 0000000000..c7c6e31bb5 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-shelve/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/os-shelve/server-post-resp.json.tpl b/nova/tests/integrated/v3/api_samples/os-shelve/server-post-resp.json.tpl new file mode 100644 index 0000000000..7af0df5ec0 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-shelve/server-post-resp.json.tpl @@ -0,0 +1,16 @@ +{ + "server": { + "admin_password": "%(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-shelve/server-post-resp.xml.tpl b/nova/tests/integrated/v3/api_samples/os-shelve/server-post-resp.xml.tpl new file mode 100644 index 0000000000..59e7ae5a99 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-shelve/server-post-resp.xml.tpl @@ -0,0 +1,6 @@ + + + + + + diff --git a/nova/tests/integrated/v3/test_shelve.py b/nova/tests/integrated/v3/test_shelve.py new file mode 100644 index 0000000000..6eaaaef2b4 --- /dev/null +++ b/nova/tests/integrated/v3/test_shelve.py @@ -0,0 +1,55 @@ +# 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 oslo.config import cfg + +from nova.tests.integrated.v3 import test_servers + +CONF = cfg.CONF + + +class ShelveJsonTest(test_servers.ServersSampleBase): + extension_name = "os-shelve" + + def setUp(self): + super(ShelveJsonTest, self).setUp() + # Don't offload instance, so we can test the offload call. + CONF.set_override('shelved_offload_time', -1) + + def _test_server_action(self, uuid, action): + response = self._do_post('servers/%s/action' % uuid, + 'os-shelve', + {'action': action}) + self.assertEqual(response.status, 202) + self.assertEqual(response.read(), "") + + def test_shelve(self): + uuid = self._post_server() + self._test_server_action(uuid, 'shelve') + + def test_shelve_offload(self): + uuid = self._post_server() + self._test_server_action(uuid, 'shelve') + self._test_server_action(uuid, 'shelve_offload') + + def test_unshelve(self): + uuid = self._post_server() + self._test_server_action(uuid, 'shelve') + self._test_server_action(uuid, 'unshelve') + + +class ShelveXmlTest(ShelveJsonTest): + ctype = 'xml'