summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-05-29 22:00:10 -0400
committerRussell Bryant <rbryant@redhat.com>2012-05-31 15:19:31 -0400
commit5a1236e469faf0f415989249d8aaa1c510fa8b3d (patch)
tree5033707f9c997ec1b26bff55d74f9a57727afbf0
parent60b6c5d53508d9c2b113dd78c5a0bc43a7fad9f8 (diff)
downloadnova-5a1236e469faf0f415989249d8aaa1c510fa8b3d.tar.gz
nova-5a1236e469faf0f415989249d8aaa1c510fa8b3d.tar.xz
nova-5a1236e469faf0f415989249d8aaa1c510fa8b3d.zip
Add compare_cpu to the compute rpcapi.
Part of bug 1006467. This patch adds compare_cpu to the compute rpcapi. This is used by the scheduler. Change-Id: Ibce3ab3797c1305829c0722be1813e462193f08b
-rw-r--r--nova/compute/rpcapi.py4
-rw-r--r--nova/scheduler/driver.py8
-rw-r--r--nova/tests/compute/test_rpcapi.py4
-rw-r--r--nova/tests/scheduler/test_scheduler.py10
4 files changed, 19 insertions, 7 deletions
diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py
index 0694d6e09..7d7b57151 100644
--- a/nova/compute/rpcapi.py
+++ b/nova/compute/rpcapi.py
@@ -84,6 +84,10 @@ class ComputeAPI(nova.rpc.proxy.RpcProxy):
mountpoint=mountpoint),
topic=self._compute_topic(ctxt, None, instance))
+ def compare_cpu(self, ctxt, cpu_info, host):
+ return self.call(ctxt, self.make_msg('compare_cpu', cpu_info=cpu_info),
+ topic=self._compute_topic(ctxt, host, None))
+
def confirm_resize(self, ctxt, instance, migration_id, host,
cast=True):
rpc_method = self.cast if cast else self.call
diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py
index 364278584..bf635ddd4 100644
--- a/nova/scheduler/driver.py
+++ b/nova/scheduler/driver.py
@@ -23,6 +23,7 @@ Scheduler base class that all Schedulers should inherit from
from nova.compute import api as compute_api
from nova.compute import power_state
+from nova.compute import rpcapi as compute_rpcapi
from nova.compute import vm_states
from nova import db
from nova import exception
@@ -137,6 +138,7 @@ class Scheduler(object):
self.host_manager = importutils.import_object(
FLAGS.scheduler_host_manager)
self.compute_api = compute_api.API()
+ self.compute_rpcapi = compute_rpcapi.ComputeAPI()
def get_host_list(self):
"""Get a list of hosts from the HostManager."""
@@ -354,10 +356,8 @@ class Scheduler(object):
# Checking cpuinfo.
try:
- rpc.call(context,
- rpc.queue_get_for(context, FLAGS.compute_topic, dest),
- {"method": 'compare_cpu',
- "args": {'cpu_info': oservice_ref['cpu_info']}})
+ self.compute_rpcapi.compare_cpu(context, oservice_ref['cpu_info'],
+ dest)
except exception.InvalidCPUInfo:
src = instance_ref['host']
diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py
index 7a4fda426..23ac55fc3 100644
--- a/nova/tests/compute/test_rpcapi.py
+++ b/nova/tests/compute/test_rpcapi.py
@@ -105,6 +105,10 @@ class ComputeRpcAPITestCase(test.TestCase):
self._test_compute_api('attach_volume', 'cast',
instance=self.fake_instance, volume_id='id', mountpoint='mp')
+ def test_compare_cpu(self):
+ self._test_compute_api('compare_cpu', 'call', cpu_info='info',
+ host='host')
+
def test_confirm_resize_cast(self):
self._test_compute_api('confirm_resize', 'cast',
instance=self.fake_instance, migration_id='id', host='host')
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index 302f22939..e7057b406 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -23,6 +23,7 @@ import json
from nova.compute import api as compute_api
from nova.compute import power_state
+from nova.compute import rpcapi as compute_rpcapi
from nova.compute import vm_states
from nova import context
from nova import db
@@ -539,7 +540,9 @@ class SchedulerTestCase(test.TestCase):
dest).AndReturn('dest_queue')
rpc.call(self.context, 'dest_queue',
{'method': 'compare_cpu',
- 'args': {'cpu_info': 'fake_cpu_info'}}).AndReturn(True)
+ 'args': {'cpu_info': 'fake_cpu_info'},
+ 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None
+ ).AndReturn(True)
db.instance_update_and_get_original(self.context, instance['id'],
{"vm_state": vm_states.MIGRATING}).AndReturn(
@@ -957,8 +960,9 @@ class SchedulerTestCase(test.TestCase):
dest).AndReturn('dest_queue')
rpc.call(self.context, 'dest_queue',
{'method': 'compare_cpu',
- 'args': {'cpu_info': 'fake_cpu_info'}}).AndRaise(
- rpc_common.RemoteError())
+ 'args': {'cpu_info': 'fake_cpu_info'},
+ 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None
+ ).AndRaise(rpc_common.RemoteError())
self.mox.ReplayAll()
self.assertRaises(rpc_common.RemoteError,