This bug has been migrated to another issue tracking site. It has been closed here and may no longer be being monitored.

If you would like to get updates for this issue, or to participate in it, you may do so at Red Hat Issue Tracker .
Bug 2172413 - Logs were duplicated after calling netinfo.show_running_config()
Summary: Logs were duplicated after calling netinfo.show_running_config()
Keywords:
Status: CLOSED MIGRATED
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: nmstate
Version: 9.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Gris Ge
QA Contact: Mingyu Shi
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-02-22 10:30 UTC by Karthik Sundaravel
Modified: 2023-08-17 09:23 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-08-17 09:23:10 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker NMT-319 0 None None None 2023-02-22 10:31:23 UTC
Red Hat Issue Tracker   RHEL-1401 0 None None None 2023-08-17 09:23:09 UTC
Red Hat Issue Tracker RHELPLAN-149625 0 None None None 2023-02-22 10:31:27 UTC

Description Karthik Sundaravel 2023-02-22 10:30:15 UTC
Description of problem:
Run the below python code

from libnmstate import netapplier
from libnmstate import netinfo
from libnmstate.schema import Interface
import logging
import sys                                                                  
import yaml
                                                                           
def logger_level(logger, verbose=False, debug=False):      
    log_level = logging.DEBUG                                              
    if debug:
        log_level = logging.DEBUG                                          
    elif verbose:                                                          
        log_level = logging.INFO
    logger.setLevel(log_level)
 
 
def configure_logger(log_file=False, verbose=False, debug=False):
    LOG_FORMAT = ('%(asctime)s.%(msecs)03d %(levelname)s '
                  '%(name)s.%(funcName)s %(message)s')
    DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
    logger = logging.getLogger("os_net_config")
    logger.handlers.clear()
    logger_level(logger, verbose, debug)
    logger.propagate = True
    formatter = logging.Formatter(fmt=LOG_FORMAT, datefmt=DATE_FORMAT)
    if log_file:
        file_handler = logging.handlers.RotatingFileHandler(
            _LOG_FILE, maxBytes=10485760, backupCount=7
        )
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)
    stream_handler = logging.StreamHandler(sys.stdout)
    stream_handler.setFormatter(formatter)
    logger.addHandler(stream_handler)
    return logger
 
 
logger = configure_logger()
 
logger.debug("---------PRE_NETINFO LOG-----------------")
 
ifaces = netinfo.show_running_config()[Interface.KEY]
ifaces_dmp = yaml.dump(ifaces,  default_flow_style = False,
                       allow_unicode = True, encoding = None)
logger.debug("-------POST_NETINFO_LOG------------------")
logger.debug("Running info: \n %s"  % ifaces_dmp)

Its found that after invoking netinfo.show_running_config(), the logs are duplicated.

Version-Release number of selected component (if applicable):
nmstatectl 2.2.6


Actual results:
[root@dell-r640-oss-14 ~]# python nmstate_test.py                                                                                                        
2023-02-14 16:53:59.240 DEBUG os_net_config.<module> ---------PRE_NETINFO LOG-----------------                                                           
2023-02-14 16:53:59.360 DEBUG os_net_config.<module> -------POST_NETINFO_LOG------------------                                                           
DEBUG:os_net_config:-------POST_NETINFO_LOG------------------               
2023-02-14 16:53:59.360 DEBUG os_net_config.<module> Running info:

.....


Expected results:

2023-02-14 16:53:59.240 DEBUG os_net_config.<module> ---------PRE_NETINFO LOG-----------------                                                           
2023-02-14 16:53:59.360 DEBUG os_net_config.<module> -------POST_NETINFO_LOG------------------                                                           
2023-02-14 16:53:59.360 DEBUG os_net_config.<module> Running info:
....


Note You need to log in before you can comment on or make changes to this bug.