Export the Pylint results via pylint.out
[functest.git] / functest / utils / functest_utils.py
index 7d993cb..dc20eea 100644 (file)
@@ -9,24 +9,25 @@
 #
 import functools
 import json
+import logging
 import os
 import re
 import shutil
 import subprocess
 import sys
 import time
-import urllib2
 from datetime import datetime as dt
 
 import dns.resolver
 import requests
+from six.moves import urllib
 import yaml
 from git import Repo
 
+from functest.utils import constants
 from functest.utils import decorators
-import functest.utils.functest_logger as ft_logger
 
-logger = ft_logger.Logger("functest_utils").getLogger()
+logger = logging.getLogger(__name__)
 
 
 # ----------------------------------------------------------
@@ -39,9 +40,9 @@ def check_internet_connectivity(url='http://www.opnfv.org/'):
     Check if there is access to the internet
     """
     try:
-        urllib2.urlopen(url, timeout=5)
+        urllib.request.urlopen(url, timeout=5)
         return True
-    except urllib2.URLError:
+    except urllib.error.URLError:
         return False
 
 
@@ -52,8 +53,8 @@ def download_url(url, dest_path):
     name = url.rsplit('/')[-1]
     dest = dest_path + "/" + name
     try:
-        response = urllib2.urlopen(url)
-    except (urllib2.HTTPError, urllib2.URLError):
+        response = urllib.request.urlopen(url)
+    except (urllib.error.HTTPError, urllib.error.URLError):
         return False
 
     with open(dest, 'wb') as f:
@@ -220,7 +221,8 @@ def push_results_to_db(project, case_name,
     error = None
     headers = {'Content-Type': 'application/json'}
     try:
-        r = requests.post(url, data=json.dumps(params), headers=headers)
+        r = requests.post(url, data=json.dumps(params, sort_keys=True),
+                          headers=headers)
         logger.debug(r)
         r.raise_for_status()
     except requests.RequestException as exc:
@@ -318,7 +320,7 @@ def execute_command(cmd, info=False, error_msg="",
             f.write(line)
         else:
             line = line.replace('\n', '')
-            print line
+            print(line)
             sys.stdout.flush()
     if output_file:
         f.close()
@@ -375,20 +377,10 @@ def get_parameter_from_yaml(parameter, file):
 
 
 def get_functest_config(parameter):
-    yaml_ = os.environ["CONFIG_FUNCTEST_YAML"]
+    yaml_ = constants.CONST.__getattribute__('CONFIG_FUNCTEST_YAML')
     return get_parameter_from_yaml(parameter, yaml_)
 
 
-def check_success_rate(case_name, result):
-    # It should be removed as TestCase tests criteria
-    # and result.
-    logger.warning('check_success_rate will be removed soon')
-    criteria = get_criteria_by_test(case_name)
-    if type(criteria) == int and result >= criteria:
-        return 'PASS'
-    return 'FAIL'
-
-
 def merge_dicts(dict1, dict2):
     for k in set(dict1.keys()).union(dict2.keys()):
         if k in dict1 and k in dict2:
@@ -407,7 +399,7 @@ def get_testcases_file_dir():
 
 
 def get_functest_yaml():
-    with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
+    with open(constants.CONST.__getattribute__('CONFIG_FUNCTEST_YAML')) as f:
         functest_yaml = yaml.safe_load(f)
     f.close()
     return functest_yaml