make elastic index configurable rather than settled in code 67/23267/1
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Tue, 18 Oct 2016 07:00:01 +0000 (15:00 +0800)
committerSerenaFeng <feng.xiaowei@zte.com.cn>
Tue, 18 Oct 2016 07:00:01 +0000 (15:00 +0800)
JIRA: FUNCTEST-519

Change-Id: I4c97c01492ed47b589b0e8981dcfb431ca0838ae
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
utils/test/dashboard/dashboard/conf/config.py
utils/test/dashboard/dashboard/elastic2kibana/main.py
utils/test/dashboard/dashboard/mongo2elastic/main.py
utils/test/dashboard/etc/config.ini

index 44cf797..6114e90 100644 (file)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
 
+import urlparse
 from ConfigParser import SafeConfigParser, NoOptionError
 
 
@@ -27,6 +28,7 @@ class APIConfig:
         self.es_creds = None
         self.kibana_url = None
         self.js_path = None
+        self.index_url = None
 
     def _get_str_parameter(self, section, param):
         try:
@@ -67,6 +69,8 @@ class APIConfig:
         obj.es_creds = obj._get_str_parameter("elastic", "creds")
         obj.kibana_url = obj._get_str_parameter("kibana", "url")
         obj.js_path = obj._get_str_parameter("kibana", "js_path")
+        index = obj._get_str_parameter("elastic", "index")
+        obj.index_url = urlparse.urljoin(obj.es_url, index)
 
         return obj
 
@@ -74,7 +78,9 @@ class APIConfig:
         return "elastic_url = %s \n" \
                "elastic_creds = %s \n" \
                "kibana_url = %s \n" \
+               "index_url = %s \n" \
                "js_path = %s \n" % (self.es_url,
                                     self.es_creds,
                                     self.kibana_url,
+                                    self.index_url,
                                     self.js_path)
index 5af512e..112d222 100644 (file)
@@ -1,6 +1,5 @@
 #! /usr/bin/env python
 import json
-import urlparse
 
 import argparse
 
@@ -131,10 +130,9 @@ class KibanaConstructor(object):
             }
         })
 
-        elastic_data = elastic_access.get_docs(
-            urlparse.urljoin(CONF.es_url, '/testapi/results'),
-            CONF.es_creds,
-            query)
+        elastic_data = elastic_access.get_docs(CONF.index_url,
+                                               CONF.es_creds,
+                                               query)
 
         pods_and_scenarios = {}
 
index c2a8d11..688f55f 100644 (file)
@@ -5,7 +5,6 @@ import json
 import os
 import subprocess
 import traceback
-import urlparse
 import uuid
 
 import argparse
@@ -188,7 +187,7 @@ class DocumentsPublisher(object):
             self._remove()
             exit(-1)
 
-    def get_existed_docs(self):
+    def get_exists(self):
         if self.days == 0:
             body = '''{{
                         "query": {{
@@ -242,10 +241,6 @@ class DocumentsPublisher(object):
 
 
 def main():
-    base_elastic_url = urlparse.urljoin(CONF.es_url, '/testapi/results')
-    days = args.latest_days
-    es_creds = CONF.es_creds
-
     for project, case_dicts in testcases.testcases_yaml.items():
         for case_dict in case_dicts:
             case = case_dict.get('name')
@@ -253,6 +248,6 @@ def main():
             DocumentsPublisher(project,
                                case,
                                fmt,
-                               days,
-                               base_elastic_url,
-                               es_creds).export().get_existed_docs().publish()
+                               args.latest_days,
+                               CONF.index_url,
+                               CONF.es_creds).export().get_exists().publish()
index d932798..77adc16 100644 (file)
@@ -2,6 +2,7 @@
 # the CONF object in config.ini must be updated
 [elastic]
 url = http://localhost:9200
+index = testapi/results
 creds =
 
 [kibana]