diff options
author | Mark Washenberger <mark.washenberger@rackspace.com> | 2012-01-05 18:15:29 -0500 |
---|---|---|
committer | Mark Washenberger <mark.washenberger@rackspace.com> | 2012-01-05 18:15:29 -0500 |
commit | 162ab4f48e573662824872da56aecbef05ba94f0 (patch) | |
tree | e636e60294b91b87d3f53f432c8582463211efe5 | |
parent | dcf5fe4d9307c0d477fb8c48df74a812244d8b97 (diff) | |
download | nova-162ab4f48e573662824872da56aecbef05ba94f0.tar.gz nova-162ab4f48e573662824872da56aecbef05ba94f0.tar.xz nova-162ab4f48e573662824872da56aecbef05ba94f0.zip |
Use instance_properties in resize.
This just makes resize behave a bit more like create, which is useful
for custom filtering.
Change-Id: I10ba726712d8f601f5ee97e0bb033bd7339a7a88
-rw-r--r-- | nova/compute/api.py | 2 | ||||
-rw-r--r-- | nova/scheduler/chance.py | 10 | ||||
-rw-r--r-- | nova/scheduler/distributed_scheduler.py | 10 | ||||
-rw-r--r-- | nova/tests/scheduler/test_chance_scheduler.py | 4 | ||||
-rw-r--r-- | nova/tests/scheduler/test_distributed_scheduler.py | 4 | ||||
-rw-r--r-- | nova/tests/test_compute.py | 6 |
6 files changed, 21 insertions, 15 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 70e9876ae..13136079c 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1317,7 +1317,7 @@ class API(base.Base): 'instance_type': new_instance_type, 'filter': None, 'num_instances': 1, - 'original_host': instance['host'], + 'instance_properties': instance, 'avoid_original_host': not FLAGS.allow_resize_to_same_host, 'local_zone': True, } diff --git a/nova/scheduler/chance.py b/nova/scheduler/chance.py index 2995bda70..be66eb3c6 100644 --- a/nova/scheduler/chance.py +++ b/nova/scheduler/chance.py @@ -34,10 +34,12 @@ class ChanceScheduler(driver.Scheduler): """Filter a list of hosts based on request_spec.""" # Filter out excluded host - if (request_spec and 'original_host' in request_spec and - request_spec.get('avoid_original_host', True)): - hosts = [host for host in hosts - if host != request_spec['original_host']] + try: + if request_spec['avoid_original_host']: + original_host = request_spec['instance_properties']['host'] + hosts = [host for host in hosts if host != original_host] + except (KeyError, TypeError): + pass return hosts diff --git a/nova/scheduler/distributed_scheduler.py b/nova/scheduler/distributed_scheduler.py index c4823efad..a7cd97da9 100644 --- a/nova/scheduler/distributed_scheduler.py +++ b/nova/scheduler/distributed_scheduler.py @@ -394,10 +394,12 @@ class DistributedScheduler(driver.Scheduler): selected_filters = self._choose_host_filters() # Filter out original host - if ('original_host' in request_spec and - request_spec.get('avoid_original_host', True)): - hosts = [(h, hi) for h, hi in hosts - if h != request_spec['original_host']] + try: + if request_spec['avoid_original_host']: + original_host = request_spec['instance_properties']['host'] + hosts = [(h, hi) for h, hi in hosts if h != original_host] + except (KeyError, TypeError): + pass # TODO(sandy): We're only using InstanceType-based specs # currently. Later we'll need to snoop for more detailed diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index 8d4c73adb..0bb3927a2 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -30,7 +30,7 @@ class ChanceSchedulerTestCase(test.TestCase): sched = chance.ChanceScheduler() hosts = ['host1', 'host2', 'host3'] - request_spec = dict(original_host='host2', + request_spec = dict(instance_properties=dict(host='host2'), avoid_original_host=True) filtered = sched._filter_hosts(request_spec, hosts) @@ -43,7 +43,7 @@ class ChanceSchedulerTestCase(test.TestCase): sched = chance.ChanceScheduler() hosts = ['host1', 'host2', 'host3'] - request_spec = dict(original_host='host2', + request_spec = dict(instance_properties=dict(host='host2'), avoid_original_host=False) filtered = sched._filter_hosts(request_spec, hosts) diff --git a/nova/tests/scheduler/test_distributed_scheduler.py b/nova/tests/scheduler/test_distributed_scheduler.py index 047c8c51a..36d2ddc5b 100644 --- a/nova/tests/scheduler/test_distributed_scheduler.py +++ b/nova/tests/scheduler/test_distributed_scheduler.py @@ -313,7 +313,7 @@ class DistributedSchedulerTestCase(test.TestCase): _fake_choose_host_filters) hosts = [('host1', '1info'), ('host2', '2info'), ('host3', '3info')] - request_spec = dict(original_host='host2', + request_spec = dict(instance_properties=dict(host='host2'), avoid_original_host=True) filtered = sched._filter_hosts('compute', request_spec, hosts, {}) @@ -333,7 +333,7 @@ class DistributedSchedulerTestCase(test.TestCase): _fake_choose_host_filters) hosts = [('host1', '1info'), ('host2', '2info'), ('host3', '3info')] - request_spec = dict(original_host='host2', + request_spec = dict(instance_properties=dict(host='host2'), avoid_original_host=False) filtered = sched._filter_hosts('compute', request_spec, hosts, {}) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index a4a5faa48..fb38e7b98 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -2060,7 +2060,8 @@ class ComputeAPITestCase(BaseTestCase): def test_resize_request_spec(self): def _fake_cast(context, args): request_spec = args['args']['request_spec'] - self.assertEqual(request_spec['original_host'], 'host2') + instance_properties = request_spec['instance_properties'] + self.assertEqual(instance_properties['host'], 'host2') self.assertEqual(request_spec['avoid_original_host'], True) self.stubs.Set(self.compute_api, '_cast_scheduler_message', @@ -2078,7 +2079,8 @@ class ComputeAPITestCase(BaseTestCase): def test_resize_request_spec_noavoid(self): def _fake_cast(context, args): request_spec = args['args']['request_spec'] - self.assertEqual(request_spec['original_host'], 'host2') + instance_properties = request_spec['instance_properties'] + self.assertEqual(instance_properties['host'], 'host2') self.assertEqual(request_spec['avoid_original_host'], False) self.stubs.Set(self.compute_api, '_cast_scheduler_message', |