diff options
| author | Brian Waldon <bcwaldon@gmail.com> | 2012-01-20 15:12:01 -0800 |
|---|---|---|
| committer | Brian Waldon <bcwaldon@gmail.com> | 2012-01-20 19:47:46 -0800 |
| commit | c7646aa88d564694b99a569c3cdd2c7ffbbb745d (patch) | |
| tree | 2fab0252183edb69fd9e99afa79dce2f41a050d2 /nova/tests | |
| parent | 16ea348a1623f055809d0d9b7fe9f046515b5dd1 (diff) | |
Add SchedulerHints compute extension
This allows arbitrary key/values to be passed in on a compute create
request or rebuild/resize action. That data will be made available to the
compute api as a filter_properties dictionary.
Change-Id: Ie2ec57dcbc0d1d178e06606cb41027f9e46719a2
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py | 103 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/test_extensions.py | 1 |
2 files changed, 104 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py b/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py new file mode 100644 index 000000000..7185873a7 --- /dev/null +++ b/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py @@ -0,0 +1,103 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# 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 import compute +from nova.api.openstack.compute import extensions +from nova.api.openstack import wsgi +import nova.db.api +import nova.rpc +from nova import test +from nova.tests.api.openstack import fakes +from nova import utils + + +UUID = fakes.FAKE_UUID + + +class SchedulerHintsTestCase(test.TestCase): + + def setUp(self): + super(SchedulerHintsTestCase, self).setUp() + + self.fake_instance = fakes.stub_instance(1, uuid=UUID) + + app = compute.APIRouter() + app = extensions.ExtensionMiddleware(app) + app = wsgi.LazySerializationMiddleware(app) + self.app = app + + def test_create_server_without_hints(self): + + def fake_create(*args, **kwargs): + self.assertEqual(kwargs['scheduler_hints'], {}) + return ([self.fake_instance], '') + + self.stubs.Set(nova.compute.api.API, 'create', fake_create) + + req = fakes.HTTPRequest.blank('/fake/servers') + req.method = 'POST' + req.content_type = 'application/json' + body = {'server': { + 'name': 'server_test', + 'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175', + 'flavorRef': '1', + }} + + req.body = utils.dumps(body) + res = req.get_response(self.app) + self.assertEqual(202, res.status_int) + + def test_create_server_with_hints(self): + + def fake_create(*args, **kwargs): + self.assertEqual(kwargs['scheduler_hints'], {'a': 'b'}) + return ([self.fake_instance], '') + + self.stubs.Set(nova.compute.api.API, 'create', fake_create) + + req = fakes.HTTPRequest.blank('/fake/servers') + req.method = 'POST' + req.content_type = 'application/json' + body = { + 'server': { + 'name': 'server_test', + 'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175', + 'flavorRef': '1', + }, + 'os:scheduler_hints': {'a': 'b'}, + } + + req.body = utils.dumps(body) + res = req.get_response(self.app) + self.assertEqual(202, res.status_int) + + def test_create_server_bad_hints(self): + req = fakes.HTTPRequest.blank('/fake/servers') + req.method = 'POST' + req.content_type = 'application/json' + body = { + 'server': { + 'name': 'server_test', + 'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175', + 'flavorRef': '1', + }, + 'os:scheduler_hints': 'here', + } + + req.body = utils.dumps(body) + res = req.get_response(self.app) + self.assertEqual(400, res.status_int) diff --git a/nova/tests/api/openstack/compute/test_extensions.py b/nova/tests/api/openstack/compute/test_extensions.py index 02356bc44..6bc56532f 100644 --- a/nova/tests/api/openstack/compute/test_extensions.py +++ b/nova/tests/api/openstack/compute/test_extensions.py @@ -173,6 +173,7 @@ class ExtensionControllerTest(ExtensionTestCase): "Multinic", "Quotas", "Rescue", + "SchedulerHints", "SecurityGroups", "ServerActionList", "ServerDiagnostics", |
