From 242ac4c9cd06b0fb77a6191eb511f80a66908e46 Mon Sep 17 00:00:00 2001
From: Eric Fischer <efischer@edx.org>
Date: Thu, 22 Mar 2018 16:10:49 -0400
Subject: [PATCH] Remove PRUNE_OLD_VERSIONS waffle flag

---
 lms/envs/common.py                            |  6 ++--
 lms/envs/test.py                              |  2 ++
 .../block_structure/config/__init__.py        |  1 -
 .../content/block_structure/models.py         |  2 +-
 .../block_structure/tests/test_models.py      | 35 +++++++++----------
 5 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/lms/envs/common.py b/lms/envs/common.py
index 55b26b1b0f7..0d193ad945a 100644
--- a/lms/envs/common.py
+++ b/lms/envs/common.py
@@ -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 ###################################
diff --git a/lms/envs/test.py b/lms/envs/test.py
index ecd383d87be..f7cf70c1b6f 100644
--- a/lms/envs/test.py
+++ b/lms/envs/test.py
@@ -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
diff --git a/openedx/core/djangoapps/content/block_structure/config/__init__.py b/openedx/core/djangoapps/content/block_structure/config/__init__.py
index 1d0d4a7016d..637df079144 100644
--- a/openedx/core/djangoapps/content/block_structure/config/__init__.py
+++ b/openedx/core/djangoapps/content/block_structure/config/__init__.py
@@ -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():
diff --git a/openedx/core/djangoapps/content/block_structure/models.py b/openedx/core/djangoapps/content/block_structure/models.py
index 7bc133886d4..bef9154ab38 100644
--- a/openedx/core/djangoapps/content/block_structure/models.py
+++ b/openedx/core/djangoapps/content/block_structure/models.py
@@ -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:
diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_models.py b/openedx/core/djangoapps/content/block_structure/tests/test_models.py
index 008ebce4249..343fe823db9 100644
--- a/openedx/core/djangoapps/content/block_structure/tests/test_models.py
+++ b/openedx/core/djangoapps/content/block_structure/tests/test_models.py
@@ -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),
-- 
GitLab