launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06599
[Merge] lp:~jtv/maas/gc into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/gc into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/gc/+merge/96054
Collect garbage from a shell command. Currently it only collects dead FileStorage files, but this may also be the sensible place to hook up other GC processes.
I arranged with Daviey that his team can run this daily from cron. Run as:
./bin/maas gc
--
https://code.launchpad.net/~jtv/maas/gc/+merge/96054
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/gc into lp:maas.
=== added file 'src/maasserver/management/commands/gc.py'
--- src/maasserver/management/commands/gc.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/management/commands/gc.py 2012-03-06 04:07:19 +0000
@@ -0,0 +1,23 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Custom django command: garabge-collect."""
+
+from __future__ import (
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = [
+ 'Command',
+ ]
+
+
+from django.core.management.base import BaseCommand
+from maasserver.models import FileStorage
+
+
+class Command(BaseCommand):
+ def handle(self, *args, **options):
+ FileStorage.objects.collect_garbage()
=== added file 'src/maasserver/tests/test_commands.py'
--- src/maasserver/tests/test_commands.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/tests/test_commands.py 2012-03-06 04:07:19 +0000
@@ -0,0 +1,39 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Test custom commands, as found in src/maasserver/management/commands."""
+
+from __future__ import (
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = []
+
+import os
+from subprocess import check_call
+
+from django.conf import settings
+from maasserver.models import FileStorage
+from maastesting import TestCase
+
+
+class TestCommands(TestCase):
+ """Happy-path integration testing for custom commands.
+
+ Detailed testing does not belong here. If there's any complexity at all
+ in a command's code, it should be extracted and unit-tested separately.
+ """
+
+ def run_command(self, command_name, *args):
+ """Run a custom command of the "maas" script."""
+ check_call(("./bin/maas", command_name) + args)
+
+ def test_gc(self):
+ upload_dir = os.path.join(settings.MEDIA_ROOT, FileStorage.upload_dir)
+ os.makedirs(upload_dir)
+ self.addCleanup(os.removedirs, upload_dir)
+ self.run_command('gc')
+ # The test is that we get here without errors.
+ pass