Merge pull request #17760 from edx/efischer/EDU-499

Remove PRUNE_OLD_VERSIONS waffle flag
This commit is contained in:
Eric Fischer
2018-03-26 11:59:31 -04:00
committed by GitHub
5 changed files with 21 additions and 25 deletions

View File

@@ -1977,10 +1977,8 @@ BLOCK_STRUCTURES_SETTINGS = dict(
# Maximum number of retries per task.
TASK_MAX_RETRIES=5,
# Backend storage
# STORAGE_CLASS='storages.backends.s3boto.S3BotoStorage',
# STORAGE_KWARGS=dict(bucket='nim-beryl-test'),
# DIRECTORY_PREFIX='/modeltest/',
# Backend storage options
PRUNING_ACTIVE=False,
)
################################ Bulk Email ###################################

View File

@@ -368,6 +368,8 @@ FILE_UPLOAD_HANDLERS = [
'django.core.files.uploadhandler.TemporaryFileUploadHandler',
]
BLOCK_STRUCTURES_SETTINGS['PRUNING_ACTIVE'] = True
########################### Server Ports ###################################
# These ports are carefully chosen so that if the browser needs to

View File

@@ -15,7 +15,6 @@ WAFFLE_NAMESPACE = u'block_structure'
INVALIDATE_CACHE_ON_PUBLISH = u'invalidate_cache_on_publish'
STORAGE_BACKING_FOR_CACHE = u'storage_backing_for_cache'
RAISE_ERROR_WHEN_NOT_FOUND = u'raise_error_when_not_found'
PRUNE_OLD_VERSIONS = u'prune_old_versions'
def waffle():

View File

@@ -226,7 +226,7 @@ class BlockStructureModel(TimeStampedModel):
"""
Deletes previous file versions for data_usage_key.
"""
if not config.waffle().is_enabled(config.PRUNE_OLD_VERSIONS):
if not settings.BLOCK_STRUCTURES_SETTINGS.get('PRUNING_ACTIVE', False):
return
if num_to_keep is None:

View File

@@ -3,6 +3,7 @@ Unit tests for Block Structure models.
"""
# pylint: disable=protected-access
import ddt
from django.conf import settings
from django.core.exceptions import SuspiciousOperation
from django.test import TestCase
from django.utils.timezone import now
@@ -12,7 +13,6 @@ from uuid import uuid4
from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator
from ..config import PRUNE_OLD_VERSIONS, waffle
from ..exceptions import BlockStructureNotFound
from ..models import BlockStructureModel, _directory_name, _storage_error_handling
@@ -30,8 +30,7 @@ class BlockStructureModelTestCase(TestCase):
self.params = self._create_bsm_params()
def tearDown(self):
with waffle().override(PRUNE_OLD_VERSIONS, active=True):
BlockStructureModel._prune_files(self.usage_key, num_to_keep=0)
BlockStructureModel._prune_files(self.usage_key, num_to_keep=0)
super(BlockStructureModelTestCase, self).tearDown()
def _assert_bsm_fields(self, bsm, expected_serialized_data):
@@ -79,6 +78,7 @@ class BlockStructureModelTestCase(TestCase):
return bsm
@patch('openedx.core.djangoapps.content.block_structure.models.log')
@patch.dict(settings.BLOCK_STRUCTURES_SETTINGS, {'PRUNING_ACTIVE': False})
def test_update_or_create(self, mock_log):
serialized_data = 'initial data'
@@ -106,22 +106,20 @@ class BlockStructureModelTestCase(TestCase):
@patch('openedx.core.djangoapps.content.block_structure.config.num_versions_to_keep', Mock(return_value=1))
def test_prune_files(self):
with waffle().override(PRUNE_OLD_VERSIONS, active=True):
self._verify_update_or_create_call('test data', expect_created=True)
self._verify_update_or_create_call('updated data', expect_created=False)
self._assert_file_count_equal(1)
self._verify_update_or_create_call('test data', expect_created=True)
self._verify_update_or_create_call('updated data', expect_created=False)
self._assert_file_count_equal(1)
@patch('openedx.core.djangoapps.content.block_structure.config.num_versions_to_keep', Mock(return_value=1))
@patch('openedx.core.djangoapps.content.block_structure.models.BlockStructureModel._delete_files')
@patch('openedx.core.djangoapps.content.block_structure.models.log')
def test_prune_exception(self, mock_log, mock_delete):
with waffle().override(PRUNE_OLD_VERSIONS, active=True):
mock_delete.side_effect = Exception
self._verify_update_or_create_call('test data', expect_created=True)
self._verify_update_or_create_call('updated data', expect_created=False)
mock_delete.side_effect = Exception
self._verify_update_or_create_call('test data', expect_created=True)
self._verify_update_or_create_call('updated data', expect_created=False)
self.assertIn('BlockStructure: Exception when deleting old files', mock_log.exception.call_args[0][0])
self._assert_file_count_equal(2) # old files not pruned
self.assertIn('BlockStructure: Exception when deleting old files', mock_log.exception.call_args[0][0])
self._assert_file_count_equal(2) # old files not pruned
@ddt.data(
*product(
@@ -135,15 +133,14 @@ class BlockStructureModelTestCase(TestCase):
'openedx.core.djangoapps.content.block_structure.config.num_versions_to_keep',
return_value=prune_keep_count,
):
for _ in range(num_prior_edits):
self._verify_update_or_create_call('data')
for x in range(num_prior_edits):
self._verify_update_or_create_call('data_{}'.format(x))
if num_prior_edits:
self._assert_file_count_equal(num_prior_edits)
self._assert_file_count_equal(min(num_prior_edits, prune_keep_count))
with waffle().override(PRUNE_OLD_VERSIONS, active=True):
self._verify_update_or_create_call('data')
self._assert_file_count_equal(min(prune_keep_count, num_prior_edits + 1))
self._verify_update_or_create_call('data_final')
self._assert_file_count_equal(min(num_prior_edits + 1, prune_keep_count))
@ddt.data(
(IOError, BlockStructureNotFound, True),