<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
sysintergratetest.py

Created by <NAME> on 2007-11-26.
Copyright (c) 2007 xBayDNS Team. All rights reserved.

这个测试是一个集成的系统测试。它从一个什么都不知道的环境开始进行测试。这里包括初始化环境，增加相关的配置，一步步的到齐全的环境。这里将会有很多的挑战，但是完成这个测试，
我们就完成了一个用户的典型操作过程。
"""

import basetest
import logging.config
import os
import shutil
import tempfile
import unittest

log = logging.getLogger('xbaydns.tests.sysintergratetest')
logging.basicConfig(level=logging.DEBUG)

from xbaydns.tools import initconf
from xbaydns.conf import sysconf
from xbaydns.tools.namedconf import *

class SysIntergrate_ConfigInit_Test(basetest.BaseTestCase):
    """测试初始化配置"""
    def setUp(self):
        self.basedir = os.path.realpath(tempfile.mkdtemp(suffix='xbaydns_sys'))
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl"),ignore_errors=True)
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master"),ignore_errors=True)
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"slave"),ignore_errors=True)
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"dynamic"),ignore_errors=True)
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"view"),ignore_errors=True)
        basetest.BaseTestCase.setUp(self)

    def tearDown(self):
        """清洁测试环境"""
        shutil.rmtree(self.basedir)
        basetest.BaseTestCase.tearDown(self)

    def _init_conf(self):
        """测试操作系统的named.conf初始化。
        为各种操作系统初始化named.conf,注意，这将清除系统中的原有文件。原有文件请提前备份。
        另一方面，请不要将本机的域名解晰放在127.0.0.1上，这样将会在测试失败时让你的机器也无法工作。"""
        initconf.main()
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"named.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"defaultzone.conf")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","acldef.conf")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master","empty.db")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master","localhost-forward.db")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master","localhost-reverse.db")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"slave")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"dynamic")))

    def _add_default_conf(self):
        #加入default的acl信息
        nc=NamedConf()
        nc.addAcl('bj-cnc',['127.0.0.1','192.168.1.0/24'])
        nc.addAcl('tj-cnc',['127.0.0.4','192.168.2.0/24'])
        nc.addAcl('gd-telecom',['127.0.0.2','10.0.10.0/24'])
        nc.addAcl('gx-telecom',['127.0.0.3','10.0.11.0/24'])
        #加入default的view信息
        nc.addView("cnc",["bj-cnc","tj-cnc"])
        nc.addView("telecom",["gd-telecom","gx-telecom"])
        nc.addDomain(["sina.com.cn","hd.com"])
        nc.save()
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","bj-cnc.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","tj-cnc.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","gd-telecom.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","gx-telecom.conf")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"view")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"view","cnc.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"view","telecom.conf")))
        self.assertTrue( os.system("named-checkconf") == 0 )
        for i in ["sina.com.cn","hd.com"]:
            for j in ["cnc","telecom"]:
                log.debug("check %s as %s"%(i,j))
                self.assertTrue( os.system("named-checkzone %s %s"%(i,os.path.join(sysconf.chroot_path,sysconf.namedconf,"dynamic","%s.%s.file"%(j,i)))) == 0 )
        self.assertTrue(nc.reload() == 0)

    def test_intergrate(self):
        """集成测试"""
        self._init_conf()
        self._add_default_conf()<commit_msg>先重启再试reload<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
sysintergratetest.py

Created by <NAME> on 2007-11-26.
Copyright (c) 2007 xBayDNS Team. All rights reserved.

这个测试是一个集成的系统测试。它从一个什么都不知道的环境开始进行测试。这里包括初始化环境，增加相关的配置，一步步的到齐全的环境。这里将会有很多的挑战，但是完成这个测试，
我们就完成了一个用户的典型操作过程。
"""

import basetest
import logging.config
import os
import shutil
import tempfile
import unittest

log = logging.getLogger('xbaydns.tests.sysintergratetest')
logging.basicConfig(level=logging.DEBUG)

from xbaydns.tools import initconf
from xbaydns.conf import sysconf
from xbaydns.tools.namedconf import *

class SysIntergrate_ConfigInit_Test(basetest.BaseTestCase):
    """测试初始化配置"""
    def setUp(self):
        self.basedir = os.path.realpath(tempfile.mkdtemp(suffix='xbaydns_sys'))
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl"),ignore_errors=True)
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master"),ignore_errors=True)
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"slave"),ignore_errors=True)
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"dynamic"),ignore_errors=True)
        shutil.rmtree(os.path.join(sysconf.chroot_path,sysconf.namedconf,"view"),ignore_errors=True)
        basetest.BaseTestCase.setUp(self)

    def tearDown(self):
        """清洁测试环境"""
        shutil.rmtree(self.basedir)
        basetest.BaseTestCase.tearDown(self)

    def _init_conf(self):
        """测试操作系统的named.conf初始化。
        为各种操作系统初始化named.conf,注意，这将清除系统中的原有文件。原有文件请提前备份。
        另一方面，请不要将本机的域名解晰放在127.0.0.1上，这样将会在测试失败时让你的机器也无法工作。"""
        initconf.main()
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"named.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"defaultzone.conf")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","acldef.conf")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master","empty.db")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master","localhost-forward.db")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"master","localhost-reverse.db")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"slave")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"dynamic")))

    def _add_default_conf(self):
        #加入default的acl信息
        nc=NamedConf()
        nc.addAcl('bj-cnc',['127.0.0.1','192.168.1.0/24'])
        nc.addAcl('tj-cnc',['127.0.0.4','192.168.2.0/24'])
        nc.addAcl('gd-telecom',['127.0.0.2','10.0.10.0/24'])
        nc.addAcl('gx-telecom',['127.0.0.3','10.0.11.0/24'])
        #加入default的view信息
        nc.addView("cnc",["bj-cnc","tj-cnc"])
        nc.addView("telecom",["gd-telecom","gx-telecom"])
        nc.addDomain(["sina.com.cn","hd.com"])
        nc.save()
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","bj-cnc.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","tj-cnc.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","gd-telecom.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"acl","gx-telecom.conf")))
        self.assertTrue(os.path.isdir(os.path.join(sysconf.chroot_path,sysconf.namedconf,"view")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"view","cnc.conf")))
        self.assertTrue(os.path.isfile(os.path.join(sysconf.chroot_path,sysconf.namedconf,"view","telecom.conf")))
        self.assertTrue( nc.check_configfile() == 0 )
        for i in ["sina.com.cn","hd.com"]:
            for j in ["cnc","telecom"]:
                log.debug("check %s as %s"%(i,j))
                self.assertTrue( os.system("named-checkzone %s %s"%(i,os.path.join(sysconf.chroot_path,sysconf.namedconf,"dynamic","%s.%s.file"%(j,i)))) == 0 )
        nc.named_restart()
        self.assertTrue(nc.reload() == 0)

    def test_intergrate(self):
        """集成测试"""
        self._init_conf()
        self._add_default_conf()
{'fraction_non_alphanumeric': 0.17024539877300612, 'fraction_numerical': 0.01796669588080631, 'mean_word_length': 4.246551724137931, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 18, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3204503', 'n_tokens_mistral': 3743, 'n_tokens_neox': 3751, 'n_words': 254}