diff options
21 files changed, 115 insertions, 46 deletions
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml index 25be1724..f1efd904 100755 --- a/functest/ci/config_functest.yaml +++ b/functest/ci/config_functest.yaml @@ -30,6 +30,7 @@ general: functest: /home/opnfv/functest functest_test: /home/opnfv/repos/functest/functest/opnfv_tests results: /home/opnfv/functest/results + functest_logging_cfg: /home/opnfv/repos/functest/functest/ci/logging.json functest_conf: /home/opnfv/functest/conf functest_data: /home/opnfv/functest/data dir_vIMS_data: /home/opnfv/functest/data/vIMS/ diff --git a/functest/ci/logging.json b/functest/ci/logging.json new file mode 100644 index 00000000..3f454e8f --- /dev/null +++ b/functest/ci/logging.json @@ -0,0 +1,29 @@ +{
+ "version": 1,
+ "disable_existing_loggers": false,
+ "formatters": {
+ "standard": {
+ "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
+ }
+ },
+ "handlers": {
+ "console": {
+ "level": "INFO",
+ "class": "logging.StreamHandler",
+ "formatter": "standard"
+ },
+ "file": {
+ "level": "DEBUG",
+ "class": "logging.FileHandler",
+ "formatter": "standard",
+ "filename": "/home/opnfv/functest/results/functest.log"
+ }
+ },
+ "loggers": {
+ "": {
+ "handlers": ["console", "file"],
+ "level": "DEBUG",
+ "propagate": "yes"
+ }
+ }
+}
diff --git a/functest/core/pytest_suite_runner.py b/functest/core/pytest_suite_runner.py index 1eed92b5..1eed92b5 100755..100644 --- a/functest/core/pytest_suite_runner.py +++ b/functest/core/pytest_suite_runner.py diff --git a/functest/core/vnf_base.py b/functest/core/vnf_base.py index 99520494..4d019858 100644 --- a/functest/core/vnf_base.py +++ b/functest/core/vnf_base.py @@ -35,6 +35,7 @@ class VnfOnBoardingBase(base.TestcaseBase): self.details['orchestrator'] = {} self.details['vnf'] = {} self.details['test_vnf'] = {} + self.images = {} try: self.tenant_name = CONST.__getattribute__( 'vnf_{}_tenant_name'.format(self.case_name)) @@ -44,7 +45,7 @@ class VnfOnBoardingBase(base.TestcaseBase): raise Exception("Unknown VNF case=" + self.case_name) try: - self.tenant_images = CONST.__getattribute__( + self.images = CONST.__getattribute__( 'vnf_{}_tenant_images'.format(self.case_name)) except: self.logger.warn("No tenant image defined for this VNF") @@ -152,14 +153,15 @@ class VnfOnBoardingBase(base.TestcaseBase): self.logger.info("Update OpenStack creds informations") self.creds.update({ - "username": self.tenant_name, - "password": self.tenant_name, "tenant": self.tenant_name, }) - self.glance_client = os_utils.get_glance_client(self.creds) self.neutron_client = os_utils.get_neutron_client(self.creds) self.nova_client = os_utils.get_nova_client(self.creds) - + self.creds.update({ + "username": self.tenant_name, + "password": self.tenant_name, + }) + self.glance_client = os_utils.get_glance_client(self.creds) self.logger.info("Upload some OS images if it doesn't exist") temp_dir = os.path.join(self.data_dir, "tmp/") diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py index 8285d93f..8285d93f 100755..100644 --- a/functest/opnfv_tests/openstack/vping/vping_base.py +++ b/functest/opnfv_tests/openstack/vping/vping_base.py diff --git a/functest/opnfv_tests/sdn/onos/sfc/sfc_onos.py b/functest/opnfv_tests/sdn/onos/sfc/sfc_onos.py index 349b42a8..090502ba 100644 --- a/functest/opnfv_tests/sdn/onos/sfc/sfc_onos.py +++ b/functest/opnfv_tests/sdn/onos/sfc/sfc_onos.py @@ -232,10 +232,8 @@ class SfcOnos: else: return(response.status_code) - url = ("http://%s:8774//v2.1/%s/ports/" - "%s/flavors?name=m1.tiny" % (self.nova_hostname, - self.tenant_id)) - + url = ("http://%s:8774/v2.1/%s/flavors?" + "name=m1.tiny" % (self.nova_hostname, self.tenant_id)) headers = {"Accept": "application/json", "Content-Type": "application/json", "X-Auth-Token": self.token_id} response = requests.get(url, headers=headers) @@ -344,7 +342,7 @@ class SfcOnos: def getPortPair(self): """Query the Portpair id value.""" for p in range(0, 1): - url = ("http://%s:9696/%s/ports/" + url = ("http://%s:9696/%s/" "sfc/port_pairs?name=PP1" % (self.neutron_hostname, self.osver)) headers = {"Accept": "application/json", diff --git a/functest/opnfv_tests/sdn/onos/teston/onos.py b/functest/opnfv_tests/sdn/onos/teston/onos.py index 213bdb7d..2537e18d 100755 --- a/functest/opnfv_tests/sdn/onos/teston/onos.py +++ b/functest/opnfv_tests/sdn/onos/teston/onos.py @@ -175,7 +175,7 @@ def CreateImage(): def SfcTest(): - cmd = "python " + ONOS_SFC_PATH + "/Sfc.py" + cmd = "python " + ONOS_SFC_PATH + "/sfc.py" logger.debug("Run sfc tests") os.system(cmd) @@ -187,7 +187,7 @@ def GetIp(type): def Replace(before, after): - file = "/Sfc_fun.py" + file = "/sfc_onos.py" cmd = "sed -i 's/" + before + "/" + after + "/g' " + ONOS_SFC_PATH + file os.system(cmd) @@ -199,7 +199,7 @@ def SetSfcConf(): Replace("glance_ip", GetIp("glance")) pwd = ft_constants.OS_PASSWORD Replace("console", pwd) - creds_neutron = openstack_utils.get_credentials("neutron") + creds_neutron = openstack_utils.get_credentials() neutron_client = neutronclient.Client(**creds_neutron) ext_net = openstack_utils.get_external_net(neutron_client) Replace("admin_floating_net", ext_net) diff --git a/functest/opnfv_tests/vnf/aaa/aaa.py b/functest/opnfv_tests/vnf/aaa/aaa.py index 8898b9fc..f1c265f4 100644 --- a/functest/opnfv_tests/vnf/aaa/aaa.py +++ b/functest/opnfv_tests/vnf/aaa/aaa.py @@ -21,8 +21,7 @@ class AaaVnf(vnf_base.VnfOnBoardingBase): logger = ft_logger.Logger("VNF AAA").getLogger() def __init__(self): - super(AaaVnf, self).__init__() - self.case_name = "aaa" + super(AaaVnf, self).__init__(case="aaa") def deploy_orchestrator(self): self.logger.info("No VNFM needed to deploy a free radius here") diff --git a/functest/opnfv_tests/vnf/ims/cloudify_ims.py b/functest/opnfv_tests/vnf/ims/cloudify_ims.py index e584519b..13a5af4f 100644 --- a/functest/opnfv_tests/vnf/ims/cloudify_ims.py +++ b/functest/opnfv_tests/vnf/ims/cloudify_ims.py @@ -25,7 +25,8 @@ from orchestrator_cloudify import Orchestrator class ImsVnf(vnf_base.VnfOnBoardingBase): - def __init__(self, project='functest', case='', repo='', cmd=''): + def __init__(self, project='functest', case='cloudify_ims', + repo='', cmd=''): super(ImsVnf, self).__init__(project, case, repo, cmd) self.logger = ft_logger.Logger("vIMS").getLogger() self.case_dir = os.path.join(CONST.functest_test, 'vnf/ims/') diff --git a/functest/opnfv_tests/vnf/ims/opera_ims.py b/functest/opnfv_tests/vnf/ims/opera_ims.py index fa8f9ec9..073a56c3 100644 --- a/functest/opnfv_tests/vnf/ims/opera_ims.py +++ b/functest/opnfv_tests/vnf/ims/opera_ims.py @@ -21,7 +21,8 @@ from functest.utils.constants import CONST class ImsVnf(vnf_base.VnfOnBoardingBase): - def __init__(self, project='functest', case='', repo='', cmd=''): + def __init__(self, project='functest', case='opera_ims', + repo='', cmd=''): super(ImsVnf, self).__init__(project, case, repo, cmd) self.logger = ft_logger.Logger("vIMS").getLogger() self.case_dir = os.path.join(CONST.functest_test, 'vnf/ims/') diff --git a/functest/opnfv_tests/vnf/ims/orchestra_ims.py b/functest/opnfv_tests/vnf/ims/orchestra_ims.py index ebd6c9ba..28f37f05 100644 --- a/functest/opnfv_tests/vnf/ims/orchestra_ims.py +++ b/functest/opnfv_tests/vnf/ims/orchestra_ims.py @@ -21,7 +21,8 @@ from functest.utils.constants import CONST class ImsVnf(vnf_base.VnfOnBoardingBase): - def __init__(self, project='functest', case='', repo='', cmd=''): + def __init__(self, project='functest', case='orchestra_ims', + repo='', cmd=''): super(ImsVnf, self).__init__(project, case, repo, cmd) self.logger = ft_logger.Logger("vIMS").getLogger() self.case_dir = os.path.join(CONST.functest_test, 'vnf/ims/') diff --git a/functest/tests/unit/cli/commands/test_cli_env.py b/functest/tests/unit/cli/commands/test_cli_env.py index f70761dc..4b6ea57a 100644 --- a/functest/tests/unit/cli/commands/test_cli_env.py +++ b/functest/tests/unit/cli/commands/test_cli_env.py @@ -11,7 +11,6 @@ import unittest from git.exc import NoSuchPathError import mock -mock.patch('logging.FileHandler').start() # noqa from functest.cli.commands import cli_env from functest.utils.constants import CONST from functest.tests.unit import test_utils diff --git a/functest/tests/unit/core/test_testcase_base.py b/functest/tests/unit/core/test_testcase_base.py index 8df524b0..94d2e966 100644..100755 --- a/functest/tests/unit/core/test_testcase_base.py +++ b/functest/tests/unit/core/test_testcase_base.py @@ -12,8 +12,6 @@ import mock import os import unittest -mock.patch('logging.FileHandler').start() # noqa - from functest.core import testcase_base diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py index 59ab2c65..568fdc82 100644 --- a/functest/tests/unit/odl/test_odl.py +++ b/functest/tests/unit/odl/test_odl.py @@ -19,7 +19,6 @@ from robot.errors import DataError, RobotError from robot.result import testcase from robot.utils.robottime import timestamp_to_secs -mock.patch('logging.FileHandler').start() # noqa from functest.core import testcase_base from functest.opnfv_tests.sdn.odl import odl diff --git a/functest/tests/unit/test_logging.ini b/functest/tests/unit/test_logging.ini new file mode 100644 index 00000000..3d5b947c --- /dev/null +++ b/functest/tests/unit/test_logging.ini @@ -0,0 +1,27 @@ +[loggers]
+keys=root,functest_logger
+
+[logger_root]
+level=DEBUG
+handlers=console
+
+[logger_functest_logger]
+level=DEBUG
+handlers=console
+qualname=functest.utils.functest_logger
+propagate=0
+
+[handlers]
+keys=console
+
+[handler_console]
+class=StreamHandler
+level=INFO
+formatter=standard
+args=(sys.stdout,)
+
+[formatters]
+keys=standard
+
+[formatter_standard]
+format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
\ No newline at end of file diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py index c4b56660..ce9086a7 100644 --- a/functest/tests/unit/utils/test_functest_utils.py +++ b/functest/tests/unit/utils/test_functest_utils.py @@ -18,7 +18,6 @@ import mock import requests from functest.tests.unit import test_utils -mock.patch('logging.FileHandler').start() # noqa from functest.utils import functest_utils diff --git a/functest/utils/functest_logger.py b/functest/utils/functest_logger.py index c0fba082..f09f56be 100644..100755 --- a/functest/utils/functest_logger.py +++ b/functest/utils/functest_logger.py @@ -20,36 +20,50 @@ # logger = fl.Logger("script_name").getLogger() # logger.info("message to be shown with - INFO - ") # logger.debug("message to be shown with - DEBUG -") - import logging +import logging.config import os +import json -class Logger: - def __init__(self, logger_name): +from functest.utils.constants import CONST + +logger = logging.getLogger(__name__) + + +def is_debug(): + if CONST.CI_DEBUG and CONST.CI_DEBUG.lower() == "true": + return True + return False - CI_DEBUG = os.getenv('CI_DEBUG') +def setup_logging(default_path=CONST.dir_functest_logging_cfg, + default_level=logging.INFO, + env_key='LOG_CFG'): + path = default_path + value = os.getenv(env_key, None) + if value: + path = value + if os.path.exists(path): + with open(path, 'rt') as f: + config = json.load(f) + if (config['handlers'] and + config['handlers']['console']): + stream_level = logging.INFO + if is_debug(): + stream_level = logging.DEBUG + config['handlers']['console']['level'] = stream_level + logging.config.dictConfig(config) + else: + logging.basicConfig(level=default_level) + + +setup_logging() + + +class Logger: + def __init__(self, logger_name): self.logger = logging.getLogger(logger_name) - self.logger.propagate = 0 - self.logger.setLevel(logging.DEBUG) - - ch = logging.StreamHandler() - formatter = logging.Formatter('%(asctime)s - %(name)s - ' - '%(levelname)s - %(message)s') - ch.setFormatter(formatter) - if CI_DEBUG is not None and CI_DEBUG.lower() == "true": - ch.setLevel(logging.DEBUG) - self.logger.parent.level = logging.DEBUG - else: - ch.setLevel(logging.INFO) - self.logger.parent.level = logging.INFO - self.logger.addHandler(ch) - - hdlr = logging.FileHandler('/home/opnfv/functest/results/functest.log') - hdlr.setFormatter(formatter) - hdlr.setLevel(logging.DEBUG) - self.logger.addHandler(hdlr) def getLogger(self): return self.logger diff --git a/functest/utils/openstack_tacker.py b/functest/utils/openstack_tacker.py index f17b421e..f17b421e 100755..100644 --- a/functest/utils/openstack_tacker.py +++ b/functest/utils/openstack_tacker.py diff --git a/requirements.txt b/requirements.txt index 28b3fed3..28b3fed3 100755..100644 --- a/requirements.txt +++ b/requirements.txt diff --git a/run_unit_tests.sh b/run_unit_tests.sh index 79d05d3d..5167d78c 100755 --- a/run_unit_tests.sh +++ b/run_unit_tests.sh @@ -38,6 +38,7 @@ nosetests --with-xunit \ --cover-package=functest.utils \ --cover-xml \ --cover-html \ + --log-config=$(pwd)/functest/tests/unit/test_logging.ini \ functest/tests/unit rc=$? diff --git a/test-requirements.txt b/test-requirements.txt index 2bf297ba..2bf297ba 100755..100644 --- a/test-requirements.txt +++ b/test-requirements.txt |