Commit 14bba674 by Clinton Blackburn

Added flag to disable record change limit for update_index command

This limit makes sense for existing installations, but not so much for
new ones (e.g. a fresh devstack). This flag allows us to disable the
check as needed.
parent a0c85225
......@@ -13,6 +13,13 @@ logger = logging.getLogger(__name__)
class Command(HaystackCommand):
backends = []
def add_arguments(self, parser):
super().add_arguments(parser)
parser.add_argument(
'--disable-change-limit', action='store_true', dest='disable_change_limit',
help='Disables checks limiting the number of records modified.'
)
def get_record_count(self, conn, index_name):
return conn.count(index_name).get('count')
......@@ -35,9 +42,13 @@ class Command(HaystackCommand):
# Set the alias (from settings) to the timestamped catalog.
for backend, index, alias in alias_mappings:
record_count_is_sane, index_info_string = self.sanity_check_new_index(backend.conn, index, record_count)
if not record_count_is_sane:
raise CommandError('Sanity check failed for new index. ' + index_info_string)
# Run a sanity check to ensure we aren't drastically changing the
# index, which could be indicative of a bug.
if not options.get('disable_change_limit', False):
record_count_is_sane, index_info_string = self.sanity_check_new_index(backend.conn, index, record_count)
if not record_count_is_sane:
raise CommandError('Sanity check failed for new index. ' + index_info_string)
self.set_alias(backend, alias, index)
def percentage_change(self, current, previous):
......
......@@ -63,3 +63,11 @@ class UpdateIndexTests(ElasticsearchTestMixin, SearchIndexTestMixin, TestCase):
with mock.patch('course_discovery.apps.edx_haystack_extensions.management.commands.'
'update_index.Command.get_record_count', return_value=record_count):
call_command('update_index')
@freeze_time('2016-06-21')
def test_sanity_check_disabled(self):
""" Verify the sanity check can be disabled. """
with mock.patch('course_discovery.apps.edx_haystack_extensions.management.commands.'
'update_index.Command.sanity_check_new_index') as mock_sanity_check_new_index:
call_command('update_index', disable_change_limit=True)
self.assertFalse(mock_sanity_check_new_index.called)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment