36
36
# Config Reload input Path
37
37
mock_db_path = os .path .join (test_path , "config_reload_input" )
38
38
39
+ # Load minigraph input Path
40
+ load_minigraph_input_path = os .path .join (test_path , "load_minigraph_input" )
41
+ load_minigraph_platform_path = os .path .join (load_minigraph_input_path , "platform" )
42
+ load_minigraph_platform_false_path = os .path .join (load_minigraph_input_path , "platform_false" )
39
43
40
44
load_minigraph_command_output = """\
41
45
Stopping SONiC target ...
47
51
Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`.
48
52
"""
49
53
54
+ load_minigraph_platform_plugin_command_output = """\
55
+ Stopping SONiC target ...
56
+ Running command: /usr/local/bin/sonic-cfggen -H -m --write-to-db
57
+ Running command: config qos reload --no-dynamic-buffer --no-delay
58
+ Running command: pfcwd start_default
59
+ Running Platform plugin ............!
60
+ Restarting SONiC target ...
61
+ Reloading Monit configuration ...
62
+ Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`.
63
+ """
64
+
50
65
load_mgmt_config_command_ipv4_only_output = """\
51
66
Running command: /usr/local/bin/sonic-cfggen -M device_desc.xml --write-to-db
52
67
parse dummy device_desc.xml
@@ -253,6 +268,7 @@ def setup_class(cls):
253
268
import config .main
254
269
importlib .reload (config .main )
255
270
271
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
256
272
def test_load_minigraph (self , get_cmd_module , setup_single_broadcom_asic ):
257
273
with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
258
274
(config , show ) = get_cmd_module
@@ -267,6 +283,35 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
267
283
mock_run_command .assert_any_call ('systemctl reset-failed swss' )
268
284
assert mock_run_command .call_count == 8
269
285
286
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = (load_minigraph_platform_path , None )))
287
+ def test_load_minigraph_platform_plugin (self , get_cmd_module , setup_single_broadcom_asic ):
288
+ with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
289
+ (config , show ) = get_cmd_module
290
+ runner = CliRunner ()
291
+ result = runner .invoke (config .config .commands ["load_minigraph" ], ["-y" ])
292
+ print (result .exit_code )
293
+ print (result .output )
294
+ traceback .print_tb (result .exc_info [2 ])
295
+ assert result .exit_code == 0
296
+ assert "\n " .join ([l .rstrip () for l in result .output .split ('\n ' )]) == load_minigraph_platform_plugin_command_output
297
+ # Verify "systemctl reset-failed" is called for services under sonic.target
298
+ mock_run_command .assert_any_call ('systemctl reset-failed swss' )
299
+ assert mock_run_command .call_count == 8
300
+
301
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = (load_minigraph_platform_false_path , None )))
302
+ def test_load_minigraph_platform_plugin_fail (self , get_cmd_module , setup_single_broadcom_asic ):
303
+ print (load_minigraph_platform_false_path )
304
+ with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
305
+ (config , show ) = get_cmd_module
306
+ runner = CliRunner ()
307
+ result = runner .invoke (config .config .commands ["load_minigraph" ], ["-y" ])
308
+ print (result .exit_code )
309
+ print (result .output )
310
+ traceback .print_tb (result .exc_info [2 ])
311
+ assert result .exit_code != 0
312
+ assert "Platform plugin failed" in result .output
313
+
314
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
270
315
def test_load_minigraph_with_port_config_bad_format (self , get_cmd_module , setup_single_broadcom_asic ):
271
316
with mock .patch (
272
317
"utilities_common.cli.run_command" ,
@@ -281,6 +326,7 @@ def test_load_minigraph_with_port_config_bad_format(self, get_cmd_module, setup_
281
326
port_config = [{}]
282
327
self .check_port_config (None , config , port_config , "Failed to load port_config.json, Error: Bad format: PORT table not exists" )
283
328
329
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
284
330
def test_load_minigraph_with_port_config_inconsistent_port (self , get_cmd_module , setup_single_broadcom_asic ):
285
331
with mock .patch (
286
332
"utilities_common.cli.run_command" ,
@@ -292,6 +338,7 @@ def test_load_minigraph_with_port_config_inconsistent_port(self, get_cmd_module,
292
338
port_config = [{"PORT" : {"Eth1" : {"admin_status" : "up" }}}]
293
339
self .check_port_config (db , config , port_config , "Failed to load port_config.json, Error: Port Eth1 is not defined in current device" )
294
340
341
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
295
342
def test_load_minigraph_with_port_config (self , get_cmd_module , setup_single_broadcom_asic ):
296
343
with mock .patch (
297
344
"utilities_common.cli.run_command" ,
@@ -309,6 +356,7 @@ def test_load_minigraph_with_port_config(self, get_cmd_module, setup_single_broa
309
356
port_config = [{"PORT" : {"Ethernet0" : {"admin_status" : "up" }}}]
310
357
self .check_port_config (db , config , port_config , "config interface startup Ethernet0" )
311
358
359
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
312
360
def check_port_config (self , db , config , port_config , expected_output ):
313
361
def read_json_file_side_effect (filename ):
314
362
return port_config
@@ -323,6 +371,7 @@ def is_file_side_effect(filename):
323
371
assert result .exit_code == 0
324
372
assert expected_output in result .output
325
373
374
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
326
375
def test_load_minigraph_with_non_exist_golden_config_path (self , get_cmd_module ):
327
376
def is_file_side_effect (filename ):
328
377
return True if 'golden_config' in filename else False
@@ -334,6 +383,7 @@ def is_file_side_effect(filename):
334
383
assert result .exit_code != 0
335
384
assert "Cannot find 'non_exist.json'" in result .output
336
385
386
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
337
387
def test_load_minigraph_with_specified_golden_config_path (self , get_cmd_module ):
338
388
def is_file_side_effect (filename ):
339
389
return True if 'golden_config' in filename else False
@@ -345,6 +395,7 @@ def is_file_side_effect(filename):
345
395
assert result .exit_code == 0
346
396
assert "config override-config-table golden_config.json" in result .output
347
397
398
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
348
399
def test_load_minigraph_with_default_golden_config_path (self , get_cmd_module ):
349
400
def is_file_side_effect (filename ):
350
401
return True if 'golden_config' in filename else False
@@ -356,6 +407,7 @@ def is_file_side_effect(filename):
356
407
assert result .exit_code == 0
357
408
assert "config override-config-table /etc/sonic/golden_config_db.json" in result .output
358
409
410
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
359
411
def test_load_minigraph_with_traffic_shift_away (self , get_cmd_module ):
360
412
with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
361
413
(config , show ) = get_cmd_module
@@ -367,6 +419,7 @@ def test_load_minigraph_with_traffic_shift_away(self, get_cmd_module):
367
419
assert result .exit_code == 0
368
420
assert "TSA" in result .output
369
421
422
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
370
423
def test_load_minigraph_with_traffic_shift_away_with_golden_config (self , get_cmd_module ):
371
424
with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
372
425
def is_file_side_effect (filename ):
0 commit comments