summaryrefslogtreecommitdiffstats
path: root/sdnvpn/lib
diff options
context:
space:
mode:
authorPeriyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>2018-04-16 15:09:16 +0200
committerPeriyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>2018-04-19 13:45:27 +0200
commit303268d0464127c52f11443404fb1baae03d615f (patch)
treeb73d71f5bf6862b332b92af65a19bcd6fd6a9943 /sdnvpn/lib
parentfdabb0a5e92200c09e1476be01bf4353b0823e63 (diff)
Make sdnvpn logging proper
* Currently no log messages are getting written into log file due to file handler is registered for logger object created at different modules. Now corresponding handler is registered for logger objects. * Making sdnvpn Feature class to use its parent class logger object to avoid unnecessary logger object creation. Change-Id: I4ec61951ba4ac39cecc137dbb818da72f0b43b35 Signed-off-by: Periyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
Diffstat (limited to 'sdnvpn/lib')
-rw-r--r--sdnvpn/lib/config.py4
-rw-r--r--sdnvpn/lib/logutil.py23
-rw-r--r--sdnvpn/lib/openstack_utils.py5
-rw-r--r--sdnvpn/lib/quagga.py4
-rw-r--r--sdnvpn/lib/results.py4
-rw-r--r--sdnvpn/lib/utils.py58
6 files changed, 61 insertions, 37 deletions
diff --git a/sdnvpn/lib/config.py b/sdnvpn/lib/config.py
index ebb5520..e63574b 100644
--- a/sdnvpn/lib/config.py
+++ b/sdnvpn/lib/config.py
@@ -8,13 +8,13 @@
# http://www.apache.org/licenses/LICENSE-2.0
import yaml
-import logging
import pkg_resources
from functest.utils import config
import functest.utils.functest_utils as ft_utils
+from sdnvpn.lib import logutil
-logger = logging.getLogger('sdnvpn_test_config')
+logger = logutil.getLogger('sdnvpn_test_config')
class CommonConfig(object):
diff --git a/sdnvpn/lib/logutil.py b/sdnvpn/lib/logutil.py
new file mode 100644
index 0000000..3710ca1
--- /dev/null
+++ b/sdnvpn/lib/logutil.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2018 All rights reserved
+# This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+import logging
+import os.path
+
+from xtesting.core import feature
+
+
+def getLogger(module_name):
+ logger = logging.getLogger(module_name)
+ log_file = "{}/{}.log".format("/var/lib/xtesting/results", "bgpvpn")
+ if os.path.exists(log_file):
+ feature.Feature.configure_logger(logger, log_file)
+ else:
+ logger.setLevel(logging.DEBUG)
+ return logger
diff --git a/sdnvpn/lib/openstack_utils.py b/sdnvpn/lib/openstack_utils.py
index 8089137..990fa7c 100644
--- a/sdnvpn/lib/openstack_utils.py
+++ b/sdnvpn/lib/openstack_utils.py
@@ -8,7 +8,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
-import logging
import os.path
import shutil
import sys
@@ -24,10 +23,10 @@ from novaclient import client as novaclient
from keystoneclient import client as keystoneclient
from neutronclient.neutron import client as neutronclient
-from functest.utils import config
from functest.utils import env
+from sdnvpn.lib import logutil
-logger = logging.getLogger(__name__)
+logger = logutil.getLogger(__name__)
DEFAULT_API_VERSION = '2'
DEFAULT_HEAT_API_VERSION = '1'
diff --git a/sdnvpn/lib/quagga.py b/sdnvpn/lib/quagga.py
index e072f1c..27bf122 100644
--- a/sdnvpn/lib/quagga.py
+++ b/sdnvpn/lib/quagga.py
@@ -9,15 +9,15 @@
#
"""Utilities for setting up quagga peering"""
-import logging
import re
import time
import functest.utils.functest_utils as ft_utils
import sdnvpn.lib.config as config
from sdnvpn.lib.utils import run_odl_cmd, exec_cmd
+from sdnvpn.lib import logutil
-logger = logging.getLogger('sdnvpn-quagga')
+logger = logutil.getLogger('sdnvpn-quagga')
COMMON_CONFIG = config.CommonConfig()
diff --git a/sdnvpn/lib/results.py b/sdnvpn/lib/results.py
index e1a5e5a..42d1865 100644
--- a/sdnvpn/lib/results.py
+++ b/sdnvpn/lib/results.py
@@ -7,12 +7,12 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
#
-import logging
import time
import functest.utils.functest_utils as ft_utils
+from sdnvpn.lib import logutil
-logger = logging.getLogger('sdnvpn-results')
+logger = logutil.getLogger('sdnvpn-results')
class Results(object):
diff --git a/sdnvpn/lib/utils.py b/sdnvpn/lib/utils.py
index ad8215c..aafd69b 100644
--- a/sdnvpn/lib/utils.py
+++ b/sdnvpn/lib/utils.py
@@ -7,7 +7,6 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
#
-import logging
import os
import time
import requests
@@ -19,8 +18,9 @@ from opnfv.deployment.factory import Factory as DeploymentFactory
from sdnvpn.lib import config as sdnvpn_config
import sdnvpn.lib.openstack_utils as os_utils
+from sdnvpn.lib import logutil
-logger = logging.getLogger('sdnvpn_test_utils')
+logger = logutil.getLogger('sdnvpn_test_utils')
common_config = sdnvpn_config.CommonConfig()
@@ -34,6 +34,7 @@ class ExtraRoute(object):
"""
Class to represent extra route for a router
"""
+
def __init__(self, destination, nexthop):
self.destination = destination
self.nexthop = nexthop
@@ -43,6 +44,7 @@ class AllowedAddressPair(object):
"""
Class to represent allowed address pair for a neutron port
"""
+
def __init__(self, ipaddress, macaddress):
self.ipaddress = ipaddress
self.macaddress = macaddress
@@ -638,9 +640,9 @@ def cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces,
if len(floatingip_ids) != 0:
for floatingip_id in floatingip_ids:
if not os_utils.delete_floating_ip(neutron_client, floatingip_id):
- logging.error('Fail to delete all floating ips. '
- 'Floating ip with id {} was not deleted.'.
- format(floatingip_id))
+ logger.error('Fail to delete all floating ips. '
+ 'Floating ip with id {} was not deleted.'.
+ format(floatingip_id))
return False
if len(bgpvpn_ids) != 0:
@@ -651,39 +653,39 @@ def cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces,
for router_id, subnet_id in interfaces:
if not os_utils.remove_interface_router(neutron_client,
router_id, subnet_id):
- logging.error('Fail to delete all interface routers. '
- 'Interface router with id {} was not deleted.'.
- format(router_id))
+ logger.error('Fail to delete all interface routers. '
+ 'Interface router with id {} was not deleted.'.
+ format(router_id))
if len(router_ids) != 0:
for router_id in router_ids:
if not os_utils.remove_gateway_router(neutron_client, router_id):
- logging.error('Fail to delete all gateway routers. '
- 'Gateway router with id {} was not deleted.'.
- format(router_id))
+ logger.error('Fail to delete all gateway routers. '
+ 'Gateway router with id {} was not deleted.'.
+ format(router_id))
if len(subnet_ids) != 0:
for subnet_id in subnet_ids:
if not os_utils.delete_neutron_subnet(neutron_client, subnet_id):
- logging.error('Fail to delete all subnets. '
- 'Subnet with id {} was not deleted.'.
- format(subnet_id))
+ logger.error('Fail to delete all subnets. '
+ 'Subnet with id {} was not deleted.'.
+ format(subnet_id))
return False
if len(router_ids) != 0:
for router_id in router_ids:
if not os_utils.delete_neutron_router(neutron_client, router_id):
- logging.error('Fail to delete all routers. '
- 'Router with id {} was not deleted.'.
- format(router_id))
+ logger.error('Fail to delete all routers. '
+ 'Router with id {} was not deleted.'.
+ format(router_id))
return False
if len(network_ids) != 0:
for network_id in network_ids:
if not os_utils.delete_neutron_net(neutron_client, network_id):
- logging.error('Fail to delete all networks. '
- 'Network with id {} was not deleted.'.
- format(network_id))
+ logger.error('Fail to delete all networks. '
+ 'Network with id {} was not deleted.'.
+ format(network_id))
return False
return True
@@ -695,9 +697,9 @@ def cleanup_nova(nova_client, instance_ids, flavor_ids=None):
if len(instance_ids) != 0:
for instance_id in instance_ids:
if not os_utils.delete_instance(nova_client, instance_id):
- logging.error('Fail to delete all instances. '
- 'Instance with id {} was not deleted.'.
- format(instance_id))
+ logger.error('Fail to delete all instances. '
+ 'Instance with id {} was not deleted.'.
+ format(instance_id))
return False
return True
@@ -706,9 +708,9 @@ def cleanup_glance(glance_client, image_ids):
if len(image_ids) != 0:
for image_id in image_ids:
if not os_utils.delete_glance_image(glance_client, image_id):
- logging.error('Fail to delete all images. '
- 'Image with id {} was not deleted.'.
- format(image_id))
+ logger.error('Fail to delete all images. '
+ 'Image with id {} was not deleted.'.
+ format(image_id))
return False
return True
@@ -779,8 +781,8 @@ def is_fail_mode_secure():
is_secure[openstack_node.name] = True
else:
# failure
- logging.error('The fail_mode for br-int was not secure '
- 'in {} node'.format(openstack_node.name))
+ logger.error('The fail_mode for br-int was not secure '
+ 'in {} node'.format(openstack_node.name))
is_secure[openstack_node.name] = False
return is_secure