Merge lp:~canonical-isd-hackers/canonical-identity-provider/flag-file-mode into lp:~canonical-isd-hackers/canonical-identity-provider/readonly-improvements

Proposed by Anthony Lenton
Status: Merged
Merge reported by: Łukasz Czyżykowski
Merged at revision: not available
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/flag-file-mode
Merge into: lp:~canonical-isd-hackers/canonical-identity-provider/readonly-improvements
Diff against target: 95 lines (+37/-1)
2 files modified
identityprovider/readonly.py (+6/-0)
identityprovider/tests/test_readonly.py (+31/-1)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/flag-file-mode
Reviewer Review Type Date Requested Status
Ricardo Kirkner (community) Approve
Review via email: mp+24759@code.launchpad.net

Description of the change

This branch implements a fix for bug #550881.

Flag files are now created with g+rw permissions, so that losas can handle them easily.

The MP is against the readonly-improvements branch which is already reviewed and ready for merging with 2.x-trunk once approved by QA.

To post a comment you must log in.
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

works beautifully :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/readonly.py'
2--- identityprovider/readonly.py 2010-05-05 14:50:36 +0000
3+++ identityprovider/readonly.py 2010-05-05 17:52:34 +0000
4@@ -2,6 +2,7 @@
5 # GNU Affero General Public License version 3 (see the file LICENSE).
6
7 import os
8+import stat
9 from django.conf import settings
10 from django.db import connection
11
12@@ -32,6 +33,9 @@
13 settings.READ_ONLY_MODE = True
14 if not os.path.exists(self.readonly_marker_file):
15 open(self.readonly_marker_file, 'a').close()
16+ mode = os.stat(self.readonly_marker_file)[stat.ST_MODE]
17+ os.chmod(self.readonly_marker_file,
18+ mode | stat.S_IRGRP | stat.S_IWGRP)
19
20 def clear_readonly(self):
21 """Clear the marker file to leave readonly mode."""
22@@ -60,6 +64,8 @@
23 filename = self.marker_file_pattern % dbname
24 if not os.path.exists(filename):
25 open(filename, 'a').close()
26+ mode = os.stat(filename)[stat.ST_MODE]
27+ os.chmod(filename, mode | stat.S_IRGRP | stat.S_IWGRP)
28 if dbname == self.master_dbid():
29 self.set_readonly()
30
31
32=== modified file 'identityprovider/tests/test_readonly.py'
33--- identityprovider/tests/test_readonly.py 2010-05-05 16:26:28 +0000
34+++ identityprovider/tests/test_readonly.py 2010-05-05 17:52:34 +0000
35@@ -1,6 +1,10 @@
36 # Copyright 2010 Canonical Ltd. This software is licensed under the
37 # GNU Affero General Public License version 3 (see the file LICENSE).
38
39+import os
40+import stat
41+import shutil
42+import tempfile
43 import socket
44 import urllib2
45 from StringIO import StringIO
46@@ -92,7 +96,8 @@
47 self.assertEquals(self.host, self.req.get_host())
48 self.restore_orig_urlopen()
49
50-class ReadOnlyDataTest(SQLCachedTestCase):
51+class ReadOnlyBackUp(SQLCachedTestCase):
52+ """A base TestCase for backing up and restoring our readonly settings"""
53 def setUp(self):
54 self.orig_readonly_secret = settings.READONLY_SECRET
55 settings.READONLY_SECRET = 'test secret'
56@@ -105,14 +110,39 @@
57 'DATABASE_HOST': 'dbhost2',
58 'DATABASE_NAME': 'slavedb',
59 }]
60+ self._DBFAILOVER_FLAG_DIR = getattr(settings, 'DBFAILOVER_FLAG_DIR',
61+ None)
62+ settings.DBFAILOVER_FLAG_DIR = tempfile.mkdtemp()
63
64 def tearDown(self):
65+ shutil.rmtree(settings.DBFAILOVER_FLAG_DIR, True)
66+ settings.DBFAILOVER_FLAG_DIR = self._DBFAILOVER_FLAG_DIR
67 settings.READONLY_SECRET = self.orig_readonly_secret
68 settings.DB_CONNECTIONS = self.orig_db_connections
69 readonly_manager.clear_readonly()
70 readonly_manager.clear_failed('master')
71 readonly_manager.set_db(settings.DB_CONNECTIONS[0])
72
73+class ReadOnlyFlagFilesTest(ReadOnlyBackUp):
74+ def test_flag_files_in_right_directory(self):
75+ readonly_manager.set_readonly()
76+ flags = os.listdir(settings.DBFAILOVER_FLAG_DIR)
77+ self.assertTrue('db.readonly' in flags)
78+
79+ def test_readonly_flag_files_have_right_mode(self):
80+ readonly_manager.set_readonly()
81+ mode = os.stat(readonly_manager.readonly_marker_file)[stat.ST_MODE]
82+ self.assertTrue(mode & stat.S_IRGRP)
83+ self.assertTrue(mode & stat.S_IWGRP)
84+
85+ def test_dbfail_flag_files_have_right_mode(self):
86+ readonly_manager.mark_failed('foo')
87+ flagfile = readonly_manager.marker_file_pattern % 'foo'
88+ mode = os.stat(flagfile)[stat.ST_MODE]
89+ self.assertTrue(mode & stat.S_IRGRP)
90+ self.assertTrue(mode & stat.S_IWGRP)
91+
92+class ReadOnlyDataTest(ReadOnlyBackUp):
93 def test_readonly_returns_404_for_get(self):
94 response = self.client.get('/readonlydata')
95 self.assertEquals(404, response.status_code)

Subscribers

People subscribed via source and target branches

to all changes: