* admin: add plugin lock coordination * shell: allow bypassing lock checks * plugin worker: add admin script handler * mini: include admin_script in plugin defaults * admin script UI: drop name and enlarge text * admin script: add default script * admin_script: make run interval configurable * plugin: gate other jobs during admin_script runs * plugin: use last completed admin_script run * admin: backfill plugin config defaults * templ Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * comparable to default version Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * default to run Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * format Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * shell: respect pre-set noLock for fix.replication * shell: add force no-lock mode for admin scripts * volume balance worker already exists Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * admin: expose scheduler status JSON * shell: add sleep command * shell: restrict sleep syntax * Revert "shell: respect pre-set noLock for fix.replication" This reverts commit 2b14e8b82602a740d3a473c085e3b3a14f1ddbb3. * templ Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * fix import Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * less logs Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * Reduce master client logs on canceled contexts * Update mini default job type count --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
101 lines
3.4 KiB
Go
101 lines
3.4 KiB
Go
package pluginworker
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/plugin_pb"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
func TestAdminScriptDescriptorDefaults(t *testing.T) {
|
|
descriptor := NewAdminScriptHandler(nil).Descriptor()
|
|
if descriptor == nil {
|
|
t.Fatalf("expected descriptor")
|
|
}
|
|
if descriptor.AdminRuntimeDefaults == nil {
|
|
t.Fatalf("expected admin runtime defaults")
|
|
}
|
|
if descriptor.AdminRuntimeDefaults.DetectionIntervalSeconds != adminScriptDetectTickSecs {
|
|
t.Fatalf("unexpected detection interval seconds: got=%d want=%d",
|
|
descriptor.AdminRuntimeDefaults.DetectionIntervalSeconds, adminScriptDetectTickSecs)
|
|
}
|
|
if descriptor.AdminConfigForm == nil {
|
|
t.Fatalf("expected admin config form")
|
|
}
|
|
runInterval := readInt64Config(descriptor.AdminConfigForm.DefaultValues, "run_interval_minutes", 0)
|
|
if runInterval != defaultAdminScriptRunMins {
|
|
t.Fatalf("unexpected run_interval_minutes default: got=%d want=%d", runInterval, defaultAdminScriptRunMins)
|
|
}
|
|
script := readStringConfig(descriptor.AdminConfigForm.DefaultValues, "script", "")
|
|
if strings.TrimSpace(script) == "" {
|
|
t.Fatalf("expected non-empty default script")
|
|
}
|
|
}
|
|
|
|
func TestAdminScriptDetectSkipsByRunInterval(t *testing.T) {
|
|
handler := NewAdminScriptHandler(nil)
|
|
sender := &recordingDetectionSender{}
|
|
err := handler.Detect(context.Background(), &plugin_pb.RunDetectionRequest{
|
|
JobType: adminScriptJobType,
|
|
LastSuccessfulRun: timestamppb.New(time.Now().Add(-2 * time.Minute)),
|
|
AdminConfigValues: map[string]*plugin_pb.ConfigValue{
|
|
"script": {
|
|
Kind: &plugin_pb.ConfigValue_StringValue{StringValue: defaultAdminScript},
|
|
},
|
|
"run_interval_minutes": {
|
|
Kind: &plugin_pb.ConfigValue_Int64Value{Int64Value: 17},
|
|
},
|
|
},
|
|
}, sender)
|
|
if err != nil {
|
|
t.Fatalf("detect returned err = %v", err)
|
|
}
|
|
if sender.proposals == nil {
|
|
t.Fatalf("expected proposals message")
|
|
}
|
|
if len(sender.proposals.Proposals) != 0 {
|
|
t.Fatalf("expected zero proposals, got %d", len(sender.proposals.Proposals))
|
|
}
|
|
if sender.complete == nil || !sender.complete.Success {
|
|
t.Fatalf("expected successful completion message")
|
|
}
|
|
if len(sender.events) == 0 {
|
|
t.Fatalf("expected detector activity events")
|
|
}
|
|
if !strings.Contains(sender.events[0].Message, "run interval") {
|
|
t.Fatalf("unexpected skip message: %q", sender.events[0].Message)
|
|
}
|
|
}
|
|
|
|
func TestAdminScriptDetectCreatesProposalWhenIntervalElapsed(t *testing.T) {
|
|
handler := NewAdminScriptHandler(nil)
|
|
sender := &recordingDetectionSender{}
|
|
err := handler.Detect(context.Background(), &plugin_pb.RunDetectionRequest{
|
|
JobType: adminScriptJobType,
|
|
LastSuccessfulRun: timestamppb.New(time.Now().Add(-20 * time.Minute)),
|
|
AdminConfigValues: map[string]*plugin_pb.ConfigValue{
|
|
"script": {
|
|
Kind: &plugin_pb.ConfigValue_StringValue{StringValue: defaultAdminScript},
|
|
},
|
|
"run_interval_minutes": {
|
|
Kind: &plugin_pb.ConfigValue_Int64Value{Int64Value: 17},
|
|
},
|
|
},
|
|
}, sender)
|
|
if err != nil {
|
|
t.Fatalf("detect returned err = %v", err)
|
|
}
|
|
if sender.proposals == nil {
|
|
t.Fatalf("expected proposals message")
|
|
}
|
|
if len(sender.proposals.Proposals) != 1 {
|
|
t.Fatalf("expected one proposal, got %d", len(sender.proposals.Proposals))
|
|
}
|
|
if sender.complete == nil || !sender.complete.Success || sender.complete.TotalProposals != 1 {
|
|
t.Fatalf("unexpected completion message: %+v", sender.complete)
|
|
}
|
|
}
|