launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #07139
[Merge] lp:~rvb/maas/clear-cache-command into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/clear-cache-command into lp:maas with lp:~rvb/maas/bug-973785-iso-script as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/clear-cache-command/+merge/102298
This branch introduces a new command clearcache which, surprisingly, clear MAAS' cache. A specific key can be specified if one wants to clear a particular key instead of the whole cache. This command is used in scripts/maas-import-isos to force a profile check after this script has run.
--
https://code.launchpad.net/~rvb/maas/clear-cache-command/+merge/102298
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/clear-cache-command into lp:maas.
=== modified file 'scripts/maas-import-isos'
--- scripts/maas-import-isos 2012-04-12 14:42:58 +0000
+++ scripts/maas-import-isos 2012-04-17 13:33:25 +0000
@@ -190,3 +190,6 @@
# Sync changes with cobbler daemon
cobbler sync
+
+# Clear MAAS' cache to force the profile check.
+maas clearcache --key=profile-check-done
=== added file 'src/maasserver/management/commands/clearcache.py'
--- src/maasserver/management/commands/clearcache.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/management/commands/clearcache.py 2012-04-17 13:33:25 +0000
@@ -0,0 +1,33 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Django command: clear the cache."""
+
+from __future__ import (
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = [
+ 'Command',
+ ]
+
+from django.core.cache import cache
+from optparse import make_option
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+ option_list = BaseCommand.option_list + (
+ make_option('--key', dest='username', default=None,
+ help="Specify a specific key to delete."),
+ )
+ help = "Clear the cache (the entire cache or only specific key)."
+
+ def handle(self, *args, **options):
+ key = options.get('key', None)
+ if key is None:
+ cache.clear()
+ else:
+ cache.delete(key)
=== modified file 'src/maasserver/management/commands/generate_api_doc.py'
--- src/maasserver/management/commands/generate_api_doc.py 2012-03-29 08:58:00 +0000
+++ src/maasserver/management/commands/generate_api_doc.py 2012-04-17 13:33:25 +0000
@@ -1,3 +1,18 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Django command: generate the API documentation."""
+
+from __future__ import (
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = [
+ 'Command',
+ ]
+
from django.core.management.base import BaseCommand
from maasserver.api import (
api_doc_title,
=== modified file 'src/maasserver/middleware.py'
--- src/maasserver/middleware.py 2012-04-17 13:33:25 +0000
+++ src/maasserver/middleware.py 2012-04-17 13:33:25 +0000
@@ -106,7 +106,7 @@
# The profiles check done by check_profiles_cached is only done at most once
# every PROFILE_CHECK_DELAY seconds for efficiency.
-PROFILE_CHECK_DELAY = 20
+PROFILE_CHECK_DELAY = 2 * 60
def check_profiles_cached():
=== modified file 'src/maasserver/tests/test_commands.py'
--- src/maasserver/tests/test_commands.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/tests/test_commands.py 2012-04-17 13:33:25 +0000
@@ -18,6 +18,7 @@
from django.conf import settings
from django.contrib.auth.models import User
+from django.core.cache import cache
from django.core.management import call_command
from maasserver.models import FileStorage
from maasserver.testing.factory import factory
@@ -102,3 +103,18 @@
self.assertTrue(users[0].check_password(password))
self.assertTrue(users[0].is_superuser)
self.assertEqual(email, users[0].email)
+
+ def test_clearcache_clears_entire_cache(self):
+ key = factory.getRandomString()
+ cache.set(key, factory.getRandomString())
+ call_command('clearcache')
+ self.assertIsNone(cache.get(key, None))
+
+ def test_clearcache_clears_specific_key(self):
+ key = factory.getRandomString()
+ cache.set(key, factory.getRandomString())
+ another_key = factory.getRandomString()
+ cache.set(another_key, factory.getRandomString())
+ call_command('clearcache', key=key)
+ self.assertIsNone(cache.get(key, None))
+ self.assertIsNotNone(cache.get(another_key, None))