Skip to content

Commit b83d2bf

Browse files
authored
[minigraph][port_config] Use imported config.main and add conditional patch (sonic-net#1724)
Signed-off-by: Jing Kan [email protected]
1 parent acb5d84 commit b83d2bf

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

tests/config_test.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -57,50 +57,54 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
5757
assert "\n".join([l.rstrip() for l in result.output.split('\n')]) == load_minigraph_command_output
5858
assert mock_run_command.call_count == 7
5959

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):
6161
with mock.patch(
6262
"utilities_common.cli.run_command",
6363
mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
64+
(config, show) = get_cmd_module
6465

6566
# Not in an array
6667
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")
6869

6970
# No PORT table
7071
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")
7273

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):
7475
with mock.patch(
7576
"utilities_common.cli.run_command",
7677
mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
78+
(config, show) = get_cmd_module
79+
7780
db = Db()
7881
db.cfgdb.set_entry("PORT", "Ethernet1", {"admin_status": "up"})
7982
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")
8184

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):
8386
with mock.patch(
8487
"utilities_common.cli.run_command",
8588
mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
89+
(config, show) = get_cmd_module
8690
db = Db()
8791

8892
# From up to down
8993
db.cfgdb.set_entry("PORT", "Ethernet0", {"admin_status": "up"})
9094
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")
9296

9397
# From down to up
9498
db.cfgdb.set_entry("PORT", "Ethernet0", {"admin_status": "down"})
9599
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")
97101

98-
def check_port_config(self, db, port_config, expected_output):
102+
def check_port_config(self, db, config, port_config, expected_output):
99103
def read_json_file_side_effect(filename):
100104
return port_config
101105
with mock.patch('config.main.read_json_file', mock.MagicMock(side_effect=read_json_file_side_effect)):
102106
def is_file_side_effect(filename):
103-
return True
107+
return True if 'port_config' in filename else False
104108
with mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
105109
runner = CliRunner()
106110
result = runner.invoke(config.config.commands["load_minigraph"], ["-y"], obj=db)

0 commit comments

Comments
 (0)