Revision 696a9617
Suppression du test unitaire sur le proxy Nagios (pas exploitable si Nagios n'est pas installé sur la machine,
et peu pertinent lorsqu'il l'est...)
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2734 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigigraph/tests/functional/test_nagiosproxy.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
''' |
|
3 |
Created on 02 feb. 2010 |
|
4 |
@author: flaheugu |
|
5 |
|
|
6 |
Tests Nagios Proxy |
|
7 |
''' |
|
8 |
|
|
9 |
import transaction |
|
10 |
import unittest |
|
11 |
|
|
12 |
from tg import config |
|
13 |
from nose.tools import eq_ |
|
14 |
|
|
15 |
from vigilo.turbogears.nagiosproxy import NagiosProxy |
|
16 |
|
|
17 |
from vigilo.models.session import DBSession |
|
18 |
from vigilo.models.tables import Host, Ventilation, VigiloServer, Application |
|
19 |
|
|
20 |
from vigigraph.tests import TestController |
|
21 |
|
|
22 |
|
|
23 |
def create_Host(name): |
|
24 |
'''Creation Host''' |
|
25 |
h = DBSession.query(Host).filter(Host.name == name).first() |
|
26 |
if not h: |
|
27 |
h = Host(name=name, |
|
28 |
checkhostcmd=u'dummy', |
|
29 |
hosttpl=u'linux', |
|
30 |
mainip=u"127.0.0.1", |
|
31 |
snmpcommunity=u"public", |
|
32 |
snmpport=161, |
|
33 |
weight=0) |
|
34 |
DBSession.add(h) |
|
35 |
DBSession.flush() |
|
36 |
return h |
|
37 |
|
|
38 |
def create_Server(name, description): |
|
39 |
'''Creation Server''' |
|
40 |
s = DBSession.query(VigiloServer).filter(VigiloServer.name == name).first() |
|
41 |
if not s: |
|
42 |
s = VigiloServer(name=name, description=description) |
|
43 |
DBSession.add(s) |
|
44 |
DBSession.flush() |
|
45 |
return s |
|
46 |
|
|
47 |
def create_Application(name): |
|
48 |
'''Creation Application''' |
|
49 |
a = DBSession.query(Application).filter(Application.name == name).first() |
|
50 |
if not a: |
|
51 |
a = Application(name=name) |
|
52 |
DBSession.add(a) |
|
53 |
DBSession.flush() |
|
54 |
return a |
|
55 |
|
|
56 |
def create_Ventilation(host, server, application): |
|
57 |
""" |
|
58 |
Peuple la base de données avec des informations sur la ventilation |
|
59 |
de la supervision, c'est-à-dire, la répartition des applications de |
|
60 |
supervision sur le parc et les machines gérées par chacune de ces |
|
61 |
applications. |
|
62 |
""" |
|
63 |
v = None |
|
64 |
h = DBSession.query(Host).filter(Host.name == host).first() |
|
65 |
s = DBSession.query(VigiloServer).filter( |
|
66 |
VigiloServer.name == server).first() |
|
67 |
a = DBSession.query(Application).filter( |
|
68 |
Application.name == application).first() |
|
69 |
if h and s: |
|
70 |
v = Ventilation(idhost=h.idhost, |
|
71 |
idvigiloserver=s.idvigiloserver, idapp=a.idapp) |
|
72 |
DBSession.add(v) |
|
73 |
DBSession.flush() |
|
74 |
return v |
|
75 |
|
|
76 |
def getServer(host): |
|
77 |
'''Server''' |
|
78 |
result = DBSession.query(VigiloServer.name) \ |
|
79 |
.filter(VigiloServer.idvigiloserver == Ventilation.idvigiloserver) \ |
|
80 |
.filter(Ventilation.idhost == Host.idhost) \ |
|
81 |
.filter(Ventilation.idapp == Application.idapp) \ |
|
82 |
.filter(Host.name == host) \ |
|
83 |
.filter(Application.name == u'nagios') \ |
|
84 |
.scalar() |
|
85 |
|
|
86 |
return result |
|
87 |
|
|
88 |
|
|
89 |
class NagiosProxy_without_nagios(NagiosProxy): |
|
90 |
""" |
|
91 |
Classe de substitution de NagiosProxy pour effectuer les tests |
|
92 |
sans nagios |
|
93 |
""" |
|
94 |
def __init__(self, content, *args, **kwargs): |
|
95 |
'''Constructeur''' |
|
96 |
super(NagiosProxy_without_nagios, self).__init__(*args, **kwargs) |
|
97 |
self.content = content |
|
98 |
|
|
99 |
def _retrieve_content(self, *args, **kwargs): |
|
100 |
'''Retour - Surcharge''' |
|
101 |
return self.content |
|
102 |
|
|
103 |
|
|
104 |
class TestNagiosProxy(unittest.TestCase): |
|
105 |
""" Test Gestion Valeur Nagios """ |
|
106 |
|
|
107 |
def __init__(self, *args, **kwargs): |
|
108 |
'''Constructeur''' |
|
109 |
super(TestNagiosProxy, self).__init__(*args, **kwargs) |
|
110 |
self.url = 'http://localhost/nagios/cgi-bin' |
|
111 |
|
|
112 |
def test_supPage(self): |
|
113 |
'''fonction vérification supPage''' |
|
114 |
result = None |
|
115 |
|
|
116 |
host = 'par.linux0' |
|
117 |
|
|
118 |
content = '''<html><head> |
|
119 |
</head></html> |
|
120 |
''' |
|
121 |
|
|
122 |
url = self.url |
|
123 |
if url is not None: |
|
124 |
nagiosproxy = NagiosProxy_without_nagios(content, url) |
|
125 |
result = nagiosproxy.get_status(host) |
|
126 |
|
|
127 |
assert(result != None) |
|
128 |
|
|
129 |
def test_servicePage(self): |
|
130 |
'''fonction vérification servicePage''' |
|
131 |
result = None |
|
132 |
|
|
133 |
host = 'par.linux0' |
|
134 |
service = 'Load' |
|
135 |
|
|
136 |
content = '''<html><head> |
|
137 |
</head></html> |
|
138 |
''' |
|
139 |
|
|
140 |
url = self.url |
|
141 |
if url is not None: |
|
142 |
nagiosproxy = NagiosProxy_without_nagios(content, url) |
|
143 |
result = nagiosproxy.get_extinfo(host, service) |
|
144 |
|
|
145 |
assert(result != None) |
|
146 |
|
|
147 |
|
|
148 |
class TestNagiosProxy_bd(TestController): |
|
149 |
""" Test Gestion Valeur Nagios """ |
|
150 |
|
|
151 |
def setUp(self): |
|
152 |
'''setup''' |
|
153 |
super(TestNagiosProxy_bd, self).setUp() |
|
154 |
|
|
155 |
# Host |
|
156 |
host = u'par.linux0' |
|
157 |
create_Host(host) |
|
158 |
|
|
159 |
# Serveurs Vigilo |
|
160 |
sv1 = create_Server(u'http://localhost', u'RRD+Nagios') |
|
161 |
|
|
162 |
# Applications Vigilo |
|
163 |
ap1 = create_Application(u'rrdgraph') |
|
164 |
ap2 = create_Application(u'nagios') |
|
165 |
|
|
166 |
# Ventilation |
|
167 |
if sv1 is not None and ap1 is not None: |
|
168 |
create_Ventilation(host, sv1.name, ap1.name) |
|
169 |
if sv1 is not None and ap2 is not None: |
|
170 |
create_Ventilation(host, sv1.name, ap2.name) |
|
171 |
|
|
172 |
DBSession.flush() |
|
173 |
transaction.commit() |
|
174 |
|
|
175 |
def test_acces_url(self): |
|
176 |
'''fonction vérification acces url via proxy''' |
|
177 |
|
|
178 |
host = u'par.linux0' |
|
179 |
server = getServer(host) |
|
180 |
url_web_path = config.get('nagios_web_path') |
|
181 |
url = '%s%s/%s' % (server, url_web_path, 'status.cgi') |
|
182 |
eq_("http://localhost/nagios/cgi-bin/status.cgi", url) |
|
183 |
|
|
184 |
if __name__ == "__main__": |
|
185 |
unittest.main() |
|
186 |
|
Also available in: Unified diff