]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add 'create_volume' to scheduler RPC API.
authorZhiteng Huang <zhiteng.huang@intel.com>
Thu, 4 Oct 2012 09:34:01 +0000 (17:34 +0800)
committerZhiteng Huang <zhiteng.huang@intel.com>
Mon, 5 Nov 2012 18:51:28 +0000 (02:51 +0800)
Instead of directly call RPC methods, 'create_volume' should be
implemented in scheduler RPC API in order to do versioning.

This increases scheduler RPC version to 1.1

Change-Id: I22d5a097ec3a73c3460f4acd35c602da57f8b52d

cinder/scheduler/manager.py
cinder/scheduler/rpcapi.py
cinder/tests/scheduler/test_rpcapi.py
cinder/volume/api.py

index c5ae6598f5bdcad9010b2307b0cbb78f15b8ad71..fae6f2004a29a3f26550ac781322c19478d84d12 100644 (file)
@@ -45,7 +45,7 @@ FLAGS.register_opt(scheduler_driver_opt)
 class SchedulerManager(manager.Manager):
     """Chooses a host to create volumes"""
 
-    RPC_API_VERSION = '1.0'
+    RPC_API_VERSION = '1.1'
 
     def __init__(self, scheduler_driver=None, *args, **kwargs):
         if not scheduler_driver:
index 325edcd33855aaf75e05762f44a8111eb679de6f..a253f0d297c979c43384aebec6a7aaf04322e8d1 100644 (file)
@@ -31,6 +31,7 @@ class SchedulerAPI(cinder.openstack.common.rpc.proxy.RpcProxy):
     API version history:
 
         1.0 - Initial version.
+        1.1 - Add create_volume() method
     '''
 
     RPC_API_VERSION = '1.0'
@@ -39,6 +40,16 @@ class SchedulerAPI(cinder.openstack.common.rpc.proxy.RpcProxy):
         super(SchedulerAPI, self).__init__(topic=FLAGS.scheduler_topic,
                 default_version=self.RPC_API_VERSION)
 
+    def create_volume(self, ctxt, topic, volume_id, snapshot_id=None,
+                      image_id=None):
+        return self.cast(ctxt, self.make_msg('create_volume',
+                                    topic=topic,
+                                    volume_id=volume_id,
+                                    snapshot_id=snapshot_id,
+                                    image_id=image_id),
+                         topic=None,
+                         version='1.1')
+
     def update_service_capabilities(self, ctxt, service_name, host,
             capabilities):
         self.fanout_cast(ctxt, self.make_msg('update_service_capabilities',
index a6ba60d45b6876e2c6cc3750dac13b8579d3bd9f..7b61fa9ab0214413e89032462ffd78b76c9d08a1 100644 (file)
@@ -40,8 +40,9 @@ class SchedulerRpcAPITestCase(test.TestCase):
         ctxt = context.RequestContext('fake_user', 'fake_project')
         rpcapi = scheduler_rpcapi.SchedulerAPI()
         expected_retval = 'foo' if method == 'call' else None
+        expected_version = kwargs.pop('version', rpcapi.RPC_API_VERSION)
         expected_msg = rpcapi.make_msg(method, **kwargs)
-        expected_msg['version'] = rpcapi.RPC_API_VERSION
+        expected_msg['version'] = expected_version
 
         self.fake_args = None
         self.fake_kwargs = None
@@ -65,3 +66,11 @@ class SchedulerRpcAPITestCase(test.TestCase):
         self._test_scheduler_api('update_service_capabilities',
                 rpc_method='fanout_cast', service_name='fake_name',
                 host='fake_host', capabilities='fake_capabilities')
+
+    def test_create_volume(self):
+        self._test_scheduler_api('create_volume',
+                rpc_method='cast', topic='fake_topic',
+                volume_id='fake_volume_id',
+                snapshot_id='fake_snapshot_id',
+                image_id='fake_image_id',
+                version='1.1')
index 418b1ef78e516e3036a94c1b9747012b87391ac9..49400b73d3c88d68f1d1ee5093540d0ae3fe354a 100644 (file)
@@ -34,7 +34,8 @@ from cinder.openstack.common import timeutils
 from cinder.volume import volume_types
 import cinder.policy
 from cinder import quota
-
+from cinder.scheduler import rpcapi as scheduler_rpcapi
+from cinder.volume import volume_types
 
 volume_host_opt = cfg.BoolOpt('snapshot_same_host',
         default=True,
@@ -79,6 +80,7 @@ class API(base.Base):
     def __init__(self, db_driver=None, image_service=None):
         self.image_service = (image_service or
                               glance.get_default_image_service())
+        self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
         super(API, self).__init__(db_driver)
 
     def create(self, context, size, name, description, snapshot=None,
@@ -195,6 +197,7 @@ class API(base.Base):
             topic = rpc.queue_get_for(context,
                                       FLAGS.volume_topic,
                                       src_volume_ref['host'])
+            # bypass scheduler and send request directly to volume
             rpc.cast(context,
                      topic,
                      {"method": "create_volume",
@@ -202,13 +205,11 @@ class API(base.Base):
                                "snapshot_id": snapshot_id,
                                "image_id": image_id}})
         else:
-            rpc.cast(context,
-                     FLAGS.scheduler_topic,
-                     {"method": "create_volume",
-                      "args": {"topic": FLAGS.volume_topic,
-                               "volume_id": volume_id,
-                               "snapshot_id": snapshot_id,
-                               "image_id": image_id}})
+            self.scheduler_rpcapi.create_volume(context,
+                FLAGS.volume_topic,
+                volume_id,
+                snapshot_id=snapshot_id,
+                image_id=image_id)
 
     @wrap_check_policy
     def delete(self, context, volume, force=False):