70
70
],
71
71
"valid-lifetime" : 900 ,
72
72
"reservations" : []
73
+ },
74
+ {
75
+ "id" : 4000 ,
76
+ "subnet" : "192.168.3.0/24" ,
77
+ "pools" : [
78
+ {
79
+ "pool" : "192.168.3.2 - 192.168.3.3" ,
80
+ "client-class" : "sonic-host:etp11"
81
+ }
82
+ ],
83
+ "option-data" : [
84
+ {
85
+ "name" : "dhcp-server-identifier" ,
86
+ "data" : "192.168.3.1"
87
+ }
88
+ ],
89
+ "valid-lifetime" : 900 ,
90
+ "reservations" : []
73
91
}
74
92
],
75
93
"loggers" : [
93
111
{
94
112
"name" : "sonic-host:etp7" ,
95
113
"test" : "substring(relay4[1].hex, -15, 15) == 'sonic-host:etp7'"
114
+ },
115
+ {
116
+ "name" : "sonic-host:etp11" ,
117
+ "test" : "substring(relay4[1].hex, -16, 16) == 'sonic-host:etp11'"
96
118
}
97
119
]
98
120
}
99
121
}
100
122
expected_dhcp_config_without_port_config = {
101
123
"Dhcp4" : {
124
+ "option-def" : [
125
+ {
126
+ "name" : "option223" ,
127
+ "code" : 223 ,
128
+ "type" : "string"
129
+ }
130
+ ],
102
131
"hooks-libraries" : [
103
132
{
104
133
"library" : "/usr/local/lib/kea/hooks/libdhcp_run_script.so" ,
194
223
"value" : "dummy_value"
195
224
}
196
225
}
226
+ },
227
+ {
228
+ "subnet" : "192.168.3.0/24" , 'id' : '4000' ,
229
+ "pools" : [{"range" : "192.168.3.2 - 192.168.3.3" , "client_class" : "sonic-host:etp11" }],
230
+ "server_id" : "192.168.3.1" , "lease_time" : "900" ,
231
+ "customized_options" : {
232
+ "option223" : {
233
+ "always_send" : "true" ,
234
+ "value" : "dummy_value"
235
+ }
236
+ }
197
237
}
198
238
],
199
239
"client_classes" : [
200
240
{"name" : "sonic-host:etp8" , "condition" : "substring(relay4[1].hex, -15, 15) == 'sonic-host:etp8'" },
201
- {"name" : "sonic-host:etp7" , "condition" : "substring(relay4[1].hex, -15, 15) == 'sonic-host:etp7'" }
241
+ {"name" : "sonic-host:etp7" , "condition" : "substring(relay4[1].hex, -15, 15) == 'sonic-host:etp7'" },
242
+ {"name" : "sonic-host:etp11" , "condition" : "substring(relay4[1].hex, -16, 16) == 'sonic-host:etp11'" }
202
243
],
203
244
"lease_update_script_path" : "/etc/kea/lease_update.sh" ,
204
245
"lease_path" : "/tmp/kea-lease.csv" ,
238
279
"id" : "218" ,
239
280
"type" : "string" ,
240
281
"value" : "long_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_value" +
241
- "long_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_value" +
242
- "long_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_value" +
243
- "long_valuelong_valuelong_valuelong_valuelong_value"
282
+ "long_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_value" +
283
+ "long_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_valuelong_value" +
284
+ "long_valuelong_valuelong_valuelong_valuelong_value"
244
285
},
245
286
"option217" : {
246
287
"id" : "217" ,
@@ -359,6 +400,11 @@ def test_construct_obj_for_template(mock_swsscommon_dbconnector_init, mock_parse
359
400
"etp9" : []
360
401
}
361
402
},
403
+ "Vlan4000" : {
404
+ "192.168.3.1/24" : {
405
+ "etp11" : [["192.168.3.2" , "192.168.3.3" ]]
406
+ }
407
+ },
362
408
"Vlan6000" : {
363
409
}
364
410
}
@@ -374,25 +420,29 @@ def test_construct_obj_for_template(mock_swsscommon_dbconnector_init, mock_parse
374
420
@pytest .mark .parametrize ("with_port_config" , [True , False ])
375
421
@pytest .mark .parametrize ("with_option_config" , [True , False ])
376
422
def test_render_config (mock_swsscommon_dbconnector_init , mock_parse_port_map_alias , with_port_config ,
377
- with_option_config ):
423
+ with_option_config , request ):
378
424
dhcp_db_connector = DhcpDbConnector ()
379
425
dhcp_cfg_generator = DhcpServCfgGenerator (dhcp_db_connector , "/usr/local/lib/kea/hooks/libdhcp_run_script.so" ,
380
426
kea_conf_template_path = "tests/test_data/kea-dhcp4.conf.j2" )
381
427
render_obj = copy .deepcopy (expected_render_obj )
382
- expected_config = copy .deepcopy (expected_dhcp_config )
383
428
if not with_port_config :
384
429
render_obj ["client_classes" ] = []
385
430
render_obj ["subnets" ] = []
386
- elif not with_option_config :
387
- render_obj ["subnets" ][0 ]["customized_options" ] = {}
431
+ expected_config = copy .deepcopy (expected_dhcp_config_without_port_config )
432
+ else :
433
+ expected_config = copy .deepcopy (expected_dhcp_config )
434
+ if not with_option_config :
435
+ for i in range (len (expected_config ["Dhcp4" ]["subnet4" ])):
436
+ render_obj ["subnets" ][i ]["customized_options" ] = {}
437
+ else :
438
+ for i in range (len (expected_config ["Dhcp4" ]["subnet4" ])):
439
+ expected_config ["Dhcp4" ]["subnet4" ][i ]["option-data" ].insert (0 , {
440
+ "name" : "option223" ,
441
+ "data" : "dummy_value" ,
442
+ "always-send" : True
443
+ })
388
444
config = dhcp_cfg_generator ._render_config (render_obj )
389
- if with_option_config :
390
- expected_config ["Dhcp4" ]["subnet4" ][0 ]["option-data" ].insert (0 , {
391
- "name" : "option223" ,
392
- "data" : "dummy_value" ,
393
- "always-send" : True
394
- })
395
- assert json .loads (config ) == expected_config if with_port_config else expected_config
445
+ assert json .loads (config ) == expected_config
396
446
397
447
398
448
def test_parse_customized_options (mock_swsscommon_dbconnector_init , mock_get_render_template ,
0 commit comments