Merge lp:~notmyname/swift/stale_headers into lp:~hudson-openstack/swift/trunk

Proposed by John Dickinson
Status: Merged
Approved by: Chuck Thier
Approved revision: 350
Merged at revision: 348
Proposed branch: lp:~notmyname/swift/stale_headers
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 65 lines (+26/-5)
2 files modified
swift/common/db.py (+6/-0)
test/unit/common/test_db.py (+20/-5)
To merge this branch: bzr merge lp:~notmyname/swift/stale_headers
Reviewer Review Type Date Requested Status
Chuck Thier (community) Approve
gholt (community) Approve
Review via email: mp+73253@code.launchpad.net

Description of the change

deleting a database (account or container) now also clears the metadata

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

Cool

review: Approve
lp:~notmyname/swift/stale_headers updated
350. By John Dickinson

cleaned up local variable

Revision history for this message
Chuck Thier (cthier) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'swift/common/db.py'
2--- swift/common/db.py 2011-08-12 18:29:16 +0000
3+++ swift/common/db.py 2011-08-29 20:27:30 +0000
4@@ -253,6 +253,12 @@
5 :param timestamp: delete timestamp
6 """
7 timestamp = normalize_timestamp(timestamp)
8+ # first, clear the metadata
9+ cleared_meta = {}
10+ for k in self.metadata.iterkeys():
11+ cleared_meta[k] = ('', timestamp)
12+ self.update_metadata(cleared_meta)
13+ # then mark the db as deleted
14 with self.get() as conn:
15 self._delete_db(conn, timestamp)
16 conn.commit()
17
18=== modified file 'test/unit/common/test_db.py'
19--- test/unit/common/test_db.py 2011-08-12 18:29:16 +0000
20+++ test/unit/common/test_db.py 2011-08-29 20:27:30 +0000
21@@ -141,24 +141,39 @@
22 conn.execute('SELECT * FROM incoming_sync')
23
24 def test_delete_db(self):
25+ def init_stub(conn, put_timestamp):
26+ conn.execute('CREATE TABLE test (one TEXT)')
27+ conn.execute('CREATE TABLE test_stat (id TEXT)')
28+ conn.execute('INSERT INTO test_stat (id) VALUES (?)',
29+ (str(uuid4),))
30+ conn.execute('INSERT INTO test (one) VALUES ("1")')
31+ conn.commit()
32 stub_called = [False]
33- def stub(*args, **kwargs):
34+ def delete_stub(*a, **kw):
35 stub_called[0] = True
36 broker = DatabaseBroker(':memory:')
37- broker._initialize = stub
38+ broker.db_type = 'test'
39+ broker._initialize = init_stub
40+ # Initializes a good broker for us
41 broker.initialize(normalize_timestamp('1'))
42 self.assert_(broker.conn is not None)
43- broker._delete_db = stub
44+ broker._delete_db = delete_stub
45 stub_called[0] = False
46 broker.delete_db('2')
47 self.assert_(stub_called[0])
48 broker = DatabaseBroker(os.path.join(self.testdir, '1.db'))
49- broker._initialize = stub
50+ broker.db_type = 'test'
51+ broker._initialize = init_stub
52 broker.initialize(normalize_timestamp('1'))
53- broker._delete_db = stub
54+ broker._delete_db = delete_stub
55 stub_called[0] = False
56 broker.delete_db('2')
57 self.assert_(stub_called[0])
58+ # ensure that metadata was cleared
59+ m2 = broker.metadata
60+ self.assert_(not any(v[0] for v in m2.itervalues()))
61+ self.assert_(all(v[1] == normalize_timestamp('2')
62+ for v in m2.itervalues()))
63
64 def test_get(self):
65 broker = DatabaseBroker(':memory:')