diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-11-16 06:10:38 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-11-16 06:10:38 +0000 |
| commit | 48967d3822299b345589673be79cbcb58fa95d79 (patch) | |
| tree | d064d7b2902f4ec7c53e04a62dd592ea9294cb5d /nova/tests | |
| parent | c6d1abd62a4fc26f8cd8cf52af6f2e828e0b0d22 (diff) | |
| parent | a220aa15b056914df1b9debc95322d01a0e408e8 (diff) | |
Merge "API extension for fpinging instances"
Diffstat (limited to 'nova/tests')
8 files changed, 139 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_fping.py b/nova/tests/api/openstack/compute/contrib/test_fping.py new file mode 100644 index 000000000..9a838162a --- /dev/null +++ b/nova/tests/api/openstack/compute/contrib/test_fping.py @@ -0,0 +1,94 @@ +# Copyright 2011 Grid Dynamics +# Copyright 2011 OpenStack LLC. +# All Rights Reserved. +# +# 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.api.openstack.compute.contrib import fping +from nova.api.openstack import extensions +from nova import exception +from nova import test +from nova.tests.api.openstack import fakes +import nova.utils + + +FAKE_UUID = fakes.FAKE_UUID + + +def execute(*cmd, **args): + return "".join(["%s is alive" % ip for ip in cmd[1:]]) + + +class FpingTest(test.TestCase): + + def setUp(self): + super(FpingTest, self).setUp() + self.flags(verbose=True, use_ipv6=False) + return_server = fakes.fake_instance_get() + return_servers = fakes.fake_instance_get_all_by_filters() + self.stubs.Set(nova.db, "instance_get_all_by_filters", + return_servers) + self.stubs.Set(nova.db, "instance_get_by_uuid", + return_server) + self.stubs.Set(nova.db, "instance_get_all_by_project", + return_servers) + self.stubs.Set(nova.utils, "execute", + execute) + self.stubs.Set(fping.FpingController, "check_fping", + lambda self: None) + self.ext_mgr = extensions.ExtensionManager() + self.ext_mgr.extensions = {} + self.controller = fping.FpingController(self.ext_mgr) + + def test_fping_index(self): + req = fakes.HTTPRequest.blank("/v2/1234/os-fping") + res_dict = self.controller.index(req) + self.assertTrue("servers" in res_dict) + for srv in res_dict["servers"]: + for key in "project_id", "id", "alive": + self.assertTrue(key in srv) + + def test_fping_index_policy(self): + req = fakes.HTTPRequest.blank("/v2/1234/os-fping?all_tenants=1") + self.assertRaises(exception.NotAuthorized, self.controller.index, req) + req = fakes.HTTPRequest.blank("/v2/1234/os-fping?all_tenants=1") + req.environ["nova.context"].is_admin = True + res_dict = self.controller.index(req) + self.assertTrue("servers" in res_dict) + + def test_fping_index_include(self): + req = fakes.HTTPRequest.blank("/v2/1234/os-fping") + res_dict = self.controller.index(req) + ids = [srv["id"] for srv in res_dict["servers"]] + req = fakes.HTTPRequest.blank("/v2/1234/os-fping?include=%s" % ids[0]) + res_dict = self.controller.index(req) + self.assertEqual(len(res_dict["servers"]), 1) + self.assertEqual(res_dict["servers"][0]["id"], ids[0]) + + def test_fping_index_exclude(self): + req = fakes.HTTPRequest.blank("/v2/1234/os-fping") + res_dict = self.controller.index(req) + ids = [srv["id"] for srv in res_dict["servers"]] + req = fakes.HTTPRequest.blank("/v2/1234/os-fping?exclude=%s" % + ",".join(ids[1:])) + res_dict = self.controller.index(req) + self.assertEqual(len(res_dict["servers"]), 1) + self.assertEqual(res_dict["servers"][0]["id"], ids[0]) + + def test_fping_show(self): + req = fakes.HTTPRequest.blank("/v2/1234/os-fping/%s" % FAKE_UUID) + res_dict = self.controller.show(req, FAKE_UUID) + self.assertTrue("server" in res_dict) + srv = res_dict["server"] + for key in "project_id", "id", "alive": + self.assertTrue(key in srv) diff --git a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl index 2ed3486eb..531508951 100644 --- a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl @@ -225,6 +225,14 @@ "updated": "%(timestamp)s" }, { + "alias": "os-fping", + "description": "%(text)s", + "links": [], + "name": "Fping", + "namespace": "http://docs.openstack.org/compute/ext/fping/api/v1.1", + "updated": "%(timestamp)s" + }, + { "alias": "os-hypervisors", "description": "%(text)s", "links": [], diff --git a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl index 3962ebe9b..5f58cc7d7 100644 --- a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl @@ -84,6 +84,9 @@ <extension alias="os-services" name="Services" namespace="http://docs.openstack.org/compute/ext/services/api/v2" updated="%(timestamp)s"> <description>%(text)s</description> </extension> + <extension alias="os-fping" updated="%(timestamp)s" namespace="http://docs.openstack.org/compute/ext/fping/api/v1.1" name="Fping"> + <description>%(text)s</description> + </extension> <extension alias="os-hypervisors" updated="%(timestamp)s" namespace="http://docs.openstack.org/compute/ext/hypervisors/api/v1.1" name="Hypervisors"> <description>%(text)s</description> </extension> diff --git a/nova/tests/integrated/api_samples/limit-get-resp.json.tpl b/nova/tests/integrated/api_samples/limit-get-resp.json.tpl index 7763dd683..a86d5faa2 100644 --- a/nova/tests/integrated/api_samples/limit-get-resp.json.tpl +++ b/nova/tests/integrated/api_samples/limit-get-resp.json.tpl @@ -66,6 +66,19 @@ ], "regex": ".*changes-since.*", "uri": "*changes-since*" + }, + { + "limit": [ + { + "next-available": "%(timestamp)s", + "remaining": 12, + "unit": "HOUR", + "value": 12, + "verb": "GET" + } + ], + "regex": "^/os-fping", + "uri": "*/os-fping" } ] } diff --git a/nova/tests/integrated/api_samples/limit-get-resp.xml.tpl b/nova/tests/integrated/api_samples/limit-get-resp.xml.tpl index 860499f8d..6f92bcee6 100644 --- a/nova/tests/integrated/api_samples/limit-get-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/limit-get-resp.xml.tpl @@ -12,6 +12,9 @@ <rate regex=".*changes-since.*" uri="*changes-since*"> <limit next-available="%(timestamp)s" unit="MINUTE" verb="GET" remaining="3" value="3"/> </rate> + <rate regex="^/os-fping" uri="*/os-fping"> + <limit next-available="%(timestamp)s" unit="HOUR" verb="GET" remaining="12" value="12"/> + </rate> </rates> <absolute> <limit name="maxServerMeta" value="128"/> diff --git a/nova/tests/integrated/api_samples/os-used-limits/usedlimits-get-resp.json.tpl b/nova/tests/integrated/api_samples/os-used-limits/usedlimits-get-resp.json.tpl index 3eef6c68b..78ddbb5af 100644 --- a/nova/tests/integrated/api_samples/os-used-limits/usedlimits-get-resp.json.tpl +++ b/nova/tests/integrated/api_samples/os-used-limits/usedlimits-get-resp.json.tpl @@ -71,6 +71,19 @@ ], "regex": ".*changes-since.*", "uri": "*changes-since*" + }, + { + "limit": [ + { + "next-available": "%(timestamp)s", + "remaining": 12, + "unit": "HOUR", + "value": 12, + "verb": "GET" + } + ], + "regex": "^/os-fping", + "uri": "*/os-fping" } ] } diff --git a/nova/tests/integrated/api_samples/os-used-limits/usedlimits-get-resp.xml.tpl b/nova/tests/integrated/api_samples/os-used-limits/usedlimits-get-resp.xml.tpl index b8e0396e8..75526473a 100644 --- a/nova/tests/integrated/api_samples/os-used-limits/usedlimits-get-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/os-used-limits/usedlimits-get-resp.xml.tpl @@ -12,6 +12,9 @@ <rate regex=".*changes-since.*" uri="*changes-since*"> <limit next-available="%(timestamp)s" unit="MINUTE" verb="GET" remaining="3" value="3"/> </rate> + <rate regex="^/os-fping" uri="*/os-fping"> + <limit next-available="%(timestamp)s" unit="HOUR" verb="GET" remaining="12" value="12"/> + </rate> </rates> <absolute> <limit name="maxServerMeta" value="128"/> diff --git a/nova/tests/policy.json b/nova/tests/policy.json index 6381a9031..b08e89baa 100644 --- a/nova/tests/policy.json +++ b/nova/tests/policy.json @@ -105,6 +105,8 @@ "compute_extension:floating_ip_dns": "", "compute_extension:floating_ip_pools": "", "compute_extension:floating_ips": "", + "compute_extension:fping": "", + "compute_extension:fping:all_tenants": "is_admin:True", "compute_extension:hosts": "", "compute_extension:hypervisors": "", "compute_extension:instance_usage_audit_log": "", |
