def __set_prepare_config_common(status, bbr_enabled_pgs, available_pgs, mapping_pgs, expected_cmds, bbr_applied_pgs=None): 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.directory.data = { "CONFIG_DB__DEVICE_METADATA": { "localhost": { "bgp_asn": "65500" } } } m.bbr_enabled_pgs = bbr_enabled_pgs m._BBRMgr__get_available_peer_groups = MagicMock( return_value=available_pgs) m._BBRMgr__get_available_peers_per_peer_group = MagicMock( return_value=mapping_pgs) cmds, peer_groups = m._BBRMgr__set_prepare_config(status) assert cmds == expected_cmds assert set(peer_groups) == (available_pgs if not bbr_applied_pgs else bbr_applied_pgs)
def __set_prepare_config_common(status, bbr_enabled_pgs, expected_cmds): 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.directory.data = { "CONFIG_DB__DEVICE_METADATA": { "localhost": { "bgp_asn": "65500" } } } m.bbr_enabled_pgs = bbr_enabled_pgs cmds = m._BBRMgr__set_prepare_config(status) assert cmds == expected_cmds
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()