Skip to content

Commit

Permalink
fix(optimizer): don't attempt to move cache again
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jan 15, 2025
1 parent eb2e9f1 commit c65c645
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/optimizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestOptimizer(t *testing.T) {
assert.Nil(t, rootCmd.Execute())

// Check if local pref is lowered
checkFile, err := os.ReadFile("/tmp/test-cache/AS65510_EXAMPLE.conf")
checkFile, err := os.ReadFile("/tmp/bird-conf/AS65510_EXAMPLE.conf")
assert.Nil(t, err)
if !strings.Contains(string(checkFile), "bgp_local_pref = 80; # pathvector:localpref") {
t.Errorf("expected bgp_local_pref = 80 but not found in file")
Expand Down
17 changes: 4 additions & 13 deletions pkg/optimizer/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,8 @@ func computeMetrics(o *config.Optimizer, global *config.Config, noConfigure bool
modifyPref(peer,
global.Peers,
o.LocalPrefModifier,
global.CacheDirectory,
global.BIRDDirectory,
global.BIRDSocket,
global.BIRDBinary,
noConfigure,
dryRun,
)
}
Expand All @@ -187,11 +184,8 @@ func modifyPref(
peerPair string,
peers map[string]*config.Peer,
localPrefModifier uint,
cacheDirectory string,
birdDirectory string,
birdSocket string,
birdBinary string,
noConfigure bool,
dryRun bool,
) {
peerASN, peerName := parsePeerDelimiter(peerPair)
Expand All @@ -214,16 +208,13 @@ func modifyPref(
if err := os.WriteFile(fileName, []byte(modified), 0644); err != nil {
log.Fatal(err)
} else {
log.Infof("[Optimizer] Lowered AS%s %s local-pref from %d to %d", peerASN, peerName, currentLocalPref, newLocalPref)
log.Infof("[Optimizer] Lowered AS%s %s local-pref from %d to %d in %s",
peerASN, peerName, currentLocalPref, newLocalPref, fileName,
)
}
}

// Run BIRD config validation
if err := bird.Validate(birdBinary, birdDirectory); err != nil {
log.Fatalf("bird config validation: %v", err)
}

if !dryRun {
bird.MoveCacheAndReconfigure(birdDirectory, cacheDirectory, birdSocket, noConfigure)
bird.Configure(birdSocket)
}
}

0 comments on commit c65c645

Please sign in to comment.