def set_handler_common(key, value, is_enabled, is_valid, has_no_push_cmd_errors, mocked_log_crit, mocked_log_info): cfg_mgr = MagicMock() common_objs = { 'directory': Directory(), 'cfg_mgr': cfg_mgr, 'tf': TemplateFabric(), 'constants': global_constants, } m = BBRMgr(common_objs, "CONFIG_DB", "BGP_BBR") m.enabled = is_enabled prepare_config_return_value = [[ "vtysh", "-c", "clear bgp peer-group PEER_V4 soft in" ], ["vtysh", "-c", "clear bgp peer-group PEER_V6 soft in"]] m._BBRMgr__set_prepare_config = MagicMock( return_value=prepare_config_return_value) m.cfg_mgr.push_list = MagicMock(return_value=has_no_push_cmd_errors) m._BBRMgr__restart_peers = MagicMock() res = m.set_handler(key, value) assert res, "Returns always True" if not is_enabled: mocked_log_info.assert_called_with( 'BBRMgr::BBR is disabled. Drop the request') else: if is_valid: m._BBRMgr__set_prepare_config.assert_called_once_with( value["status"]) m.cfg_mgr.push_list.assert_called_once_with( prepare_config_return_value) if has_no_push_cmd_errors: m._BBRMgr__restart_peers.assert_called_once() else: mocked_log_crit.assert_called_with( "BBRMgr::can't apply configuration") m._BBRMgr__restart_peers.assert_not_called() else: m._BBRMgr__set_prepare_config.assert_not_called() m.cfg_mgr.push_list.assert_not_called() m._BBRMgr__restart_peers.assert_not_called()
def set_handler_common(key, value, is_enabled, is_valid, mocked_log_info): cfg_mgr = MagicMock() common_objs = { 'directory': Directory(), 'cfg_mgr': cfg_mgr, 'tf': TemplateFabric(), 'constants': global_constants, } m = BBRMgr(common_objs, "CONFIG_DB", "BGP_BBR") m.enabled = is_enabled prepare_config_return_value = ([[ "vtysh", "-c", "clear bgp peer-group PEER_V4 soft in" ], ["vtysh", "-c", "clear bgp peer-group PEER_V6 soft in"]], ["PEER_V4", "PEER_V6"]) m._BBRMgr__set_prepare_config = MagicMock( return_value=prepare_config_return_value) m.cfg_mgr.push_list = MagicMock(return_value=None) m.cfg_mgr.restart_peer_groups = MagicMock( return_value=None) # FIXME: check for input res = m.set_handler(key, value) assert res, "Returns always True" if not is_enabled: mocked_log_info.assert_called_with( 'BBRMgr::BBR is disabled. Drop the request') else: if is_valid: m._BBRMgr__set_prepare_config.assert_called_once_with( value["status"]) m.cfg_mgr.push_list.assert_called_once_with( prepare_config_return_value[0]) m.cfg_mgr.restart_peer_groups.assert_called_once_with( prepare_config_return_value[1]) else: m._BBRMgr__set_prepare_config.assert_not_called() m.cfg_mgr.push_list.assert_not_called() m.cfg_mgr.restart_peer_groups.assert_not_called()