~ubuntu-branches/ubuntu/utopic/exabgp/utopic

« back to all changes in this revision

Viewing changes to dev/unittest/configuration.py

  • Committer: Package Import Robot
  • Author(s): Henry-Nicolas Tourneur
  • Date: 2014-03-08 19:07:00 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140308190700-xjbibpg1g6001c9x
Tags: 3.3.1-1
* New upstream release
* Bump python minimal required version (2.7)
* Closes: #726066 Debian packaging improvements proposed by Vincent Bernat
* Closes: #703774 not existent rundir (/var/run/exabgp) after reboot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# encoding: utf-8
 
3
"""
 
4
configuration.py
 
5
 
 
6
Created by Thomas Mangin on 2009-08-25.
 
7
Copyright (c) 2009-2013 Exa Networks. All rights reserved.
 
8
"""
 
9
 
 
10
import unittest
 
11
 
 
12
from exabgp.configuration.environment import environment
 
13
env = environment.setup('')
 
14
 
 
15
from exabgp.configuration.file import Configuration
 
16
 
 
17
 
 
18
class TestConfiguration (unittest.TestCase):
 
19
        def setUp(self):
 
20
                pass
 
21
 
 
22
        def test_valid (self):
 
23
                for config in self.valid:
 
24
                        configuration = Configuration(config,True)
 
25
                        try:
 
26
                                self.assertEqual(configuration.reload(),True,configuration.error)
 
27
                        except:
 
28
                                print
 
29
                                print config
 
30
                                print
 
31
                                print configuration.error
 
32
                                print
 
33
                                raise
 
34
#               for ip in self.configuration.neighbor:
 
35
#                       print self.configuration.neighbor[ip]
 
36
 
 
37
        def test_reload (self):
 
38
                configuration = Configuration(self.valid[0],True)
 
39
                configuration.reload()
 
40
 
 
41
        valid = [
 
42
"""\
 
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;
 
47
        local-as 65000;
 
48
        peer-as 65000;
 
49
 
 
50
        static {
 
51
                route 10.0.1.0/24 {
 
52
                        next-hop 10.0.255.1;
 
53
                }
 
54
                route 10.0.2.0/24 {
 
55
                        next-hop 10.0.255.2;
 
56
                        community 30740:30740;
 
57
                }
 
58
                route 10.0.3.0/24 {
 
59
                        next-hop 10.0.255.3;
 
60
                        community [ 30740:30740 30740:0 ];
 
61
                }
 
62
                route 10.0.4.0/24 {
 
63
                        next-hop 10.0.255.4;
 
64
                        local-preference 200;
 
65
                }
 
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;
 
72
        }
 
73
}
 
74
"""
 
75
,
 
76
"""\
 
77
neighbor 192.168.127.128 {
 
78
        description "Configuration One";
 
79
        router-id 192.168.127.2;
 
80
        local-address 192.168.127.1;
 
81
        local-as 65001;
 
82
        peer-as 65000;
 
83
 
 
84
        static {
 
85
                route 10.0.1.0/24 {
 
86
                        next-hop 10.0.255.1;
 
87
                }
 
88
                route 10.0.2.0/24 {
 
89
                        next-hop 10.0.255.2;
 
90
                        community 30740:30740;
 
91
                }
 
92
                route 10.0.3.0/24 {
 
93
                        next-hop 10.0.255.3;
 
94
                        community [ 30740:30740 30740:0 ];
 
95
                }
 
96
                route 10.0.4.0/24 {
 
97
                        next-hop 10.0.255.4;
 
98
                        local-preference 200;
 
99
                }
 
100
        }
 
101
}
 
102
neighbor 10.0.0.10 {
 
103
        description "Configuration Two";
 
104
        local-address 10.0.0.2;
 
105
        local-as 65001;
 
106
        peer-as 65001;
 
107
 
 
108
        static {
 
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;
 
115
        }
 
116
}
 
117
"""
 
118
]
 
119
 
 
120
        def test_faults (self):
 
121
                for config,error in self._faults.iteritems():
 
122
                        configuration = Configuration(config,True)
 
123
 
 
124
                        try:
 
125
                                self.assertEqual(configuration.reload(),False)
 
126
                                self.assertEqual(config + ' '*10 + configuration.error,config + ' '*10 + error)
 
127
                        except AssertionError:
 
128
                                print
 
129
                                print config
 
130
                                print
 
131
                                print configuration.error
 
132
                                print
 
133
                                raise
 
134
 
 
135
 
 
136
 
 
137
        _faults = {
 
138
"""\
 
139
        neighbor A {
 
140
        }
 
141
""" : 'syntax error in section neighbor\nline 1 : neighbor a {\n"a" is not a valid IP address'
 
142
,
 
143
"""\
 
144
neighbor 10.0.0.10 {
 
145
        invalid-command value ;
 
146
}
 
147
""": 'syntax error in section neighbor\nline 2 : invalid-command value ;\ninvalid keyword "invalid-command"'
 
148
,
 
149
"""\
 
150
neighbor 10.0.0.10 {
 
151
        description A non quoted description;
 
152
}
 
153
""" : 'syntax error in section neighbor\nline 2 : description a non quoted description ;\nsyntax: description "<description>"'
 
154
,
 
155
"""\
 
156
neighbor 10.0.0.10 {
 
157
        description "A quoted description with "quotes" inside";
 
158
}
 
159
""" : 'syntax error in section neighbor\nline 2 : description "a quoted description with "quotes" inside" ;\nsyntax: description "<description>"'
 
160
,
 
161
"""\
 
162
neighbor 10.0.0.10 {
 
163
        local-address A;
 
164
}
 
165
""" : 'syntax error in section neighbor\nline 2 : local-address a ;\n"a" is an invalid IP address'
 
166
,
 
167
"""\
 
168
neighbor 10.0.0.10 {
 
169
        local-as A;
 
170
}
 
171
""" : 'syntax error in section neighbor\nline 2 : local-as a ;\n"a" is an invalid ASN'
 
172
,
 
173
"""\
 
174
neighbor 10.0.0.10 {
 
175
        peer-as A;
 
176
}
 
177
""" : 'syntax error in section neighbor\nline 2 : peer-as a ;\n"a" is an invalid ASN'
 
178
,
 
179
"""\
 
180
neighbor 10.0.0.10 {
 
181
        router-id A;
 
182
}
 
183
""" : 'syntax error in section neighbor\nline 2 : router-id a ;\n"a" is an invalid IP address'
 
184
,
 
185
"""\
 
186
neighbor 10.0.0.10 {
 
187
        static {
 
188
                route A/24 next-hop 10.0.255.5;
 
189
        }
 
190
}
 
191
""" : 'syntax error in section static\nline 3 : route a/24 next-hop 10.0.255.5 ;\n' + Configuration._str_route_error
 
192
,
 
193
"""\
 
194
neighbor 10.0.0.10 {
 
195
        static {
 
196
                route 10.0.5.0/A next-hop 10.0.255.5;
 
197
        }
 
198
}
 
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
 
200
,
 
201
"""\
 
202
neighbor 10.0.0.10 {
 
203
        static {
 
204
                route A next-hop 10.0.255.5;
 
205
        }
 
206
}
 
207
""" : 'syntax error in section static\nline 3 : route a next-hop 10.0.255.5 ;\n' + Configuration._str_route_error
 
208
,
 
209
"""\
 
210
neighbor 10.0.0.10 {
 
211
        static {
 
212
                route 10.0.5.0/24 next-hop A;
 
213
        }
 
214
}
 
215
""" : 'syntax error in section static\nline 3 : route 10.0.5.0/24 next-hop a ;\n' + Configuration._str_route_error
 
216
,
 
217
"""\
 
218
neighbor 10.0.0.10 {
 
219
        static {
 
220
                route 10.0.5.0/24 next-hop 10.0.255.5 local-preference A;
 
221
        }
 
222
}
 
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
 
224
,
 
225
"""\
 
226
neighbor 10.0.0.10 {
 
227
        static {
 
228
                route 10.0.5.0/24 next-hop 10.0.255.5 community a;
 
229
        }
 
230
}
 
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
 
232
,
 
233
"""\
 
234
neighbor 10.0.0.10 {
 
235
        static {
 
236
                route 10.0.5.0/24 next-hop 10.0.255.5 community [ A B ];
 
237
        }
 
238
}
 
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
 
240
,
 
241
"""\
 
242
neighbor 192.168.127.128 {
 
243
        local-address 192.168.127.1;
 
244
        local-as 65000;
 
245
        peer-as 65000;
 
246
        static {
 
247
                route 10.0.1.0/24 {
 
248
                }
 
249
        }
 
250
}
 
251
""" : 'syntax error in section static\nline 7 : }\nsyntax: route IP/MASK { next-hop IP; }'
 
252
,
 
253
"""\
 
254
neighbor 192.168.127.128 {
 
255
        static {
 
256
                route 10.0.1.0/24 {
 
257
                        next-hop A;
 
258
                }
 
259
        }
 
260
}
 
261
""" : 'syntax error in section route\nline 4 : next-hop a ;\n' + Configuration._str_route_error
 
262
,
 
263
"""\
 
264
neighbor 192.168.127.128 {
 
265
        static {
 
266
                route 10.0.1.0/24 {
 
267
                        next-hop 10.0.255.5;
 
268
                        local-preference A;
 
269
                }
 
270
        }
 
271
}
 
272
""" : 'syntax error in section route\nline 5 : local-preference a ;\n' + Configuration._str_route_error
 
273
,
 
274
"""\
 
275
neighbor 192.168.127.128 {
 
276
        static {
 
277
                route 10.0.1.0/24 {
 
278
                        next-hop 10.0.255.5;
 
279
                        community A;
 
280
                }
 
281
        }
 
282
}
 
283
""" : 'syntax error in section route\nline 5 : community a ;\n' + Configuration._str_route_error
 
284
,
 
285
"""\
 
286
neighbor 192.168.127.128 {
 
287
        static {
 
288
                route 10.0.1.0/24 {
 
289
                        next-hop 10.0.255.5;
 
290
                        community [ A B ];
 
291
                }
 
292
        }
 
293
}
 
294
""" : 'syntax error in section route\nline 5 : community [ a b ] ;\n' + Configuration._str_route_error
 
295
,
 
296
"""\
 
297
neighbor 192.168.127.128 {
 
298
        local-address 192.168.127.1;
 
299
        local-as 65000;
 
300
        peer-as 65000;
 
301
 
 
302
        static {
 
303
                route 10.0.1.0/24 {
 
304
                        next-hop 10.0.255.1;
 
305
                }
 
306
        }
 
307
""" : 'syntax error in section neighbor\nline 10 : }\nconfiguration file incomplete (most likely missing })'
 
308
,
 
309
 
 
310
}
 
311
 
 
312
 
 
313
if __name__ == '__main__':
 
314
        unittest.main()