From 303268d0464127c52f11443404fb1baae03d615f Mon Sep 17 00:00:00 2001 From: Periyasamy Palanisamy Date: Mon, 16 Apr 2018 15:09:16 +0200 Subject: 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 --- sdnvpn/lib/utils.py | 58 +++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'sdnvpn/lib/utils.py') 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 -- cgit 1.2.3-korg