]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove check_volume_az_zone functor and associated passing
authorJoshua Harlow <harlowja@yahoo-inc.com>
Mon, 9 Jun 2014 23:20:31 +0000 (16:20 -0700)
committerJoshua Harlow <harlowja@yahoo-inc.com>
Mon, 23 Jun 2014 23:09:10 +0000 (16:09 -0700)
To make it easier to understand why a volume is being rejected
when its availability zone is not allowed remove the functor
that does this check and use the set of valid availability zones
as the master list of valid zones that can be used (and use this
inside the task that validates this data).

Change-Id: Ib8462dbbbc33242edbbf02a7c737746d3142d043

cinder/volume/api.py
cinder/volume/flows/api/create_volume.py

index 1466c0913ccbbe473f7dee15bc6244b7c502bf6f..39e9d9fc51d834537dbc950b892c049c60247256 100644 (file)
@@ -110,13 +110,6 @@ class API(base.Base):
         self.key_manager = keymgr.API()
         super(API, self).__init__(db_driver)
 
-    def _valid_availability_zone(self, availability_zone):
-        azs = self.list_availability_zones(enable_cache=True)
-        names = set([az['name'] for az in azs])
-        if CONF.storage_availability_zone:
-            names.add(CONF.storage_availability_zone)
-        return availability_zone in names
-
     def list_availability_zones(self, enable_cache=False):
         """Describe the known availability zones
 
@@ -174,13 +167,13 @@ class API(base.Base):
                         "You should omit the argument.")
                 raise exception.InvalidInput(reason=msg)
 
-        def check_volume_az_zone(availability_zone):
-            try:
-                return self._valid_availability_zone(availability_zone)
-            except exception.CinderException:
-                LOG.exception(_("Unable to query if %s is in the "
-                                "availability zone set"), availability_zone)
-                return False
+        # Determine the valid availability zones that the volume could be
+        # created in (a task in the flow will/can use this information to
+        # ensure that the availability zone requested is valid).
+        raw_zones = self.list_availability_zones(enable_cache=True)
+        availability_zones = set([az['name'] for az in raw_zones])
+        if CONF.storage_availability_zone:
+            availability_zones.add(CONF.storage_availability_zone)
 
         create_what = {
             'context': context,
@@ -198,13 +191,12 @@ class API(base.Base):
             'backup_source_volume': backup_source_volume,
             'optional_args': {'is_quota_committed': False}
         }
-
         try:
             flow_engine = create_volume.get_flow(self.scheduler_rpcapi,
                                                  self.volume_rpcapi,
                                                  self.db,
                                                  self.image_service,
-                                                 check_volume_az_zone,
+                                                 availability_zones,
                                                  create_what)
         except Exception:
             LOG.exception(_("Failed to create api volume flow"))
index b294d2d06d04b081c25cf2b805375643dd0e132d..99d11ff692cc346767db771230d658c679fb5173 100644 (file)
@@ -59,13 +59,11 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask):
                             'source_volid', 'volume_type', 'volume_type_id',
                             'encryption_key_id'])
 
-    def __init__(self, image_service, az_check_functor=None, **kwargs):
+    def __init__(self, image_service, availability_zones, **kwargs):
         super(ExtractVolumeRequestTask, self).__init__(addons=[ACTION],
                                                        **kwargs)
         self.image_service = image_service
-        self.az_check_functor = az_check_functor
-        if not self.az_check_functor:
-            self.az_check_functor = lambda az: True
+        self.availability_zones = availability_zones
 
     @staticmethod
     def _extract_snapshot(snapshot):
@@ -256,7 +254,7 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask):
             else:
                 # For backwards compatibility use the storage_availability_zone
                 availability_zone = CONF.storage_availability_zone
-        if not self.az_check_functor(availability_zone):
+        if availability_zone not in self.availability_zones:
             msg = _("Availability zone '%s' is invalid") % (availability_zone)
             LOG.warn(msg)
             raise exception.InvalidInput(reason=msg)
@@ -692,9 +690,8 @@ class VolumeCastTask(flow_utils.CinderTask):
         LOG.error(_('Unexpected build error:'), exc_info=exc_info)
 
 
-def get_flow(scheduler_rpcapi, volume_rpcapi, db,
-             image_service,
-             az_check_functor,
+def get_flow(scheduler_rpcapi, volume_rpcapi, db_api,
+             image_service_api, availability_zones,
              create_what):
     """Constructs and returns the api entrypoint flow.
 
@@ -712,18 +709,18 @@ def get_flow(scheduler_rpcapi, volume_rpcapi, db,
     api_flow = linear_flow.Flow(flow_name)
 
     api_flow.add(ExtractVolumeRequestTask(
-        image_service,
-        az_check_functor,
+        image_service_api,
+        availability_zones,
         rebind={'size': 'raw_size',
                 'availability_zone': 'raw_availability_zone',
                 'volume_type': 'raw_volume_type'}))
     api_flow.add(QuotaReserveTask(),
-                 EntryCreateTask(db),
+                 EntryCreateTask(db_api),
                  QuotaCommitTask())
 
     # This will cast it out to either the scheduler or volume manager via
     # the rpc apis provided.
-    api_flow.add(VolumeCastTask(scheduler_rpcapi, volume_rpcapi, db))
+    api_flow.add(VolumeCastTask(scheduler_rpcapi, volume_rpcapi, db_api))
 
     # Now load (but do not run) the flow using the provided initial data.
     return taskflow.engines.load(api_flow, store=create_what)