mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-25 17:34:28 +00:00
Six-task checkpoint hardening the promotion and failover paths:
T1: 4-gate candidate evaluation (heartbeat freshness, WAL lag, role,
server liveness) with structured rejection reasons.
T2: Orphaned-primary re-evaluation on replica reconnect (B-06/B-08).
T3: Deferred timer safety — epoch validation prevents stale timers
from firing on recreated/changed volumes (B-07).
T4: Rebuild addr cleanup on promotion (B-11), NVMe publication
refresh on heartbeat, and preflight endpoint wiring.
T5: Manual promote API — POST /block/volume/{name}/promote with
force flag, target server selection, and structured rejection
response. Shared applyPromotionLocked/finalizePromotion helpers
eliminate duplication between auto and manual paths.
T6: Read-only preflight endpoint (GET /block/volume/{name}/preflight)
and blockapi client wrappers (Preflight, Promote).
BUG-T5-1: PromotionsTotal counter moved to finalizePromotion (shared
by both auto and manual paths) to prevent metrics divergence.
24 files changed, ~6500 lines added. 42 new QA adversarial tests.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
168 lines
4.1 KiB
Go
168 lines
4.1 KiB
Go
package actions
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
|
|
tr "github.com/seaweedfs/seaweedfs/weed/storage/blockvol/testrunner"
|
|
)
|
|
|
|
func TestDevOpsActions_Registration(t *testing.T) {
|
|
registry := tr.NewRegistry()
|
|
RegisterDevOpsActions(registry)
|
|
|
|
expected := []string{
|
|
"build_deploy_weed",
|
|
"start_weed_master",
|
|
"start_weed_volume",
|
|
"stop_weed",
|
|
"wait_cluster_ready",
|
|
"create_block_volume",
|
|
"expand_block_volume",
|
|
"lookup_block_volume",
|
|
"delete_block_volume",
|
|
"wait_block_servers",
|
|
"cluster_status",
|
|
"wait_block_primary",
|
|
"assert_block_field",
|
|
"block_status",
|
|
"block_promote",
|
|
}
|
|
|
|
for _, name := range expected {
|
|
if _, err := registry.Get(name); err != nil {
|
|
t.Errorf("action %q not registered: %v", name, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDevOpsActions_Tier(t *testing.T) {
|
|
registry := tr.NewRegistry()
|
|
RegisterDevOpsActions(registry)
|
|
|
|
byTier := registry.ListByTier()
|
|
devopsActions := byTier[tr.TierDevOps]
|
|
|
|
if len(devopsActions) != 15 {
|
|
t.Errorf("devops tier has %d actions, want 15", len(devopsActions))
|
|
}
|
|
|
|
// Verify all are in devops tier.
|
|
sort.Strings(devopsActions)
|
|
for _, name := range devopsActions {
|
|
if tier := registry.ActionTier(name); tier != tr.TierDevOps {
|
|
t.Errorf("action %q has tier %q, want devops", name, tier)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDevOpsActions_TierGating(t *testing.T) {
|
|
registry := tr.NewRegistry()
|
|
RegisterDevOpsActions(registry)
|
|
|
|
// Without gating, all should be accessible.
|
|
if _, err := registry.Get("start_weed_master"); err != nil {
|
|
t.Errorf("ungated: %v", err)
|
|
}
|
|
|
|
// Enable only core tier — devops should be blocked.
|
|
registry.EnableTiers([]string{tr.TierCore})
|
|
if _, err := registry.Get("start_weed_master"); err == nil {
|
|
t.Error("expected error when devops tier is disabled")
|
|
}
|
|
|
|
// Enable devops tier — should work again.
|
|
registry.EnableTiers([]string{tr.TierDevOps})
|
|
if _, err := registry.Get("start_weed_master"); err != nil {
|
|
t.Errorf("devops enabled: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestAllActions_Registration(t *testing.T) {
|
|
registry := tr.NewRegistry()
|
|
RegisterAll(registry)
|
|
|
|
byTier := registry.ListByTier()
|
|
|
|
// Verify tier counts.
|
|
if n := len(byTier[tr.TierCore]); n != 11 {
|
|
t.Errorf("core: %d, want 11", n)
|
|
}
|
|
if n := len(byTier[tr.TierBlock]); n != 58 {
|
|
t.Errorf("block: %d, want 58", n)
|
|
}
|
|
if n := len(byTier[tr.TierDevOps]); n != 15 {
|
|
t.Errorf("devops: %d, want 15", n)
|
|
}
|
|
if n := len(byTier[tr.TierChaos]); n != 5 {
|
|
t.Errorf("chaos: %d, want 5", n)
|
|
}
|
|
if n := len(byTier[TierK8s]); n != 14 {
|
|
t.Errorf("k8s: %d, want 14", n)
|
|
}
|
|
|
|
// Total should be 103 (99 prev + 4 devops: wait_block_primary, assert_block_field, block_status, block_promote).
|
|
total := 0
|
|
for _, actions := range byTier {
|
|
total += len(actions)
|
|
}
|
|
if total != 103 {
|
|
t.Errorf("total actions: %d, want 103", total)
|
|
}
|
|
}
|
|
|
|
func TestK8sActions_Registration(t *testing.T) {
|
|
registry := tr.NewRegistry()
|
|
RegisterK8sActions(registry)
|
|
|
|
expected := []string{
|
|
"kubectl_apply",
|
|
"kubectl_delete",
|
|
"kubectl_get_field",
|
|
"kubectl_wait_condition",
|
|
"kubectl_set_image",
|
|
"kubectl_assert_exists",
|
|
"kubectl_assert_not_exists",
|
|
"kubectl_logs",
|
|
"kubectl_rollout_status",
|
|
"kubectl_exec",
|
|
"kubectl_delete_pod",
|
|
"kubectl_pod_ready_count",
|
|
"kubectl_label",
|
|
"kubectl_get_condition",
|
|
}
|
|
|
|
for _, name := range expected {
|
|
if _, err := registry.Get(name); err != nil {
|
|
t.Errorf("action %q not registered: %v", name, err)
|
|
}
|
|
}
|
|
|
|
byTier := registry.ListByTier()
|
|
if n := len(byTier[TierK8s]); n != 14 {
|
|
t.Errorf("k8s tier has %d actions, want 14", n)
|
|
}
|
|
}
|
|
|
|
func TestK8sActions_TierGating(t *testing.T) {
|
|
registry := tr.NewRegistry()
|
|
RegisterK8sActions(registry)
|
|
|
|
// Without gating, all should be accessible.
|
|
if _, err := registry.Get("kubectl_apply"); err != nil {
|
|
t.Errorf("ungated: %v", err)
|
|
}
|
|
|
|
// Enable only core tier — k8s should be blocked.
|
|
registry.EnableTiers([]string{tr.TierCore})
|
|
if _, err := registry.Get("kubectl_apply"); err == nil {
|
|
t.Error("expected error when k8s tier is disabled")
|
|
}
|
|
|
|
// Enable k8s tier — should work again.
|
|
registry.EnableTiers([]string{TierK8s})
|
|
if _, err := registry.Get("kubectl_apply"); err != nil {
|
|
t.Errorf("k8s enabled: %v", err)
|
|
}
|
|
}
|