~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/scripts/tests/test_garbo.py

[r=wgrant][bug=1832477] Allow configuring the binary file retention
 period of a LiveFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
154
154
    )
155
155
 
156
156
 
 
157
_default = object()
 
158
 
 
159
 
157
160
class TestGarboScript(TestCase):
158
161
    layer = LaunchpadScriptLayer
159
162
 
1513
1516
            'PopulateLatestPersonSourcePackageReleaseCache')
1514
1517
        self.assertEqual(spph_2.id, job_data['last_spph_id'])
1515
1518
 
1516
 
    def _test_LiveFSFilePruner(self, content_type, interval, expected_count=0):
 
1519
    def _test_LiveFSFilePruner(self, content_type, interval,
 
1520
                               keep_binary_files_days=_default,
 
1521
                               expected_count=0):
1517
1522
        # Garbo should (or should not, if `expected_count=1`) remove LiveFS
1518
1523
        # files of MIME type `content_type` that finished more than
1519
 
        # `interval` days ago.
 
1524
        # `interval` days ago.  If `keep_binary_files_days` is given, set
 
1525
        # that on the test LiveFS.
1520
1526
        now = datetime.now(UTC)
1521
1527
        switch_dbuser('testadmin')
1522
1528
        self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: u'on'}))
1523
1529
        store = IMasterStore(LiveFSFile)
1524
1530
 
 
1531
        livefs_kwargs = {}
 
1532
        if keep_binary_files_days is not _default:
 
1533
            livefs_kwargs['keep_binary_files_days'] = keep_binary_files_days
1525
1534
        db_build = self.factory.makeLiveFSBuild(
1526
1535
            date_created=now - timedelta(days=interval, minutes=15),
1527
 
            status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=10))
 
1536
            status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=10),
 
1537
            **livefs_kwargs)
1528
1538
        db_lfa = self.factory.makeLibraryFileAlias(content_type=content_type)
1529
1539
        db_file = self.factory.makeLiveFSFile(
1530
1540
            livefsbuild=db_build, libraryfile=db_lfa)
1537
1547
        self.assertEqual(expected_count, store.find(LiveFSFile).count())
1538
1548
 
1539
1549
    def test_LiveFSFilePruner_old_binary_files(self):
1540
 
        # LiveFS binary files attached to builds over a day old are pruned.
 
1550
        # By default, LiveFS binary files attached to builds over a day old
 
1551
        # are pruned.
1541
1552
        self._test_LiveFSFilePruner('application/octet-stream', 1)
1542
1553
 
1543
1554
    def test_LiveFSFilePruner_old_text_files(self):
1550
1561
        self._test_LiveFSFilePruner(
1551
1562
            'application/octet-stream', 0, expected_count=1)
1552
1563
 
 
1564
    def test_LiveFSFilePruner_custom_interval_old_binary_files(self):
 
1565
        # If a custom retention interval is set, LiveFS binary files
 
1566
        # attached to builds over that interval old are pruned.
 
1567
        self._test_LiveFSFilePruner(
 
1568
            'application/octet-stream', 7, keep_binary_files_days=7)
 
1569
 
 
1570
    def test_LiveFSFilePruner_custom_interval_recent_binary_files(self):
 
1571
        # If a custom retention interval is set, LiveFS binary files
 
1572
        # attached to builds less than that interval old are pruned.
 
1573
        self._test_LiveFSFilePruner(
 
1574
            'application/octet-stream', 6, keep_binary_files_days=7,
 
1575
            expected_count=1)
 
1576
 
 
1577
    def test_LiveFSFilePruner_null_interval_disables_pruning(self):
 
1578
        # A null retention interval disables pruning.
 
1579
        self._test_LiveFSFilePruner(
 
1580
            'application/octet-stream', 100, keep_binary_files_days=None,
 
1581
            expected_count=1)
 
1582
 
1553
1583
    def _test_SnapFilePruner(self, filename, job_status, interval,
1554
1584
                             expected_count=0):
1555
1585
        # Garbo should (or should not, if `expected_count=1`) remove snap