@@ -987,8 +987,13 @@ def is_file_side_effect(filename):
987
987
def test_load_minigraph_with_specified_golden_config_path (self , get_cmd_module ):
988
988
def is_file_side_effect (filename ):
989
989
return True if 'golden_config' in filename else False
990
+
991
+ def read_json_file_side_effect (filename ):
992
+ return {}
993
+
990
994
with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command , \
991
- mock .patch ('os.path.isfile' , mock .MagicMock (side_effect = is_file_side_effect )):
995
+ mock .patch ('os.path.isfile' , mock .MagicMock (side_effect = is_file_side_effect )), \
996
+ mock .patch ('config.main.read_json_file' , mock .MagicMock (side_effect = read_json_file_side_effect )):
992
997
(config , show ) = get_cmd_module
993
998
runner = CliRunner ()
994
999
result = runner .invoke (config .config .commands ["load_minigraph" ], ["--override_config" , "--golden_config_path" , "golden_config.json" , "-y" ])
@@ -999,14 +1004,48 @@ def is_file_side_effect(filename):
999
1004
def test_load_minigraph_with_default_golden_config_path (self , get_cmd_module ):
1000
1005
def is_file_side_effect (filename ):
1001
1006
return True if 'golden_config' in filename else False
1007
+
1008
+ def read_json_file_side_effect (filename ):
1009
+ return {}
1010
+
1002
1011
with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command , \
1003
- mock .patch ('os.path.isfile' , mock .MagicMock (side_effect = is_file_side_effect )):
1012
+ mock .patch ('os.path.isfile' , mock .MagicMock (side_effect = is_file_side_effect )), \
1013
+ mock .patch ('config.main.read_json_file' , mock .MagicMock (side_effect = read_json_file_side_effect )):
1004
1014
(config , show ) = get_cmd_module
1005
1015
runner = CliRunner ()
1006
1016
result = runner .invoke (config .config .commands ["load_minigraph" ], ["--override_config" , "-y" ])
1007
1017
assert result .exit_code == 0
1008
1018
assert "config override-config-table /etc/sonic/golden_config_db.json" in result .output
1009
1019
1020
+ @mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' ,
1021
+ mock .MagicMock (return_value = ("dummy_path" , None )))
1022
+ def test_load_minigraph_hard_dependency_check (self , get_cmd_module ):
1023
+ def is_file_side_effect (filename ):
1024
+ return True if 'golden_config' in filename else False
1025
+
1026
+ def read_json_file_side_effect (filename ):
1027
+ return {
1028
+ "AAA" : {
1029
+ "authentication" : {
1030
+ "login" : "tacacs+"
1031
+ }
1032
+ },
1033
+ "TACPLUS" : {
1034
+ "global" : {
1035
+ "passkey" : ""
1036
+ }
1037
+ }
1038
+ }
1039
+
1040
+ with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )), \
1041
+ mock .patch ('os.path.isfile' , mock .MagicMock (side_effect = is_file_side_effect )), \
1042
+ mock .patch ('config.main.read_json_file' , mock .MagicMock (side_effect = read_json_file_side_effect )):
1043
+ (config , _ ) = get_cmd_module
1044
+ runner = CliRunner ()
1045
+ result = runner .invoke (config .config .commands ["load_minigraph" ], ["--override_config" , "-y" ])
1046
+ assert result .exit_code != 0
1047
+ assert "Authentication with 'tacacs+' is not allowed when passkey not exits." in result .output
1048
+
1010
1049
@mock .patch ('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs' , mock .MagicMock (return_value = ("dummy_path" , None )))
1011
1050
def test_load_minigraph_with_traffic_shift_away (self , get_cmd_module ):
1012
1051
with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
@@ -1024,7 +1063,12 @@ def test_load_minigraph_with_traffic_shift_away_with_golden_config(self, get_cmd
1024
1063
with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
1025
1064
def is_file_side_effect (filename ):
1026
1065
return True if 'golden_config' in filename else False
1027
- with mock .patch ('os.path.isfile' , mock .MagicMock (side_effect = is_file_side_effect )):
1066
+
1067
+ def read_json_file_side_effect (filename ):
1068
+ return {}
1069
+
1070
+ with mock .patch ('os.path.isfile' , mock .MagicMock (side_effect = is_file_side_effect )), \
1071
+ mock .patch ('config.main.read_json_file' , mock .MagicMock (side_effect = read_json_file_side_effect )):
1028
1072
(config , show ) = get_cmd_module
1029
1073
db = Db ()
1030
1074
golden_config = {}
0 commit comments