示例#1
0
 def test_remove_conffile_on_parent_svn_remove(self):
     ConfFile.get_or_create(u"dummydir/dummy2.xml")
     os.mkdir(os.path.join(self.tmpdir, "dummydir"))
     open(os.path.join(self.tmpdir, "dummydir", "dummy2.xml"), "w").close()
     self.rm.dummy_status["removed"] = [os.path.join(self.tmpdir, "dummydir"), ]
     self.hostloader.load()
     self.assertEqual(0, DBSession.query(ConfFile).filter_by(
                         name=u"dummydir/dummy2.xml").count())
示例#2
0
 def setUp(self):
     setup_db()
     conf.hostsConf = {}
     # Prepare temporary directory
     self.tmpdir = setup_tmpdir()
     self.basedir = os.path.join(self.tmpdir, "deploy")
     self.old_conf_path = settings["vigiconf"]["confdir"]
     settings["vigiconf"]["confdir"] = os.path.join(self.tmpdir, "conf.d")
     os.mkdir(settings["vigiconf"]["confdir"])
     self.testfactory = TestFactory(confdir=settings["vigiconf"]["confdir"])
     self.host = Host(conf.hostsConf, "dummy.xml", "testserver1",
                      "192.168.1.1", "Servers")
     self.host.set_attribute("collectorTimeout", "3")
     # attention, le fichier dummy.xml doit exister ou l'hôte sera supprimé
     # juste après avoir été inséré
     open(os.path.join(self.tmpdir, "conf.d", "dummy.xml"), "w").close()
     conffile = ConfFile.get_or_create("dummy.xml")
     add_host("testserver1", conffile)
     self.apps = self._get_apps()
     self.genmanager = GeneratorManager(self.apps.values())
     self.substitutions = {
         'nagios_bin': 'nagios',
         'nagios_init': '/etc/init.d/nagios',
         'targetconfdir': '/etc/vigilo/vigiconf/',
         'nagios_cfg': '/etc/nagios/nagios.cfg',
     }
示例#3
0
 def test_parents_directive(self):
     """Nagios: parents"""
     # On ajoute un 2ème hôte et on génère une dépendance topologique
     # de "testserver1" sur "testserver2".
     Host(conf.hostsConf, "host/localhost.xml", u"testserver2",
                  "192.168.1.2", "Servers")
     add_host("testserver2", ConfFile.get_or_create("dummy.xml"))
     dep_group = add_dependency_group('testserver1', None, 'topology')
     add_dependency(dep_group, ("testserver2", None))
     # "testserver2" doit apparaître comme parent de "testserver1"
     # dans le fichier de configuration généré pour Nagios.
     self._generate()
     nagiosconffile = os.path.join(self.basedir, "localhost",
                                   "nagios", "nagios.cfg")
     self.assert_(os.path.exists(nagiosconffile),
                  "Nagios conf file was not generated")
     nagiosconf = open(nagiosconffile).read()
     print nagiosconf
     self.assertTrue(re.search("^\s*parents\s+testserver2\s*$",
                     nagiosconf, re.M))
示例#4
0
 def test_remove_conffile_on_missing_files(self):
     ConfFile.get_or_create(u"dummy2.xml")
     self.hostloader.load()
     self.assertEqual(0, DBSession.query(ConfFile).filter_by(
                         name=u"dummy2.xml").count())