Merge "Delete invalid codes and Add a unit test for elastic 1.In _validate_opts: The following code is True forever, We will delete it. 2. Add unit test for ca_certs in _validate_opts."
This commit is contained in:
commit
bebf9c341f
|
@ -327,10 +327,6 @@ class ElasticSearchEngine(object):
|
|||
self.init(**self.conf)
|
||||
|
||||
def _validate_opts(self):
|
||||
if not 'hosts' or 'endpoint' in self.conf.keys():
|
||||
raise ValueError("Couldn't find hosts in {0} section".format(
|
||||
self.backend)
|
||||
)
|
||||
if self.conf.get('ca_certs'):
|
||||
if not os.path.isfile(self.conf.get('ca_certs')):
|
||||
raise Exception("File not found: ca_certs file ({0}) not "
|
||||
|
|
|
@ -336,10 +336,6 @@ class ElasticSearchEngineV2(object):
|
|||
self.init(**self.conf)
|
||||
|
||||
def _validate_opts(self):
|
||||
if not 'hosts' or 'endpoint' in self.conf.keys():
|
||||
raise ValueError("Couldn't find hosts in {0} section".format(
|
||||
self.backend)
|
||||
)
|
||||
if self.conf.get('ca_certs'):
|
||||
if not os.path.isfile(self.conf.get('ca_certs')):
|
||||
raise Exception("File not found: ca_certs file ({0}) not "
|
||||
|
|
|
@ -1331,3 +1331,19 @@ class TestElasticSearchEngine_session(unittest.TestCase):
|
|||
session_id=common.fake_session_0['session_id'],
|
||||
doc=common.get_fake_session_0())
|
||||
self.assertEqual(3, res)
|
||||
|
||||
|
||||
class TestElasticSearchEngine(unittest.TestCase):
|
||||
|
||||
@patch('freezer_api.storage.elastic.logging')
|
||||
@patch('freezer_api.storage.elastic.elasticsearch')
|
||||
def setUp(self, mock_elasticsearch, mock_logging):
|
||||
mock_elasticsearch.Elasticsearch.return_value = mock.Mock()
|
||||
kwargs = {'hosts': 'http://elasticservaddr:1997'}
|
||||
self.eng = elastic.ElasticSearchEngine(backend="elasticsearch")
|
||||
self.eng.init(index='freezer', **kwargs)
|
||||
|
||||
def test_raise_validate_opts_when_ca_certs_file_not_exist(self):
|
||||
self.eng.conf.update({'ca_certs': 'invalid_ca_certs_file'})
|
||||
self.assertRaises(Exception,
|
||||
self.eng._validate_opts)
|
||||
|
|
|
@ -1499,3 +1499,23 @@ class TestElasticSearchEngine_session(unittest.TestCase, ElasticSearchDB):
|
|||
session_id=common.fake_session_0['session_id'],
|
||||
doc=common.get_fake_session_0())
|
||||
self.assertEqual(3, res)
|
||||
|
||||
|
||||
class TestElasticSearchEngineV2(unittest.TestCase, ElasticSearchDB):
|
||||
|
||||
@patch('freezer_api.storage.elasticv2.logging')
|
||||
@patch('freezer_api.storage.elasticv2.elasticsearch')
|
||||
def setUp(self, mock_logging, mock_elasticsearch):
|
||||
backend = 'elasticsearch'
|
||||
grp = cfg.OptGroup(backend)
|
||||
CONF.register_group(grp)
|
||||
CONF.register_opts(self._ES_OPTS, group=backend)
|
||||
mock_elasticsearch.Elasticsearch.return_value = mock.Mock()
|
||||
kwargs = {'hosts': 'http://elasticservaddr:1997'}
|
||||
self.eng = elastic.ElasticSearchEngineV2(backend=backend)
|
||||
self.eng.init(index='freezer', **kwargs)
|
||||
|
||||
def test_raise_validate_opts_when_ca_certs_file_not_exist(self):
|
||||
self.eng.conf.update({'ca_certs': 'invalid_ca_certs_file'})
|
||||
self.assertRaises(Exception,
|
||||
self.eng._validate_opts)
|
||||
|
|
Loading…
Reference in New Issue