6
Created by Thomas Mangin on 2009-08-25.
7
Copyright (c) 2009-2013 Exa Networks. All rights reserved.
12
from exabgp.configuration.environment import environment
13
env = environment.setup('')
15
from exabgp.configuration.file import Configuration
18
class TestConfiguration (unittest.TestCase):
22
def test_valid (self):
23
for config in self.valid:
24
configuration = Configuration(config,True)
26
self.assertEqual(configuration.reload(),True,configuration.error)
31
print configuration.error
34
# for ip in self.configuration.neighbor:
35
# print self.configuration.neighbor[ip]
37
def test_reload (self):
38
configuration = Configuration(self.valid[0],True)
39
configuration.reload()
43
neighbor 192.168.127.128 {
44
description "a quagga test peer";
45
router-id 192.168.127.1;
46
local-address 192.168.127.1;
56
community 30740:30740;
60
community [ 30740:30740 30740:0 ];
66
route 10.0.5.0/24 next-hop 10.0.255.5 local-preference 200;
67
route 10.0.6.0/24 next-hop 10.0.255.6 community 30740:30740;
68
route 10.0.7.0/24 next-hop 10.0.255.7 local-preference 200 community 30740:30740;
69
route 10.0.8.0/24 next-hop 10.0.255.8 community 30740:30740 local-preference 200;
70
route 10.0.9.0/24 next-hop 10.0.255.9 local-preference 200 community [30740:0 30740:30740];
71
route 10.0.10.0/24 next-hop 10.0.255.10 community [30740:0 30740:30740] local-preference 200;
77
neighbor 192.168.127.128 {
78
description "Configuration One";
79
router-id 192.168.127.2;
80
local-address 192.168.127.1;
90
community 30740:30740;
94
community [ 30740:30740 30740:0 ];
103
description "Configuration Two";
104
local-address 10.0.0.2;
109
route 10.0.5.0/24 next-hop 10.0.255.5 local-preference 200;
110
route 10.0.6.0/24 next-hop 10.0.255.6 community 30740:30740;
111
route 10.0.7.0/24 next-hop 10.0.255.7 local-preference 200 community 30740:30740;
112
route 10.0.8.0/24 next-hop 10.0.255.8 community 30740:30740 local-preference 200;
113
route 10.0.9.0/24 next-hop 10.0.255.9 local-preference 200 community [30740:0 30740:30740];
114
route 10.0.10.0/24 next-hop 10.0.255.10 community [30740:0 30740:30740] local-preference 200;
120
def test_faults (self):
121
for config,error in self._faults.iteritems():
122
configuration = Configuration(config,True)
125
self.assertEqual(configuration.reload(),False)
126
self.assertEqual(config + ' '*10 + configuration.error,config + ' '*10 + error)
127
except AssertionError:
131
print configuration.error
141
""" : 'syntax error in section neighbor\nline 1 : neighbor a {\n"a" is not a valid IP address'
145
invalid-command value ;
147
""": 'syntax error in section neighbor\nline 2 : invalid-command value ;\ninvalid keyword "invalid-command"'
151
description A non quoted description;
153
""" : 'syntax error in section neighbor\nline 2 : description a non quoted description ;\nsyntax: description "<description>"'
157
description "A quoted description with "quotes" inside";
159
""" : 'syntax error in section neighbor\nline 2 : description "a quoted description with "quotes" inside" ;\nsyntax: description "<description>"'
165
""" : 'syntax error in section neighbor\nline 2 : local-address a ;\n"a" is an invalid IP address'
171
""" : 'syntax error in section neighbor\nline 2 : local-as a ;\n"a" is an invalid ASN'
177
""" : 'syntax error in section neighbor\nline 2 : peer-as a ;\n"a" is an invalid ASN'
183
""" : 'syntax error in section neighbor\nline 2 : router-id a ;\n"a" is an invalid IP address'
188
route A/24 next-hop 10.0.255.5;
191
""" : 'syntax error in section static\nline 3 : route a/24 next-hop 10.0.255.5 ;\n' + Configuration._str_route_error
196
route 10.0.5.0/A next-hop 10.0.255.5;
199
""" : 'syntax error in section static\nline 3 : route 10.0.5.0/a next-hop 10.0.255.5 ;\n' + Configuration._str_route_error
204
route A next-hop 10.0.255.5;
207
""" : 'syntax error in section static\nline 3 : route a next-hop 10.0.255.5 ;\n' + Configuration._str_route_error
212
route 10.0.5.0/24 next-hop A;
215
""" : 'syntax error in section static\nline 3 : route 10.0.5.0/24 next-hop a ;\n' + Configuration._str_route_error
220
route 10.0.5.0/24 next-hop 10.0.255.5 local-preference A;
223
""" : 'syntax error in section static\nline 3 : route 10.0.5.0/24 next-hop 10.0.255.5 local-preference a ;\n' + Configuration._str_route_error
228
route 10.0.5.0/24 next-hop 10.0.255.5 community a;
231
""" : 'syntax error in section static\nline 3 : route 10.0.5.0/24 next-hop 10.0.255.5 community a ;\n' + Configuration._str_route_error
236
route 10.0.5.0/24 next-hop 10.0.255.5 community [ A B ];
239
""" : 'syntax error in section static\nline 3 : route 10.0.5.0/24 next-hop 10.0.255.5 community [ a b ] ;\n' + Configuration._str_route_error
242
neighbor 192.168.127.128 {
243
local-address 192.168.127.1;
251
""" : 'syntax error in section static\nline 7 : }\nsyntax: route IP/MASK { next-hop IP; }'
254
neighbor 192.168.127.128 {
261
""" : 'syntax error in section route\nline 4 : next-hop a ;\n' + Configuration._str_route_error
264
neighbor 192.168.127.128 {
272
""" : 'syntax error in section route\nline 5 : local-preference a ;\n' + Configuration._str_route_error
275
neighbor 192.168.127.128 {
283
""" : 'syntax error in section route\nline 5 : community a ;\n' + Configuration._str_route_error
286
neighbor 192.168.127.128 {
294
""" : 'syntax error in section route\nline 5 : community [ a b ] ;\n' + Configuration._str_route_error
297
neighbor 192.168.127.128 {
298
local-address 192.168.127.1;
307
""" : 'syntax error in section neighbor\nline 10 : }\nconfiguration file incomplete (most likely missing })'
313
if __name__ == '__main__':