summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2012-01-20 10:36:00 -0800
committerChris Behrens <cbehrens@codestud.com>2012-01-20 14:41:46 -0800
commit1bf066c59bbfe40a30e498f2b24fdddd82fb2508 (patch)
tree3428a589a6b6dda3c63e1dce4f2f7c10c0ec2d31 /nova
parentfd1aa4613b9a644ad2d702ac2d15cf12cef589c5 (diff)
downloadnova-1bf066c59bbfe40a30e498f2b24fdddd82fb2508.tar.gz
nova-1bf066c59bbfe40a30e498f2b24fdddd82fb2508.tar.xz
nova-1bf066c59bbfe40a30e498f2b24fdddd82fb2508.zip
pass filter_properties into scheduling requests for run_instance
Cleans up the resize stuff for avoiding a host Allows for user-specified or compute-specified filters. Change-Id: I0c6066240f602788eff1e0b5856ac52c03a4ebf0
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/api.py24
-rw-r--r--nova/scheduler/distributed_scheduler.py15
-rw-r--r--nova/tests/scheduler/test_distributed_scheduler.py38
-rw-r--r--nova/tests/test_compute.py6
4 files changed, 28 insertions, 55 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 244930402..9cc9744b8 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -525,11 +525,12 @@ class API(base.Base):
LOG.debug(_("Sending create to scheduler for %(pid)s/%(uid)s's") %
locals())
+ filter_properties = {}
+
request_spec = {
'image': image,
'instance_properties': base_options,
'instance_type': instance_type,
- 'filter': None,
'blob': zone_blob,
'num_instances': num_instances,
'block_device_mapping': block_device_mapping,
@@ -543,7 +544,8 @@ class API(base.Base):
"request_spec": request_spec,
"admin_password": admin_password,
"injected_files": injected_files,
- "requested_networks": requested_networks}})
+ "requested_networks": requested_networks,
+ "filter_properties": filter_properties}})
def create(self, context, instance_type,
image_href, kernel_id=None, ramdisk_id=None,
@@ -1391,13 +1393,14 @@ class API(base.Base):
**kwargs)
request_spec = {
- 'instance_type': new_instance_type,
- 'filter': None,
- 'num_instances': 1,
- 'instance_properties': instance,
- 'avoid_original_host': not FLAGS.allow_resize_to_same_host,
- 'local_zone': True,
- }
+ 'instance_type': new_instance_type,
+ 'num_instances': 1,
+ 'instance_properties': instance}
+
+ filter_properties = {'local_zone_only': True, 'ignore_hosts': []}
+
+ if not FLAGS.allow_resize_to_same_host:
+ filter_properties['ignore_hosts'].append(instance['host'])
self._cast_scheduler_message(context,
{"method": "prep_resize",
@@ -1405,7 +1408,8 @@ class API(base.Base):
"instance_uuid": instance['uuid'],
"update_db": False,
"instance_type_id": new_instance_type['id'],
- "request_spec": request_spec}})
+ "request_spec": request_spec,
+ "filter_properties": filter_properties}})
@wrap_check_policy
@scheduler_api.reroute_compute("add_fixed_ip")
diff --git a/nova/scheduler/distributed_scheduler.py b/nova/scheduler/distributed_scheduler.py
index 4e3c7c277..172a7f88d 100644
--- a/nova/scheduler/distributed_scheduler.py
+++ b/nova/scheduler/distributed_scheduler.py
@@ -282,12 +282,7 @@ class DistributedScheduler(driver.Scheduler):
"""Stuff things into filter_properties. Can be overriden in a
subclass to add more data.
"""
- try:
- if request_spec['avoid_original_host']:
- original_host = request_spec['instance_properties']['host']
- filter_properties['ignore_hosts'].append(original_host)
- except (KeyError, TypeError):
- pass
+ pass
def _schedule(self, elevated, topic, request_spec, *args, **kwargs):
"""Returns a list of hosts that meet the required specs,
@@ -311,9 +306,9 @@ class DistributedScheduler(driver.Scheduler):
config_options = self._get_configuration_options()
- filter_properties = {'config_options': config_options,
- 'instance_type': instance_type,
- 'ignore_hosts': []}
+ filter_properties = kwargs.get('filter_properties', {})
+ filter_properties.update({'config_options': config_options,
+ 'instance_type': instance_type})
self.populate_filter_properties(request_spec, filter_properties)
@@ -356,7 +351,7 @@ class DistributedScheduler(driver.Scheduler):
instance_properties)
# Next, tack on the host weights from the child zones
- if not request_spec.get('local_zone', False):
+ if not filter_properties.get('local_zone_only', False):
json_spec = json.dumps(request_spec)
all_zones = self._zone_get_all(elevated)
child_results = self._call_zone_method(elevated, "select",
diff --git a/nova/tests/scheduler/test_distributed_scheduler.py b/nova/tests/scheduler/test_distributed_scheduler.py
index 05c5d18e1..3e909d005 100644
--- a/nova/tests/scheduler/test_distributed_scheduler.py
+++ b/nova/tests/scheduler/test_distributed_scheduler.py
@@ -234,7 +234,8 @@ class DistributedSchedulerTestCase(test.TestCase):
def test_schedule_local_zone(self):
"""Test to make sure _schedule makes no call out to zones if
- local_zone in the request spec is True."""
+ local_zone_only in the filter_properties is True.
+ """
self.next_weight = 1.0
@@ -259,11 +260,11 @@ class DistributedSchedulerTestCase(test.TestCase):
'instance_type': {'memory_mb': 512, 'local_gb': 512},
'instance_properties': {'project_id': 1,
'memory_mb': 512,
- 'local_gb': 512},
- 'local_zone': True}
+ 'local_gb': 512}}
+ filter_properties = {'local_zone_only': True}
self.mox.ReplayAll()
weighted_hosts = sched._schedule(fake_context, 'compute',
- request_spec)
+ request_spec, filter_properties=filter_properties)
self.mox.VerifyAll()
self.assertEquals(len(weighted_hosts), 10)
for weighted_host in weighted_hosts:
@@ -300,32 +301,3 @@ class DistributedSchedulerTestCase(test.TestCase):
hostinfo.update_from_compute_node(dict(memory_mb=1000,
local_gb=0))
self.assertEquals(1000 - 128, fn(hostinfo, {}))
-
- def test_populate_filter_properties(self):
- request_spec = {'instance_properties': {}}
- fixture = fakes.FakeDistributedScheduler()
- filter_properties = {'ignore_hosts': []}
- fixture.populate_filter_properties(request_spec, filter_properties)
- self.assertEqual(len(filter_properties['ignore_hosts']), 0)
-
- # No original host results in not ignoring
- request_spec = {'instance_properties': {},
- 'avoid_original_host': True}
- fixture = fakes.FakeDistributedScheduler()
- fixture.populate_filter_properties(request_spec, filter_properties)
- self.assertEqual(len(filter_properties['ignore_hosts']), 0)
-
- # Original host but avoid is False should not ignore it
- request_spec = {'instance_properties': {'host': 'foo'},
- 'avoid_original_host': False}
- fixture = fakes.FakeDistributedScheduler()
- fixture.populate_filter_properties(request_spec, filter_properties)
- self.assertEqual(len(filter_properties['ignore_hosts']), 0)
-
- # Original host but avoid is True should ignore it
- request_spec = {'instance_properties': {'host': 'foo'},
- 'avoid_original_host': True}
- fixture = fakes.FakeDistributedScheduler()
- fixture.populate_filter_properties(request_spec, filter_properties)
- self.assertEqual(len(filter_properties['ignore_hosts']), 1)
- self.assertEqual(filter_properties['ignore_hosts'][0], 'foo')
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 77daa4564..992b1076f 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -2171,9 +2171,10 @@ class ComputeAPITestCase(BaseTestCase):
def test_resize_request_spec(self):
def _fake_cast(context, args):
request_spec = args['args']['request_spec']
+ filter_properties = args['args']['filter_properties']
instance_properties = request_spec['instance_properties']
self.assertEqual(instance_properties['host'], 'host2')
- self.assertEqual(request_spec['avoid_original_host'], True)
+ self.assertIn('host2', filter_properties['ignore_hosts'])
self.stubs.Set(self.compute_api, '_cast_scheduler_message',
_fake_cast)
@@ -2190,9 +2191,10 @@ class ComputeAPITestCase(BaseTestCase):
def test_resize_request_spec_noavoid(self):
def _fake_cast(context, args):
request_spec = args['args']['request_spec']
+ filter_properties = args['args']['filter_properties']
instance_properties = request_spec['instance_properties']
self.assertEqual(instance_properties['host'], 'host2')
- self.assertEqual(request_spec['avoid_original_host'], False)
+ self.assertNotIn('host2', filter_properties['ignore_hosts'])
self.stubs.Set(self.compute_api, '_cast_scheduler_message',
_fake_cast)