author | Tero Marttila <terom@fixme.fi> |
Thu, 02 Apr 2009 22:52:26 +0300 | |
changeset 4 | 8b633782f02d |
parent 3 | ff98fa9b84ce |
permissions | -rwxr-xr-x |
1
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
1 |
#!/usr/bin/env python2.5 |
0 | 2 |
""" |
4 | 3 |
Test dhcp_conf |
0 | 4 |
""" |
5 |
||
4 | 6 |
import dhcp_conf as dhcpc |
7 |
import test_conf, dhcp, addr |
|
0 | 8 |
|
9 |
import unittest |
|
10 |
||
4 | 11 |
class TestDHCPConf (test_conf._TestConfBase) : |
0 | 12 |
def assert_stmt (self, stmt, line) : |
13 |
""" |
|
2
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
14 |
Formats the given Statement, and compares the output against the given line. |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
15 |
|
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
16 |
Note that the dhcpc.Statement doesn't have a working fmt_lines implementation. |
0 | 17 |
""" |
18 |
||
19 |
self.assertEqual(stmt._fmt_data(), line) |
|
20 |
||
2
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
21 |
def test_comment (self) : |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
22 |
self.assert_obj(dhcpc.Comment("foo bar"), [ "# foo bar" ]) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
23 |
|
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
24 |
def test_section (self) : |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
25 |
self.assert_obj(dhcpc.Section(comment="test"), [ "# test" ]) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
26 |
|
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
27 |
self.assert_obj(dhcpc.Section(params=[ |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
28 |
dhcpc.Parameter("param0"), None |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
29 |
], comment="foo"), [ |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
30 |
"# foo", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
31 |
"param0;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
32 |
]) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
33 |
|
0 | 34 |
def test_statement (self) : |
35 |
self.assert_stmt(dhcpc.Statement("stmt0"), "stmt0") |
|
1
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
36 |
self.assert_stmt(dhcpc.Statement("stmt1", [ "this", "that" ]), "stmt1 this, that") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
37 |
self.assert_stmt(dhcpc.Statement("stmt2", dhcpc.Literal("...")), "stmt2 ...") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
38 |
self.assert_stmt(dhcpc.Statement("stmt3", u"quux"), "stmt3 quux") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
39 |
self.assert_stmt(dhcpc.Statement("stmt4", "bar"), "stmt4 bar") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
40 |
self.assert_stmt(dhcpc.Statement("stmt5", 1), "stmt5 1") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
41 |
self.assert_stmt(dhcpc.Statement("stmt6", 1, None, 2), "stmt6 1 2") |
2
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
42 |
|
0 | 43 |
def test_literal (self) : |
44 |
self.assert_obj(dhcpc.Literal("///"), [ "///" ]) |
|
45 |
||
46 |
def test_parameter (self) : |
|
47 |
self.assert_obj(dhcpc.Parameter("param0", "this", 13, "that"), [ "param0 this 13 that;" ]) |
|
3 | 48 |
self.assert_obj(dhcpc.Parameter("param1", comment="testing"), [ "# testing", "param1;" ]) |
0 | 49 |
|
50 |
def test_declaration (self) : |
|
51 |
self.assert_obj(dhcpc.Declaration("decl0", ["arg0", "arg1"], [ |
|
1
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
52 |
dhcpc.Parameter("param0"), |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
53 |
None |
0 | 54 |
], [ |
55 |
dhcpc.Declaration("decl0.0", params=[ |
|
56 |
dhcpc.Parameter("param0.0.1", "value") |
|
57 |
]) |
|
3 | 58 |
], comment="foo"), [ |
59 |
"# foo", |
|
0 | 60 |
"decl0 arg0 arg1 {", |
61 |
"\tparam0;", |
|
62 |
"\tdecl0.0 {", |
|
63 |
"\t\tparam0.0.1 value;", |
|
64 |
"\t}", |
|
65 |
"}", |
|
66 |
]) |
|
67 |
||
68 |
def test_shared_network (self) : |
|
69 |
self.assert_obj(dhcpc.SharedNetwork("net0", params=[ |
|
70 |
dhcpc.Parameter("param0") |
|
71 |
]), [ |
|
72 |
"shared-network net0 {", |
|
73 |
"\tparam0;", |
|
74 |
"}" |
|
75 |
]) |
|
76 |
||
77 |
def test_subnet (self) : |
|
78 |
self.assert_obj(dhcpc.Subnet(addr.Network("194.197.235.0/24"), params=[ |
|
79 |
dhcpc.Parameter("param0") |
|
80 |
]), [ |
|
81 |
"subnet 194.197.235.0 netmask 255.255.255.0 {", |
|
82 |
"\tparam0;", |
|
83 |
"}" |
|
84 |
]) |
|
85 |
||
86 |
def test_group (self) : |
|
87 |
self.assert_obj(dhcpc.Group(decls=[ |
|
88 |
dhcpc.Declaration("decl0.0", params=[ |
|
89 |
dhcpc.Parameter("param0.0.1", "value") |
|
90 |
]) |
|
91 |
]), [ |
|
92 |
"group {", |
|
93 |
"\tdecl0.0 {", |
|
94 |
"\t\tparam0.0.1 value;", |
|
95 |
"\t}", |
|
96 |
"}" |
|
97 |
]) |
|
98 |
||
99 |
def test_host (self) : |
|
100 |
self.assert_obj(dhcpc.Host("test-hostname", params=[ |
|
101 |
dhcpc.Parameter("param0") |
|
102 |
]), [ |
|
103 |
"host test-hostname {", |
|
104 |
"\tparam0;", |
|
105 |
"}" |
|
106 |
]) |
|
107 |
||
108 |
def test_option (self) : |
|
109 |
self.assert_obj(dhcpc.Option("foo", "example.com"), [ |
|
110 |
"option foo example.com;", |
|
111 |
]) |
|
112 |
||
2
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
113 |
class TestDHCP (_TestConfObj) : |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
114 |
def test_host (self) : |
4 | 115 |
self.assert_obj(dhcp.Host("testhost", addr.MAC("12:34:56:78:90:ab"), addr.IP("1.2.3.4"), comment="foo"), [ |
116 |
"# foo", |
|
2
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
117 |
"host testhost {", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
118 |
"\thardware ethernet 12:34:56:78:90:ab;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
119 |
"\tfixed-address 1.2.3.4;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
120 |
"}" |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
121 |
]) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
122 |
|
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
123 |
def test_subnet (self) : |
4 | 124 |
self.assert_obj(dhcp.Subnet(addr.Network("1.2.3.0/24"), comment="bar"), [ |
125 |
"# bar", |
|
2
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
126 |
"subnet 1.2.3.0 netmask 255.255.255.0 {", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
127 |
"\toption routers 1.2.3.1;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
128 |
"}" |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
129 |
]) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
130 |
|
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
131 |
self.assert_obj(dhcp.Subnet(addr.Network("1.2.3.0/24"), router_idx=10, range=(20, 30), unknown_clients='allow'), [ |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
132 |
"subnet 1.2.3.0 netmask 255.255.255.0 {", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
133 |
"\toption routers 1.2.3.10;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
134 |
"\trange 1.2.3.20 1.2.3.30;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
135 |
"\tallow unknown-clients;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
136 |
"}" |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
137 |
]) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
138 |
|
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
139 |
def test_config (self) : |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
140 |
self.assert_obj(dhcp.Config( |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
141 |
settings = { 'foo-setting': 'someval' }, |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
142 |
options = { 'bar-opt': ['one', 'two'] }, |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
143 |
shared_network = "FOO-NET", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
144 |
subnets = [ |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
145 |
dhcp.Subnet(addr.Network("1.2.3.0/24")) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
146 |
], |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
147 |
hosts = [ |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
148 |
dhcp.Host("testhost", addr.MAC("12:34:56:78:90:ab"), addr.IP("1.2.3.4")) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
149 |
], |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
150 |
), [ |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
151 |
"foo-setting someval;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
152 |
"option bar-opt one, two;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
153 |
"shared-network FOO-NET {", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
154 |
"\tsubnet 1.2.3.0 netmask 255.255.255.0 {", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
155 |
"\t\toption routers 1.2.3.1;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
156 |
"\t}", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
157 |
"}", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
158 |
"host testhost {", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
159 |
"\thardware ethernet 12:34:56:78:90:ab;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
160 |
"\tfixed-address 1.2.3.4;", |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
161 |
"}" |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
162 |
]) |
e66102ab7048
fix up data.load_py, and make conf.File be a ConfObject itself - implement this for dhcp_conf
Tero Marttila <terom@fixme.fi>
parents:
1
diff
changeset
|
163 |
|
0 | 164 |
if __name__ == '__main__' : |
165 |
unittest.main() |
|
166 |