UnboundLocalError: local variable 'volume' referenced before assignment

Bug #1322958 reported by ugvddm
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Medium
ugvddm

Bug Description

When the driver was not initialized, I uploaded a volume as image into glance, I got some error as follow:

[01;31mException during message handling: local variable 'volume' referenced before assignment^[[00m
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00mTraceback (most recent call last):
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00m File "/usr/local/lib/python2.7/dist-packages/oslo/messaging/rpc/dispatcher.py", line 133, in _dispatch_and_reply
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00m incoming.message))
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00m File "/usr/local/lib/python2.7/dist-packages/oslo/messaging/rpc/dispatcher.py", line 176, in _dispatch
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00m return self._do_dispatch(endpoint, method, ctxt, args)
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00m File "/usr/local/lib/python2.7/dist-packages/oslo/messaging/rpc/dispatcher.py", line 122, in _do_dispatch
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00m result = getattr(endpoint, method)(ctxt, **new_args)
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00m File "/opt/stack/cinder/cinder/volume/manager.py", line 721, in copy_volume_to_image
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00m if (volume['instance_uuid'] is None and
^[[01;31m2014-05-25 00:09:40.599 TRACE oslo.messaging.rpc.dispatcher ^[[01;35m^[[00mUnboundLocalError: local variable 'volume' referenced before assignment

As we can see the code from cinder/volume/manager.py, the method require_driver_initialized occurs exception so that the method volume_get will be not executed, and the variable 'volume' is not defined.

 def copy_volume_to_image(self, context, volume_id, image_meta):
        payload = {'volume_id': volume_id, 'image_id': image_meta['id']}
        try:
            # NOTE(flaper87): Verify the driver is enabled
            # before going forward. The exception will be caught
            # and the volume status updated.
            utils.require_driver_initialized(self.driver)

            volume = self.db.volume_get(context, volume_id)
            image_service, image_id = \
                glance.get_remote_image_service(context, image_meta['id'])
            self.driver.copy_volume_to_image(context, volume, image_service,
                                             image_meta)
            LOG.debug(_("Uploaded volume %(volume_id)s to "
                        "image (%(image_id)s) successfully"),
                      {'volume_id': volume_id, 'image_id': image_id})
        except Exception as error:
            with excutils.save_and_reraise_exception():
                payload['message'] = unicode(error)
        finally:
            if (volume['instance_uuid'] is None and
                    volume['attached_host'] is None):
                self.db.volume_update(context, volume_id,
                                      {'status': 'available'})
            else:
                self.db.volume_update(context, volume_id,
                                      {'status': 'in-use'})

ugvddm (271025598-9)
Changed in cinder:
assignee: nobody → ugvddm (271025598-9)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/95371

Changed in cinder:
status: New → In Progress
Mike Perez (thingee)
Changed in cinder:
importance: Undecided → Medium
milestone: none → juno-1
tags: added: icehouse-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/95371
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=c08211b19e2b9c38e537e155d11ffced37af0e85
Submitter: Jenkins
Branch: master

commit c08211b19e2b9c38e537e155d11ffced37af0e85
Author: Zhengguang--reset-author <email address hidden>
Date: Tue May 6 09:05:34 2014 +0800

    Add exception handling for copy_volume_to_image()

    The method require_driver_initialized occurs exception so that the
    method volume_get will be not executed, and the variable 'volume'
    will be not defined. In the "finally" code segment, the
    volume['instance_uuid'] will get the UnboundLocalError, this patch
    gets volume before require_driver_initialized to avoid the above
    problem.

    Change-Id: Ic8167383eb67c5016c9853da274455e0f202dc4d
    Closes-Bug: #1322958

Changed in cinder:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in cinder:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in cinder:
milestone: juno-1 → 2014.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.