From ed80ed615762e0ff24235b7d57fa8b356c659e11 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Sun, 12 Aug 2012 10:01:09 -0700 Subject: Key auto_disk_config in create server off of ext. Implements part of blueprint disable-server-extensions Makes sure that auto_disk_config is only accepted in the create server request if the extension is enabled. Note that the extension alias is OS-DCF because it also adds output to the server request. Change-Id: I59fafe769e1e562e6bf9f6db768acc9b0f8d2b93 --- nova/api/openstack/compute/servers.py | 4 +++- nova/tests/api/openstack/compute/test_servers.py | 26 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index ca446f24b..797c498b8 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -678,7 +678,9 @@ class Controller(wsgi.Controller): if min_count > max_count: min_count = max_count - auto_disk_config = server_dict.get('auto_disk_config') + auto_disk_config = False + if self.ext_mgr.is_loaded('OS-DCF'): + auto_disk_config = server_dict.get('auto_disk_config') scheduler_hints = {} if self.ext_mgr.is_loaded('os-scheduler-hints'): diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index a1db243da..8d5a36168 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1790,6 +1790,32 @@ class ServersControllerCreateTest(test.TestCase): self.stubs.Set(nova.compute.api.API, 'create', create) self._test_create_extra(params) + def test_create_instance_with_disk_config_enabled(self): + self.ext_mgr.extensions = {'OS-DCF': 'fake'} + # NOTE(vish): the extension converts OS-DCF:disk_config into + # auto_disk_config, so we are testing with + # the_internal_value + params = {'auto_disk_config': True} + old_create = nova.compute.api.API.create + + def create(*args, **kwargs): + self.assertEqual(kwargs['auto_disk_config'], True) + return old_create(*args, **kwargs) + + self.stubs.Set(nova.compute.api.API, 'create', create) + self._test_create_extra(params) + + def test_create_instance_with_disk_config_disabled(self): + params = {'auto_disk_config': True} + old_create = nova.compute.api.API.create + + def create(*args, **kwargs): + self.assertEqual(kwargs['auto_disk_config'], False) + return old_create(*args, **kwargs) + + self.stubs.Set(nova.compute.api.API, 'create', create) + self._test_create_extra(params) + def test_create_instance_with_scheduler_hints_enabled(self): self.ext_mgr.extensions = {'os-scheduler-hints': 'fake'} hints = {'a': 'b'} -- cgit