Browse files

Deal with Bonsai locked-down permissions

Bonsai doesn't allow access to /_cluster/health, which causes the call to
...indices.refresh() to fail.
  • Loading branch information...
1 parent 2254aee commit bdc638d9bdc87d8b0b3899f9e8a59a314436b3fe @nickstenning nickstenning committed Feb 15, 2013
Showing with 8 additions and 3 deletions.
  1. +4 −1 annotator/elasticsearch.py
  2. +4 −2 tests/test_annotation.py
View
5 annotator/elasticsearch.py
@@ -152,7 +152,10 @@ def save(self, refresh=True):
res = self.es.conn.index(self, self.es.index, self.__type__, self.id)
self.id = res['_id']
if refresh:
- self.es.conn.indices.refresh(self.es.index)
+ # Can't simply call self.es.conn.indices.refresh(self.es.index)
+ # here, as that automatically makes a cluster health call
+ # afterwards that the Bonsai API refuses to service.
+ self.es.conn._send_request('POST', '/{0}/_refresh'.format(self.es.index))
def delete(self):
if self.id:
View
6 tests/test_annotation.py
@@ -32,14 +32,16 @@ def test_save_refresh(self):
def test_save_refresh(self):
a = Annotation(name='bob')
a.es = MagicMock()
+ a.es.index = 'foo'
a.save()
- assert_equal(1, a.es.conn.indices.refresh.call_count)
+ a.es.conn._send_request.assert_called_with('POST', '/foo/_refresh')
def test_save_refresh_disable(self):
a = Annotation(name='bob')
a.es = MagicMock()
+ a.es.index = 'foo'
a.save(refresh=False)
- assert_false(a.es.conn.indices.refresh.called)
+ a.es.conn._send_request.assert_not_called_with('POST', '/foo/_refresh')
def test_fetch(self):
a = Annotation(foo='bar')

0 comments on commit bdc638d

Please sign in to comment.