summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgengchc2 <geng.changcai2@zte.com.cn>2018-12-28 22:07:28 -0800
committergengchc2 <geng.changcai2@zte.com.cn>2018-12-28 22:07:28 -0800
commitdf5cca26bb3a100047da354142a8c97c156578cb (patch)
treed9413aa964f31ab13f20173ebfc613904cfc57a7
parentedb258dbb6bcdb3bdf414ecd26cefa2d9fe55dbc (diff)
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. Change-Id: I25a9a4aaae6fd5677d07d376f66188dc0b92bc3b
Notes
Notes (review): Code-Review+2: gecong <ge.cong@zte.com.cn> Workflow+1: gecong <ge.cong@zte.com.cn> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Sat, 29 Dec 2018 07:27:32 +0000 Reviewed-on: https://review.openstack.org/627763 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/storage/elastic.py4
-rw-r--r--freezer_api/storage/elasticv2.py4
-rw-r--r--freezer_api/tests/unit/test_elastic.py16
-rw-r--r--freezer_api/tests/unit/test_elasticv2.py20
4 files changed, 36 insertions, 8 deletions
diff --git a/freezer_api/storage/elastic.py b/freezer_api/storage/elastic.py
index 574f219..8743f9d 100644
--- a/freezer_api/storage/elastic.py
+++ b/freezer_api/storage/elastic.py
@@ -327,10 +327,6 @@ class ElasticSearchEngine(object):
327 self.init(**self.conf) 327 self.init(**self.conf)
328 328
329 def _validate_opts(self): 329 def _validate_opts(self):
330 if not 'hosts' or 'endpoint' in self.conf.keys():
331 raise ValueError("Couldn't find hosts in {0} section".format(
332 self.backend)
333 )
334 if self.conf.get('ca_certs'): 330 if self.conf.get('ca_certs'):
335 if not os.path.isfile(self.conf.get('ca_certs')): 331 if not os.path.isfile(self.conf.get('ca_certs')):
336 raise Exception("File not found: ca_certs file ({0}) not " 332 raise Exception("File not found: ca_certs file ({0}) not "
diff --git a/freezer_api/storage/elasticv2.py b/freezer_api/storage/elasticv2.py
index ff249fe..b254c89 100644
--- a/freezer_api/storage/elasticv2.py
+++ b/freezer_api/storage/elasticv2.py
@@ -336,10 +336,6 @@ class ElasticSearchEngineV2(object):
336 self.init(**self.conf) 336 self.init(**self.conf)
337 337
338 def _validate_opts(self): 338 def _validate_opts(self):
339 if not 'hosts' or 'endpoint' in self.conf.keys():
340 raise ValueError("Couldn't find hosts in {0} section".format(
341 self.backend)
342 )
343 if self.conf.get('ca_certs'): 339 if self.conf.get('ca_certs'):
344 if not os.path.isfile(self.conf.get('ca_certs')): 340 if not os.path.isfile(self.conf.get('ca_certs')):
345 raise Exception("File not found: ca_certs file ({0}) not " 341 raise Exception("File not found: ca_certs file ({0}) not "
diff --git a/freezer_api/tests/unit/test_elastic.py b/freezer_api/tests/unit/test_elastic.py
index 5c55f90..bdb9073 100644
--- a/freezer_api/tests/unit/test_elastic.py
+++ b/freezer_api/tests/unit/test_elastic.py
@@ -1331,3 +1331,19 @@ class TestElasticSearchEngine_session(unittest.TestCase):
1331 session_id=common.fake_session_0['session_id'], 1331 session_id=common.fake_session_0['session_id'],
1332 doc=common.get_fake_session_0()) 1332 doc=common.get_fake_session_0())
1333 self.assertEqual(3, res) 1333 self.assertEqual(3, res)
1334
1335
1336class TestElasticSearchEngine(unittest.TestCase):
1337
1338 @patch('freezer_api.storage.elastic.logging')
1339 @patch('freezer_api.storage.elastic.elasticsearch')
1340 def setUp(self, mock_elasticsearch, mock_logging):
1341 mock_elasticsearch.Elasticsearch.return_value = mock.Mock()
1342 kwargs = {'hosts': 'http://elasticservaddr:1997'}
1343 self.eng = elastic.ElasticSearchEngine(backend="elasticsearch")
1344 self.eng.init(index='freezer', **kwargs)
1345
1346 def test_raise_validate_opts_when_ca_certs_file_not_exist(self):
1347 self.eng.conf.update({'ca_certs': 'invalid_ca_certs_file'})
1348 self.assertRaises(Exception,
1349 self.eng._validate_opts)
diff --git a/freezer_api/tests/unit/test_elasticv2.py b/freezer_api/tests/unit/test_elasticv2.py
index 4eb896e..aead4ae 100644
--- a/freezer_api/tests/unit/test_elasticv2.py
+++ b/freezer_api/tests/unit/test_elasticv2.py
@@ -1499,3 +1499,23 @@ class TestElasticSearchEngine_session(unittest.TestCase, ElasticSearchDB):
1499 session_id=common.fake_session_0['session_id'], 1499 session_id=common.fake_session_0['session_id'],
1500 doc=common.get_fake_session_0()) 1500 doc=common.get_fake_session_0())
1501 self.assertEqual(3, res) 1501 self.assertEqual(3, res)
1502
1503
1504class TestElasticSearchEngineV2(unittest.TestCase, ElasticSearchDB):
1505
1506 @patch('freezer_api.storage.elasticv2.logging')
1507 @patch('freezer_api.storage.elasticv2.elasticsearch')
1508 def setUp(self, mock_logging, mock_elasticsearch):
1509 backend = 'elasticsearch'
1510 grp = cfg.OptGroup(backend)
1511 CONF.register_group(grp)
1512 CONF.register_opts(self._ES_OPTS, group=backend)
1513 mock_elasticsearch.Elasticsearch.return_value = mock.Mock()
1514 kwargs = {'hosts': 'http://elasticservaddr:1997'}
1515 self.eng = elastic.ElasticSearchEngineV2(backend=backend)
1516 self.eng.init(index='freezer', **kwargs)
1517
1518 def test_raise_validate_opts_when_ca_certs_file_not_exist(self):
1519 self.eng.conf.update({'ca_certs': 'invalid_ca_certs_file'})
1520 self.assertRaises(Exception,
1521 self.eng._validate_opts)