Ejemplo n.º 1
0
    def test_delete_old_indices_other_indices_are_not_deleted(self):
        """Verify that non-week-based indices are not removed"""
        # Create a temporary index.
        self.index_creator.create_index('socorro_test_temp', {})

        api = IndexCleaner(self.config)
        api.delete_old_indices()

        # Verify the email index is still there.
        assert self.index_client.exists('socorro_test_temp')
Ejemplo n.º 2
0
    def test_delete_old_indices_other_indices_are_not_deleted(self):
        """Verify that non-week-based indices are not removed.
        """
        # Create a temporary index.
        self.index_creator.create_index('socorro_test_temp', {})

        api = IndexCleaner(self.config)
        api.delete_old_indices()

        # Verify the email index is still there.
        assert self.index_client.exists('socorro_test_temp')
Ejemplo n.º 3
0
    def test_delete_indices_without_predicate(self):
        self.create_index('test_socorro201801')
        self.create_index('test_socorro201802')
        self.create_index('test_socorro_non_week')

        api = IndexCleaner(self.config)
        api.delete_indices()

        # Without a predicate, all week-based indices should be deleted
        assert not self.index_client.exists('test_socorro201801')
        assert not self.index_client.exists('test_socorro201802')
        assert self.index_client.exists('test_socorro_non_week')
Ejemplo n.º 4
0
    def test_delete_indices_without_predicate(self):
        self.create_index('test_socorro201801')
        self.create_index('test_socorro201802')
        self.create_index('test_socorro_non_week')

        api = IndexCleaner(self.config)
        api.delete_indices()

        # Without a predicate, all week-based indices should be deleted
        assert not self.index_client.exists('test_socorro201801')
        assert not self.index_client.exists('test_socorro201802')
        assert self.index_client.exists('test_socorro_non_week')
Ejemplo n.º 5
0
    def test_delete_indices_with_predicate(self):
        self.create_index('test_socorro201801')
        self.create_index('test_socorro201802')
        self.create_index('test_socorro_non_week')

        api = IndexCleaner(self.config)
        api.delete_indices(lambda index: index.endswith('2'))

        # Only week-based indices that match the predicate should be
        # deleted.
        assert self.index_client.exists('test_socorro201801')
        assert not self.index_client.exists('test_socorro201802')
        assert self.index_client.exists('test_socorro_non_week')
Ejemplo n.º 6
0
    def test_delete_indices_with_predicate(self):
        self.create_index('test_socorro201801')
        self.create_index('test_socorro201802')
        self.create_index('test_socorro_non_week')

        api = IndexCleaner(self.config)
        api.delete_indices(lambda index: index.endswith('2'))

        # Only week-based indices that match the predicate should be
        # deleted.
        assert self.index_client.exists('test_socorro201801')
        assert not self.index_client.exists('test_socorro201802')
        assert self.index_client.exists('test_socorro_non_week')
Ejemplo n.º 7
0
    def test_delete_old_indices(self):
        # Create old indices to be deleted.
        self.index_client.create('socorro200142', {})
        self.indices.append('socorro200142')

        self.index_client.create('socorro200000', {})
        self.indices.append('socorro200000')

        # Create an old aliased index.
        self.index_client.create('socorro200201_20030101', {})
        self.indices.append('socorro200201_20030101')
        self.index_client.put_alias(
            index='socorro200201_20030101',
            name='socorro200201',
        )

        # Create a recent aliased index.
        last_week_index = self.get_index_for_date(
            utc_now() - datetime.timedelta(weeks=1)
        )
        self.index_client.create('socorro_some_aliased_index', {})
        self.indices.append('socorro_some_aliased_index')
        self.index_client.put_alias(
            index='socorro_some_aliased_index',
            name=last_week_index,
        )

        # Create a recent index that should not be deleted.
        now_index = self.get_index_for_date(utc_now())
        self.index_client.create(now_index, {})
        self.indices.append(now_index)

        # These will raise an error if an index was not correctly created.
        assert self.index_client.exists('socorro200142')
        assert self.index_client.exists('socorro200000')
        assert self.index_client.exists('socorro200201')
        assert self.index_client.exists(now_index)
        assert self.index_client.exists(last_week_index)

        api = IndexCleaner(self.config)
        api.delete_old_indices()

        # Verify the recent index is still there.
        ok_(self.index_client.exists(now_index))
        ok_(self.index_client.exists(last_week_index))

        # Verify the old indices are gone.
        ok_(not self.index_client.exists('socorro200142'))
        ok_(not self.index_client.exists('socorro200000'))
        ok_(not self.index_client.exists('socorro200201'))
Ejemplo n.º 8
0
    def test_delete_old_indices(self):
        # Create old indices to be deleted.
        self.index_client.create('socorro200142', {})
        self.indices.append('socorro200142')

        self.index_client.create('socorro200000', {})
        self.indices.append('socorro200000')

        # Create an old aliased index.
        self.index_client.create('socorro200201_20030101', {})
        self.indices.append('socorro200201_20030101')
        self.index_client.put_alias(
            index='socorro200201_20030101',
            name='socorro200201',
        )

        # Create a recent aliased index.
        last_week_index = self.get_index_for_date(
            utc_now() - datetime.timedelta(weeks=1)
        )
        self.index_client.create('socorro_some_aliased_index', {})
        self.indices.append('socorro_some_aliased_index')
        self.index_client.put_alias(
            index='socorro_some_aliased_index',
            name=last_week_index,
        )

        # Create a recent index that should not be deleted.
        now_index = self.get_index_for_date(utc_now())
        self.index_client.create(now_index, {})
        self.indices.append(now_index)

        # These will raise an error if an index was not correctly created.
        assert self.index_client.exists('socorro200142')
        assert self.index_client.exists('socorro200000')
        assert self.index_client.exists('socorro200201')
        assert self.index_client.exists(now_index)
        assert self.index_client.exists(last_week_index)

        api = IndexCleaner(self.config)
        api.delete_old_indices()

        # Verify the recent index is still there.
        ok_(self.index_client.exists(now_index))
        ok_(self.index_client.exists(last_week_index))

        # Verify the old indices are gone.
        ok_(not self.index_client.exists('socorro200142'))
        ok_(not self.index_client.exists('socorro200000'))
        ok_(not self.index_client.exists('socorro200201'))
Ejemplo n.º 9
0
    def test_other_indices_are_not_deleted(self):
        """Verify that non-week-based indices are not removed. For example,
        the socorro_email index should not be deleted by the cron job.
        """
        # Create the socorro emails index.
        self.index_creator.create_emails_index()
        self.indices.append('socorro_emails')

        assert self.index_client.exists('socorro_emails')

        api = IndexCleaner(self.config)
        api.delete_old_indices()

        # Verify the email index is still there.
        ok_(self.index_client.exists('socorro_emails'))
Ejemplo n.º 10
0
    def test_other_indices_are_not_deleted(self):
        """Verify that non-week-based indices are not removed. For example,
        the socorro_email index should not be deleted by the cron job.
        """
        # Create the socorro emails index.
        self.index_creator.create_emails_index()
        self.indices.append('socorro_emails')

        assert self.index_client.exists('socorro_emails')

        api = IndexCleaner(self.config)
        api.delete_old_indices()

        # Verify the email index is still there.
        ok_(self.index_client.exists('socorro_emails'))