Fixes attribute content checking

Use proper way to check the volume attribute contents in display_name
and display_description. If they are not empty, translate them to
volume backend description. Modify other places where return empty
string makes sense than None as well as the return value checking.

Closes-Bug: 1414247
Change-Id: I87b8d09baf75b227b479f8a79ace90a85cf84177
This commit is contained in:
Jay Wang 2015-01-27 12:02:59 -08:00
parent a36100bd34
commit 7f88689a20
2 changed files with 26 additions and 20 deletions

View File

@ -215,7 +215,9 @@ class NimbleDriverVolumeTestCase(NimbleDriverBaseTestCase):
'provider_location': '172.18.108.21:3260 iqn.test 0', 'provider_location': '172.18.108.21:3260 iqn.test 0',
'provider_auth': None}, 'provider_auth': None},
self.driver.create_volume({'name': 'testvolume', self.driver.create_volume({'name': 'testvolume',
'size': 1})) 'size': 1,
'display_name': '',
'display_description': ''}))
self.mock_client_service.service.createVol.assert_called_once_with( self.mock_client_service.service.createVol.assert_called_once_with(
request={ request={
'attr': {'snap-quota': 1073741824, 'warn-level': 858993459, 'attr': {'snap-quota': 1073741824, 'warn-level': 858993459,
@ -236,7 +238,9 @@ class NimbleDriverVolumeTestCase(NimbleDriverBaseTestCase):
exception.VolumeBackendAPIException, exception.VolumeBackendAPIException,
self.driver.create_volume, self.driver.create_volume,
{'name': 'testvolume', {'name': 'testvolume',
'size': 1}) 'size': 1,
'display_name': '',
'display_description': ''})
@mock.patch(NIMBLE_URLLIB2) @mock.patch(NIMBLE_URLLIB2)
@mock.patch(NIMBLE_CLIENT) @mock.patch(NIMBLE_CLIENT)
@ -352,7 +356,9 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase):
FAKE_GENERIC_POSITIVE_RESPONSE FAKE_GENERIC_POSITIVE_RESPONSE
self.driver.create_snapshot( self.driver.create_snapshot(
{'volume_name': 'testvolume', {'volume_name': 'testvolume',
'name': 'testvolume-snap1'}) 'name': 'testvolume-snap1',
'display_name': '',
'display_description': ''})
self.mock_client_service.service.snapVol.assert_called_once_with( self.mock_client_service.service.snapVol.assert_called_once_with(
request={'vol': 'testvolume', request={'vol': 'testvolume',
'snapAttr': {'name': 'testvolume-snap1', 'snapAttr': {'name': 'testvolume-snap1',

View File

@ -95,7 +95,7 @@ class NimbleISCSIDriver(SanISCSIDriver):
subnet_label = self.configuration.nimble_subnet_label subnet_label = self.configuration.nimble_subnet_label
LOG.debug('subnet_label used %(netlabel)s, netconfig %(netconf)s' LOG.debug('subnet_label used %(netlabel)s, netconfig %(netconf)s'
% {'netlabel': subnet_label, 'netconf': netconfig}) % {'netlabel': subnet_label, 'netconf': netconfig})
ret_discovery_ip = None ret_discovery_ip = ''
for subnet in netconfig['subnet-list']: for subnet in netconfig['subnet-list']:
LOG.info(_LI('Exploring array subnet label %s') % subnet['label']) LOG.info(_LI('Exploring array subnet label %s') % subnet['label'])
if subnet_label == '*': if subnet_label == '*':
@ -207,7 +207,9 @@ class NimbleISCSIDriver(SanISCSIDriver):
self._generate_random_string(12)) self._generate_random_string(12))
snapshot = {'volume_name': src_vref['name'], snapshot = {'volume_name': src_vref['name'],
'name': snapshot_name, 'name': snapshot_name,
'volume_size': src_vref['size']} 'volume_size': src_vref['size'],
'display_name': '',
'display_description': ''}
self.APIExecutor.snap_vol(snapshot) self.APIExecutor.snap_vol(snapshot)
self._clone_volume_from_snapshot(volume, snapshot) self._clone_volume_from_snapshot(volume, snapshot)
return self._get_model_info(volume['name']) return self._get_model_info(volume['name'])
@ -310,7 +312,7 @@ class NimbleISCSIDriver(SanISCSIDriver):
'iname': initiator_name}) 'iname': initiator_name})
return initiator_group['name'] return initiator_group['name']
LOG.info(_LI('No igroup found for initiator %s') % initiator_name) LOG.info(_LI('No igroup found for initiator %s') % initiator_name)
return None return ''
def initialize_connection(self, volume, connector): def initialize_connection(self, volume, connector):
"""Driver entry point to attach a volume to an instance.""" """Driver entry point to attach a volume to an instance."""
@ -469,20 +471,21 @@ class NimbleAPIExecutor:
# Set volume size, display name and description # Set volume size, display name and description
volume_size = volume['size'] * units.Gi volume_size = volume['size'] * units.Gi
reserve_size = volume_size if reserve else 0 reserve_size = volume_size if reserve else 0
display_name = (volume['display_name'] # Set volume description
if 'display_name' in volume else '') display_list = [getattr(volume, 'display_name', ''),
display_description = (': ' + volume['display_description'] getattr(volume, 'display_description', '')]
if 'display_description' in volume else '') description = ':'.join(filter(None, display_list))
description = display_name + display_description
# Limit description size to 254 characters # Limit description size to 254 characters
description = description[:254] description = description[:254]
LOG.info(_LI('Creating a new volume=%(vol)s size=%(size)s' LOG.info(_LI('Creating a new volume=%(vol)s size=%(size)s'
' reserve=%(reserve)s in pool=%(pool)s') ' reserve=%(reserve)s in pool=%(pool)s'
' description=%(description)s')
% {'vol': volume['name'], % {'vol': volume['name'],
'size': volume_size, 'size': volume_size,
'reserve': reserve, 'reserve': reserve,
'pool': pool_name}) 'pool': pool_name,
'description': description})
return self.client.service.createVol( return self.client.service.createVol(
request={'sid': self.sid, request={'sid': self.sid,
'attr': {'name': volume['name'], 'attr': {'name': volume['name'],
@ -603,13 +606,10 @@ class NimbleAPIExecutor:
"""Execute snapVol API.""" """Execute snapVol API."""
volume_name = snapshot['volume_name'] volume_name = snapshot['volume_name']
snap_name = snapshot['name'] snap_name = snapshot['name']
# Set description # Set snapshot description
snap_display_name = (snapshot['display_name'] display_list = [getattr(snapshot, 'display_name', ''),
if 'display_name' in snapshot else '') getattr(snapshot, 'display_description', '')]
snap_display_description = ( snap_description = ':'.join(filter(None, display_list))
': ' + snapshot['display_description']
if 'display_description' in snapshot else '')
snap_description = snap_display_name + snap_display_description
# Limit to 254 characters # Limit to 254 characters
snap_description = snap_description[:254] snap_description = snap_description[:254]
LOG.info(_LI('Creating snapshot for volume_name=%(vol)s' LOG.info(_LI('Creating snapshot for volume_name=%(vol)s'