Firebrick: Fix an issue which led to duplication of BGP peers. (#12932)
* Firebrick: Fix an issue which led to duplication of BGP peers. * Code style. * Attempt to get some sanity with BGP Table 0. * Attempt to make it so peers are not immediately added then deleted. * Force vrfId to Null if empty. * Another attempt at keeping the DB clean. * Code style. * Stop the dicovery deleting peers it just created.
This commit is contained in:
parent
b111ab6ff9
commit
b7d1420020
|
@ -33,8 +33,7 @@ foreach ($bgpPeersCache as $key => $value) {
|
|||
if (strlen($address) > 15) {
|
||||
$address = IP::fromHexString($address)->compressed();
|
||||
}
|
||||
|
||||
if (isset($value['fbBgpPeerTableId'])) {
|
||||
if (isset($value['fbBgpPeerTableId']) && $value['fbBgpPeerTableId'] !== '') {
|
||||
$bgpPeers[$value['fbBgpPeerTableId']][$address] = $value;
|
||||
} else {
|
||||
$bgpPeers[0][$address] = $value;
|
||||
|
@ -45,6 +44,8 @@ unset($bgpPeersCache);
|
|||
foreach ($bgpPeers as $vrfId => $vrf) {
|
||||
if (empty($vrfId)) {
|
||||
$checkVrf = ' AND `vrf_id` IS NULL ';
|
||||
// Force to null to avoid 0s going to the DB instead of Nulls
|
||||
$vrfId = null;
|
||||
} else {
|
||||
$checkVrf = ' AND vrf_id = ? ';
|
||||
$vrfs = [
|
||||
|
@ -93,19 +94,25 @@ foreach ($bgpPeers as $vrfId => $vrf) {
|
|||
$peers = dbFetchRows('SELECT `vrf_id`, `bgpPeerIdentifier` FROM `bgpPeers` WHERE `device_id` = ?', [$device['device_id']]);
|
||||
foreach ($peers as $value) {
|
||||
$vrfId = $value['vrf_id'];
|
||||
if ($vrfId === null) {
|
||||
$vrfId = 0;
|
||||
}
|
||||
$address = $value['bgpPeerIdentifier'];
|
||||
|
||||
if (empty($bgpPeers[$vrfId][$address])) {
|
||||
// Cleanup code to deal with 0 vs Null in the DB
|
||||
if ($vrfId === 0) {
|
||||
// Database says it's table 0 - which is wrong. It should be "null" for global table
|
||||
$deleted = dbDelete('bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? AND vrf_id = ?', [$device['device_id'], $address, $vrfId]);
|
||||
echo str_repeat('-', $deleted);
|
||||
continue;
|
||||
} else {
|
||||
$testVrfId = empty($vrfId) ? 0 : $vrfId;
|
||||
}
|
||||
|
||||
if (empty($bgpPeers[$testVrfId][$address])) {
|
||||
if ($vrfId === null) {
|
||||
$deleted = dbDelete('bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? AND vrf_id IS NULL', [$device['device_id'], $address]);
|
||||
} else {
|
||||
$deleted = dbDelete('bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? AND vrf_id = ?', [$device['device_id'], $address, $vrfId]);
|
||||
}
|
||||
echo str_repeat('-', $deleted);
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue