@@ -57,50 +57,54 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
57
57
assert "\n " .join ([l .rstrip () for l in result .output .split ('\n ' )]) == load_minigraph_command_output
58
58
assert mock_run_command .call_count == 7
59
59
60
- def test_load_minigraph_with_port_config_bad_format (self , setup_single_broadcom_asic ):
60
+ def test_load_minigraph_with_port_config_bad_format (self , get_cmd_module , setup_single_broadcom_asic ):
61
61
with mock .patch (
62
62
"utilities_common.cli.run_command" ,
63
63
mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
64
+ (config , show ) = get_cmd_module
64
65
65
66
# Not in an array
66
67
port_config = {"PORT" : {"Ethernet0" : {"admin_status" : "up" }}}
67
- self .check_port_config (None , port_config , "Failed to load port_config.json, Error: Bad format: port_config is not an array" )
68
+ self .check_port_config (None , config , port_config , "Failed to load port_config.json, Error: Bad format: port_config is not an array" )
68
69
69
70
# No PORT table
70
71
port_config = [{}]
71
- self .check_port_config (None , port_config , "Failed to load port_config.json, Error: Bad format: PORT table not exists" )
72
+ self .check_port_config (None , config , port_config , "Failed to load port_config.json, Error: Bad format: PORT table not exists" )
72
73
73
- def test_load_minigraph_with_port_config_inconsistent_port (self , setup_single_broadcom_asic ):
74
+ def test_load_minigraph_with_port_config_inconsistent_port (self , get_cmd_module , setup_single_broadcom_asic ):
74
75
with mock .patch (
75
76
"utilities_common.cli.run_command" ,
76
77
mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
78
+ (config , show ) = get_cmd_module
79
+
77
80
db = Db ()
78
81
db .cfgdb .set_entry ("PORT" , "Ethernet1" , {"admin_status" : "up" })
79
82
port_config = [{"PORT" : {"Eth1" : {"admin_status" : "up" }}}]
80
- self .check_port_config (db , port_config , "Failed to load port_config.json, Error: Port Eth1 is not defined in current device" )
83
+ self .check_port_config (db , config , port_config , "Failed to load port_config.json, Error: Port Eth1 is not defined in current device" )
81
84
82
- def test_load_minigraph_with_port_config (self , setup_single_broadcom_asic ):
85
+ def test_load_minigraph_with_port_config (self , get_cmd_module , setup_single_broadcom_asic ):
83
86
with mock .patch (
84
87
"utilities_common.cli.run_command" ,
85
88
mock .MagicMock (side_effect = mock_run_command_side_effect )) as mock_run_command :
89
+ (config , show ) = get_cmd_module
86
90
db = Db ()
87
91
88
92
# From up to down
89
93
db .cfgdb .set_entry ("PORT" , "Ethernet0" , {"admin_status" : "up" })
90
94
port_config = [{"PORT" : {"Ethernet0" : {"admin_status" : "down" }}}]
91
- self .check_port_config (db , port_config , "config interface shutdown Ethernet0" )
95
+ self .check_port_config (db , config , port_config , "config interface shutdown Ethernet0" )
92
96
93
97
# From down to up
94
98
db .cfgdb .set_entry ("PORT" , "Ethernet0" , {"admin_status" : "down" })
95
99
port_config = [{"PORT" : {"Ethernet0" : {"admin_status" : "up" }}}]
96
- self .check_port_config (db , port_config , "config interface startup Ethernet0" )
100
+ self .check_port_config (db , config , port_config , "config interface startup Ethernet0" )
97
101
98
- def check_port_config (self , db , port_config , expected_output ):
102
+ def check_port_config (self , db , config , port_config , expected_output ):
99
103
def read_json_file_side_effect (filename ):
100
104
return port_config
101
105
with mock .patch ('config.main.read_json_file' , mock .MagicMock (side_effect = read_json_file_side_effect )):
102
106
def is_file_side_effect (filename ):
103
- return True
107
+ return True if 'port_config' in filename else False
104
108
with mock .patch ('os.path.isfile' , mock .MagicMock (side_effect = is_file_side_effect )):
105
109
runner = CliRunner ()
106
110
result = runner .invoke (config .config .commands ["load_minigraph" ], ["-y" ], obj = db )
0 commit comments