Fixes 'ElastichSearch' typo -> 'ElasticSearch' in freezer-api

Change-Id: Idb8c17032bb231f5cd6a8d4aaafdbd7aa2b2fbac
Closes-Bug: #1600750
This commit is contained in:
Domhnall Walsh 2016-07-11 11:08:03 +01:00
parent 6f8455d632
commit 65cde89ac0
3 changed files with 38 additions and 36 deletions

View File

@ -44,7 +44,7 @@ class NumberOfReplicasException(Exception):
pass
class ElastichsearchEngine(object):
class ElasticSearchEngine(object):
def __init__(self, es_url, es_index, args):
self.es_url = es_url
self.es_index = es_index
@ -362,9 +362,9 @@ def main():
elasticsearch_replicas or
DEFAULT_REPLICAS)
es_manager = ElastichsearchEngine(es_url=elasticsearch_url,
es_index=elasticsearch_index,
args=args)
es_manager = ElasticSearchEngine(es_url=elasticsearch_url,
es_index=elasticsearch_index,
args=args)
if args.verbose:
print(" db url: {0}".format(elasticsearch_url))
print("db index: {0}".format(elasticsearch_index))

View File

@ -74,7 +74,7 @@ def register_elk_opts():
def get_options():
if CONF.storage.ca_certs:
if not os.path.isfile(CONF.storage.ca_certs):
raise Exception('Elasticsearch configuration error: '
raise Exception('ElasticSearch configuration error: '
'CA_certs file not found ({0})'
.format(CONF.storage.ca_certs))
@ -92,7 +92,7 @@ def get_db():
opts = get_options()
db_engine = opts.pop('db')
if db_engine == 'elasticsearch':
logging.debug(_i18n._LI('Elastichsearch config options: %s') % str(opts))
logging.debug(_i18n._LI('ElasticSearch config options: %s') % str(opts))
db = elastic.ElasticSearchEngine(**opts)
else:
raise Exception(_i18n._('Database Engine %s not supported') % db_engine)

View File

@ -16,12 +16,12 @@ limitations under the License.
"""
import os
import unittest
import json
import unittest
from mock import Mock, patch
import requests
from freezer_api.cmd.db_init import (ElastichsearchEngine,
from freezer_api.cmd.db_init import (ElasticSearchEngine,
get_args,
find_config_file,
parse_config_file,
@ -33,7 +33,8 @@ from freezer_api.cmd.db_init import (ElastichsearchEngine,
from freezer_api.common import db_mappings
class TestElasticsearchEngine(unittest.TestCase):
class TestElasticSearchEngine(unittest.TestCase):
def setUp(self):
self.test_mappings = {
@ -50,17 +51,17 @@ class TestElasticsearchEngine(unittest.TestCase):
self.mock_args.select_mapping = ''
self.mock_args.erase = False
self.mock_args.replicas = 0
self.es_manager = ElastichsearchEngine(es_url='http://test:9333',
es_index='freezerindex',
args=self.mock_args)
self.es_manager = ElasticSearchEngine(es_url='http://test:9333',
es_index='freezerindex',
args=self.mock_args)
def test_new(self):
self.assertIsInstance(self.es_manager, ElastichsearchEngine)
self.assertIsInstance(self.es_manager, ElasticSearchEngine)
@patch.object(ElastichsearchEngine, 'check_index_exists')
@patch.object(ElastichsearchEngine, 'mapping_match')
@patch.object(ElastichsearchEngine, 'askput_mapping')
@patch.object(ElastichsearchEngine, 'set_number_of_replicas')
@patch.object(ElasticSearchEngine, 'check_index_exists')
@patch.object(ElasticSearchEngine, 'mapping_match')
@patch.object(ElasticSearchEngine, 'askput_mapping')
@patch.object(ElasticSearchEngine, 'set_number_of_replicas')
def test_put_mappings_does_nothing_when_mappings_match(self,
mock_set_number_of_replicas,
mock_askput_mapping,
@ -69,10 +70,10 @@ class TestElasticsearchEngine(unittest.TestCase):
self.es_manager.put_mappings(self.test_mappings)
self.assertEquals(mock_askput_mapping.call_count, 0)
@patch.object(ElastichsearchEngine, 'check_index_exists')
@patch.object(ElastichsearchEngine, 'mapping_match')
@patch.object(ElastichsearchEngine, 'askput_mapping')
@patch.object(ElastichsearchEngine, 'set_number_of_replicas')
@patch.object(ElasticSearchEngine, 'check_index_exists')
@patch.object(ElasticSearchEngine, 'mapping_match')
@patch.object(ElasticSearchEngine, 'askput_mapping')
@patch.object(ElasticSearchEngine, 'set_number_of_replicas')
def test_put_mappings_calls_askput_when_mappings_match_not(self,
mock_set_number_of_replicas,
mock_askput_mapping,
@ -82,10 +83,10 @@ class TestElasticsearchEngine(unittest.TestCase):
self.es_manager.put_mappings(self.test_mappings)
self.assertEquals(mock_askput_mapping.call_count, 3)
@patch.object(ElastichsearchEngine, 'proceed')
@patch.object(ElastichsearchEngine, 'delete_type')
@patch.object(ElastichsearchEngine, 'put_mapping')
@patch.object(ElastichsearchEngine, 'set_number_of_replicas')
@patch.object(ElasticSearchEngine, 'proceed')
@patch.object(ElasticSearchEngine, 'delete_type')
@patch.object(ElasticSearchEngine, 'put_mapping')
@patch.object(ElasticSearchEngine, 'set_number_of_replicas')
def test_askput_calls_delete_and_put_mappings_when_always_yes_and_erase(self,
mock_set_number_of_replicas,
mock_put_mapping,
@ -103,7 +104,6 @@ class TestElasticsearchEngine(unittest.TestCase):
res = self.es_manager.askput_mapping('jobs', self.test_mappings['jobs'])
self.assertEquals(None, res)
@patch('freezer_api.cmd.db_init.requests')
def test_mapping_match_not_found_returns_false(self, mock_requests):
self.mock_resp.status_code = 404
@ -218,7 +218,6 @@ class TestElasticsearchEngine(unittest.TestCase):
res = self.es_manager.check_index_exists()
self.assertEquals(res, None)
@patch('freezer_api.cmd.db_init.requests')
def test_check_index_raises_Exception_when_return_code_not_in_OK_BADREQ(self, mock_requests):
self.mock_resp.status_code = 500
@ -378,7 +377,7 @@ class TestDbInit(unittest.TestCase):
@patch('freezer_api.cmd.db_init.parse_config_file')
def test_get_db_params_returns_args_parameters(self, mock_parse_config_file):
mock_parse_config_file.return_value = (None, None, None, None )
mock_parse_config_file.return_value = (None, None, None, None)
mock_args = Mock()
mock_args.host = 'pumpkin'
mock_args.port = 12345
@ -387,32 +386,35 @@ class TestDbInit(unittest.TestCase):
self.assertEquals(elasticsearch_url, 'http://pumpkin:12345')
self.assertEquals(elasticsearch_index, 'ciccio')
@patch('freezer_api.cmd.db_init.ElastichsearchEngine')
@patch('freezer_api.cmd.db_init.ElasticSearchEngine')
@patch('freezer_api.cmd.db_init.get_db_params')
@patch('freezer_api.cmd.db_init.get_args')
def test_main_calls_esmanager_put_mappings_with_mappings(self, mock_get_args, mock_get_db_params,
mock_ElastichsearchEngine):
def test_main_calls_esmanager_put_mappings_with_mappings(self,
mock_get_args,
mock_get_db_params,
mock_es_engine):
mock_get_args.return_value = self.mock_args
mock_get_db_params.return_value = 'url', 'index', 0
mock_es_manager = Mock()
mock_es_manager.exit_code = os.EX_OK
mock_ElastichsearchEngine.return_value = mock_es_manager
mock_es_engine.return_value = mock_es_manager
res = main()
self.assertEquals(res, os.EX_OK)
mappings = db_mappings.get_mappings()
mock_es_manager.put_mappings.assert_called_with(mappings)
@patch('freezer_api.cmd.db_init.ElastichsearchEngine')
@patch('freezer_api.cmd.db_init.ElasticSearchEngine')
@patch('freezer_api.cmd.db_init.get_db_params')
@patch('freezer_api.cmd.db_init.get_args')
def test_main_return_EX_DATAERR_exitcode_on_error(self, mock_get_args, mock_get_db_params,
mock_ElastichsearchEngine):
def test_main_return_EX_DATAERR_exitcode_on_error(self, mock_get_args,
mock_get_db_params,
mock_es_engine):
mock_get_args.return_value = self.mock_args
mock_get_db_params.return_value = 'url', 'index', 0
mock_es_manager = Mock()
mock_ElastichsearchEngine.return_value = mock_es_manager
mock_es_engine.return_value = mock_es_manager
mock_es_manager.put_mappings.side_effect = Exception('test error')