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, )
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, )
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)
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)
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)
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)
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)
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))
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 )
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, )