From 762cc5532ba68a09299f48aa7ea43b9ce3315f11 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 20 Aug 2013 18:06:32 -0700 Subject: [PATCH] Move create_volume flow to a subfolder In order to start splitting up the create_volume flow into smaller files we will start by moving the create_volume.py file to a folder with just __init__.py and this will then act as the base for create_volume task modules. Also add in a utils file that contains to start the commonly used debug listener attachment mechanism. Change-Id: Ie2fd0c77bb04f8153afecdce75588614b48fed8a --- .../__init__.py} | 37 ++----------- cinder/volume/flows/utils.py | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+), 33 deletions(-) rename cinder/volume/flows/{create_volume.py => create_volume/__init__.py} (97%) create mode 100644 cinder/volume/flows/utils.py diff --git a/cinder/volume/flows/create_volume.py b/cinder/volume/flows/create_volume/__init__.py similarity index 97% rename from cinder/volume/flows/create_volume.py rename to cinder/volume/flows/create_volume/__init__.py index b91ba58e4..b0e0a6a1e 100644 --- a/cinder/volume/flows/create_volume.py +++ b/cinder/volume/flows/create_volume/__init__.py @@ -39,6 +39,7 @@ from cinder.taskflow import task from cinder import units from cinder import utils from cinder.volume.flows import base +from cinder.volume.flows import utils as flow_utils from cinder.volume import utils as volume_utils from cinder.volume import volume_types @@ -1516,36 +1517,6 @@ class CreateVolumeOnFinishTask(NotifyVolumeActionTask): }) -def _attach_debug_listeners(flow): - """Sets up a nice set of debug listeners for the flow. - - These listeners will log when tasks/flows are transitioning from state to - state so that said states can be seen in the debug log output which is very - useful for figuring out where problems are occuring. - """ - - def flow_log_change(state, details): - # TODO(harlowja): the bug 1214083 is causing problems - LOG.debug(_("%(flow)s has moved into state %(state)s from state" - " %(old_state)s") % {'state': state, - 'old_state': details.get('old_state'), - 'flow': str(details['flow'])}) - - def task_log_change(state, details): - # TODO(harlowja): the bug 1214083 is causing problems - LOG.debug(_("%(flow)s has moved %(runner)s into state %(state)s with" - " result: %(result)s") % {'state': state, - 'flow': str(details['flow']), - 'runner': str(details['runner']), - 'result': details.get('result')}) - - # Register * for all state changes (and not selective state changes to be - # called upon) since all the changes is more useful. - flow.notifier.register('*', flow_log_change) - flow.task_notifier.register('*', task_log_change) - return flow - - def get_api_flow(scheduler_rpcapi, volume_rpcapi, db, image_service, az_check_functor, @@ -1586,7 +1557,7 @@ def get_api_flow(scheduler_rpcapi, volume_rpcapi, db, # Note(harlowja): this will return the flow as well as the uuid of the # task which will produce the 'volume' database reference (since said # reference is returned to other callers in the api for further usage). - return (_attach_debug_listeners(api_flow), v_uuid) + return (flow_utils.attach_debug_listeners(api_flow), v_uuid) def get_scheduler_flow(db, driver, request_spec=None, filter_properties=None, @@ -1673,7 +1644,7 @@ def get_scheduler_flow(db, driver, request_spec=None, filter_properties=None, scheduler_flow.add(schedule_create_volume) - return _attach_debug_listeners(scheduler_flow) + return flow_utils.attach_debug_listeners(scheduler_flow) def get_manager_flow(db, driver, scheduler_rpcapi, host, volume_id, @@ -1739,4 +1710,4 @@ def get_manager_flow(db, driver, scheduler_rpcapi, host, volume_id, volume_flow.add(CreateVolumeFromSpecTask(db, host, driver)) volume_flow.add(CreateVolumeOnFinishTask(db, host, "create.end")) - return _attach_debug_listeners(volume_flow) + return flow_utils.attach_debug_listeners(volume_flow) diff --git a/cinder/volume/flows/utils.py b/cinder/volume/flows/utils.py new file mode 100644 index 000000000..2f88df704 --- /dev/null +++ b/cinder/volume/flows/utils.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2013 Yahoo! Inc. All Rights Reserved. +# Copyright (c) 2013 OpenStack, LLC. +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from cinder.openstack.common import log as logging + +LOG = logging.getLogger(__name__) + + +def attach_debug_listeners(flow): + """Sets up a nice set of debug listeners for the flow. + + These listeners will log when tasks/flows are transitioning from state to + state so that said states can be seen in the debug log output which is very + useful for figuring out where problems are occuring. + """ + + def flow_log_change(state, details): + # TODO(harlowja): the bug 1214083 is causing problems + LOG.debug(_("%(flow)s has moved into state %(state)s from state" + " %(old_state)s") % {'state': state, + 'old_state': details.get('old_state'), + 'flow': str(details['flow'])}) + + def task_log_change(state, details): + # TODO(harlowja): the bug 1214083 is causing problems + LOG.debug(_("%(flow)s has moved %(runner)s into state %(state)s with" + " result: %(result)s") % {'state': state, + 'flow': str(details['flow']), + 'runner': str(details['runner']), + 'result': details.get('result')}) + + # Register * for all state changes (and not selective state changes to be + # called upon) since all the changes is more useful. + flow.notifier.register('*', flow_log_change) + flow.task_notifier.register('*', task_log_change) + return flow -- 2.45.2