Add python3 support in energy
authorCédric Ollivier <cedric.ollivier@orange.com>
Tue, 12 Dec 2017 04:36:53 +0000 (05:36 +0100)
committerCédric Ollivier <cedric.ollivier@orange.com>
Tue, 12 Dec 2017 04:48:09 +0000 (05:48 +0100)
It also converts Exception to str when expected.
All energy modules are also listed in files rated 10/10 by pylint.

Change-Id: Id382d60eb35f50c98b15423f9559a920ce5dac62
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
functest/energy/energy.py
functest/tests/unit/energy/test_functest_energy.py
tox.ini

index 119942b..2835e05 100644 (file)
 
 import json
 import logging
-import urllib
 
 from functools import wraps
 import requests
+from six.moves import urllib
 
 from functest.utils.constants import CONST
 import functest.utils.functest_utils as ft_utils
@@ -103,7 +103,7 @@ class EnergyRecorder(object):
             assert environment
 
             uri_comp = "/recorders/environment/"
-            uri_comp += urllib.quote_plus(environment)
+            uri_comp += urllib.parse.quote_plus(environment)
 
             # Creds
             creds_usr = ft_utils.get_functest_config(
@@ -130,7 +130,7 @@ class EnergyRecorder(object):
             except Exception as exc:  # pylint: disable=broad-except
                 EnergyRecorder.logger.info(
                     "Energy recorder API is not available, cause=%s",
-                    exc.message)
+                    str(exc))
                 api_available = False
             # Final config
             EnergyRecorder.energy_recorder_api = {
index 9911080..9e19a33 100644 (file)
@@ -266,7 +266,7 @@ class EnergyRecorderTest(unittest.TestCase):
         with self.assertRaises(Exception) as context:
             self.__decorated_method_with_ex()
         self.assertTrue(
-            self.exception_message_to_preserve in context.exception
+            self.exception_message_to_preserve in str(context.exception)
         )
         self.assertTrue(finish_mock.called)
 
diff --git a/tox.ini b/tox.ini
index 328eccd..9d5988a 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -31,8 +31,10 @@ whitelist_externals = bash
 modules =
   functest.api
   functest.core
+  functest.energy
   functest.opnfv_tests.sdn.odl
   functest.tests.unit.core
+  functest.tests.unit.energy
   functest.tests.unit.odl
   functest.tests.unit.utils.test_decorators
   functest.utils.decorators
@@ -56,6 +58,7 @@ commands =
 dirs =
   functest/tests/unit/ci
   functest/tests/unit/core
+  functest/tests/unit/energy
   functest/tests/unit/odl
   functest/tests/unit/utils
 commands = nosetests {[testenv:py35]dirs}