From 1861cb557ecf65669a3076f59741f27a418cf893 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 17 Sep 2012 16:23:46 -0400 Subject: [PATCH] sample api testing for os-floating-ips extension API testing for negative error codes now removed so this is only sample api testing Change-Id: I144a6b69498b86be56ceecb680c5be2a51acdbb8 --- .../floating-ips-create-nopool-req.json | 0 .../floating-ips-create-nopool-req.xml | 0 .../floating-ips-create-req.json | 3 + .../floating-ips-create-req.xml | 2 + .../floating-ips-create-resp.json | 9 ++ .../floating-ips-create-resp.xml | 2 + .../floating-ips-list-empty-resp.json | 3 + .../floating-ips-list-empty-resp.xml | 2 + .../floating-ips-list-resp.json | 18 ++++ .../floating-ips-list-resp.xml | 5 + .../floating-ips-create-nopool-req.json.tpl | 0 .../floating-ips-create-nopool-req.xml.tpl | 0 .../floating-ips-create-req.json.tpl | 3 + .../floating-ips-create-req.xml.tpl | 2 + .../floating-ips-create-resp.json.tpl | 9 ++ .../floating-ips-create-resp.xml.tpl | 2 + .../floating-ips-get-resp.json.tpl | 9 ++ .../floating-ips-get-resp.xml.tpl | 2 + .../floating-ips-list-empty-resp.json.tpl | 3 + .../floating-ips-list-empty-resp.xml.tpl | 2 + .../floating-ips-list-resp.json.tpl | 19 ++++ .../floating-ips-list-resp.xml.tpl | 5 + nova/tests/integrated/test_api_samples.py | 95 +++++++++++++++++++ 23 files changed, 195 insertions(+) create mode 100644 doc/api_samples/os-floating-ips/floating-ips-create-nopool-req.json create mode 100644 doc/api_samples/os-floating-ips/floating-ips-create-nopool-req.xml create mode 100644 doc/api_samples/os-floating-ips/floating-ips-create-req.json create mode 100644 doc/api_samples/os-floating-ips/floating-ips-create-req.xml create mode 100644 doc/api_samples/os-floating-ips/floating-ips-create-resp.json create mode 100644 doc/api_samples/os-floating-ips/floating-ips-create-resp.xml create mode 100644 doc/api_samples/os-floating-ips/floating-ips-list-empty-resp.json create mode 100644 doc/api_samples/os-floating-ips/floating-ips-list-empty-resp.xml create mode 100644 doc/api_samples/os-floating-ips/floating-ips-list-resp.json create mode 100644 doc/api_samples/os-floating-ips/floating-ips-list-resp.xml create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-nopool-req.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-nopool-req.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-req.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-req.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-get-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-get-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-empty-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-empty-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-resp.xml.tpl diff --git a/doc/api_samples/os-floating-ips/floating-ips-create-nopool-req.json b/doc/api_samples/os-floating-ips/floating-ips-create-nopool-req.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/doc/api_samples/os-floating-ips/floating-ips-create-nopool-req.xml b/doc/api_samples/os-floating-ips/floating-ips-create-nopool-req.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/doc/api_samples/os-floating-ips/floating-ips-create-req.json b/doc/api_samples/os-floating-ips/floating-ips-create-req.json new file mode 100644 index 000000000000..511b009bede9 --- /dev/null +++ b/doc/api_samples/os-floating-ips/floating-ips-create-req.json @@ -0,0 +1,3 @@ +{ + "pool": "nova" +} \ No newline at end of file diff --git a/doc/api_samples/os-floating-ips/floating-ips-create-req.xml b/doc/api_samples/os-floating-ips/floating-ips-create-req.xml new file mode 100644 index 000000000000..f77525e74983 --- /dev/null +++ b/doc/api_samples/os-floating-ips/floating-ips-create-req.xml @@ -0,0 +1,2 @@ + +nova \ No newline at end of file diff --git a/doc/api_samples/os-floating-ips/floating-ips-create-resp.json b/doc/api_samples/os-floating-ips/floating-ips-create-resp.json new file mode 100644 index 000000000000..fe161a7dd129 --- /dev/null +++ b/doc/api_samples/os-floating-ips/floating-ips-create-resp.json @@ -0,0 +1,9 @@ +{ + "floating_ip": { + "fixed_ip": null, + "id": 1, + "instance_id": null, + "ip": "10.10.10.1", + "pool": "nova" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-floating-ips/floating-ips-create-resp.xml b/doc/api_samples/os-floating-ips/floating-ips-create-resp.xml new file mode 100644 index 000000000000..e0f68ef503a6 --- /dev/null +++ b/doc/api_samples/os-floating-ips/floating-ips-create-resp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/doc/api_samples/os-floating-ips/floating-ips-list-empty-resp.json b/doc/api_samples/os-floating-ips/floating-ips-list-empty-resp.json new file mode 100644 index 000000000000..121dbd084e87 --- /dev/null +++ b/doc/api_samples/os-floating-ips/floating-ips-list-empty-resp.json @@ -0,0 +1,3 @@ +{ + "floating_ips": [] +} \ No newline at end of file diff --git a/doc/api_samples/os-floating-ips/floating-ips-list-empty-resp.xml b/doc/api_samples/os-floating-ips/floating-ips-list-empty-resp.xml new file mode 100644 index 000000000000..da6f0d4ce993 --- /dev/null +++ b/doc/api_samples/os-floating-ips/floating-ips-list-empty-resp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/doc/api_samples/os-floating-ips/floating-ips-list-resp.json b/doc/api_samples/os-floating-ips/floating-ips-list-resp.json new file mode 100644 index 000000000000..4d58e0676a93 --- /dev/null +++ b/doc/api_samples/os-floating-ips/floating-ips-list-resp.json @@ -0,0 +1,18 @@ +{ + "floating_ips": [ + { + "fixed_ip": null, + "id": 1, + "instance_id": null, + "ip": "10.10.10.1", + "pool": "nova" + }, + { + "fixed_ip": null, + "id": 2, + "instance_id": null, + "ip": "10.10.10.2", + "pool": "nova" + } + ] +} \ No newline at end of file diff --git a/doc/api_samples/os-floating-ips/floating-ips-list-resp.xml b/doc/api_samples/os-floating-ips/floating-ips-list-resp.xml new file mode 100644 index 000000000000..78348be553d1 --- /dev/null +++ b/doc/api_samples/os-floating-ips/floating-ips-list-resp.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-nopool-req.json.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-nopool-req.json.tpl new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-nopool-req.xml.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-nopool-req.xml.tpl new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-req.json.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-req.json.tpl new file mode 100644 index 000000000000..24129f4958e0 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-req.json.tpl @@ -0,0 +1,3 @@ +{ + "pool": "%(pool)s" +} \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-req.xml.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-req.xml.tpl new file mode 100644 index 000000000000..a80147389daa --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-req.xml.tpl @@ -0,0 +1,2 @@ + +%(pool)s \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-resp.json.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-resp.json.tpl new file mode 100644 index 000000000000..10ee8d9bd402 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-resp.json.tpl @@ -0,0 +1,9 @@ +{ + "floating_ip": { + "fixed_ip": null, + "id": 1, + "instance_id": null, + "ip": "10.10.10.1", + "pool": "nova" + } +} diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-resp.xml.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-resp.xml.tpl new file mode 100644 index 000000000000..e0f68ef503a6 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-create-resp.xml.tpl @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-get-resp.json.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-get-resp.json.tpl new file mode 100644 index 000000000000..10ee8d9bd402 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-get-resp.json.tpl @@ -0,0 +1,9 @@ +{ + "floating_ip": { + "fixed_ip": null, + "id": 1, + "instance_id": null, + "ip": "10.10.10.1", + "pool": "nova" + } +} diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-get-resp.xml.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-get-resp.xml.tpl new file mode 100644 index 000000000000..e0f68ef503a6 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-get-resp.xml.tpl @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-empty-resp.json.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-empty-resp.json.tpl new file mode 100644 index 000000000000..12f118da50dd --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-empty-resp.json.tpl @@ -0,0 +1,3 @@ +{ + "floating_ips": [] +} diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-empty-resp.xml.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-empty-resp.xml.tpl new file mode 100644 index 000000000000..da6f0d4ce993 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-empty-resp.xml.tpl @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-resp.json.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-resp.json.tpl new file mode 100644 index 000000000000..06f57451c9d8 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-resp.json.tpl @@ -0,0 +1,19 @@ +{ + "floating_ips": [ + { + "fixed_ip": null, + "id": 1, + "instance_id": null, + "ip": "10.10.10.1", + "pool": "nova" + }, + { + "fixed_ip": null, + "id": 2, + "instance_id": null, + "ip": "10.10.10.2", + "pool": "nova" + } + ] +} + diff --git a/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-resp.xml.tpl b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-resp.xml.tpl new file mode 100644 index 000000000000..bbd0b117ef61 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-floating-ips/floating-ips-list-resp.xml.tpl @@ -0,0 +1,5 @@ + + + + + diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index 2ec8a912d77e..455debdc361f 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -19,6 +19,7 @@ import uuid from lxml import etree +from nova import context from nova import flags from nova.openstack.common import importutils from nova.openstack.common import jsonutils @@ -741,3 +742,97 @@ class ExtendedServerAttributesJsonTest(ServersSampleBase): class ExtendedServerAttributesXmlTest(ExtendedServerAttributesJsonTest): ctype = 'xml' + + +class FloatingIpsJsonTest(ApiSampleTestBase): + extension_name = "nova.api.openstack.compute.contrib." \ + "floating_ips.Floating_ips" + + def setUp(self): + super(FloatingIpsJsonTest, self).setUp() + pool = FLAGS.default_floating_pool + interface = FLAGS.public_interface + + self.ip_pool = [ + { + 'address': "10.10.10.1", + 'pool': pool, + 'interface': interface + }, + { + 'address': "10.10.10.2", + 'pool': pool, + 'interface': interface + }, + { + 'address': "10.10.10.3", + 'pool': pool, + 'interface': interface + }, + ] + self.compute.db.floating_ip_bulk_create( + context.get_admin_context(), self.ip_pool) + + def tearDown(self): + self.compute.db.floating_ip_bulk_destroy( + context.get_admin_context(), self.ip_pool) + super(FloatingIpsJsonTest, self).tearDown() + + def test_floating_ips_list_empty(self): + response = self._do_get('os-floating-ips') + + self.assertEqual(response.status, 200) + subs = self._get_regexes() + return self._verify_response('floating-ips-list-empty-resp', + subs, response) + + def test_floating_ips_list(self): + self._do_post('os-floating-ips', + 'floating-ips-create-nopool-req', + {}) + self._do_post('os-floating-ips', + 'floating-ips-create-nopool-req', + {}) + + response = self._do_get('os-floating-ips') + self.assertEqual(response.status, 200) + subs = self._get_regexes() + return self._verify_response('floating-ips-list-resp', + subs, response) + + def test_floating_ips_create_nopool(self): + response = self._do_post('os-floating-ips', + 'floating-ips-create-nopool-req', + {}) + self.assertEqual(response.status, 200) + subs = self._get_regexes() + self._verify_response('floating-ips-create-resp', + subs, response) + + def test_floating_ips_create(self): + response = self._do_post('os-floating-ips', + 'floating-ips-create-req', + {"pool": FLAGS.default_floating_pool}) + self.assertEqual(response.status, 200) + subs = self._get_regexes() + self._verify_response('floating-ips-create-resp', + subs, response) + + def test_floating_ips_get(self): + self.test_floating_ips_create() + # NOTE(sdague): the first floating ip will always have 1 as an id, + # but it would be better if we could get this from the create + response = self._do_get('os-floating-ips/%d' % 1) + self.assertEqual(response.status, 200) + subs = self._get_regexes() + self._verify_response('floating-ips-create-resp', + subs, response) + + def test_floating_ips_delete(self): + self.test_floating_ips_create() + response = self._do_delete('os-floating-ips/%d' % 1) + self.assertEqual(response.status, 202) + + +class FloatingIpsXmlTest(FloatingIpsJsonTest): + ctype = 'xml'