Пример #1
0
    def test_succesfully_updates_the_index_settings(self, client, esversion, mapping):
        client.version = esversion
        client.conn.indices.get_alias.return_value = {
            'old-target': {'aliases': {'foo': {}}},
        }
        client.conn.indices.get_settings.return_value = {
            "old-target": {
                "settings": {
                    "index": {
                        "analysis": {
                            "old_setting": "val",
                        }
                    }
                }
            }
        }

        update_index_settings(client)

        client.conn.indices.put_settings.assert_called_once_with(
            index="old-target",
            body={
                "analysis": ANALYSIS_SETTINGS,
            },
        )
        client.conn.indices.put_mapping.assert_called_once_with(
            index="old-target",
            doc_type=client.mapping_type,
            body=mapping,
        )
Пример #2
0
    def test_succesfully_updates_the_index_settings(self, client):
        client.conn.indices.get_alias.return_value = {
            'old-target': {'aliases': {'foo': {}}},
        }
        client.conn.indices.get_settings.return_value = {
            "old-target": {
                "settings": {
                    "index": {
                        "analysis": {
                            "old_setting": "val",
                        }
                    }
                }
            }
        }

        update_index_settings(client)

        client.conn.indices.put_settings.assert_called_once_with(
            index="old-target",
            body={
                "analysis": ANALYSIS_SETTINGS,
            },
        )
        client.conn.indices.put_mapping.assert_called_once_with(
            index="old-target",
            doc_type=client.mapping_type,
            body=ANNOTATION_MAPPING,
        )
Пример #3
0
    def test_raises_runtime_exception_if_merge_mapping_exception(self, client, error):
        client.conn.indices.get_alias.return_value = {
            'old-target': {'aliases': {'foo': {}}},
        }
        client.conn.indices.put_mapping.side_effect = error('test', 'MergeMappingException')

        with pytest.raises(RuntimeError):
            update_index_settings(client)
Пример #4
0
    def test_raises_original_exception_if_not_merge_mapping_exception(self, client, error):
        client.conn.indices.get_alias.return_value = {
            'old-target': {'aliases': {'foo': {}}},
        }
        client.conn.indices.put_mapping.side_effect = error('test', 'test desc')

        with pytest.raises(error):
            update_index_settings(client)
Пример #5
0
    def test_raises_original_exception_if_not_merge_mapping_exception(self, client):
        client.conn.indices.get_alias.return_value = {
            "old-target": {"aliases": {"foo": {}}}
        }
        error = elasticsearch.exceptions.RequestError
        client.conn.indices.put_mapping.side_effect = error("test", "test desc")

        with pytest.raises(error):
            update_index_settings(client)
Пример #6
0
    def test_raises_runtime_exception_if_merge_mapping_exception(self, mock_es_client):
        mock_es_client.conn.indices.get_alias.return_value = {
            "old-target": {"aliases": {"foo": {}}}
        }
        mock_es_client.conn.indices.put_mapping.side_effect = (
            elasticsearch.exceptions.RequestError("test", "MergeMappingException")
        )

        with pytest.raises(RuntimeError):
            update_index_settings(mock_es_client)
Пример #7
0
    def test_raises_runtime_exception_if_merge_mapping_exception(self, client):
        client.conn.indices.get_alias.return_value = {
            "old-target": {"aliases": {"foo": {}}}
        }
        client.conn.indices.put_mapping.side_effect = elasticsearch.exceptions.RequestError(
            "test", "MergeMappingException"
        )

        with pytest.raises(RuntimeError):
            update_index_settings(client)
Пример #8
0
def update_settings(ctx):
    """
    Attempt to update mappings and settings in elasticsearch.

    Attempts to update mappings and index settings. This may fail if the
    pending changes to mappings are not compatible with the current index. In
    this case you will likely need to reindex.
    """
    request = ctx.obj["bootstrap"]()

    try:
        config.update_index_settings(request.es)
    except RuntimeError as e:
        raise click.ClickException(str(e))
Пример #9
0
def update_settings(ctx):
    """
    Attempt to update mappings and settings in elasticsearch.

    Attempts to update mappings and index settings. This may fail if the
    pending changes to mappings are not compatible with the current index. In
    this case you will likely need to reindex.
    """
    request = ctx.obj["bootstrap"]()

    try:
        config.update_index_settings(request.es)
    except RuntimeError as e:
        raise click.ClickException(str(e))
Пример #10
0
    def test_succesfully_updates_the_index_settings(self, client):
        client.conn.indices.get_alias.return_value = {
            "old-target": {"aliases": {"foo": {}}}
        }
        client.conn.indices.get_settings.return_value = {
            "old-target": {"settings": {"index": {"analysis": {"old_setting": "val"}}}}
        }

        update_index_settings(client)

        client.conn.indices.put_settings.assert_called_once_with(
            index="old-target", body={"analysis": ANALYSIS_SETTINGS}
        )
        client.conn.indices.put_mapping.assert_called_once_with(
            index="old-target", doc_type=client.mapping_type, body=ANNOTATION_MAPPING
        )
Пример #11
0
    def test_succesfully_updates_the_index_settings(self, mock_es_client):
        mock_es_client.conn.indices.get_alias.return_value = {
            "old-target": {"aliases": {"foo": {}}}
        }
        mock_es_client.conn.indices.get_settings.return_value = {
            "old-target": {"settings": {"index": {"analysis": {"old_setting": "val"}}}}
        }

        update_index_settings(mock_es_client)

        mock_es_client.conn.indices.put_settings.assert_called_once_with(
            index="old-target", body={"analysis": ANALYSIS_SETTINGS}
        )
        mock_es_client.conn.indices.put_mapping.assert_called_once_with(
            index="old-target",
            doc_type=mock_es_client.mapping_type,
            body=ANNOTATION_MAPPING,
        )