|
4 | 4 | import signal |
5 | 5 | import psutil |
6 | 6 | import swsscommon as swsscommon_package |
| 7 | +from subprocess import CalledProcessError |
7 | 8 | from sonic_py_common import device_info |
8 | 9 | from swsscommon import swsscommon |
9 | 10 | from parameterized import parameterized |
@@ -324,6 +325,29 @@ def test_mgmtiface_event(self): |
324 | 325 | ] |
325 | 326 | mocked_check_output.assert_has_calls(expected) |
326 | 327 |
|
| 328 | + def test_mgmtvrf_route_check_failed(self): |
| 329 | + mgmtiface = hostcfgd.MgmtIfaceCfg() |
| 330 | + mgmtiface.load({}, {'mgmtVrfEnabled' : "false"}) |
| 331 | + with mock.patch('hostcfgd.check_output_pipe') as mocked_check_output: |
| 332 | + with mock.patch('hostcfgd.subprocess') as mocked_subprocess: |
| 333 | + popen_mock = mock.Mock() |
| 334 | + attrs = {'communicate.return_value': ('output', 'error')} |
| 335 | + popen_mock.configure_mock(**attrs) |
| 336 | + mocked_subprocess.Popen.return_value = popen_mock |
| 337 | + mocked_subprocess.CalledProcessError = CalledProcessError |
| 338 | + # Simulate the case where there is no default route |
| 339 | + mocked_check_output.side_effect = CalledProcessError(returncode=1, cmd="", output="") |
| 340 | + |
| 341 | + mgmtiface.update_mgmt_vrf({'mgmtVrfEnabled' : "true"}) |
| 342 | + expected = [ |
| 343 | + call(['cat', '/proc/net/route'], ['grep', '-E', r"eth0\s+00000000\s+[0-9A-Z]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+202"], ['wc', '-l']) |
| 344 | + ] |
| 345 | + mocked_check_output.assert_has_calls(expected) |
| 346 | + assert mgmtiface.mgmt_vrf_enabled == "true" |
| 347 | + |
| 348 | + mgmtiface.update_mgmt_vrf({'mgmtVrfEnabled' : "false"}) |
| 349 | + assert mgmtiface.mgmt_vrf_enabled == "false" |
| 350 | + |
327 | 351 | def test_dns_events(self): |
328 | 352 | MockConfigDb.set_config_db(HOSTCFG_DAEMON_CFG_DB) |
329 | 353 | MockConfigDb.event_queue = [('DNS_NAMESERVER', '1.1.1.1')] |
|
0 commit comments