Merge lp:~sinzui/charmworld/migrate-new-index into lp:~juju-jitsu/charmworld/trunk

Proposed by Curtis Hovey
Status: Merged
Approved by: Aaron Bentley
Approved revision: 386
Merged at revision: 387
Proposed branch: lp:~sinzui/charmworld/migrate-new-index
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 79 lines (+25/-11)
2 files modified
charmworld/migrations/versions/018_delete_all_bundles.py (+11/-3)
charmworld/migrations/versions/tests/test_migrations.py (+14/-8)
To merge this branch: bzr merge lp:~sinzui/charmworld/migrate-new-index
Reviewer Review Type Date Requested Status
Benji York (community) Approve
Review via email: mp+184292@code.launchpad.net

Commit message

Update migration script to handle new deploys.

Description of the change

Update migration script to handle new deploys.

RULES

    Pre-implementation: no one
    * Update migration 18 to not fail when there is no ES index to update.
      * Either look before acting, or recover from an IndexMissing error

QA

    * Do a new deploy of apache, charmworld, elasticsearch and mongodb
    * Verify all services start without error. The bug manifested itself
      as a relation-error. The migration script was called when the db
      and the index joined.

IMPLEMENTATION

    * I used translate_error to adapt the ES failure and the script
      treats IndexMissing as a success because there are no bundles
      to delete.
    * Note I had to add the index back at the end of the test to ensure
      tear down succeeded. I could have instead replaced the setup
      method with another method that each test calls to get a preexisting
      ES.

To post a comment you must log in.
Revision history for this message
Benji York (benji) 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 'charmworld/migrations/versions/018_delete_all_bundles.py'
2--- charmworld/migrations/versions/018_delete_all_bundles.py 2013-08-23 12:12:25 +0000
3+++ charmworld/migrations/versions/018_delete_all_bundles.py 2013-09-06 13:06:48 +0000
4@@ -1,10 +1,18 @@
5 # Copyright 2013 Canonical Ltd. This software is licensed under the
6 # GNU Affero General Public License version 3 (see the file LICENSE).
7
8-from pyelasticsearch.exceptions import ElasticHttpNotFoundError
9+from charmworld.search import (
10+ BUNDLE,
11+ IndexMissing,
12+ translate_error,
13+)
14
15-from charmworld.search import BUNDLE
16
17 def upgrade(db, index_client):
18 db.bundles.remove({}, False)
19- index_client._client.delete_all(index_client.index_name, BUNDLE)
20+ try:
21+ with translate_error():
22+ index_client._client.delete_all(index_client.index_name, BUNDLE)
23+ except IndexMissing:
24+ # There is nothing to migrate.
25+ pass
26
27=== modified file 'charmworld/migrations/versions/tests/test_migrations.py'
28--- charmworld/migrations/versions/tests/test_migrations.py 2013-08-28 20:26:59 +0000
29+++ charmworld/migrations/versions/tests/test_migrations.py 2013-09-06 13:06:48 +0000
30@@ -6,23 +6,17 @@
31
32 from charmworld.models import (
33 Bundle,
34- CharmSource,
35- construct_charm_id,
36- FeaturedSource,
37- QADataSource,
38 store_bundles,
39 )
40 from charmworld.search import (
41 BUNDLE,
42- CHARM,
43+ IndexMissing,
44 )
45 from charmworld.testing import (
46- factory,
47 MongoTestBase,
48 )
49 from charmworld.migrations import migrate
50 from charmworld.migrations.migrate import Versions
51-from charmworld.tests.test_search import put_mapping
52
53 import mock
54
55@@ -62,7 +56,8 @@
56 basket_id = "%s/%d" % (basket_name, basket_rev)
57 self.search_id = Bundle.construct_id(
58 owner, basket_name, bundle_name)
59- store_bundles(self.db.bundles, parsed, owner, basket_id,
60+ store_bundles(
61+ self.db.bundles, parsed, owner, basket_id,
62 index_client=self.index_client)
63
64 def test_bundles_are_removed_from_elastic_search(self):
65@@ -78,3 +73,14 @@
66 self.versions.run_migration(
67 self.db, self.index_client, '018_delete_all_bundles.py')
68 self.assertIsNone(self.db.bundles.find_one({}))
69+
70+ def test_new_db_and_index_are_noop(self):
71+ # The migration script survives MIssingIndex errors.
72+ # New installs don't have ES indexes yet.
73+ self.index_client.delete_index()
74+ with self.assertRaises(IndexMissing):
75+ self.index_client.get_status()
76+ self.versions.run_migration(
77+ self.db, self.index_client, '018_delete_all_bundles.py')
78+ # Put the index back for the test case to handle.
79+ self.index_client.create_index()

Subscribers

People subscribed via source and target branches