aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Lausuch <jose.lausuch@ericsson.com>2017-05-05 07:51:35 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-05-05 07:51:35 +0000
commite9b9d37c1c8268c9cde8db48458e39bce1f5b133 (patch)
tree685694273ab372360642ed5fcfd91148dcc06b13
parent533e08503e5888adb7a7cfa8b112502385130a8f (diff)
parent3154346cfd22a3d500dc2fd01495e181308d12d6 (diff)
Merge "Define loggers as class-private members"
-rw-r--r--functest/core/feature.py14
-rw-r--r--functest/core/testcase.py15
-rw-r--r--functest/core/vnf_base.py39
-rw-r--r--functest/opnfv_tests/features/barometer.py6
-rwxr-xr-xfunctest/opnfv_tests/sdn/odl/odl.py30
5 files changed, 56 insertions, 48 deletions
diff --git a/functest/core/feature.py b/functest/core/feature.py
index 992de98a..ed9efc70 100644
--- a/functest/core/feature.py
+++ b/functest/core/feature.py
@@ -27,7 +27,7 @@ __author__ = ("Serena Feng <feng.xiaowei@zte.com.cn>, "
class Feature(base.TestCase):
"""Base model for single feature."""
- logger = logging.getLogger(__name__)
+ __logger = logging.getLogger(__name__)
def __init__(self, **kwargs):
super(Feature, self).__init__(**kwargs)
@@ -83,10 +83,10 @@ class Feature(base.TestCase):
ft_utils.logger_test_results(
self.project_name, self.case_name,
self.result, self.details)
- self.logger.info("%s %s", self.project_name, self.result)
+ self.__logger.info("%s %s", self.project_name, self.result)
except Exception: # pylint: disable=broad-except
- self.logger.exception("%s FAILED", self.project_name)
- self.logger.info("Test result is stored in '%s'", self.result_file)
+ self.__logger.exception("%s FAILED", self.project_name)
+ self.__logger.info("Test result is stored in '%s'", self.result_file)
self.stop_time = time.time()
return exit_code
@@ -94,6 +94,8 @@ class Feature(base.TestCase):
class BashFeature(Feature):
"""Class designed to run any bash command."""
+ __logger = logging.getLogger(__name__)
+
def execute(self, **kwargs):
"""Execute the cmd passed as arg
@@ -109,7 +111,7 @@ class BashFeature(Feature):
cmd = kwargs["cmd"]
ret = ft_utils.execute_command(cmd, output_file=self.result_file)
except KeyError:
- self.logger.error("Please give cmd as arg. kwargs: %s", kwargs)
+ self.__logger.error("Please give cmd as arg. kwargs: %s", kwargs)
except Exception: # pylint: disable=broad-except
- self.logger.exception("Execute cmd: %s failed", cmd)
+ self.__logger.exception("Execute cmd: %s failed", cmd)
return ret
diff --git a/functest/core/testcase.py b/functest/core/testcase.py
index 0b87f265..217f07e5 100644
--- a/functest/core/testcase.py
+++ b/functest/core/testcase.py
@@ -32,7 +32,7 @@ class TestCase(object):
EX_TESTCASE_FAILED = os.EX_SOFTWARE - 2
"""results are false"""
- logger = logging.getLogger(__name__)
+ __logger = logging.getLogger(__name__)
def __init__(self, **kwargs):
self.details = {}
@@ -65,12 +65,12 @@ class TestCase(object):
# It must be removed as soon as TestCase subclasses
# stop setting result = 'PASS' or 'FAIL'.
# In this case criteria is unread.
- self.logger.warning(
+ self.__logger.warning(
"Please update result which must be an int!")
if self.result == 'PASS':
return TestCase.EX_OK
except AssertionError:
- self.logger.error("Please run test before checking the results")
+ self.__logger.error("Please run test before checking the results")
return TestCase.EX_TESTCASE_FAILED
def run(self, **kwargs):
@@ -96,7 +96,7 @@ class TestCase(object):
TestCase.EX_RUN_ERROR.
"""
# pylint: disable=unused-argument
- self.logger.error("Run must be implemented")
+ self.__logger.error("Run must be implemented")
return TestCase.EX_RUN_ERROR
def push_to_db(self):
@@ -128,11 +128,12 @@ class TestCase(object):
if ft_utils.push_results_to_db(
self.project_name, self.case_name, self.start_time,
self.stop_time, pub_result, self.details):
- self.logger.info("The results were successfully pushed to DB")
+ self.__logger.info(
+ "The results were successfully pushed to DB")
return TestCase.EX_OK
else:
- self.logger.error("The results cannot be pushed to DB")
+ self.__logger.error("The results cannot be pushed to DB")
return TestCase.EX_PUSH_TO_DB_ERROR
except Exception: # pylint: disable=broad-except
- self.logger.exception("The results cannot be pushed to DB")
+ self.__logger.exception("The results cannot be pushed to DB")
return TestCase.EX_PUSH_TO_DB_ERROR
diff --git a/functest/core/vnf_base.py b/functest/core/vnf_base.py
index d91a608b..90bc80b3 100644
--- a/functest/core/vnf_base.py
+++ b/functest/core/vnf_base.py
@@ -19,7 +19,7 @@ import functest.utils.openstack_utils as os_utils
class VnfOnBoardingBase(base.TestCase):
- logger = logging.getLogger(__name__)
+ __logger = logging.getLogger(__name__)
def __init__(self, **kwargs):
super(VnfOnBoardingBase, self).__init__(**kwargs)
@@ -44,28 +44,28 @@ class VnfOnBoardingBase(base.TestCase):
'vnf_{}_tenant_description'.format(self.case_name))
except Exception:
# raise Exception("Unknown VNF case=" + self.case_name)
- self.logger.error("Unknown VNF case={}".format(self.case_name))
+ self.__logger.error("Unknown VNF case={}".format(self.case_name))
try:
self.images = CONST.__getattribute__(
'vnf_{}_tenant_images'.format(self.case_name))
except Exception:
- self.logger.warn("No tenant image defined for this VNF")
+ self.__logger.warn("No tenant image defined for this VNF")
def execute(self):
self.start_time = time.time()
# Prepare the test (Create Tenant, User, ...)
try:
- self.logger.info("Create VNF Onboarding environment")
+ self.__logger.info("Create VNF Onboarding environment")
self.prepare()
except Exception:
- self.logger.error("Error during VNF Onboarding environment" +
- "creation", exc_info=True)
+ self.__logger.error("Error during VNF Onboarding environment"
+ "creation", exc_info=True)
return base.TestCase.EX_TESTCASE_FAILED
# Deploy orchestrator
try:
- self.logger.info("Deploy orchestrator (if necessary)")
+ self.__logger.info("Deploy orchestrator (if necessary)")
orchestrator_ready_time = time.time()
res_orchestrator = self.deploy_orchestrator()
# orchestrator is not mandatory
@@ -77,11 +77,11 @@ class VnfOnBoardingBase(base.TestCase):
self.details['orchestrator']['duration'] = round(
orchestrator_ready_time - self.start_time, 1)
except Exception:
- self.logger.warn("Problem with the Orchestrator", exc_info=True)
+ self.__logger.warn("Problem with the Orchestrator", exc_info=True)
# Deploy VNF
try:
- self.logger.info("Deploy VNF " + self.case_name)
+ self.__logger.info("Deploy VNF " + self.case_name)
res_deploy_vnf = self.deploy_vnf()
vnf_ready_time = time.time()
self.details['vnf']['status'] = res_deploy_vnf['status']
@@ -89,12 +89,12 @@ class VnfOnBoardingBase(base.TestCase):
self.details['vnf']['duration'] = round(
vnf_ready_time - orchestrator_ready_time, 1)
except Exception:
- self.logger.error("Error during VNF deployment", exc_info=True)
+ self.__logger.error("Error during VNF deployment", exc_info=True)
return base.TestCase.EX_TESTCASE_FAILED
# Test VNF
try:
- self.logger.info("Test VNF")
+ self.__logger.info("Test VNF")
res_test_vnf = self.test_vnf()
test_vnf_done_time = time.time()
self.details['test_vnf']['status'] = res_test_vnf['status']
@@ -102,7 +102,7 @@ class VnfOnBoardingBase(base.TestCase):
self.details['test_vnf']['duration'] = round(
test_vnf_done_time - vnf_ready_time, 1)
except Exception:
- self.logger.error("Error when running VNF tests", exc_info=True)
+ self.__logger.error("Error when running VNF tests", exc_info=True)
return base.TestCase.EX_TESTCASE_FAILED
# Clean the system
@@ -121,7 +121,8 @@ class VnfOnBoardingBase(base.TestCase):
self.creds = os_utils.get_credentials()
self.keystone_client = os_utils.get_keystone_client()
- self.logger.info("Prepare OpenStack plateform(create tenant and user)")
+ self.__logger.info(
+ "Prepare OpenStack plateform(create tenant and user)")
admin_user_id = os_utils.get_user_id(self.keystone_client,
self.creds['username'])
if not admin_user_id:
@@ -164,7 +165,7 @@ class VnfOnBoardingBase(base.TestCase):
os_utils.add_role_user(self.keystone_client, user_id,
role_id, tenant_id)
- self.logger.info("Update OpenStack creds informations")
+ self.__logger.info("Update OpenStack creds informations")
self.admin_creds = self.creds.copy()
self.admin_creds.update({
"tenant": self.tenant_name
@@ -183,21 +184,21 @@ class VnfOnBoardingBase(base.TestCase):
# TODO see how to use built-in exception from releng module
def deploy_vnf(self):
- self.logger.error("VNF must be deployed")
+ self.__logger.error("VNF must be deployed")
raise Exception("VNF not deployed")
def test_vnf(self):
- self.logger.error("VNF must be tested")
+ self.__logger.error("VNF must be tested")
raise Exception("VNF not tested")
# clean before openstack clean run
def clean(self):
- self.logger.info("test cleaning")
+ self.__logger.info("test cleaning")
def parse_results(self):
exit_code = self.EX_OK
self.result = "PASS"
- self.logger.info(self.details)
+ self.__logger.info(self.details)
# The 2 VNF steps must be OK to get a PASS result
if (self.details['vnf']['status'] is not "PASS" or
self.details['test_vnf']['status'] is not "PASS"):
@@ -213,7 +214,7 @@ class VnfOnBoardingBase(base.TestCase):
def step_failure(self, error_msg):
part = inspect.stack()[1][3]
- self.logger.error("Step {0} failed: {1}".format(part, error_msg))
+ self.__logger.error("Step {0} failed: {1}".format(part, error_msg))
try:
step_name = self.details_step_mapping[part]
part_info = self.details[step_name]
diff --git a/functest/opnfv_tests/features/barometer.py b/functest/opnfv_tests/features/barometer.py
index 8a409406..cbfe7d9a 100644
--- a/functest/opnfv_tests/features/barometer.py
+++ b/functest/opnfv_tests/features/barometer.py
@@ -6,6 +6,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+import logging
+
from baro_tests import collectd
import functest.core.feature as base
@@ -16,5 +18,7 @@ class BarometerCollectd(base.Feature):
Class for executing barometercollectd testcase.
'''
+ __logger = logging.getLogger(__name__)
+
def execute(self):
- return collectd.main(self.logger)
+ return collectd.main(self.__logger)
diff --git a/functest/opnfv_tests/sdn/odl/odl.py b/functest/opnfv_tests/sdn/odl/odl.py
index 00745d07..f92cb95d 100755
--- a/functest/opnfv_tests/sdn/odl/odl.py
+++ b/functest/opnfv_tests/sdn/odl/odl.py
@@ -70,7 +70,7 @@ class ODLTests(testcase.TestCase):
"csit/suites/integration/basic")
default_suites = [basic_suite_dir, neutron_suite_dir]
res_dir = '/home/opnfv/functest/results/odl/'
- logger = logging.getLogger(__name__)
+ __logger = logging.getLogger(__name__)
@classmethod
def set_robotframework_vars(cls, odlusername="admin", odlpassword="admin"):
@@ -91,7 +91,7 @@ class ODLTests(testcase.TestCase):
line.rstrip())
return True
except Exception as ex: # pylint: disable=broad-except
- cls.logger.error("Cannot set ODL creds: %s", str(ex))
+ cls.__logger.error("Cannot set ODL creds: %s", str(ex))
return False
def parse_results(self):
@@ -154,15 +154,15 @@ class ODLTests(testcase.TestCase):
'PORT:' + kwargs['odlwebport'],
'RESTCONFPORT:' + kwargs['odlrestconfport']]
except KeyError as ex:
- self.logger.error("Cannot run ODL testcases. Please check "
- "%s", str(ex))
+ self.__logger.error("Cannot run ODL testcases. Please check "
+ "%s", str(ex))
return self.EX_RUN_ERROR
if self.set_robotframework_vars(odlusername, odlpassword):
try:
os.makedirs(self.res_dir)
except OSError as ex:
if ex.errno != errno.EEXIST:
- self.logger.exception(
+ self.__logger.exception(
"Cannot create %s", self.res_dir)
return self.EX_RUN_ERROR
stdout_file = os.path.join(self.res_dir, 'stdout.txt')
@@ -174,19 +174,19 @@ class ODLTests(testcase.TestCase):
report='NONE',
stdout=stdout)
stdout.seek(0, 0)
- self.logger.info("\n" + stdout.read())
- self.logger.info("ODL results were successfully generated")
+ self.__logger.info("\n" + stdout.read())
+ self.__logger.info("ODL results were successfully generated")
try:
self.parse_results()
- self.logger.info("ODL results were successfully parsed")
+ self.__logger.info("ODL results were successfully parsed")
except RobotError as ex:
- self.logger.error("Run tests before publishing: %s",
- ex.message)
+ self.__logger.error("Run tests before publishing: %s",
+ ex.message)
return self.EX_RUN_ERROR
try:
os.remove(stdout_file)
except OSError:
- self.logger.warning("Cannot remove %s", stdout_file)
+ self.__logger.warning("Cannot remove %s", stdout_file)
return self.EX_OK
else:
return self.EX_RUN_ERROR
@@ -237,12 +237,12 @@ class ODLTests(testcase.TestCase):
else:
kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP']
except KeyError as ex:
- self.logger.error("Cannot run ODL testcases. "
- "Please check env var: "
- "%s", str(ex))
+ self.__logger.error("Cannot run ODL testcases. "
+ "Please check env var: "
+ "%s", str(ex))
return self.EX_RUN_ERROR
except Exception: # pylint: disable=broad-except
- self.logger.exception("Cannot run ODL testcases.")
+ self.__logger.exception("Cannot run ODL testcases.")
return self.EX_RUN_ERROR
return self.main(suites, **kwargs)