feat: implement effective peer enabling logic during peer creation. Update CreatePeer methods in Postgres and Memory stores to utilize EffectivePeerEnabledOnCreate function, ensuring new peers are enabled by default unless specified otherwise. Add tests for effective enabling behavior.
CI / changes (push) Successful in 5s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 25s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Successful in 1m9s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Successful in 1m2s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 14s
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Successful in 1m1s
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Successful in 1m24s
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Successful in 1m28s
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Successful in 1m21s
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Successful in 1m24s
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Successful in 1m10s
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Successful in 1m19s
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Has been cancelled
CI / changes (push) Successful in 5s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 25s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Successful in 1m9s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Successful in 1m2s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 14s
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Successful in 1m1s
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Successful in 1m24s
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Successful in 1m28s
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Successful in 1m21s
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Successful in 1m24s
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Successful in 1m10s
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Successful in 1m19s
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Has been cancelled
This commit is contained in:
@@ -331,10 +331,11 @@ func (p *Postgres) CreatePeer(tenantID string, in *store.BGPPeer) (*store.BGPPee
|
||||
if in.SpeakerID != nil && strings.TrimSpace(*in.SpeakerID) != "" {
|
||||
sp = strings.TrimSpace(*in.SpeakerID)
|
||||
}
|
||||
enabled := store.EffectivePeerEnabledOnCreate(in.Enabled, in.SessionState)
|
||||
_, err := p.pool.Exec(ctx, `
|
||||
INSERT INTO bgp_peer (id, tenant_id, bgp_speaker_id, neighbor, remote_asn, enabled, policies_json, meta_json)
|
||||
VALUES ($1,$2,$3,$4::inet, $5, $6, $7::jsonb, $8::jsonb)`,
|
||||
id, tenantID, sp, neighbor, in.RemoteASN, in.Enabled, pol, string(mb))
|
||||
id, tenantID, sp, neighbor, in.RemoteASN, enabled, pol, string(mb))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -629,12 +629,10 @@ func (m *Memory) CreatePeer(tenantID string, in *BGPPeer) (*BGPPeer, error) {
|
||||
id := uuid.NewString()
|
||||
p := &BGPPeer{
|
||||
ID: id, TenantID: tenantID, SpeakerID: in.SpeakerID, Name: in.Name,
|
||||
Neighbor: neighbor, RemoteASN: in.RemoteASN, Enabled: in.Enabled,
|
||||
Neighbor: neighbor, RemoteASN: in.RemoteASN,
|
||||
Enabled: EffectivePeerEnabledOnCreate(in.Enabled, in.SessionState),
|
||||
SessionState: in.SessionState, PoliciesJSON: in.PoliciesJSON,
|
||||
}
|
||||
if !p.Enabled && p.SessionState == "" {
|
||||
p.Enabled = true
|
||||
}
|
||||
m.peers[id] = p
|
||||
return p, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,19 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// EffectivePeerEnabledOnCreate matches API/JSON decoding: omitted "enabled" unmarshals as false in Go,
|
||||
// but new peers should be enabled by default. If session_state is non-empty, false is preserved
|
||||
// (agent-managed rows may be intentionally disabled).
|
||||
func EffectivePeerEnabledOnCreate(inEnabled bool, sessionState string) bool {
|
||||
if inEnabled {
|
||||
return true
|
||||
}
|
||||
if strings.TrimSpace(sessionState) != "" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ParsePeerNeighbor parses a BGP neighbor value for BIRD output: a plain IPv4/IPv6
|
||||
// address, or a host prefix (/32 or /128) which is a common input mistake.
|
||||
func ParsePeerNeighbor(s string) (netip.Addr, bool) {
|
||||
|
||||
@@ -2,6 +2,21 @@ package store
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEffectivePeerEnabledOnCreate(t *testing.T) {
|
||||
if !EffectivePeerEnabledOnCreate(false, "") {
|
||||
t.Fatal("omitted enabled (false) + empty session should default to enabled")
|
||||
}
|
||||
if !EffectivePeerEnabledOnCreate(true, "") {
|
||||
t.Fatal("explicit true")
|
||||
}
|
||||
if !EffectivePeerEnabledOnCreate(true, "down") {
|
||||
t.Fatal("true with session")
|
||||
}
|
||||
if EffectivePeerEnabledOnCreate(false, "Idle") {
|
||||
t.Fatal("false with non-empty session should stay disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePeerNeighbor(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
|
||||
@@ -112,7 +112,8 @@
|
||||
await apiMutate(`/v1/peers/${peerEdit.id}`, 'PATCH', peerForm);
|
||||
toast.success('Пир обновлён');
|
||||
} else {
|
||||
await apiMutate('/v1/peers', 'POST', peerForm);
|
||||
// API: omitted "enabled" decodes as false in Go; default new peers to enabled.
|
||||
await apiMutate('/v1/peers', 'POST', { ...peerForm, enabled: true });
|
||||
toast.success('Пир создан');
|
||||
}
|
||||
peerDialog = false;
|
||||
|
||||
Reference in New Issue
Block a user