@@ -408,9 +408,66 @@ def setup_class(cls):
408
408
print ("SETUP" )
409
409
import config .main
410
410
importlib .reload (config .main )
411
- open (cls .dummy_cfg_file , 'w' ).close ()
411
+
412
+ def add_sysinfo_to_cfg_file (self ):
413
+ with open (self .dummy_cfg_file , 'w' ) as f :
414
+ device_metadata = {
415
+ "DEVICE_METADATA" : {
416
+ "localhost" : {
417
+ "platform" : "some_platform" ,
418
+ "mac" : "02:42:f0:7f:01:05"
419
+ }
420
+ }
421
+ }
422
+ f .write (json .dumps (device_metadata ))
423
+
424
+ def test_reload_config_invalid_input (self , get_cmd_module , setup_single_broadcom_asic ):
425
+ open (self .dummy_cfg_file , 'w' ).close ()
426
+ with mock .patch (
427
+ "utilities_common.cli.run_command" ,
428
+ mock .MagicMock (side_effect = mock_run_command_side_effect )
429
+ ) as mock_run_command :
430
+ (config , show ) = get_cmd_module
431
+ runner = CliRunner ()
432
+
433
+ result = runner .invoke (
434
+ config .config .commands ["reload" ],
435
+ [self .dummy_cfg_file , '-y' , '-f' ])
436
+
437
+ print (result .exit_code )
438
+ print (result .output )
439
+ traceback .print_tb (result .exc_info [2 ])
440
+ assert result .exit_code != 0
441
+
442
+ def test_reload_config_no_sysinfo (self , get_cmd_module , setup_single_broadcom_asic ):
443
+ with open (self .dummy_cfg_file , 'w' ) as f :
444
+ device_metadata = {
445
+ "DEVICE_METADATA" : {
446
+ "localhost" : {
447
+ "hwsku" : "some_hwsku"
448
+ }
449
+ }
450
+ }
451
+ f .write (json .dumps (device_metadata ))
452
+
453
+ with mock .patch (
454
+ "utilities_common.cli.run_command" ,
455
+ mock .MagicMock (side_effect = mock_run_command_side_effect )
456
+ ) as mock_run_command :
457
+ (config , show ) = get_cmd_module
458
+ runner = CliRunner ()
459
+
460
+ result = runner .invoke (
461
+ config .config .commands ["reload" ],
462
+ [self .dummy_cfg_file , '-y' , '-f' ])
463
+
464
+ print (result .exit_code )
465
+ print (result .output )
466
+ traceback .print_tb (result .exc_info [2 ])
467
+ assert result .exit_code == 0
412
468
413
469
def test_reload_config (self , get_cmd_module , setup_single_broadcom_asic ):
470
+ self .add_sysinfo_to_cfg_file ()
414
471
with mock .patch (
415
472
"utilities_common.cli.run_command" ,
416
473
mock .MagicMock (side_effect = mock_run_command_side_effect )
@@ -430,6 +487,7 @@ def test_reload_config(self, get_cmd_module, setup_single_broadcom_asic):
430
487
== RELOAD_CONFIG_DB_OUTPUT
431
488
432
489
def test_config_reload_disabled_service (self , get_cmd_module , setup_single_broadcom_asic ):
490
+ self .add_sysinfo_to_cfg_file ()
433
491
with mock .patch (
434
492
"utilities_common.cli.run_command" ,
435
493
mock .MagicMock (side_effect = mock_run_command_side_effect_disabled_timer )
@@ -449,6 +507,7 @@ def test_config_reload_disabled_service(self, get_cmd_module, setup_single_broad
449
507
assert "\n " .join ([l .rstrip () for l in result .output .split ('\n ' )]) == reload_config_with_disabled_service_output
450
508
451
509
def test_reload_config_masic (self , get_cmd_module , setup_multi_broadcom_masic ):
510
+ self .add_sysinfo_to_cfg_file ()
452
511
with mock .patch (
453
512
"utilities_common.cli.run_command" ,
454
513
mock .MagicMock (side_effect = mock_run_command_side_effect )
0 commit comments