def test_init_logger(): """ Assert that multiple calls of init_logger() return the same logger object. """ logger1 = logging.getLogger() utils.init_logger(logger1) logger2 = logging.getLogger() utils.init_logger(logger2) assert logger1 == logger2
import os import logging topdir = os.path.dirname(os.path.realpath(__file__)) + "../.." topdir = os.path.realpath(topdir) sys.path.insert(0, topdir) from vyos_session import utils from servicemanager.validation import validation as vld from operations import configOpts from execformat.formator import showConfig from execformat.executor import session from pprint import pprint NSR = "nat source rule" NDR = "nat destination rule" logger = logging.getLogger(__name__) utils.init_logger(logger) class natHandler(configOpts): type=['source','destination'] show=showConfig() def check_nat_rule_number(self,type,rule_num): if type not in self.type: logger.error("type %s is not valid!"%type) return False rules=self.show.formator(['nat'])[type]['rule'].keys() if rule_num not in rules: return False return True def nat_config(self,action,type,suffix):
class IpformatError(Exception): pass class InterfaceError(Exception): pass class ActionError(Exception): pass show = showConfig() logger = logging.getLogger(__name__) utils.init_logger(logger) class validation(): """check if a given ip address is into a valid format""" @staticmethod def testip(ipaddr): addr_portions = ipaddr.split('.') if len(addr_portions) != 4: logger.error( "provided ip address %s is not in the correct format!" % ipaddr) return False for portion in addr_portions: if not portion.isdigit(): logger.error(