Cinder driver: TypeError in _open_cinder_volume

Most of the drivers return a string as the value of device['path']
which is then opened and returned as a file-like object.  When the
volume driver type is 'rbd', the volume of device['path'] is already
a file-like object that can be returned directly.  This patch adds
code to handle this special case.

Change-Id: I0c73a740505420c48a1d1ec7d21449fb8848f6ff
Closes-bug: 1643516
This commit is contained in:
zhangdaolong 2017-03-21 17:28:27 +08:00 committed by Brian Rosmaita
parent 2508c093fc
commit 0c5b04a59c
1 changed files with 7 additions and 4 deletions

View File

@ -493,10 +493,13 @@ class Store(glance_store.driver.Store):
device = conn.connect_volume(connection_info['data'])
volume.attach(None, None, attach_mode, host_name=host)
volume = self._wait_volume_status(volume, 'attaching', 'in-use')
LOG.debug('Opening host device "%s"', device['path'])
with temporary_chown(device['path']), \
open(device['path'], mode) as f:
yield f
if (connection_info['driver_volume_type'] == 'rbd' and
not conn.do_local_attach):
yield device['path']
else:
with temporary_chown(device['path']), \
open(device['path'], mode) as f:
yield f
except Exception:
LOG.exception(_LE('Exception while accessing to cinder volume '
'%(volume_id)s.'), {'volume_id': volume.id})