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()
+ 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.
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 ------- ------- ------- ------- ------- ------- ------- ---- search. py' search. py 2013-06-04 14:40:57 +0000 search. py 2013-06-04 15:28:33 +0000
kwargs[ 'size'] = limit search( dsl, **kwargs) search( dsl, **kwargs) 'hits'] ['hits' ]) < hits['hits' ]['total' ]:
kwargs[ 'size'] = hits['hits' ]['total' ] search( dsl, **kwargs)
copy. put_mapping( ) search( valid_charms_ only=False) search( valid_charms_ only=False)
copy. index_charms( charms) get_aliased( ) delete_ index() delete_ index()
index_ client. update_ aliased( new_index. index_name, aliased)
new_index. delete_ index()
-------
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/
--- charmworld/
+++ charmworld/
@@ -233,7 +233,8 @@
kwargs = {'index': self.index_name}
if limit is not None:
- hits = self._client.
+ with translate_error():
+ hits = self._client.
if limit is None and len(hits[
hits = self._client.
@@ -365,7 +366,10 @@
try:
if charms is None:
- charms = self.api_
+ try:
+ charms = self.api_
+ except IndexMissing:
+ charms = []
return copy
except:
@@ -387,7 +391,10 @@
try:
aliased = index_client.
if aliased == []:
- index_client.
+ try:
+ index_client.
+ except IndexMissing:
+ pass
except:
=== modified file 'charmworld/ tests/test_ search. py' tests/test_ search. py 2013-06-04 14:40:57 +0000 tests/test_ search. py 2013-06-04 15:28:33 +0000
self. assertIn( 'series' , copy.get_ mapping( )['charm' ]['properties' ])
self. assertEqual( {'_id': 'a', 'name': 'bar'}, copy.get('a'))
--- charmworld/
+++ charmworld/
@@ -461,6 +461,11 @@
+ def test_create_ replacement_ misssing( self): ient.from_ settings( get_ini( ), 'temp-index') create_ replacement( ) (copy.delete_ index) mapping_ incompatible_ mapping_ error(self) : client( name='foo' , put_mapping=False)
self. assertEqual( 'not_analyzed' ,
mapping[ 'charm' ]['properties' ]['name' ]['index' ]) no_client_ charms( self): ient.from_ settings( get_ini( )) delete_ index()
+ client = ElasticSearchCl
+ copy = client.
+ self.addCleanup
+
def test_put_
# The error we get from an incompatible mapping is IncompatibleMapping
context = temp_index_
@@ -610,3 +615,8 @@
mapping = alias.get_mapping()
+
+ def test_reindexed_
+ client = ElasticSearchCl
+ new_client = reindex(client, charms=[])
+ new_client.
And here's how to get the merge proposal where it was further described: annotate: charmworld/ tests/test_ search. py:1224
bzr lp-find-proposal -r mainline:
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.