Remove version when creating records in elasticsearch

Closes-Bug: 1557091

(cherry picked from commit 67a8bdb9e4 )

Change-Id: Ieecde522f228d01d3054855ea8096b6352ac3667
This commit is contained in:
Jonas Pfannschmidt
2016-03-15 17:31:28 +00:00
committed by Saad Zaher
parent 0f33e2f7e9
commit 93b02750cb
3 changed files with 26 additions and 6 deletions

View File

@@ -92,10 +92,9 @@ class TypeManager:
return [x['_source'] for x in hit_list]
def insert(self, doc, doc_id=None):
version = doc.pop('_version', 0)
try:
res = self.es.index(index=self.index, doc_type=self.doc_type,
body=doc, id=doc_id, version=version)
body=doc, id=doc_id)
created = res['created']
version = res['_version']
self.es.indices.refresh(index=self.index)

View File

@@ -0,0 +1,21 @@
#!/bin/bash -xe
# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# Called by gate-freezer-api-devstack-dsvm job.
echo 'Running freezer-api pre_test_hook'
# Nothing to do. Can be used when needed.

View File

@@ -99,25 +99,25 @@ class TypeManager(unittest.TestCase):
test_doc = {'test_key_412': 'test_value_412', '_version': 5}
res = self.type_manager.insert(doc=test_doc)
self.assertEqual(res, (True, 15))
self.mock_es.index.assert_called_with(index='freezer', doc_type='base_doc_type', body=test_doc, id=None, version=5)
self.mock_es.index.assert_called_with(index='freezer', doc_type='base_doc_type', body=test_doc, id=None)
def test_insert_raise_StorageEngineError_on_ES_Exception(self):
self.mock_es.index.side_effect = Exception('regular test failure')
test_doc = {'test_key_412': 'test_value_412', '_version': 5}
self.assertRaises(StorageEngineError, self.type_manager.insert, doc=test_doc)
self.mock_es.index.assert_called_with(index='freezer', doc_type='base_doc_type', body=test_doc, id=None, version=5)
self.mock_es.index.assert_called_with(index='freezer', doc_type='base_doc_type', body=test_doc, id=None)
def test_insert_raise_StorageEngineError_on_ES_TransportError_exception(self):
self.mock_es.index.side_effect = TransportError(500, 'regular test failure')
test_doc = {'test_key_412': 'test_value_412', '_version': 5}
self.assertRaises(StorageEngineError, self.type_manager.insert, doc=test_doc)
self.mock_es.index.assert_called_with(index='freezer', doc_type='base_doc_type', body=test_doc, id=None, version=5)
self.mock_es.index.assert_called_with(index='freezer', doc_type='base_doc_type', body=test_doc, id=None)
def test_insert_raise_DocumentExists_on_ES_TransportError409_exception(self):
self.mock_es.index.side_effect = TransportError(409, 'regular test failure')
test_doc = {'test_key_412': 'test_value_412', '_version': 5}
self.assertRaises(DocumentExists, self.type_manager.insert, doc=test_doc)
self.mock_es.index.assert_called_with(index='freezer', doc_type='base_doc_type', body=test_doc, id=None, version=5)
self.mock_es.index.assert_called_with(index='freezer', doc_type='base_doc_type', body=test_doc, id=None)
@patch('freezer_api.storage.elastic.es_helpers')
def test_delete_raises_StorageEngineError_on_scan_exception(self, mock_helpers):