'display_description': 'test volume',
'volume_type_id': None,
'provider_location': '11',
- 'volume': {"volume_id": '21ec7341-9256-497b-97d9-ef48edcf0635'}
+ 'volume': {"volume_id": '21ec7341-9256-497b-97d9-ef48edcf0635'},
+ 'volume': {'provider_location': '12'},
}
test_host = {'host': 'ubuntu001@backend001#OpenStack_Pool',
MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator?ISFREE=true&'
'range=[0-8191]/GET'] = (
FAKE_FC_INFO_RESPONSE)
+MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator/10000090fa0d6754/GET'] = (
+ FAKE_FC_INFO_RESPONSE)
MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator/10000090fa0d6754/PUT'] = (
FAKE_COMMON_SUCCESS_RESPONSE)
MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator/GET'] = (
FAKE_GET_FC_PORT_RESPONSE)
+MAP_COMMAND_TO_FAKE_RESPONSE['/lun/associate/cachepartition/POST'] = (
+ FAKE_SYSTEM_VERSION_RESPONSE)
+
MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator?range=[0-100]/GET'] = (
FAKE_GET_FC_PORT_RESPONSE)
lun_info = self.driver.create_snapshot(test_snap)
self.assertEqual(11, lun_info['provider_location'])
+ test_snap['volume']['provider_location'] = ''
+ lun_info = self.driver.create_snapshot(test_snap)
+ self.assertEqual(11, lun_info['provider_location'])
+
+ test_snap['volume']['provider_location'] = None
+ lun_info = self.driver.create_snapshot(test_snap)
+ self.assertEqual(11, lun_info['provider_location'])
+
def test_delete_snapshot_success(self):
self.driver.restclient.login()
delete_flag = self.driver.delete_snapshot(test_snap)
def test_create_volume_fail(self):
self.driver.restclient.login()
self.driver.restclient.test_fail = True
+ self.assertRaises(exception.VolumeBackendAPIException,
+ self.driver.create_volume, test_volume)
+
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.create_volume, error_volume)
lun_info = self.driver.create_snapshot(test_snap)
self.assertEqual(11, lun_info['provider_location'])
+ test_snap['volume']['provider_location'] = ''
+ lun_info = self.driver.create_snapshot(test_snap)
+ self.assertEqual(11, lun_info['provider_location'])
+
+ test_snap['volume']['provider_location'] = None
+ lun_info = self.driver.create_snapshot(test_snap)
+ self.assertEqual(11, lun_info['provider_location'])
+
def test_delete_snapshot_success(self):
self.driver.restclient.login()
delete_flag = self.driver.delete_snapshot(test_snap)
def __init__(self, *args, **kwargs):
super(HuaweiBaseDriver, self).__init__(*args, **kwargs)
- self.configuration = kwargs.get('configuration', None)
+ self.configuration = kwargs.get('configuration')
if not self.configuration:
msg = _('_instantiate_driver: configuration not found.')
raise exception.InvalidInput(reason=msg)
Thirdly, remove the lun.
"""
name = huawei_utils.encode_name(volume['id'])
- lun_id = volume.get('provider_location', None)
+ lun_id = volume.get('provider_location')
LOG.info(_LI('Delete volume: %(name)s, array lun id: %(lun_id)s.'),
{'name': name, 'lun_id': lun_id},)
if lun_id:
pool_info = self.restclient.find_pool_info(pool_name, pools)
src_volume_name = huawei_utils.encode_name(volume['id'])
dst_volume_name = six.text_type(hash(src_volume_name))
- src_id = volume.get('provider_location', None)
+ src_id = volume.get('provider_location')
src_lun_params = self.restclient.get_lun_info(src_id)
"""
snapshotname = huawei_utils.encode_name(snapshot['id'])
- snapshot_id = snapshot.get('provider_location', None)
+ snapshot_id = snapshot.get('provider_location')
if snapshot_id is None:
snapshot_id = self.restclient.get_snapshotid_by_name(snapshotname)
if snapshot_id is None:
'oldsize': volume_size,
'newsize': new_volume_size},)
- lun_id = self.restclient.get_volume_by_name(volume_name)
-
- if lun_id is None:
- msg = (_(
- "Can't find lun info on the array, lun name is: %(name)s.")
- % {'name': volume_name})
- LOG.error(msg)
- raise exception.VolumeBackendAPIException(data=msg)
-
+ lun_id = self.restclient.get_lunid(volume, volume_name)
luninfo = self.restclient.extend_volume(lun_id, new_volume_size)
return {'provider_location': luninfo['ID'],
{'snapshot': snapshotname,
'volume': volume_name},)
- snapshot_id = snapshot.get('provider_location', None)
+ snapshot_id = snapshot.get('provider_location')
if snapshot_id is None:
snapshot_id = self.restclient.get_snapshotid_by_name(snapshotname)
return False
def modify_lun(self, lun_id, change_opts):
- if change_opts.get('partitionid', None):
+ if change_opts.get('partitionid'):
old, new = change_opts['partitionid']
old_id = old[0]
old_name = old[1]
"old_id": old_id, "old_name": old_name,
"new_id": new_id, "new_name": new_name})
- if change_opts.get('cacheid', None):
+ if change_opts.get('cacheid'):
old, new = change_opts['cacheid']
old_id = old[0]
old_name = old[1]
'old_id': old_id, "old_name": old_name,
'new_id': new_id, "new_name": new_name})
- if change_opts.get('policy', None):
+ if change_opts.get('policy'):
old_policy, new_policy = change_opts['policy']
self.restclient.change_lun_smarttier(lun_id, new_policy)
LOG.info(_LI("Retype LUN(id: %(lun_id)s) smarttier policy from "
'old_policy': old_policy,
'new_policy': new_policy})
- if change_opts.get('qos', None):
+ if change_opts.get('qos'):
old_qos, new_qos = change_opts['qos']
old_qos_id = old_qos[0]
old_qos_value = old_qos[1]
'LUNType': None,
}
- lun_id = volume.get('provider_location', None)
+ lun_id = volume.get('provider_location')
old_opts = self.get_lun_specs(lun_id)
new_specs = new_type['extra_specs']
host_id)
hostgroup_id = self.restclient.add_host_into_hostgroup(host_id)
+ lun_id = self.restclient.get_lunid(volume, volume_name)
+
# Mapping lungroup and hostgroup to view.
- lun_id = self.restclient.mapping_hostgroup_and_lungroup(volume_name,
- hostgroup_id,
- host_id,
- portgroup_id)
+ self.restclient.do_mapping(volume_name, hostgroup_id,
+ host_id, portgroup_id)
hostlun_id = self.restclient.find_host_lun_id(host_id, lun_id)
"""Delete map between a volume and a host."""
initiator_name = connector['initiator']
volume_name = huawei_utils.encode_name(volume['id'])
- lun_id = volume.get('provider_location', None)
+ lun_id = volume.get('provider_location')
host_name = connector['host']
lungroup_id = None
{'wwpns': wwns,
'volume': volume_name},)
+ lun_id = self.restclient.get_lunid(volume, volume_name)
+
host_name_before_hash = None
host_name = connector['host']
if host_name and (len(host_name) > constants.MAX_HOSTNAME_LENGTH):
# Add host into hostgroup.
hostgroup_id = self.restclient.add_host_into_hostgroup(host_id)
- lun_id = self.restclient.mapping_hostgroup_and_lungroup(volume_name,
- hostgroup_id,
- host_id)
+ self.restclient.do_mapping(volume_name, hostgroup_id, host_id)
host_lun_id = self.restclient.find_host_lun_id(host_id, lun_id)
# Return FC properties.
"""Delete map between a volume and a host."""
wwns = connector['wwpns']
volume_name = huawei_utils.encode_name(volume['id'])
- lun_id = volume.get('provider_location', None)
+ lun_id = volume.get('provider_location')
host_name = connector['host']
left_lunnum = -1
lungroup_id = None
{'snapshot': snapshot_name,
'volume': volume_name})
- lun_id = self.get_volume_by_name(volume_name)
- if lun_id is None:
- msg = (_("Can't find lun info on the array, "
- "lun name is: %(name)s.") % {'name': volume_name})
- LOG.error(msg)
- raise exception.VolumeBackendAPIException(data=msg)
+ volume = snapshot['volume']
+ lun_id = self.get_lunid(volume, volume_name)
url = "/snapshot"
data = json.dumps({"TYPE": "27",
return result['data']
+ def get_lunid(self, volume, volume_name):
+ lun_id = (volume.get('provider_location') or
+ self.get_volume_by_name(volume_name))
+ if not lun_id:
+ msg = (_("Can't find lun info on the array, "
+ "lun name is: %(name)s.") % {'name': volume_name})
+ LOG.error(msg)
+ raise exception.VolumeBackendAPIException(data=msg)
+ return lun_id
+
def check_snapshot_exist(self, snapshot_id):
url = "/snapshot/%s" % snapshot_id
data = json.dumps({"TYPE": "27",
return True
return False
- def mapping_hostgroup_and_lungroup(self, volume_name, hostgroup_id,
- host_id, tgtportgroup_id=None):
+ def do_mapping(self, lun_id, hostgroup_id, host_id, tgtportgroup_id=None):
"""Add hostgroup and lungroup to mapping view."""
lungroup_name = constants.LUNGROUP_PREFIX + host_id
mapping_view_name = constants.MAPPING_VIEW_PREFIX + host_id
lungroup_id = self._find_lungroup(lungroup_name)
- lun_id = self.get_volume_by_name(volume_name)
view_id = self.find_mapping_view(mapping_view_name)
LOG.info(_LI(
- 'mapping_hostgroup_and_lungroup, lun_group: %(lun_group)s, '
+ 'do_mapping, lun_group: %(lun_group)s, '
'view_id: %(view_id)s, lun_id: %(lun_id)s.'),
{'lun_group': lungroup_id,
'view_id': view_id,
'view. Remove lun from lungroup now.'))
self.remove_lun_from_lungroup(lungroup_id, lun_id)
- return lun_id
-
def ensure_initiator_added(self, xml_file_path, initiator_name, host_id):
added = self._initiator_is_added_to_array(initiator_name)
if not added:
return result['data']['IOCLASSID']
def get_lungroupids_by_lunid(self, lun_id):
- """Get lungroup id by lun id."""
+ """Get lungroup ids by lun id."""
url = ("/lungroup/associate?TYPE=256"
"&ASSOCIATEOBJTYPE=11&ASSOCIATEOBJID=%s" % lun_id)