def test_map_volume_to_single_host_volume_not_mapped(self): self.mock_object(self.client, "create_volume_mapping", mock.Mock(return_value=eseries_fakes.VOLUME_MAPPING)) host_mapper.map_volume_to_single_host( self.client, get_fake_volume(), eseries_fakes.VOLUME, eseries_fakes.HOST, None, False ) self.assertTrue(self.client.create_volume_mapping.called)
def test_map_volume_to_single_host_volume_not_mapped(self): self.mock_object(self.client, 'create_volume_mapping', mock.Mock(return_value=eseries_fakes.VOLUME_MAPPING)) host_mapper.map_volume_to_single_host(self.client, get_fake_volume(), eseries_fakes.VOLUME, eseries_fakes.HOST, None, False) self.assertTrue(self.client.create_volume_mapping.called)
def test_map_volume_to_single_host_volume_already_mapped_to_target_host( self): """Should be a no-op""" self.mock_object(self.client, 'create_volume_mapping', mock.Mock()) host_mapper.map_volume_to_single_host(self.client, get_fake_volume(), eseries_fakes.VOLUME, eseries_fakes.HOST, eseries_fakes.VOLUME_MAPPING) self.assertFalse(self.client.create_volume_mapping.called)
def test_map_volume_to_single_host_volume_already_mapped_to_target_host( self): """Should be a no-op""" self.mock_object(self.client, 'create_volume_mapping') host_mapper.map_volume_to_single_host(self.client, get_fake_volume(), eseries_fakes.VOLUME, eseries_fakes.HOST, eseries_fakes.VOLUME_MAPPING, False) self.assertFalse(self.client.create_volume_mapping.called)
def test_map_volume_to_single_host_volume_mapped_to_multiattach_host_group(self): """Should move mapping to target host if volume is not migrating or attached(in-use). If volume is not in use then it should not require a mapping making it ok to sever the mapping to the host group. """ fake_mapping_to_other_host = copy.deepcopy(eseries_fakes.VOLUME_MAPPING) fake_mapping_to_other_host["mapRef"] = eseries_fakes.MULTIATTACH_HOST_GROUP["clusterRef"] self.mock_object(self.client, "move_volume_mapping_via_symbol", mock.Mock(return_value={"lun": 5})) host_mapper.map_volume_to_single_host( self.client, get_fake_volume(), eseries_fakes.VOLUME, eseries_fakes.HOST, fake_mapping_to_other_host, False ) self.assertTrue(self.client.move_volume_mapping_via_symbol.called)
def initialize_connection(self, volume, connector): """Allow connection to connector and return connection info.""" initiator_name = connector['initiator'] eseries_vol = self._get_volume(volume['name_id']) existing_maps = host_mapper.get_host_mapping_for_vol_frm_array( self._client, eseries_vol) host = self._get_or_create_host(initiator_name, self.host_type) # There can only be one or zero mappings on a volume in E-Series current_map = existing_maps[0] if existing_maps else None if self.configuration.netapp_enable_multiattach and current_map: self._ensure_multi_attach_host_group_exists() mapping = host_mapper.map_volume_to_multiple_hosts( self._client, volume, eseries_vol, host, current_map) else: mapping = host_mapper.map_volume_to_single_host( self._client, volume, eseries_vol, host, current_map) lun_id = mapping['lun'] msg = _("Mapped volume %(id)s to the initiator %(initiator_name)s.") msg_fmt = {'id': volume['id'], 'initiator_name': initiator_name} LOG.debug(msg % msg_fmt) iscsi_details = self._get_iscsi_service_details() iscsi_portal = self._get_iscsi_portal_for_vol(eseries_vol, iscsi_details) msg = _("Successfully fetched target details for volume %(id)s and " "initiator %(initiator_name)s.") LOG.debug(msg % msg_fmt) iqn = iscsi_portal['iqn'] address = iscsi_portal['ip'] port = iscsi_portal['tcp_port'] properties = na_utils.get_iscsi_connection_properties( lun_id, volume, iqn, address, port) return properties
def test_map_volume_to_single_host_volume_mapped_to_multiattach_host_group( self): """Should move mapping to target host if volume is not migrating or attached(in-use). If volume is not in use then it should not require a mapping making it ok to sever the mapping to the host group. """ fake_mapping_to_other_host = copy.deepcopy( eseries_fakes.VOLUME_MAPPING) fake_mapping_to_other_host['mapRef'] = \ eseries_fakes.MULTIATTACH_HOST_GROUP['clusterRef'] self.mock_object(self.client, 'move_volume_mapping_via_symbol', mock.Mock(return_value={'lun': 5})) host_mapper.map_volume_to_single_host(self.client, get_fake_volume(), eseries_fakes.VOLUME, eseries_fakes.HOST, fake_mapping_to_other_host) self.assertTrue(self.client.move_volume_mapping_via_symbol.called)
def map_volume_to_host(self, volume, eseries_volume, initiators): """Ensures the specified initiator has access to the volume.""" existing_maps = self._client.get_volume_mappings_for_volume(eseries_volume) host = self._get_or_create_host(initiators, self.host_type) # There can only be one or zero mappings on a volume in E-Series current_map = existing_maps[0] if existing_maps else None if self.configuration.netapp_enable_multiattach and current_map: self._ensure_multi_attach_host_group_exists() mapping = host_mapper.map_volume_to_multiple_hosts(self._client, volume, eseries_volume, host, current_map) else: mapping = host_mapper.map_volume_to_single_host( self._client, volume, eseries_volume, host, current_map, self.configuration.netapp_enable_multiattach ) return mapping
def map_volume_to_host(self, volume, eseries_volume, initiators): """Ensures the specified initiator has access to the volume.""" existing_maps = self._client.get_volume_mappings_for_volume( eseries_volume) host = self._get_or_create_host(initiators, self.host_type) # There can only be one or zero mappings on a volume in E-Series current_map = existing_maps[0] if existing_maps else None if self.configuration.netapp_enable_multiattach and current_map: self._ensure_multi_attach_host_group_exists() mapping = host_mapper.map_volume_to_multiple_hosts( self._client, volume, eseries_volume, host, current_map) else: mapping = host_mapper.map_volume_to_single_host( self._client, volume, eseries_volume, host, current_map, self.configuration.netapp_enable_multiattach) return mapping
def initialize_connection(self, volume, connector): """Allow connection to connector and return connection info.""" initiator_name = connector['initiator'] eseries_vol = self._get_volume(volume['name_id']) existing_maps = host_mapper.get_host_mapping_for_vol_frm_array( self._client, eseries_vol) host = self._get_or_create_host(initiator_name, self.host_type) # There can only be one or zero mappings on a volume in E-Series current_map = existing_maps[0] if existing_maps else None if self.configuration.netapp_enable_multiattach and current_map: self._ensure_multi_attach_host_group_exists() mapping = host_mapper.map_volume_to_multiple_hosts(self._client, volume, eseries_vol, host, current_map) else: mapping = host_mapper.map_volume_to_single_host(self._client, volume, eseries_vol, host, current_map) lun_id = mapping['lun'] msg = _("Mapped volume %(id)s to the initiator %(initiator_name)s.") msg_fmt = {'id': volume['id'], 'initiator_name': initiator_name} LOG.debug(msg % msg_fmt) iscsi_details = self._get_iscsi_service_details() iscsi_portal = self._get_iscsi_portal_for_vol(eseries_vol, iscsi_details) msg = _("Successfully fetched target details for volume %(id)s and " "initiator %(initiator_name)s.") LOG.debug(msg % msg_fmt) iqn = iscsi_portal['iqn'] address = iscsi_portal['ip'] port = iscsi_portal['tcp_port'] properties = na_utils.get_iscsi_connection_properties(lun_id, volume, iqn, address, port) return properties