@@ -114,27 +114,7 @@ def test_dhcp_single_pool_range(self):
114114 range_1_start = inc_ip (subnet , 40 )
115115 range_1_stop = inc_ip (subnet , 50 )
116116
117- self .cli_set (base_path + ['listen-interface' , interface ])
118-
119- self .cli_set (base_path + ['shared-network-name' , shared_net_name , 'ping-check' ])
120-
121- pool = base_path + ['shared-network-name' , shared_net_name , 'subnet' , subnet ]
122- self .cli_set (pool + ['subnet-id' , '1' ])
123- self .cli_set (pool + ['ignore-client-id' ])
124- self .cli_set (pool + ['ping-check' ])
125- # we use the first subnet IP address as default gateway
126- self .cli_set (pool + ['option' , 'default-router' , router ])
127- self .cli_set (pool + ['option' , 'name-server' , dns_1 ])
128- self .cli_set (pool + ['option' , 'name-server' , dns_2 ])
129- self .cli_set (pool + ['option' , 'domain-name' , domain_name ])
130-
131- # check validate() - No DHCP address range or active static-mapping set
132- with self .assertRaises (ConfigSessionError ):
133- self .cli_commit ()
134- self .cli_set (pool + ['range' , '0' , 'start' , range_0_start ])
135- self .cli_set (pool + ['range' , '0' , 'stop' , range_0_stop ])
136- self .cli_set (pool + ['range' , '1' , 'start' , range_1_start ])
137- self .cli_set (pool + ['range' , '1' , 'stop' , range_1_stop ])
117+ self .setup_single_pool_range (range_0_start , range_0_stop , range_1_start , range_1_stop , shared_net_name )
138118
139119 # commit changes
140120 self .cli_commit ()
@@ -211,6 +191,112 @@ def test_dhcp_single_pool_range(self):
211191 # Check for running process
212192 self .verify_service_running ()
213193
194+ def setup_single_pool_range (self , range_0_start , range_0_stop , range_1_start , range_1_stop , shared_net_name ):
195+ self .cli_set (base_path + ['listen-interface' , interface ])
196+ self .cli_set (base_path + ['shared-network-name' , shared_net_name , 'ping-check' ])
197+
198+ pool = base_path + ['shared-network-name' , shared_net_name , 'subnet' , subnet ]
199+
200+ self .cli_set (pool + ['subnet-id' , '1' ])
201+ self .cli_set (pool + ['ignore-client-id' ])
202+ self .cli_set (pool + ['ping-check' ])
203+ # we use the first subnet IP address as default gateway
204+ self .cli_set (pool + ['option' , 'default-router' , router ])
205+ self .cli_set (pool + ['option' , 'name-server' , dns_1 ])
206+ self .cli_set (pool + ['option' , 'name-server' , dns_2 ])
207+ self .cli_set (pool + ['option' , 'domain-name' , domain_name ])
208+
209+ # check validate() - No DHCP address range or active static-mapping set
210+ with self .assertRaises (ConfigSessionError ):
211+ self .cli_commit ()
212+
213+ self .cli_set (pool + ['range' , '0' , 'start' , range_0_start ])
214+ self .cli_set (pool + ['range' , '0' , 'stop' , range_0_stop ])
215+ self .cli_set (pool + ['range' , '1' , 'start' , range_1_start ])
216+ self .cli_set (pool + ['range' , '1' , 'stop' , range_1_stop ])
217+
218+ def test_dhcp_client_class (self ):
219+ shared_net_name = 'SMOKE-1'
220+
221+ range_0_start = inc_ip (subnet , 10 )
222+ range_0_stop = inc_ip (subnet , 20 )
223+ range_1_start = inc_ip (subnet , 40 )
224+ range_1_stop = inc_ip (subnet , 50 )
225+
226+ self .setup_single_pool_range (range_0_start , range_0_stop , range_1_start , range_1_stop , shared_net_name )
227+
228+ self .cli_set (base_path + ['shared-network-name' , shared_net_name , 'subnet' , subnet , 'client-class' , 'test' ])
229+
230+ # check validate() - Client class referenced that doesn't exist yet
231+ with self .assertRaises (ConfigSessionError ):
232+ self .cli_commit ()
233+
234+ self .cli_delete (base_path + ['shared-network-name' , shared_net_name , 'subnet' , subnet , 'client-class' , 'test' ])
235+
236+ self .cli_set (base_path + ['shared-network-name' , shared_net_name , 'subnet' , subnet , 'range' , '0' , 'client-class' , 'test' ])
237+
238+ # check validate() - Client class referenced that doesn't exist yet
239+ with self .assertRaises (ConfigSessionError ):
240+ self .cli_commit ()
241+
242+ self .cli_set (base_path + ['shared-network-name' , shared_net_name , 'subnet' , subnet , 'client-class' , 'test' ])
243+
244+ client_class = base_path + ['client-class' , 'test' ]
245+
246+ # Test that invalid hex is rejected
247+ self .cli_set (client_class + ['relay-agent-information' , 'circuit-id' , '0xHELLOWORLD' ])
248+
249+ with self .assertRaises (ConfigSessionError ):
250+ self .cli_commit ()
251+
252+ self .cli_delete (client_class + ['relay-agent-information' , 'circuit-id' ])
253+ self .cli_set (client_class + ['relay-agent-information' , 'remote-id' , '0xHELLOWORLD' ])
254+
255+ with self .assertRaises (ConfigSessionError ):
256+ self .cli_commit ()
257+
258+ self .cli_delete (client_class + ['relay-agent-information' , 'remote-id' ])
259+
260+ # Test string literals
261+ self .cli_set (client_class + ['relay-agent-information' , 'circuit-id' , 'foo' ])
262+ self .cli_set (client_class + ['relay-agent-information' , 'remote-id' , 'bar' ])
263+
264+ self .cli_commit ()
265+
266+ self .check_client_class_in_config ()
267+
268+ self .cli_delete (client_class + ['relay-agent-information' , 'circuit-id' ])
269+ self .cli_delete (client_class + ['relay-agent-information' , 'remote-id' ])
270+
271+ # Test hex strings
272+ self .cli_set (client_class + ['relay-agent-information' , 'circuit-id' , '0x666f6f' ])
273+ self .cli_set (client_class + ['relay-agent-information' , 'remote-id' , '0x626172' ])
274+
275+ self .cli_commit ()
276+
277+ self .check_client_class_in_config ()
278+
279+ def check_client_class_in_config (self ):
280+ config = read_file (KEA4_CONF )
281+ obj = loads (config )
282+ self .verify_config_value (
283+ obj , ['Dhcp4' , 'client-classes' , 0 ], 'name' , 'test'
284+ )
285+ self .verify_config_value (
286+ obj , ['Dhcp4' , 'client-classes' , 0 ], 'test' ,
287+ 'relay4[1].hex == 0x666f6f and relay4[2].hex == 0x626172'
288+ )
289+ self .verify_config_value (
290+ obj , ['Dhcp4' , 'shared-networks' , 0 , 'subnet4' , 0 ], 'client-class' ,
291+ 'test'
292+ )
293+ self .verify_config_value (
294+ obj , ['Dhcp4' , 'shared-networks' , 0 , 'subnet4' , 0 , 'pools' , 0 ],
295+ 'client-class' , 'test'
296+ )
297+ # Check for running process
298+ self .verify_service_running ()
299+
214300 def test_dhcp_single_pool_options (self ):
215301 shared_net_name = 'SMOKE-0815'
216302
0 commit comments