The leading control plane tells the mirror over its API (PUT /v1/firewall, kept as .firewall.json beside the models and applied by the same path unit control planes use), and keeps the state in the store's cluster_state for members that run no llmgw, which a root timer reads from the member's own copy. The mirror also lets in the network of every node and control plane the leader knows. Tried on the PoC: off, on and a network added, on every kind of machine. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package mirror
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/tlsconf"
|
|
)
|
|
|
|
func TestTheMirrorKeepsWhatTheSettingsSayOfItsFirewall(t *testing.T) {
|
|
root := t.TempDir()
|
|
srv := httptest.NewServer(NewAPI(NewManager(root, discardLog()), "http://m:8081").Handler())
|
|
defer srv.Close()
|
|
c, err := NewClient(srv.URL, tlsconf.Config{}, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx := context.Background()
|
|
st := FirewallState{Enabled: true, Networks: []string{"192.168.5.0/24"}, Toward: []string{"10.0.0.147"}}
|
|
if changed, err := c.SetFirewall(ctx, st); err != nil || !changed {
|
|
t.Fatalf("first: %v %v", changed, err)
|
|
}
|
|
if changed, err := c.SetFirewall(ctx, st); err != nil || changed {
|
|
t.Errorf("the same again: %v %v", changed, err)
|
|
}
|
|
var back FirewallState
|
|
b, _ := os.ReadFile(filepath.Join(root, FirewallFile))
|
|
if err := json.Unmarshal(b, &back); err != nil || !back.Enabled || back.Toward[0] != "10.0.0.147" {
|
|
t.Errorf("kept %s", b)
|
|
}
|
|
if all, err := c.List(ctx); err != nil || len(all.Models) != 0 {
|
|
t.Errorf("the file is taken for a model: %+v %v", all, err)
|
|
}
|
|
}
|