56fcf8b399
orca init transforms from a bare mkdir into a full single-node cluster bootstrap. After `orca init`, `orca doctor` passes with zero FAILs on the bootstrap checks (CA, cert, db, localhost node). Changes: - migration 0006: nodes.kind + nodes.os nullable columns (REQ-049) - model.Node: Kind + OS fields + NodeKind constants (localhost|linux|proxmox) - NodeRepo: extended Insert/Get/List/Watch/scanNode for kind/os columns (NULL -> "" mapping); added GetByName + UpdateLastSeenAndOS helpers - internal/cli/osdetect.go: detectOS() from /etc/os-release ID= field (D-032); fallback to /usr/lib/os-release then "linux" - internal/cli/init.go: full bootstrap sequence (REQ-047, REQ-048): 1. MkdirAll namespace dir 2. store.Open (runs migrations 0001..0006) 3. security.CAInit (idempotent fast-path) 4. server cert gen if absent (D-036: skip if present) 5. detectOS from /etc/os-release 6. localhost node upsert (insert if new, refresh last_seen+os if exists) Idempotent re-run: no duplicate node, no cert regen, id/joined_at preserved - --json output: full bootstrap summary (namespace, db, ca_fp, cert_fp, os, node_id, steps array) - tests: init idempotency, osdetect parsing (ubuntu/debian/alpine/pve), kind/os round-trip, NULL->"" mapping, GetByName, UpdateLastSeenAndOS E2E smoke test: orca init -> 5 PASS / 0 WARN / 1 FAIL (network=daemon not running, expected); orca node list shows localhost node (os=ubuntu). ---ci--- project: orca phase: 1 milestone: v0.6 status: execute ---/ci---
138 lines
3.5 KiB
Go
138 lines
3.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseOSReleaseID_Ubuntu(t *testing.T) {
|
|
content := `NAME="Ubuntu"
|
|
VERSION="24.04.4 LTS (Noble Numbat)"
|
|
ID=ubuntu
|
|
ID_LIKE=debian
|
|
PRETTY_NAME="Ubuntu 24.04.4 LTS"`
|
|
if got := parseOSReleaseID([]byte(content)); got != "ubuntu" {
|
|
t.Errorf("got %q, want ubuntu", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_Debian(t *testing.T) {
|
|
content := `PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
|
|
NAME="Debian GNU/Linux"
|
|
VERSION_ID="12"
|
|
VERSION="12 (bookworm)"
|
|
ID=debian`
|
|
if got := parseOSReleaseID([]byte(content)); got != "debian" {
|
|
t.Errorf("got %q, want debian", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_Alpine(t *testing.T) {
|
|
content := `NAME="Alpine Linux"
|
|
ID=alpine
|
|
VERSION_ID=3.20.3
|
|
PRETTY_NAME="Alpine Linux v3.20"`
|
|
if got := parseOSReleaseID([]byte(content)); got != "alpine" {
|
|
t.Errorf("got %q, want alpine", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_PVE(t *testing.T) {
|
|
content := `NAME="Proxmox Virtual Environment"
|
|
VERSION="9.2.3"
|
|
ID=pve
|
|
ID_LIKE=debian`
|
|
if got := parseOSReleaseID([]byte(content)); got != "pve" {
|
|
t.Errorf("got %q, want pve", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_QuotedValue(t *testing.T) {
|
|
content := `ID="ubuntu"`
|
|
if got := parseOSReleaseID([]byte(content)); got != "ubuntu" {
|
|
t.Errorf("got %q, want ubuntu", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_UnquotedValue(t *testing.T) {
|
|
content := `ID=alpine`
|
|
if got := parseOSReleaseID([]byte(content)); got != "alpine" {
|
|
t.Errorf("got %q, want alpine", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_MissingID(t *testing.T) {
|
|
content := `NAME="Some Distro"
|
|
VERSION="1.0"`
|
|
if got := parseOSReleaseID([]byte(content)); got != "" {
|
|
t.Errorf("got %q, want empty", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_EmptyContent(t *testing.T) {
|
|
if got := parseOSReleaseID([]byte("")); got != "" {
|
|
t.Errorf("got %q, want empty", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_CommentsAndBlankLines(t *testing.T) {
|
|
content := `# This is a comment
|
|
|
|
NAME="Test"
|
|
# ID is set below
|
|
ID=arch
|
|
PRETTY_NAME="Test Arch"`
|
|
if got := parseOSReleaseID([]byte(content)); got != "arch" {
|
|
t.Errorf("got %q, want arch", got)
|
|
}
|
|
}
|
|
|
|
func TestParseOSReleaseID_UnknownIDReturnedVerbatim(t *testing.T) {
|
|
content := `ID=fedora`
|
|
if got := parseOSReleaseID([]byte(content)); got != "fedora" {
|
|
t.Errorf("got %q, want fedora (unknown IDs returned verbatim)", got)
|
|
}
|
|
}
|
|
|
|
func TestDetectOS_FallbackToLinux(t *testing.T) {
|
|
// Temporarily point osReleasePaths at non-existent files.
|
|
orig := osReleasePaths
|
|
defer func() { osReleasePaths = orig }()
|
|
osReleasePaths = []string{
|
|
filepath.Join(t.TempDir(), "nonexistent-os-release"),
|
|
}
|
|
if got := detectOS(); got != "linux" {
|
|
t.Errorf("got %q, want linux (fallback)", got)
|
|
}
|
|
}
|
|
|
|
func TestDetectOS_ReadsEtcOSRelease(t *testing.T) {
|
|
dir := t.TempDir()
|
|
orig := osReleasePaths
|
|
defer func() { osReleasePaths = orig }()
|
|
osReleasePaths = []string{filepath.Join(dir, "os-release")}
|
|
if err := os.WriteFile(osReleasePaths[0], []byte("ID=ubuntu\n"), 0o644); err != nil {
|
|
t.Fatalf("write: %v", err)
|
|
}
|
|
if got := detectOS(); got != "ubuntu" {
|
|
t.Errorf("got %q, want ubuntu", got)
|
|
}
|
|
}
|
|
|
|
func TestDetectOS_FallbackToUsrLib(t *testing.T) {
|
|
dir := t.TempDir()
|
|
orig := osReleasePaths
|
|
defer func() { osReleasePaths = orig }()
|
|
osReleasePaths = []string{
|
|
filepath.Join(dir, "etc-os-release"), // missing
|
|
filepath.Join(dir, "usr-lib-os-release"), // fallback
|
|
}
|
|
if err := os.WriteFile(osReleasePaths[1], []byte("ID=alpine\n"), 0o644); err != nil {
|
|
t.Fatalf("write: %v", err)
|
|
}
|
|
if got := detectOS(); got != "alpine" {
|
|
t.Errorf("got %q, want alpine (from fallback path)", got)
|
|
}
|
|
}
|