Skip to content

Commit

Permalink
Merge pull request #585 from untergeek/3.5.1_patches
Browse files Browse the repository at this point in the history
3.5.1 patches
  • Loading branch information
untergeek committed Mar 21, 2016
2 parents 80a31f8 + e21182f commit 2c0e798
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion curator/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.5.0'
__version__ = '3.5.1'
19 changes: 11 additions & 8 deletions curator/api/seal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .utils import *
import elasticsearch
import logging
import urllib3
logger = logging.getLogger(__name__)

def seal_indices(client, indices):
Expand All @@ -14,19 +15,21 @@ def seal_indices(client, indices):
:rtype: bool
"""
indices = prune_closed(client, indices)
if not len(indices) > 0:
logger.info('No indices to seal.')
return True
es_version = get_version(client)
if not es_version >= (1, 6, 0):
logger.warn('Your version of Elasticsearch ({0}) does not support index sealing (synced flush). Must be 1.6.0 or higher.'.format(es_version))
return True # Non-fatal error
errcode = ''
results = {}
try:
if es_version >= (1, 6, 0):
if len(indices) > 0:
results = client.indices.flush_synced(index=to_csv(indices))
else:
logger.warn('No indices to seal.')
return True
else:
logger.error('Your version of Elasticsearch ({0}) does not support index sealing (synced flush). Must be 1.6.0 or higher.'.format(es_version))
results = client.indices.flush_synced(index=to_csv(indices))
except Exception as e:
if str(type(e)) == "<class 'urllib3.exceptions.ReadTimeoutError'>":
logger.error('{0} consider using a larger value for --timeout'.format(e))
return False
logger.warn('Non-fatal error encountered.')
try:
logger.debug('Error: {0}. Message: {1}'.format(e.status_code, e.error))
Expand Down
4 changes: 2 additions & 2 deletions curator/api/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ def delete_snapshot(client, snapshot=None, repository=None):
logger.info("Deleting snapshot {0}".format(snapshot))
client.snapshot.delete(repository=repository, snapshot=snapshot)
return True
except elasticsearch.RequestError:
logger.error("Unable to delete snapshot {0} from repository {1}. Run with --debug flag and/or check Elasticsearch logs for more information.".format(snapshot, repository))
except elasticsearch.TransportError as e:
logger.error("Unable to delete snapshot {0} from repository {1}. Error message: {2}. Run with --debug flag and/or check Elasticsearch logs for more information.".format(snapshot, repository, e))
return False
17 changes: 9 additions & 8 deletions curator/cli/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ def snapshot(
msgout('Missing required parameter --repository', error=True, quiet=ctx.parent.params['quiet'])
sys.exit(1)
# Check if `name` contains upper-case characters, which are forbidden #562
if any(c.isupper() for c in name):
msgout(
'Snapshot name: "{0}" contains upper-case characters, which are not allowed.'.format(name),
error=True,
quiet=ctx.parent.params['quiet']
)
logger.error('Snapshot name: "{0}" contains upper-case characters, which are not allowed.'.format(name))
sys.exit(1)
if name:
if any(c.isupper() for c in name):
msgout(
'Snapshot name: "{0}" contains upper-case characters, which are not allowed.'.format(name),
error=True,
quiet=ctx.parent.params['quiet']
)
logger.error('Snapshot name: "{0}" contains upper-case characters, which are not allowed.'.format(name))
sys.exit(1)
snapshot.add_command(indices)
10 changes: 7 additions & 3 deletions curator/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ def override_timeout(ctx):
Override the default timeout for optimize and snapshot operations if the
default value of 30 is provided at the command-line.
"""
timeout = 21600
if ctx.parent.info_name in ['optimize', 'snapshot']:
if ctx.parent.info_name in ['optimize', 'snapshot', 'seal']:
# Check for default timeout of 30s
if ctx.parent.parent.params['timeout'] == 30:
logger.warn('Overriding default connection timeout. New timeout: {0}'.format(timeout))
if ctx.parent.info_name in ['optimize', 'snapshot']:
timeout = 21600
elif ctx.parent.info_name == 'seal':
timeout = 180
ctx.parent.parent.params['timeout'] = timeout
logger.info('Overriding default connection timeout for {0} action. New timeout: {1}'.format(ctx.parent.info_name,timeout))

def filter_callback(ctx, param, value):
"""
Expand Down
12 changes: 11 additions & 1 deletion docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
Changelog
=========

3.5.1 (21 March 2016)
---------------------

**Bug fixes**

* Add more logging information to snapshot delete method #582 (untergeek)
* Improve default timeout, logging, and exception handling for `seal` command
#583 (untergeek)
* Fix use of default snapshot name. #584 (untergeek)

3.5.0 (16 March 2016)
----------------------
---------------------

**General**

Expand Down
11 changes: 10 additions & 1 deletion test/unit/test_api_commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
from unittest import TestCase
import urllib3
from mock import Mock
import sys
try:
Expand Down Expand Up @@ -509,6 +510,14 @@ def test_seal_indices_attribute_exception(self):
client.indices.flush_synced.side_effect = fake_fail
client.info.return_value = {'version': {'number': '1.6.0'} }
self.assertTrue(curator.seal_indices(client, named_index))
def test_seal_indices_timeout_error(self):
client = Mock()
client.cluster.state.return_value = open_index
client.indices.flush_synced.return_value = synced_fail
client.indices.flush_synced.side_effect = urllib3.exceptions.ReadTimeoutError('foo', 'bar', 'message')
client.info.return_value = {'version': {'number': '1.6.0'} }
self.assertFalse(curator.seal_indices(client, named_index))


class TestShow(TestCase):
def setUp(self):
Expand Down Expand Up @@ -687,5 +696,5 @@ def test_delete_snapshot_positive(self):
self.assertTrue(curator.delete_snapshot(client, repository=repo_name, snapshot=snap_name))
def test_delete_snapshot_negative(self):
client = Mock()
client.snapshot.delete.side_effect = elasticsearch.RequestError
client.snapshot.delete.side_effect = elasticsearch.TransportError(400, 'This is an error message')
self.assertFalse(curator.delete_snapshot(client, repository=repo_name, snapshot=snap_name))

0 comments on commit 2c0e798

Please sign in to comment.