/
cfg_opts.py
196 lines (194 loc) · 6.73 KB
/
cfg_opts.py
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
"""Config options used in test_routing.py.
Listing of advanced-routing-config options to be tested in test_juju_routing
"""
JSON_CONFIGS = [
{
"input": [
{"type": "table", "table": "SF1"},
{
"type": "route",
"default_route": True,
"net": "192.170.1.0/24",
"gateway": "10.191.86.2",
"table": "SF1",
"metric": 101,
"device": "eth0",
},
{"type": "route", "net": "6.6.6.0/24", "gateway": "10.191.86.2"},
{
"type": "rule",
"from-net": "192.170.2.0/24",
"to-net": "192.170.2.0/24",
"table": "SF1",
"priority": 101,
},
],
"expected_ifup": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip route flush cache\n"
"# Table: name SF1\n"
"ip route replace default via 10.191.86.2 table SF1 dev eth0 metric 101\n"
"ip route replace 6.6.6.0/24 via 10.191.86.2\n"
"ip rule add from 192.170.2.0/24 to 192.170.2.0/24 table SF1 priority 101\n"
),
"expected_ifdown": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip rule del from 192.170.2.0/24 to 192.170.2.0/24 table SF1 priority 101\n"
"ip route del 6.6.6.0/24 via 10.191.86.2\n"
"ip route del default via 10.191.86.2 table SF1 dev eth0 metric 101\n"
"ip route flush table SF1\n"
"ip rule del table SF1\n"
"ip route flush cache\n"
),
},
{
"input": [
{"type": "table", "table": "mytable"},
{
"type": "route",
"default_route": True,
"gateway": "10.205.6.1",
"table": "mytable",
},
{
"type": "rule",
"from-net": "10.205.6.0/24",
"to-net": "1.1.1.1/32",
"priority": 100,
},
{
"type": "rule",
"from-net": "10.205.6.0/24",
"table": "mytable",
"priority": 101,
},
],
"expected_ifup": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip route flush cache\n"
"# Table: name mytable\n"
"ip route replace default via 10.205.6.1 table mytable\n"
"ip rule add from 10.205.6.0/24 to 1.1.1.1/32 priority 100\n"
"ip rule add from 10.205.6.0/24 table mytable priority 101\n"
),
"expected_ifdown": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip rule del from 10.205.6.0/24 table mytable priority 101\n"
"ip rule del from 10.205.6.0/24 to 1.1.1.1/32 priority 100\n"
"ip route del default via 10.205.6.1 table mytable\n"
"ip route flush table mytable\n"
"ip rule del table mytable\n"
"ip route flush cache\n"
),
},
{ # Test "all" in rules, and test a directly connected route
"input": [
{"type": "table", "table": "mytable"},
{
"type": "route",
"net": "1.1.2.0/24",
"device": "eth0",
"table": "mytable",
},
{
"type": "rule",
"from-net": "all",
"to-net": "1.1.2.1/32",
"priority": 100,
},
{
"type": "rule",
"from-net": "10.205.7.0/24",
"to-net": "all",
"table": "mytable",
"priority": 101,
},
],
"expected_ifup": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip route flush cache\n"
"# Table: name mytable\n"
"ip route replace 1.1.2.0/24 dev eth0 table mytable\n"
"ip rule add from all to 1.1.2.1/32 priority 100\n"
"ip rule add from 10.205.7.0/24 to all table mytable priority 101\n"
),
"expected_ifdown": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip rule del from 10.205.7.0/24 to all table mytable priority 101\n"
"ip rule del from all to 1.1.2.1/32 priority 100\n"
"ip route del 1.1.2.0/24 dev eth0 table mytable\n"
"ip route flush table mytable\n"
"ip rule del table mytable\n"
"ip route flush cache\n"
),
},
{ # Test a rule for a builtin table ("main")
"input": [
{"type": "table", "table": "main"},
{
"type": "rule",
"from-net": "10.205.7.0/24",
"to-net": "all",
"table": "main",
},
],
"expected_ifup": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip route flush cache\n"
"# Table: name main\n"
"ip rule add from 10.205.7.0/24 to all table main\n"
),
"expected_ifdown": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip rule del from 10.205.7.0/24 to all table main\n"
"# Skip removing builtin table main\n"
"ip route flush cache\n"
),
},
{
"input": [
{"type": "table", "table": "mytable"},
{"type": "route", "net": "1.1.2.0/24", "device": "eth0"},
{
"type": "rule",
"from-net": "all",
"to-net": "1.1.2.1/32",
"priority": 100,
},
{
"type": "rule",
"from-net": "10.205.7.0/24",
"to-net": "all",
"table": "mytable",
"priority": 101,
},
],
"expected_ifup": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip route flush cache\n"
"# Table: name mytable\n"
"ip route replace 1.1.2.0/24 dev eth0\n"
"ip rule add from all to 1.1.2.1/32 priority 100\n"
"ip rule add from 10.205.7.0/24 to all table mytable priority 101\n"
),
"expected_ifdown": (
"#!/bin/sh\n"
"# This file is managed by Juju.\n"
"ip rule del from 10.205.7.0/24 to all table mytable priority 101\n"
"ip rule del from all to 1.1.2.1/32 priority 100\n"
"ip route del 1.1.2.0/24 dev eth0\n"
"ip route flush table mytable\n"
"ip rule del table mytable\n"
"ip route flush cache\n"
),
},
]