def test_all_daily_indices_found(self): client = Mock() client.indices.get_settings.return_value = { 'prefix-2014.01.03': True, 'prefix-2014.01.02': True, 'prefix-2014.01.01': True, 'prefix-2013.12.31': True, 'prefix-2013.12.30': True, 'prefix-2013.12.29': True, 'prefix-2013.01.03': True, 'prefix-2013.01.03.10': True, } expired = curator.find_expired_indices(client, 'days', 3, prefix='prefix-', utc_now=datetime(2014, 1, 3)) expired = list(expired) self.assertEquals([ ('prefix-2013.01.03', timedelta(days=362)), ('prefix-2013.12.29', timedelta(days=2)), ('prefix-2013.12.30', timedelta(days=1)), ], expired)
def test_find_indices_ignores_indices_with_different_prefix_or_time_unit(self): self.create_index('logstash-2012.01.01') # wrong precision self.create_index('not-logstash-2012.01.01.00') # wrong prefix self.create_index('logstash-2012.01.01.00') expired = list(curator.find_expired_indices(self.client, 'hours', 1)) self.assertEquals(1, len(expired)) self.assertEquals('logstash-2012.01.01.00', expired[0][0])
def test_find_reports_correct_time_interval_from_cutoff(self): self.create_index('l-2014.01.01') self.create_index('l-2014.01.02') # yesterday is always save since we reset to mignight and do <, not <= self.create_index('l-2014.01.03') expired = list(curator.find_expired_indices(self.client, 'days', 1, utc_now=datetime(2014, 1, 4, 3, 45, 50), prefix='l-')) self.assertEquals( [ (u'l-2014.01.01', timedelta(2)), (u'l-2014.01.02', timedelta(1)) ], expired )
def test_find_closed_indices(self): self.create_index('l-2014.01.03') self.client.indices.close(index='l-2014.01.03') self.create_index('l-2014.01.01') # all indices should be expired expired = list(curator.find_expired_indices(self.client, 'days', 1, utc_now=datetime(2014, 1, 8, 3, 45, 50), prefix='l-')) self.assertEquals( [ ('l-2014.01.01', timedelta(6)), ('l-2014.01.03', timedelta(4)), ], expired )
def test_all_daily_indices_found(self): client = Mock() client.indices.get_settings.return_value = { 'prefix-2014.01.03': True, 'prefix-2014.01.02': True, 'prefix-2014.01.01': True, 'prefix-2013.12.31': True, 'prefix-2013.12.30': True, 'prefix-2013.12.29': True, 'prefix-2013.01.03': True, 'prefix-2013.01.03.10': True, } expired = curator.find_expired_indices(client, 'days', 3, prefix='prefix-', utc_now=datetime(2014, 1, 3)) expired = list(expired) self.assertEquals([ ('prefix-2013.01.03', timedelta(days=362)), ('prefix-2013.12.29', timedelta(days=2)), ('prefix-2013.12.30', timedelta(days=1)), ], expired )