VMware: Add volume name in vCenter to conn info

The VMware Nova driver uses the volume reference in vCenter
which is passed in the connection info to identify the volume
during attach and detach. If the vCenter inventory is restored
from a backup using backup solutions such as HP data protector,
the volume reference in vCenter may change, but the volume name
(in vCenter) remains the same. This patch adds the volume name
in vCenter to the connection info so that the VMware Nova driver
can use it to identify the volume during detach as a fallback
option.

Change-Id: I0bc2f73a8b50f2b2247531df200c07b4eeb02bf7
Partial-bug: #1593742
This commit is contained in:
Vipin Balachandran 2016-07-18 20:14:37 +05:30
parent 3ad7384913
commit ddabae3ce8
2 changed files with 26 additions and 8 deletions

View File

@ -27,8 +27,10 @@ from oslo_vmware import exceptions
from oslo_vmware import image_transfer
import six
from cinder import context
from cinder import exception as cinder_exceptions
from cinder import test
from cinder.tests.unit import fake_volume
from cinder.volume import configuration
from cinder.volume.drivers.vmware import datastore as hub
from cinder.volume.drivers.vmware import exceptions as vmdk_exceptions
@ -111,6 +113,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
create_session=False)
self._volumeops = volumeops.VMwareVolumeOps(self._session,
self.MAX_OBJECTS)
self._context = context.get_admin_context()
def test_get_volume_stats(self):
stats = self._driver.get_volume_stats()
@ -140,6 +143,19 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
'project_id': project_id,
}
def _create_volume_obj(self,
vol_id=VOL_ID,
display_name=DISPLAY_NAME,
volume_type_id=VOL_TYPE_ID,
status='available',
size=VOL_SIZE,
attachment=None,
project_id=PROJECT_ID):
vol = self._create_volume_dict(
vol_id, display_name, volume_type_id, status, size, attachment,
project_id)
return fake_volume.fake_volume_obj(self._context, **vol)
@mock.patch.object(VMDK_DRIVER, '_select_ds_for_volume')
def test_verify_volume_creation(self, select_ds_for_volume):
volume = self._create_volume_dict()
@ -1689,12 +1705,13 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
else:
connector = {}
volume = self._create_volume_dict()
volume = self._create_volume_obj()
conn_info = self._driver.initialize_connection(volume, connector)
self.assertEqual('vmdk', conn_info['driver_volume_type'])
self.assertEqual(backing_val, conn_info['data']['volume'])
self.assertEqual(volume['id'], conn_info['data']['volume_id'])
self.assertEqual(volume.id, conn_info['data']['volume_id'])
self.assertEqual(volume.name, conn_info['data']['name'])
if instance_exists:
vops.get_host.assert_called_once_with(instance_moref)

View File

@ -513,7 +513,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
"""
connection_info = {'driver_volume_type': 'vmdk'}
backing = self.volumeops.get_backing(volume['name'])
backing = self.volumeops.get_backing(volume.name)
if 'instance' in connector:
# The instance exists
instance = vim_util.get_moref(connector['instance'],
@ -526,7 +526,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
# Create a backing in case it does not exist under the
# host managing the instance.
LOG.info(_LI("There is no backing for the volume: %s. "
"Need to create one."), volume['name'])
"Need to create one."), volume.name)
backing = self._create_backing(volume, host)
else:
# Relocate volume is necessary
@ -539,18 +539,19 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
# Create a backing in case it does not exist. It is a bad use
# case to boot from an empty volume.
LOG.warning(_LW("Trying to boot from an empty volume: %s."),
volume['name'])
volume.name)
# Create backing
backing = self._create_backing(volume)
# Set volume's moref value and name
# Set volume ID and backing moref value and name.
connection_info['data'] = {'volume': backing.value,
'volume_id': volume['id']}
'volume_id': volume.id,
'name': volume.name}
LOG.info(_LI("Returning connection_info: %(info)s for volume: "
"%(volume)s with connector: %(connector)s."),
{'info': connection_info,
'volume': volume['name'],
'volume': volume.name,
'connector': connector})
return connection_info