summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-08-03 22:50:21 -0400
committerRussell Bryant <rbryant@redhat.com>2012-08-06 15:09:33 -0400
commit98f753d4c5e8bdf31716a7452f89930a51b3edf5 (patch)
tree1bf25777e0c38629dd9dc8017dd124c290acf86b /nova
parent7677354e3ba0954158d33feef3667b0fe7dcc2a3 (diff)
downloadnova-98f753d4c5e8bdf31716a7452f89930a51b3edf5.tar.gz
nova-98f753d4c5e8bdf31716a7452f89930a51b3edf5.tar.xz
nova-98f753d4c5e8bdf31716a7452f89930a51b3edf5.zip
Send full instance to scheduler live_migration.
Remove the instance_id parameter and send a full instance dict to the live_migration method of the scheduler manager. This cuts down on some unnecessary database access in the scheduler. Part of blueprint no-db-messaging. Change-Id: Ic45105300c967c760559df2225e59e515cea8b7b
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/api.py8
-rw-r--r--nova/scheduler/driver.py27
-rw-r--r--nova/scheduler/manager.py2
-rw-r--r--nova/scheduler/rpcapi.py8
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_admin_actions.py7
-rw-r--r--nova/tests/scheduler/test_rpcapi.py3
-rw-r--r--nova/tests/scheduler/test_scheduler.py12
7 files changed, 32 insertions, 35 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 7ff66aa93..900ab706f 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1719,12 +1719,8 @@ class API(base.Base):
"""Migrate a server lively to a new host."""
LOG.debug(_("Going to try to live migrate instance"),
instance=instance)
- self.scheduler_rpcapi.live_migration(context,
- block_migration,
- disk_over_commit,
- instance["id"],
- host,
- topic=FLAGS.compute_topic)
+ self.scheduler_rpcapi.live_migration(context, block_migration,
+ disk_over_commit, instance, host)
class HostAPI(base.Base):
diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py
index 36be81f48..6494957e2 100644
--- a/nova/scheduler/driver.py
+++ b/nova/scheduler/driver.py
@@ -200,13 +200,14 @@ class Scheduler(object):
msg = _("Driver must implement schedule_run_instance")
raise NotImplementedError(msg)
- def schedule_live_migration(self, context, instance_id, dest,
- block_migration=False,
- disk_over_commit=False):
+ def schedule_live_migration(self, context, dest,
+ block_migration=False, disk_over_commit=False,
+ instance=None, instance_id=None):
"""Live migration scheduling method.
:param context:
- :param instance_id:
+ :param instance_id: (deprecated)
+ :param instance: instance dict
:param dest: destination host
:param block_migration: if true, block_migration.
:param disk_over_commit: if True, consider real(not virtual)
@@ -217,27 +218,29 @@ class Scheduler(object):
Then scheduler send request that host.
"""
# Check we can do live migration
- instance_ref = db.instance_get(context, instance_id)
- self._live_migration_src_check(context, instance_ref)
- self._live_migration_dest_check(context, instance_ref, dest)
- self._live_migration_common_check(context, instance_ref, dest)
+ if not instance:
+ instance = db.instance_get(context, instance_id)
+
+ self._live_migration_src_check(context, instance)
+ self._live_migration_dest_check(context, instance, dest)
+ self._live_migration_common_check(context, instance, dest)
self.compute_rpcapi.check_can_live_migrate_destination(context,
- instance_ref, dest, block_migration, disk_over_commit)
+ instance, dest, block_migration, disk_over_commit)
# Change instance_state
values = {"task_state": task_states.MIGRATING}
# update instance state and notify
(old_ref, new_instance_ref) = db.instance_update_and_get_original(
- context, instance_ref['uuid'], values)
+ context, instance['uuid'], values)
notifications.send_update(context, old_ref, new_instance_ref,
service="scheduler")
# Perform migration
- src = instance_ref['host']
+ src = instance['host']
cast_to_compute_host(context, src, 'live_migration',
update_db=False,
- instance_id=instance_id,
+ instance_id=instance['id'],
dest=dest,
block_migration=block_migration)
diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py
index ad3441593..924e5d426 100644
--- a/nova/scheduler/manager.py
+++ b/nova/scheduler/manager.py
@@ -53,7 +53,7 @@ QUOTAS = quota.QUOTAS
class SchedulerManager(manager.Manager):
"""Chooses a host to run instances on."""
- RPC_API_VERSION = '1.2'
+ RPC_API_VERSION = '1.3'
def __init__(self, scheduler_driver=None, *args, **kwargs):
if not scheduler_driver:
diff --git a/nova/scheduler/rpcapi.py b/nova/scheduler/rpcapi.py
index a553b202c..9965a162e 100644
--- a/nova/scheduler/rpcapi.py
+++ b/nova/scheduler/rpcapi.py
@@ -37,6 +37,7 @@ class SchedulerAPI(nova.openstack.common.rpc.proxy.RpcProxy):
- remove instance_type_id, add instance_type
- remove topic, it was unused
1.2 - Remove topic from run_instance, it was unused
+ 1.3 - Remove instance_id, add instance to live_migration
'''
BASE_RPC_API_VERSION = '1.0'
@@ -70,13 +71,14 @@ class SchedulerAPI(nova.openstack.common.rpc.proxy.RpcProxy):
return self.call(ctxt, self.make_msg('show_host_resources', host=host))
def live_migration(self, ctxt, block_migration, disk_over_commit,
- instance_id, dest, topic):
+ instance, dest, topic):
# NOTE(comstud): Call vs cast so we can get exceptions back, otherwise
# this call in the scheduler driver doesn't return anything.
+ instance_p = jsonutils.to_primitive(instance)
return self.call(ctxt, self.make_msg('live_migration',
block_migration=block_migration,
- disk_over_commit=disk_over_commit, instance_id=instance_id,
- dest=dest, topic=topic))
+ disk_over_commit=disk_over_commit, instance=instance_p,
+ dest=dest, topic=topic), version='1.3')
def update_service_capabilities(self, ctxt, service_name, host,
capabilities):
diff --git a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py
index 89ac3d9a0..8da846125 100644
--- a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py
+++ b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py
@@ -62,9 +62,10 @@ def fake_compute_api_get(self, context, instance_id):
'task_state': None}
-def fake_scheduler_api_live_migration(self, context, block_migration,
- disk_over_commit, instance_id,
- dest, topic):
+def fake_scheduler_api_live_migration(self, context, dest,
+ block_migration=False,
+ disk_over_commit=False, instance=None,
+ instance_id=None):
return None
diff --git a/nova/tests/scheduler/test_rpcapi.py b/nova/tests/scheduler/test_rpcapi.py
index 20874c365..ff17d9183 100644
--- a/nova/tests/scheduler/test_rpcapi.py
+++ b/nova/tests/scheduler/test_rpcapi.py
@@ -95,7 +95,8 @@ class SchedulerRpcAPITestCase(test.TestCase):
self._test_scheduler_api('live_migration', rpc_method='call',
block_migration='fake_block_migration',
disk_over_commit='fake_disk_over_commit',
- instance_id='fake_id', dest='fake_dest', topic='fake_topic')
+ instance='fake_instance', dest='fake_dest', topic='fake_topic',
+ version='1.3')
def test_update_service_capabilities(self):
self._test_scheduler_api('update_service_capabilities',
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index 0c416dc72..3950d1ef6 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -403,7 +403,6 @@ class SchedulerTestCase(test.TestCase):
def test_live_migration_basic(self):
"""Test basic schedule_live_migration functionality"""
- self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
self.mox.StubOutWithMock(self.driver, '_live_migration_dest_check')
self.mox.StubOutWithMock(self.driver, '_live_migration_common_check')
@@ -416,11 +415,9 @@ class SchedulerTestCase(test.TestCase):
dest = 'fake_host2'
block_migration = False
disk_over_commit = False
- instance = self._live_migration_instance()
+ instance = jsonutils.to_primitive(self._live_migration_instance())
instance_id = instance['id']
instance_uuid = instance['uuid']
- db.instance_get(self.context,
- instance_id).AndReturn(instance)
self.driver._live_migration_src_check(self.context, instance)
self.driver._live_migration_dest_check(self.context, instance, dest)
@@ -441,14 +438,13 @@ class SchedulerTestCase(test.TestCase):
self.mox.ReplayAll()
self.driver.schedule_live_migration(self.context,
- instance_id=instance['id'], dest=dest,
+ instance=instance, dest=dest,
block_migration=block_migration,
disk_over_commit=disk_over_commit)
def test_live_migration_all_checks_pass(self):
"""Test live migration when all checks pass."""
- self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(utils, 'service_is_up')
self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
@@ -463,8 +459,6 @@ class SchedulerTestCase(test.TestCase):
instance = jsonutils.to_primitive(self._live_migration_instance())
instance_id = instance['id']
instance_uuid = instance['uuid']
- db.instance_get(self.context,
- instance_id).AndReturn(instance)
# Source checks
db.service_get_all_compute_by_host(self.context,
@@ -511,7 +505,7 @@ class SchedulerTestCase(test.TestCase):
self.mox.ReplayAll()
result = self.driver.schedule_live_migration(self.context,
- instance_id=instance_id, dest=dest,
+ instance=instance, dest=dest,
block_migration=block_migration,
disk_over_commit=disk_over_commit)
self.assertEqual(result, None)