Comment 3 for bug 1317567

Revision history for this message
Aaron Bentley (abentley) wrote :

Even in the case where the index is deleted, you should be able to restore it with bin/es-update, which is *much* faster than re-ingesting.

The purpose of the test is to ensure reindexing doesn't raise an exception when charms are not supplied and there's no existing index. Here's how to find that kind of thing out in the future:

$ bzr log --show-diff -r annotate:charmworld/tests/test_search.py:1224
------------------------------------------------------------
revno: 241.1.5
committer: Aaron Bentley <email address hidden>
branch nick: remove-api-0
timestamp: Tue 2013-06-04 11:28:33 -0400
message:
  Handle reindexing when the index does not exist.
diff:
=== modified file 'charmworld/search.py'
--- charmworld/search.py 2013-06-04 14:40:57 +0000
+++ charmworld/search.py 2013-06-04 15:28:33 +0000
@@ -233,7 +233,8 @@
         kwargs = {'index': self.index_name}
         if limit is not None:
             kwargs['size'] = limit
- hits = self._client.search(dsl, **kwargs)
+ with translate_error():
+ hits = self._client.search(dsl, **kwargs)
         if limit is None and len(hits['hits']['hits']) < hits['hits']['total']:
             kwargs['size'] = hits['hits']['total']
             hits = self._client.search(dsl, **kwargs)
@@ -365,7 +366,10 @@
         try:
             copy.put_mapping()
             if charms is None:
- charms = self.api_search(valid_charms_only=False)
+ try:
+ charms = self.api_search(valid_charms_only=False)
+ except IndexMissing:
+ charms = []
             copy.index_charms(charms)
             return copy
         except:
@@ -387,7 +391,10 @@
     try:
         aliased = index_client.get_aliased()
         if aliased == []:
- index_client.delete_index()
+ try:
+ index_client.delete_index()
+ except IndexMissing:
+ pass
         index_client.update_aliased(new_index.index_name, aliased)
     except:
         new_index.delete_index()

=== modified file 'charmworld/tests/test_search.py'
--- charmworld/tests/test_search.py 2013-06-04 14:40:57 +0000
+++ charmworld/tests/test_search.py 2013-06-04 15:28:33 +0000
@@ -461,6 +461,11 @@
         self.assertIn('series', copy.get_mapping()['charm']['properties'])
         self.assertEqual({'_id': 'a', 'name': 'bar'}, copy.get('a'))

+ def test_create_replacement_misssing(self):
+ client = ElasticSearchClient.from_settings(get_ini(), 'temp-index')
+ copy = client.create_replacement()
+ self.addCleanup(copy.delete_index)
+
     def test_put_mapping_incompatible_mapping_error(self):
         # The error we get from an incompatible mapping is IncompatibleMapping
         context = temp_index_client(name='foo', put_mapping=False)
@@ -610,3 +615,8 @@
         mapping = alias.get_mapping()
         self.assertEqual('not_analyzed',
                          mapping['charm']['properties']['name']['index'])
+
+ def test_reindexed_no_client_charms(self):
+ client = ElasticSearchClient.from_settings(get_ini())
+ new_client = reindex(client, charms=[])
+ new_client.delete_index()

And here's how to get the merge proposal where it was further described:
bzr lp-find-proposal -r mainline:annotate:charmworld/tests/test_search.py:1224

There are major portions of the test suite that it's a bad idea to run under anything but test_ini. I don't think you'd want to add @unittest.skipUnless(run_under_testini) to all of them, and it wouldn't fix this case, anyhow.