From c9d6c65dc5e820e581b6c0582053b4cd0369553b Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 12 Sep 2012 16:49:19 -0400 Subject: [PATCH] Add user-data extension to API samples tests Change-Id: Ia7da11820e0008c6a46715fb4016da4474c3ddcc --- .../os-user-data/userdata-post-req.json | 17 +++++++++++++ .../os-user-data/userdata-post-req.xml | 25 +++++++++++++++++++ .../os-user-data/userdata-post-resp.json | 16 ++++++++++++ .../os-user-data/userdata-post-resp.xml | 6 +++++ .../os-user-data/userdata-post-req.json.tpl | 17 +++++++++++++ .../os-user-data/userdata-post-req.xml.tpl | 25 +++++++++++++++++++ .../os-user-data/userdata-post-resp.json.tpl | 16 ++++++++++++ .../os-user-data/userdata-post-resp.xml.tpl | 8 ++++++ nova/tests/integrated/test_api_samples.py | 23 +++++++++++++++++ 9 files changed, 153 insertions(+) create mode 100644 doc/api_samples/os-user-data/userdata-post-req.json create mode 100644 doc/api_samples/os-user-data/userdata-post-req.xml create mode 100644 doc/api_samples/os-user-data/userdata-post-resp.json create mode 100644 doc/api_samples/os-user-data/userdata-post-resp.xml create mode 100644 nova/tests/integrated/api_samples/os-user-data/userdata-post-req.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-user-data/userdata-post-req.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-user-data/userdata-post-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-user-data/userdata-post-resp.xml.tpl diff --git a/doc/api_samples/os-user-data/userdata-post-req.json b/doc/api_samples/os-user-data/userdata-post-req.json new file mode 100644 index 000000000000..255d14820a40 --- /dev/null +++ b/doc/api_samples/os-user-data/userdata-post-req.json @@ -0,0 +1,17 @@ +{ + "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" + }, + "user_data" : "IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg==", + "personality" : [ + { + "path" : "/etc/banner.txt", + "contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==" + } + ] + } +} \ No newline at end of file diff --git a/doc/api_samples/os-user-data/userdata-post-req.xml b/doc/api_samples/os-user-data/userdata-post-req.xml new file mode 100644 index 000000000000..f2b427c314db --- /dev/null +++ b/doc/api_samples/os-user-data/userdata-post-req.xml @@ -0,0 +1,25 @@ + + + + IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg== + + + Apache1 + + + + ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp + dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k + IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs + c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g + QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo + ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv + dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy + c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 + b25zLiINCg0KLVJpY2hhcmQgQmFjaA== + + + \ No newline at end of file diff --git a/doc/api_samples/os-user-data/userdata-post-resp.json b/doc/api_samples/os-user-data/userdata-post-resp.json new file mode 100644 index 000000000000..347095525e99 --- /dev/null +++ b/doc/api_samples/os-user-data/userdata-post-resp.json @@ -0,0 +1,16 @@ +{ + "server": { + "adminPass": "bwQZtcB28c29", + "id": "55116d7b-2cad-4d65-9c7c-964cde61946e", + "links": [ + { + "href": "http://openstack.example.com/v2/openstack/servers/55116d7b-2cad-4d65-9c7c-964cde61946e", + "rel": "self" + }, + { + "href": "http://openstack.example.com/openstack/servers/55116d7b-2cad-4d65-9c7c-964cde61946e", + "rel": "bookmark" + } + ] + } +} \ No newline at end of file diff --git a/doc/api_samples/os-user-data/userdata-post-resp.xml b/doc/api_samples/os-user-data/userdata-post-resp.xml new file mode 100644 index 000000000000..24f94ba218f6 --- /dev/null +++ b/doc/api_samples/os-user-data/userdata-post-resp.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-user-data/userdata-post-req.json.tpl b/nova/tests/integrated/api_samples/os-user-data/userdata-post-req.json.tpl new file mode 100644 index 000000000000..fb7744a3d0a3 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-user-data/userdata-post-req.json.tpl @@ -0,0 +1,17 @@ +{ + "server" : { + "name" : "new-server-test", + "imageRef" : "%(host)s/openstack/images/%(image_id)s", + "flavorRef" : "%(host)s/openstack/flavors/1", + "metadata" : { + "My Server Name" : "Apache1" + }, + "user_data" : "%(user_data)s", + "personality" : [ + { + "path" : "/etc/banner.txt", + "contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==" + } + ] + } +} diff --git a/nova/tests/integrated/api_samples/os-user-data/userdata-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-user-data/userdata-post-req.xml.tpl new file mode 100644 index 000000000000..22ec4d5c5fea --- /dev/null +++ b/nova/tests/integrated/api_samples/os-user-data/userdata-post-req.xml.tpl @@ -0,0 +1,25 @@ + + + + %(user_data)s + + + Apache1 + + + + ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp + dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k + IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs + c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g + QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo + ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv + dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy + c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 + b25zLiINCg0KLVJpY2hhcmQgQmFjaA== + + + diff --git a/nova/tests/integrated/api_samples/os-user-data/userdata-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-user-data/userdata-post-resp.json.tpl new file mode 100644 index 000000000000..d5f030c8730b --- /dev/null +++ b/nova/tests/integrated/api_samples/os-user-data/userdata-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-user-data/userdata-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-user-data/userdata-post-resp.xml.tpl new file mode 100644 index 000000000000..2ad5c102b088 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-user-data/userdata-post-resp.xml.tpl @@ -0,0 +1,8 @@ + + + + + + diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index dc4883315747..b35dbf00d7d8 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import base64 import os import re import uuid @@ -590,6 +591,28 @@ class ServerStartStopXmlTest(ServerStartStopJsonTest): ctype = 'xml' +class UserDataJsonTest(ApiSampleTestBase): + extension_name = "nova.api.openstack.compute.contrib.user_data.User_data" + + def test_user_data_post(self): + user_data_contents = '#!/bin/bash\n/bin/su\necho "I am in you!"\n' + user_data = base64.b64encode(user_data_contents) + subs = { + 'image_id': fake.get_valid_image_id(), + 'host': self._get_host(), + 'user_data': user_data + } + response = self._do_post('servers', 'userdata-post-req', subs) + + self.assertEqual(response.status, 202) + subs.update(self._get_regexes()) + return self._verify_response('userdata-post-resp', subs, response) + + +class UserDataXmlTest(UserDataJsonTest): + ctype = 'xml' + + class FlavorsExtraDataJsonTest(ApiSampleTestBase): extension_name = ('nova.api.openstack.compute.contrib.flavorextradata.' 'Flavorextradata')