Beispiel #1
0
    def test_map_volume_to_multiple_hosts_volume_mapped_to_another_host(self):
        """Test that mapping moves to another host group.

        Should ensure both existing host and destination host are in
        multiattach host group and move the mapping to the host group.
        """

        existing_host = copy.deepcopy(eseries_fakes.HOST)
        existing_host['clusterRef'] = utils.NULL_REF
        target_host = copy.deepcopy(eseries_fakes.HOST_2)
        target_host['clusterRef'] = utils.NULL_REF
        self.mock_object(self.client, 'get_host',
                         mock.Mock(return_value=existing_host))
        self.mock_object(self.client, 'set_host_group_for_host')
        self.mock_object(self.client, 'get_host_group',
                         mock.Mock(side_effect=exception.NotFound))
        mock_move_mapping = mock.Mock(
            return_value=eseries_fakes.VOLUME_MAPPING_TO_MULTIATTACH_GROUP)
        self.mock_object(self.client,
                         'move_volume_mapping_via_symbol',
                         mock_move_mapping)

        host_mapper.map_volume_to_multiple_hosts(self.client,
                                                 get_fake_volume(),
                                                 eseries_fakes.VOLUME,
                                                 target_host,
                                                 eseries_fakes.VOLUME_MAPPING)

        self.assertEqual(
            2, self.client.set_host_group_for_host.call_count)

        self.assertTrue(self.client.move_volume_mapping_via_symbol
                        .called)
Beispiel #2
0
    def test_map_volume_to_multiple_hosts_volume_mapped_to_another_host(self):
        """Should ensure both existing host and destination host are in
        multiattach host group and move the mapping to the host group.
        """

        existing_host = copy.deepcopy(eseries_fakes.HOST)
        existing_host['clusterRef'] = utils.NULL_REF
        target_host = copy.deepcopy(eseries_fakes.HOST_2)
        target_host['clusterRef'] = utils.NULL_REF
        self.mock_object(self.client, 'get_host',
                         mock.Mock(return_value=existing_host))
        self.mock_object(self.client, 'set_host_group_for_host')
        self.mock_object(self.client, 'get_host_group',
                         mock.Mock(side_effect=exception.NotFound))
        mock_move_mapping = mock.Mock(
            return_value=eseries_fakes.VOLUME_MAPPING_TO_MULTIATTACH_GROUP)
        self.mock_object(self.client, 'move_volume_mapping_via_symbol',
                         mock_move_mapping)

        host_mapper.map_volume_to_multiple_hosts(self.client,
                                                 get_fake_volume(),
                                                 eseries_fakes.VOLUME,
                                                 target_host,
                                                 eseries_fakes.VOLUME_MAPPING)

        self.assertEqual(2, self.client.set_host_group_for_host.call_count)

        self.assertTrue(self.client.move_volume_mapping_via_symbol.called)
Beispiel #3
0
    def test_map_volume_to_multiple_hosts_volume_mapped_to_multiattach_host_group(  # noqa
            self):
        """Should ensure target host is in the multiattach host group."""
        fake_host = copy.deepcopy(eseries_fakes.HOST_2)
        fake_host['clusterRef'] = utils.NULL_REF

        fake_mapping_to_host_group = copy.deepcopy(
            eseries_fakes.VOLUME_MAPPING)
        fake_mapping_to_host_group['mapRef'] = \
            eseries_fakes.MULTIATTACH_HOST_GROUP['clusterRef']

        self.mock_object(self.client, 'set_host_group_for_host')
        self.mock_object(self.client, 'get_host_group',
                         mock.Mock(
                             return_value=eseries_fakes.MULTIATTACH_HOST_GROUP)
                         )

        host_mapper.map_volume_to_multiple_hosts(self.client,
                                                 get_fake_volume(),
                                                 eseries_fakes.VOLUME,
                                                 fake_host,
                                                 fake_mapping_to_host_group)

        self.assertEqual(
            1, self.client.set_host_group_for_host.call_count)
Beispiel #4
0
    def test_map_volume_to_multiple_hosts_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_multiple_hosts(
            self.client, get_fake_volume(), eseries_fakes.VOLUME, eseries_fakes.HOST, eseries_fakes.VOLUME_MAPPING
        )

        self.assertFalse(self.client.create_volume_mapping.called)
Beispiel #5
0
    def test_map_volume_to_multiple_hosts_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_multiple_hosts(self.client,
                                                 get_fake_volume(),
                                                 eseries_fakes.VOLUME,
                                                 eseries_fakes.HOST,
                                                 eseries_fakes.VOLUME_MAPPING)

        self.assertFalse(self.client.create_volume_mapping.called)
Beispiel #6
0
    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
Beispiel #7
0
    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
Beispiel #8
0
    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
Beispiel #9
0
    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