-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.py
More file actions
219 lines (178 loc) · 8.17 KB
/
Copy pathtests.py
File metadata and controls
219 lines (178 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# file: bgp/tests.py
from django.test import TestCase
from django.urls import reverse
from django.contrib.auth.models import User
from netdevice.tests import create_router, create_interface
from bgp.models import aut_num, neighbor
def create_aut_num(asn):
test_asn = aut_num.objects.create(asn=asn,
name='Test ASN',
contact='test@test.com',
)
return test_asn
def create_neighbor(test_router, aut_num, peer_ip):
test_neighbor = neighbor.objects.create(router=test_router,
aut_num=aut_num,
peer_ip=peer_ip,
soft_inbound=True,
)
return test_neighbor
class AddressViewTests(TestCase):
def setUp(self):
test_user = User.objects.get_or_create(username='testuser')[0]
self.client.force_login(test_user)
def test_config_view_with_one_ios_neighbor(self):
"""
Create a test IOS router, with one ipv4 and one ipv6 neighbors
then check config view.
"""
test_router = create_router('ios')
test_asn = create_aut_num('65001')
test_v4_neighbor = create_neighbor(test_router, test_asn, '1.1.1.1')
test_v6_neighbor = create_neighbor(
test_router,
test_asn,
'2001:db8::1'
)
url = reverse(
'netdevice:router_config',
kwargs={'router_id': test_router.id},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'neighbor 1.1.1.1 remote-as 65001')
self.assertContains(response, 'neighbor 2001:db8::1 remote-as 65001')
def test_config_view_with_one_junos_neighbor(self):
"""
Create a test JunOS router, with one ipv4 and one ipv6 neighbors
then check config view.
"""
test_router = create_router('junos')
test_asn = create_aut_num('65001')
test_v4_neighbor = create_neighbor(test_router, test_asn, '1.1.1.1')
test_v6_neighbor = create_neighbor(test_router, test_asn, '2001:db8::1')
url = reverse(
'netdevice:router_config',
kwargs={'router_id': test_router.id},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'peer-as 65001;')
self.assertContains(response, 'neighbor 1.1.1.1;')
self.assertContains(response, 'neighbor 2001:db8::1;')
def test_config_view_with_multiple_ios_neighbor(self):
"""
Create a test IOS router, with 100 ipv4 and ipv6 neighbors
then check the config view.
"""
test_router = create_router('ios')
test_asn = create_aut_num('65001')
neighbor_count = 100
for i in range(1, neighbor_count):
create_neighbor(test_router, test_asn, '1.1.' + str(i) + '.1')
create_neighbor(
test_router,
test_asn,
'2001:db8:' + str(i) + '::1'
)
url = reverse(
'netdevice:router_config',
kwargs={'router_id': test_router.id},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
for i in range(1, neighbor_count):
v4_text = 'neighbor 1.1.' + str(i) + '.1 remote-as 65001'
v6_text = 'neighbor 2001:db8:' + str(i) + '::1 remote-as 65001'
self.assertContains(response, v4_text)
self.assertContains(response, v6_text)
def test_config_view_with_multiple_junos_neighbor(self):
"""
Create a test IOS router, with 100 ipv4 and ipv6 neighbors
then check the config view.
"""
test_router = create_router('junos')
test_asn_one = create_aut_num('65001')
test_asn_two = create_aut_num('65002')
neighbor_count = 50
asn_one_config = ' group test-asn {\n'
asn_one_config += ' type external;\n'
asn_two_config = asn_one_config
asn_two_config += ' peer-as 65002; \n'
asn_one_config += ' peer-as 65001; \n'
for i in range(1, neighbor_count):
create_neighbor(test_router, test_asn_one, '1.1.' + str(i) + '.1')
asn_one_config += ' neighbor 1.1.' + str(i) + '.1; \n'
create_neighbor(test_router, test_asn_two, '2.2.' + str(i) + '.1')
asn_two_config += ' neighbor 2.2.' + str(i) + '.1; \n'
for i in range(1, neighbor_count):
create_neighbor(
test_router,
test_asn_one,
'2001:db8:' + str(i) + '::1'
)
asn_one_config += ' neighbor 2001:db8:'
asn_one_config += str(i) + '::1; \n'
create_neighbor(
test_router,
test_asn_two,
'2001:db8:' + str(i) + ':2::1'
)
asn_two_config += ' neighbor 2001:db8:'
asn_two_config += str(i) + ':2::1; \n'
asn_one_config += ' }'
asn_two_config += ' }'
url = reverse(
'netdevice:router_config',
kwargs={'router_id': test_router.id},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, asn_one_config)
self.assertContains(response, asn_two_config)
def test_create_neighbor_form_view(self):
"""
Create a test router, and then test the form view of create display.
"""
test_router = create_router('junos')
url = reverse(
'bgp:neighbor_create',
kwargs={'router_id': test_router.id},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_edit_neighbor_form_view(self):
"""
Create a test router, and neighbor, then test the form view of neighbor
edit is displayed correctly.
"""
test_router = create_router('junos')
test_asn_one = create_aut_num('65001')
test_neighbor = create_neighbor(
test_router,
test_asn_one,
'2001:db8:1::1'
)
url = reverse(
'bgp:neighbor_edit',
kwargs={'neighbor_id': test_neighbor.id},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_create_aut_num_form_view(self):
"""
Test the form view of create ASN display.
"""
response = self.client.get(reverse('bgp:aut_num_create'))
self.assertEqual(response.status_code, 200)
def test_edit_aut_num_form_view(self):
"""
Create an ASN, then test the form view of the edit ASN display.
"""
test_asn = create_aut_num('65001')
url = reverse(
'bgp:aut_num_edit',
kwargs={'aut_num_id': test_asn.id},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)