f-55: lab: l'outil devient labctl, noms et chemins neutres #55

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-12 16:18:50 +02:00
commit 070faec37a
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
9 changed files with 88 additions and 88 deletions

View file

@ -46,7 +46,7 @@ func flags(name string, stderr io.Writer) (*flag.FlagSet, *string) {
func lab(runDir string, plan string, stdout, stderr io.Writer) (machine.Lab, bool) {
dir, err := filepath.Abs(runDir)
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return machine.Lab{}, false
}
p, ok := load(plan, stderr)
@ -67,7 +67,7 @@ func lab(runDir string, plan string, stdout, stderr io.Writer) (machine.Lab, boo
func current(runDir string, stdout, stderr io.Writer) (machine.Lab, bool) {
saved := filepath.Join(runDir, topologyFile)
if _, err := os.Stat(saved); err != nil {
fmt.Fprintf(stderr, "lab: no lab in %s: %v\n", runDir, err)
fmt.Fprintf(stderr, "labctl: no lab in %s: %v\n", runDir, err)
return machine.Lab{}, false
}
return lab(runDir, saved, stdout, stderr)
@ -75,7 +75,7 @@ func current(runDir string, stdout, stderr io.Writer) (machine.Lab, bool) {
func upCmd(args []string, stdout, stderr io.Writer) int {
fs, runDir := flags("up", stderr)
cacheDir := fs.String("cache", defaultDir(".cache", "two-lab"), "image cache directory")
cacheDir := fs.String("cache", defaultDir(".cache", "labctl"), "image cache directory")
timeout := fs.Duration("timeout", 20*time.Minute, "how long to wait for the nodes to be ready")
if err := fs.Parse(args); err != nil || fs.NArg() != 1 {
fs.Usage()
@ -83,7 +83,7 @@ func upCmd(args []string, stdout, stderr io.Writer) int {
}
cache, err := filepath.Abs(*cacheDir)
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
@ -94,11 +94,11 @@ func upCmd(args []string, stdout, stderr io.Writer) int {
}
running, err := previous.Running()
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
if len(running) > 0 {
fmt.Fprintf(stderr, "lab: lab %s is still running in %s: 'lab down' first\n", previous.Plan.Name, previous.RunDir)
fmt.Fprintf(stderr, "labctl: lab %s is still running in %s: 'lab down' first\n", previous.Plan.Name, previous.RunDir)
return 1
}
}
@ -109,15 +109,15 @@ func upCmd(args []string, stdout, stderr io.Writer) int {
}
source, err := os.ReadFile(fs.Arg(0))
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
if err := os.MkdirAll(l.RunDir, 0o700); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
if err := os.WriteFile(filepath.Join(l.RunDir, topologyFile), source, 0o600); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
@ -125,7 +125,7 @@ func upCmd(args []string, stdout, stderr io.Writer) int {
defer stop()
fetcher := provision.Fetcher{Client: &http.Client{}, CacheDir: cache}
if err := l.Up(ctx, fetcher, *timeout); err != nil {
fmt.Fprintf(stderr, "lab: %v\nlab: started nodes keep running: 'lab status', 'lab down'\n", err)
fmt.Fprintf(stderr, "labctl: %v\nlab: started nodes keep running: 'lab status', 'lab down'\n", err)
return 1
}
return 0
@ -142,7 +142,7 @@ func statusCmd(args []string, stdout, stderr io.Writer) int {
return 1
}
if err := l.Status(stdout); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
return 0
@ -159,7 +159,7 @@ func downCmd(args []string, stdout, stderr io.Writer) int {
return 1
}
if err := l.Down(context.Background()); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
return 0
@ -177,16 +177,16 @@ func sshCmd(args []string, stdout, stderr io.Writer) int {
}
argv, err := l.SSH(fs.Arg(0), isTerminal(os.Stdin), fs.Args()[1:])
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
path, err := exec.LookPath(argv[0])
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
if err := execve(path, argv, os.Environ()); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
return 0

View file

@ -13,7 +13,7 @@ import (
"git.g3e.fr/syonad/two/internal/lab/topology"
)
const usage = `usage: lab <command> [options] <topology.yml> [dir]
const usage = `usage: labctl <command> [options] <topology.yml> [dir]
plan <topology.yml>
validate the topology and print the deterministic plan: addresses, cables, ports
@ -36,7 +36,7 @@ const usage = `usage: lab <command> [options] <topology.yml> [dir]
ssh [-run dir] <node> [command...]
open a shell on a node, or run a command on it, with the key generated by up
defaults: -run $HOME/lab-run, -cache $HOME/.cache/two-lab, -timeout 20m
defaults: -run $HOME/lab-run, -cache $HOME/.cache/labctl, -timeout 20m
`
type keyFiles []string
@ -79,12 +79,12 @@ func run(args []string, stdout, stderr io.Writer) int {
func load(path string, stderr io.Writer) (*topology.Plan, bool) {
t, err := topology.Load(path)
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return nil, false
}
p, err := topology.Compute(t)
if err != nil {
fmt.Fprintf(stderr, "lab: %s:\n%v\n", path, err)
fmt.Fprintf(stderr, "labctl: %s:\n%v\n", path, err)
return nil, false
}
return p, true
@ -96,7 +96,7 @@ func plan(path string, stdout, stderr io.Writer) int {
return 1
}
if err := p.Write(stdout); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
return 0
@ -122,27 +122,27 @@ func renderCmd(args []string, stdout, stderr io.Writer) int {
}
dir, err := filepath.Abs(fs.Arg(1))
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
authorized, err := readKeys(keys)
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
opts := render.Options{RunDir: dir, AuthorizedKeys: authorized}
if err := provision.ReadInputs(p, &opts); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
nodes, err := render.Render(p, opts)
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
for _, n := range nodes {
if err := provision.WriteFiles(n); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
fmt.Fprintf(stdout, "%s\n", n.Dir)

View file

@ -78,7 +78,7 @@ func TestRun_MissingFile(t *testing.T) {
func TestRun_RenderWritesEveryNodeFiles(t *testing.T) {
dir := t.TempDir()
key := filepath.Join(dir, "lab.pub")
if err := os.WriteFile(key, []byte("# lab key\n\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O two-lab-automation\n"), 0o600); err != nil {
if err := os.WriteFile(key, []byte("# lab key\n\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O lab-automation\n"), 0o600); err != nil {
t.Fatal(err)
}
out := filepath.Join(dir, "run")
@ -112,7 +112,7 @@ func TestRun_RenderWritesEveryNodeFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(userData), "two-lab-automation") || strings.Contains(string(userData), "# lab key") {
if !strings.Contains(string(userData), "lab-automation") || strings.Contains(string(userData), "# lab key") {
t.Errorf("keys not read as an authorized_keys file:\n%s", userData)
}
}
@ -157,7 +157,7 @@ func TestRun_CommandsWithoutALabInTheRunDir(t *testing.T) {
args = append(args, "hv1")
}
code, _, stderr := runLab(args...)
if code != 1 || !strings.Contains(stderr, "lab: no lab in "+run) {
if code != 1 || !strings.Contains(stderr, "labctl: no lab in "+run) {
t.Errorf("%s: code %d, stderr %q", cmd, code, stderr)
}
}
@ -304,7 +304,7 @@ func TestRun_UpRefusesToReplaceARunningLab(t *testing.T) {
func TestRun_RenderShipsTheExampleFRRConfigs(t *testing.T) {
dir := t.TempDir()
key := filepath.Join(dir, "lab.pub")
if err := os.WriteFile(key, []byte("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O two-lab-automation\n"), 0o600); err != nil {
if err := os.WriteFile(key, []byte("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O lab-automation\n"), 0o600); err != nil {
t.Fatal(err)
}
out := filepath.Join(dir, "run")

View file

@ -24,7 +24,7 @@ import (
"git.g3e.fr/syonad/two/internal/lab/topology"
)
const labKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O two-lab"
const labKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O labctl"
type exitErr int

View file

@ -16,7 +16,7 @@ import (
const (
KeyFile = "lab_ed25519"
KeyLabel = "two-lab"
KeyLabel = "labctl"
DiskSize = "20G"
SeedLabel = "cidata"

View file

@ -15,7 +15,7 @@ import (
"git.g3e.fr/syonad/two/internal/lab/topology"
)
const generatedKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O two-lab"
const generatedKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O labctl"
type fakeRunner struct {
calls [][]string
@ -98,7 +98,7 @@ func TestPrepare_StagesEveryNode(t *testing.T) {
base := filepath.Join(cache, "debian12", "debian-12-generic-amd64.qcow2")
want := [][]string{
{"ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-C", "two-lab", "-f", filepath.Join(run, "lab_ed25519")},
{"ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-C", "labctl", "-f", filepath.Join(run, "lab_ed25519")},
}
for _, n := range []string{"sw1", "rr1", "hv1", "hv2"} {
dir := filepath.Join(run, n)
@ -332,7 +332,7 @@ func TestEnsureKey_WithTheRealSSHKeygen(t *testing.T) {
if err != nil {
t.Fatalf("EnsureKey: %v", err)
}
if !strings.HasPrefix(key, "ssh-ed25519 ") || !strings.HasSuffix(key, " two-lab") {
if !strings.HasPrefix(key, "ssh-ed25519 ") || !strings.HasSuffix(key, " labctl") {
t.Errorf("key = %q", key)
}
info, err := os.Stat(filepath.Join(dir, "lab_ed25519"))

View file

@ -10,7 +10,7 @@ import (
"git.g3e.fr/syonad/two/internal/lab/topology"
)
const labKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O two-lab-automation"
const labKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O lab-automation"
const twoHypervisors = `name: evpn-2hv
images:

View file

@ -1,21 +1,21 @@
#!/usr/bin/env bash
API_URL="${SCW_API_URL:-https://api.scaleway.com}"
CREDENTIALS_FILE="${LAB_CREDENTIALS_FILE:-${HOME}/.config/two-lab/scaleway.env}"
CREDENTIALS_FILE="${LAB_CREDENTIALS_FILE:-${HOME}/.config/labctl/scaleway.env}"
OFFER_NAME="${LAB_OFFER:-EM-B420E-NVME}"
ALL_ZONES="fr-par-1 fr-par-2 nl-ams-1 nl-ams-2 pl-waw-2 pl-waw-3"
OS_NAME="${LAB_OS_NAME:-Debian}"
OS_VERSION="${LAB_OS_VERSION:-12}"
LAB_NAME="${LAB_NAME:-two-lab}"
LAB_TAG="${LAB_TAG:-two-lab}"
LAB_NAME="${LAB_NAME:-labctl}"
LAB_TAG="${LAB_TAG:-labctl}"
INSTALL_TIMEOUT="${LAB_INSTALL_TIMEOUT:-3600}"
DELETE_TIMEOUT="${LAB_DELETE_TIMEOUT:-900}"
SSH_TIMEOUT="${LAB_SSH_TIMEOUT:-600}"
POLL_INTERVAL="${LAB_POLL_INTERVAL:-20}"
HTTP_CONNECT_TIMEOUT="${LAB_HTTP_CONNECT_TIMEOUT:-10}"
HTTP_TIMEOUT="${LAB_HTTP_TIMEOUT:-60}"
STATE_DIR="${LAB_STATE_DIR:-${HOME}/.cache/two-lab}"
SSH_KEY="${LAB_SSH_KEY:-${HOME}/.config/two-lab/ssh/lab_ed25519}"
STATE_DIR="${LAB_STATE_DIR:-${HOME}/.cache/labctl}"
SSH_KEY="${LAB_SSH_KEY:-${HOME}/.config/labctl/ssh/lab_ed25519}"
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CREATED_ID=""
@ -34,11 +34,11 @@ usage: ${0##*/} <commande> [arguments]
status liste les serveurs de lab du projet, dans toutes les zones candidates
ssh [commande] se connecte au serveur de lab ; avec une commande, un terminal n'est demandé
que si l'entrée standard en est un
prepare installe sur le serveur ce dont lab a besoin (qemu, genisoimage), vérifie
prepare installe sur le serveur ce dont labctl a besoin (qemu, genisoimage), vérifie
/dev/kvm, la virtualisation imbriquée et un CPU x86-64-v3 ; lancé aussi par up
push <topologie> compile cmd/lab pour linux/amd64 et dépose sur le serveur ~/lab et le
push <topologie> compile cmd/labctl pour linux/amd64 et dépose sur le serveur ~/labctl et le
répertoire de la topologie dans ~/topology/ (avec les fichiers qu'elle
référence) ; ensuite : ssh './lab up topology/<topologie>'
référence) ; ensuite : ssh './labctl up topology/<topologie>'
down supprime tous les serveurs de lab du projet, dans toutes les zones candidates,
et attend leur disparition
session [cmd] up, puis la commande distante (ou un shell), puis down quoi qu'il arrive
@ -170,7 +170,7 @@ build_request () {
local KEYS="${3}"
jq -nc --argjson offer "${OFFER}" --argjson os "${OS}" --argjson keys "${KEYS}" \
--arg project "${PROJECT_ID}" --arg name "${LAB_NAME}" --arg tag "${LAB_TAG}" \
'{offer_id: $offer.id, project_id: $project, name: $name, description: "lab two (#50)",
'{offer_id: $offer.id, project_id: $project, name: $name, description: "labctl",
tags: [$tag], install: {os_id: $os.id, hostname: $name, ssh_key_ids: $keys}}'
}
@ -383,17 +383,17 @@ push_dir () {
cmd_push () {
local TOPOLOGY="${1:-}"
local NAME="${TOPOLOGY##*/}"
local BINARY="${STATE_DIR}/lab"
local BINARY="${STATE_DIR}/labctl"
[[ $# -eq 1 && -n "${TOPOLOGY}" ]] || usage
[[ -f "${TOPOLOGY}" ]] || die "topologie introuvable : ${TOPOLOGY}"
[[ "${NAME}" =~ ^[A-Za-z0-9._-]+$ ]] || die "nom de topologie refusé : ${NAME} (lettres, chiffres, '.', '_', '-')"
require_known_server
info "compilation de lab (linux/amd64)"
(cd "${REPO_DIR}" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "${BINARY}" ./cmd/lab) \
|| die "compilation de lab échouée"
push_file "${BINARY}" lab 755 || die "envoi de lab échoué"
info "compilation de labctl (linux/amd64)"
(cd "${REPO_DIR}" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "${BINARY}" ./cmd/labctl) \
|| die "compilation de labctl échouée"
push_file "${BINARY}" labctl 755 || die "envoi de labctl échoué"
push_dir "$(dirname "${TOPOLOGY}")" || die "envoi du répertoire de ${NAME} échoué"
info "déposés sur le serveur : ~/lab, ~/topology/ — ensuite : ${0##*/} ssh './lab up topology/${NAME}'"
info "déposés sur le serveur : ~/labctl, ~/topology/ — ensuite : ${0##*/} ssh './labctl up topology/${NAME}'"
}
delete_server () {

View file

@ -193,7 +193,7 @@ base_state () {
],
keys: [{id: "key-1", disabled: false}, {id: "key-off", disabled: true}],
servers: {
"foreign-1": {id: "foreign-1", name: "prod-db", project_id: $o, tags: ["two-lab"], status: "ready", install: {status: "completed"}, ips: []},
"foreign-1": {id: "foreign-1", name: "prod-db", project_id: $o, tags: ["labctl"], status: "ready", install: {status: "completed"}, ips: []},
"foreign-2": {id: "foreign-2", name: "autre", project_id: $p, tags: ["autre"], status: "ready", install: {status: "completed"}, ips: []}
}
}'
@ -305,16 +305,16 @@ test_up_creates_and_waits_for_installation () {
mutate '.progress = [["delivering","to_install"],["ready","installing"],["ready","completed"]]'
run_lab up || fail "code de sortie $?"
[[ $(jq -r '.offer_id' "${WORK}/create.json") == "${HOURLY_ID}" ]] || fail "offre créée incorrecte"
[[ $(jq -r '.tags | join(",")' "${WORK}/create.json") == "two-lab" ]] || fail "tag absent"
[[ $(jq -r '.tags | join(",")' "${WORK}/create.json") == "labctl" ]] || fail "tag absent"
[[ $(jq -r '.project_id' "${WORK}/create.json") == "${PROJECT}" ]] || fail "projet incorrect"
[[ $(cat "${WORK}/.cache/two-lab/ip" 2>/dev/null) == "203.0.113.7" ]] || fail "IPv4 non retenue"
[[ $(cat "${WORK}/.cache/two-lab/user" 2>/dev/null) == "debian" ]] || fail "utilisateur non retenu"
[[ $(cat "${WORK}/.cache/labctl/ip" 2>/dev/null) == "203.0.113.7" ]] || fail "IPv4 non retenue"
[[ $(cat "${WORK}/.cache/labctl/user" 2>/dev/null) == "debian" ]] || fail "utilisateur non retenu"
teardown
}
test_up_refuses_when_lab_server_exists () {
setup "up : refus si un serveur de lab existe déjà"
mutate '.servers["srv-old"] = {id: "srv-old", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "completed"}, ips: []}'
mutate '.servers["srv-old"] = {id: "srv-old", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "completed"}, ips: []}'
run_lab up && fail "up a réussi"
grep -q "^POST" "${WORK}/calls.log" && fail "second serveur créé"
teardown
@ -331,7 +331,7 @@ test_secret_never_in_argv () {
test_down_deletes_only_lab_servers_of_project () {
setup "down : ne supprime que les serveurs de lab du projet"
mutate '.servers["srv-lab"] = {id: "srv-lab", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "completed"}, ips: []}'
mutate '.servers["srv-lab"] = {id: "srv-lab", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "completed"}, ips: []}'
run_lab down || fail "code de sortie $?"
[[ $(remaining) == "foreign-1,foreign-2" ]] || fail "restants : $(remaining)"
teardown
@ -339,7 +339,7 @@ test_down_deletes_only_lab_servers_of_project () {
test_down_retries_refused_deletion () {
setup "down : réessaie une suppression refusée"
mutate '.delete_refusals = 2 | .servers["srv-lab"] = {id: "srv-lab", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "installing"}, ips: []}'
mutate '.delete_refusals = 2 | .servers["srv-lab"] = {id: "srv-lab", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "installing"}, ips: []}'
run_lab down || fail "code de sortie $?"
[[ $(grep -c "^DELETE" "${WORK}/calls.log") -eq 3 ]] || fail "$(grep -c "^DELETE" "${WORK}/calls.log") DELETE au lieu de 3"
[[ $(remaining) == "foreign-1,foreign-2" ]] || fail "restants : $(remaining)"
@ -348,7 +348,7 @@ test_down_retries_refused_deletion () {
test_down_fails_loudly_when_deletion_keeps_failing () {
setup "down : échec bruyant si la suppression n'aboutit jamais"
mutate '.delete_refusals = 1000 | .servers["srv-lab"] = {id: "srv-lab", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "installing"}, ips: []}'
mutate '.delete_refusals = 1000 | .servers["srv-lab"] = {id: "srv-lab", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "installing"}, ips: []}'
LAB_DELETE_TIMEOUT=1 run_lab down && fail "down a réussi"
grep -q "TOUJOURS FACTURÉ" "${WORK}/out.log" || fail "pas d'alerte de facturation"
teardown
@ -356,7 +356,7 @@ test_down_fails_loudly_when_deletion_keeps_failing () {
test_down_waits_until_server_is_gone () {
setup "down : attend que le serveur ait disparu"
mutate '.linger = 3 | .servers["srv-lab"] = {id: "srv-lab", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "completed"}, ips: []}'
mutate '.linger = 3 | .servers["srv-lab"] = {id: "srv-lab", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "completed"}, ips: []}'
run_lab down || fail "code de sortie $?"
[[ $(grep -c "^GET /baremetal/v1/zones/fr-par-1/servers/srv-lab$" "${WORK}/calls.log") -ge 4 ]] || fail "disparition non attendue"
[[ $(remaining) == "foreign-1,foreign-2" ]] || fail "restants : $(remaining)"
@ -365,7 +365,7 @@ test_down_waits_until_server_is_gone () {
test_down_fails_loudly_when_server_never_disappears () {
setup "down : échec bruyant si le serveur ne disparaît jamais"
mutate '.linger = 100000 | .servers["srv-lab"] = {id: "srv-lab", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "completed"}, ips: []}'
mutate '.linger = 100000 | .servers["srv-lab"] = {id: "srv-lab", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "completed"}, ips: []}'
LAB_DELETE_TIMEOUT=1 run_lab down && fail "down a réussi"
grep -q "TOUJOURS FACTURÉ" "${WORK}/out.log" || fail "pas d'alerte de facturation"
teardown
@ -373,7 +373,7 @@ test_down_fails_loudly_when_server_never_disappears () {
test_down_does_not_mistake_api_error_for_disappearance () {
setup "down : une erreur de l'API n'est pas prise pour une disparition"
mutate '.linger = 100000 | .get_errors = 1 | .servers["srv-lab"] = {id: "srv-lab", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "completed"}, ips: []}'
mutate '.linger = 100000 | .get_errors = 1 | .servers["srv-lab"] = {id: "srv-lab", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "completed"}, ips: []}'
LAB_DELETE_TIMEOUT=1 run_lab down && fail "down a réussi alors que le serveur existe encore"
grep -q "TOUJOURS FACTURÉ" "${WORK}/out.log" || fail "pas d'alerte de facturation"
teardown
@ -417,7 +417,7 @@ test_session_deletes_server_when_installation_times_out () {
test_session_does_not_touch_existing_lab_server () {
setup "session : ne supprime pas un serveur de lab lancé à côté"
mutate '.servers["srv-old"] = {id: "srv-old", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "completed"}, ips: []}'
mutate '.servers["srv-old"] = {id: "srv-old", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "completed"}, ips: []}'
run_lab session true && fail "session a réussi"
grep -q "^DELETE" "${WORK}/calls.log" && fail "suppression lancée"
[[ $(remaining) == "foreign-1,foreign-2,srv-old" ]] || fail "restants : $(remaining)"
@ -432,8 +432,8 @@ test_missing_credentials_are_refused_before_any_call () {
teardown
}
LAB_SERVER='{id: "srv-lab", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "completed"}, ips: []}'
INSTALLING_LAB_SERVER='{id: "srv-lab", name: "two-lab", project_id: "'"${PROJECT}"'", tags: ["two-lab"], status: "ready", install: {status: "installing"}, ips: []}'
LAB_SERVER='{id: "srv-lab", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "completed"}, ips: []}'
INSTALLING_LAB_SERVER='{id: "srv-lab", name: "labctl", project_id: "'"${PROJECT}"'", tags: ["labctl"], status: "ready", install: {status: "installing"}, ips: []}'
test_down_keeps_retrying_while_server_is_installing () {
setup "down : réessaie au-delà du délai tant que le serveur s'installe"
@ -619,11 +619,11 @@ test_session_deletes_server_when_ssh_never_answers () {
test_ssh_uses_dedicated_lab_key_only_when_present () {
setup "ssh : clé dédiée du lab utilisée seule quand elle existe"
mutate '.progress = [["ready","completed"]]'
mkdir -p "${WORK}/.config/two-lab/ssh"
: > "${WORK}/.config/two-lab/ssh/lab_ed25519"
mkdir -p "${WORK}/.config/labctl/ssh"
: > "${WORK}/.config/labctl/ssh/lab_ed25519"
run_lab session uname || fail "code de sortie $?"
grep -q " uname" "${WORK}/ssh.log" || fail "commande non lancée"
[[ $(grep -c -- "-i ${WORK}/.config/two-lab/ssh/lab_ed25519 -o IdentitiesOnly=yes -o IdentityAgent=none" "${WORK}/ssh.log") -eq $(wc -l < "${WORK}/ssh.log") ]] \
[[ $(grep -c -- "-i ${WORK}/.config/labctl/ssh/lab_ed25519 -o IdentitiesOnly=yes -o IdentityAgent=none" "${WORK}/ssh.log") -eq $(wc -l < "${WORK}/ssh.log") ]] \
|| fail "une connexion n'a pas utilisé la clé dédiée seule"
teardown
}
@ -638,10 +638,10 @@ test_ssh_falls_back_to_agent_without_lab_key () {
}
known_server () {
mkdir -p "${WORK}/.cache/two-lab"
echo 203.0.113.7 > "${WORK}/.cache/two-lab/ip"
echo debian > "${WORK}/.cache/two-lab/user"
: > "${WORK}/.cache/two-lab/known_hosts"
mkdir -p "${WORK}/.cache/labctl"
echo 203.0.113.7 > "${WORK}/.cache/labctl/ip"
echo debian > "${WORK}/.cache/labctl/user"
: > "${WORK}/.cache/labctl/known_hosts"
}
test_up_prepares_the_server_after_ssh () {
@ -691,7 +691,7 @@ test_prepare_without_known_server_is_refused () {
}
test_push_builds_for_linux_and_sends_binary_and_topology () {
setup "push : compile lab pour linux/amd64, envoie le binaire et le répertoire de la topologie"
setup "push : compile labctl pour linux/amd64, envoie le binaire et le répertoire de la topologie"
known_server
mkdir -p "${WORK}/conf/frr"
printf 'name: evpn-2hv\n' > "${WORK}/conf/evpn-2hv.yml"
@ -700,9 +700,9 @@ test_push_builds_for_linux_and_sends_binary_and_topology () {
run_lab push "${WORK}/conf/evpn-2hv.yml" || fail "code de sortie $?"
local REPO LISTING
REPO="$(cd "$(dirname "${SCRIPT}")/.." && pwd)"
[[ $(cat "${WORK}/go.log") == "${REPO}|build -o ${WORK}/.cache/two-lab/lab ./cmd/lab|CGO_ENABLED=0 GOOS=linux GOARCH=amd64" ]] \
[[ $(cat "${WORK}/go.log") == "${REPO}|build -o ${WORK}/.cache/labctl/labctl ./cmd/labctl|CGO_ENABLED=0 GOOS=linux GOARCH=amd64" ]] \
|| fail "compilation : $(cat "${WORK}/go.log")"
grep -q "debian@203.0.113.7 cat > 'lab.part' && chmod 755 'lab.part' && mv 'lab.part' 'lab'" "${WORK}/ssh.log" || fail "envoi de lab absent"
grep -q "debian@203.0.113.7 cat > 'labctl.part' && chmod 755 'labctl.part' && mv 'labctl.part' 'labctl'" "${WORK}/ssh.log" || fail "envoi de labctl absent"
grep -q "debian@203.0.113.7 rm -rf topology.part && mkdir topology.part && tar -C topology.part --no-same-owner -xf - && rm -rf topology && mv topology.part topology" "${WORK}/ssh.log" \
|| fail "envoi du répertoire absent"
[[ $(cat "${WORK}/pushed.1") == "binaire-lab" ]] || fail "contenu de lab : $(cat "${WORK}/pushed.1")"
@ -711,7 +711,7 @@ test_push_builds_for_linux_and_sends_binary_and_topology () {
grep -aq 'LIBARCHIVE.xattr' "${WORK}/pushed.2" && fail "attributs étendus macOS dans l'archive"
mkdir "${WORK}/x" && tar -C "${WORK}/x" -xf "${WORK}/pushed.2"
[[ $(cat "${WORK}/x/frr/rr1.conf") == "hostname rr1" ]] || fail "frr/rr1.conf altéré"
grep -q "ssh './lab up topology/evpn-2hv.yml'" "${WORK}/out.log" || fail "consigne finale absente"
grep -q "ssh './labctl up topology/evpn-2hv.yml'" "${WORK}/out.log" || fail "consigne finale absente"
teardown
}
@ -721,7 +721,7 @@ test_push_stops_when_the_build_fails () {
printf 'name: x\n' > "${WORK}/x.yml"
FAKE_GO_FAIL=1 run_lab push "${WORK}/x.yml" && fail "push a réussi"
[[ -s "${WORK}/ssh.log" ]] && fail "ssh lancé"
grep -q "compilation de lab échouée" "${WORK}/out.log" || fail "message absent"
grep -q "compilation de labctl échouée" "${WORK}/out.log" || fail "message absent"
teardown
}
@ -730,7 +730,7 @@ test_push_fails_when_a_transfer_fails () {
known_server
printf 'name: x\n' > "${WORK}/x.yml"
FAKE_PUSH_RC=1 run_lab push "${WORK}/x.yml" && fail "push a réussi"
grep -q "envoi de lab échoué" "${WORK}/out.log" || fail "message absent"
grep -q "envoi de labctl échoué" "${WORK}/out.log" || fail "message absent"
teardown
}
@ -753,8 +753,8 @@ test_push_refusals () {
test_ssh_without_terminal_does_not_ask_for_one () {
setup "ssh : pas de -t quand l'entrée n'est pas un terminal"
known_server
run_lab ssh './lab status' < /dev/null || fail "code de sortie $?"
[[ $(cat "${WORK}/ssh.log") == *"debian@203.0.113.7 ./lab status" ]] || fail "commande : $(cat "${WORK}/ssh.log")"
run_lab ssh './labctl status' < /dev/null || fail "code de sortie $?"
[[ $(cat "${WORK}/ssh.log") == *"debian@203.0.113.7 ./labctl status" ]] || fail "commande : $(cat "${WORK}/ssh.log")"
grep -q -- " -t " "${WORK}/ssh.log" && fail "-t demandé sans terminal"
teardown
}
@ -766,9 +766,9 @@ run_lab_without_env_credentials () {
}
write_credentials () {
mkdir -p "${WORK}/.config/two-lab"
printf '%s\n' "$@" > "${WORK}/.config/two-lab/scaleway.env"
chmod 600 "${WORK}/.config/two-lab/scaleway.env"
mkdir -p "${WORK}/.config/labctl"
printf '%s\n' "$@" > "${WORK}/.config/labctl/scaleway.env"
chmod 600 "${WORK}/.config/labctl/scaleway.env"
}
test_credentials_file_is_used_when_environment_is_empty () {
@ -782,9 +782,9 @@ test_credentials_file_is_used_when_environment_is_empty () {
test_credentials_file_without_final_newline_is_read () {
setup "identifiants : dernière ligne sans retour à la ligne lue quand même"
mkdir -p "${WORK}/.config/two-lab"
printf 'SCW_DEFAULT_PROJECT_ID=%s\nSCW_SECRET_KEY=%s' "${PROJECT}" "${SECRET}" > "${WORK}/.config/two-lab/scaleway.env"
chmod 600 "${WORK}/.config/two-lab/scaleway.env"
mkdir -p "${WORK}/.config/labctl"
printf 'SCW_DEFAULT_PROJECT_ID=%s\nSCW_SECRET_KEY=%s' "${PROJECT}" "${SECRET}" > "${WORK}/.config/labctl/scaleway.env"
chmod 600 "${WORK}/.config/labctl/scaleway.env"
run_lab_without_env_credentials || fail "code de sortie $?"
teardown
}
@ -808,7 +808,7 @@ test_environment_value_kept_when_file_completes_the_rest () {
test_credentials_file_readable_by_others_is_refused () {
setup "identifiants : fichier lisible par d'autres refusé, sans aucun appel"
write_credentials "SCW_SECRET_KEY=${SECRET}" "SCW_DEFAULT_PROJECT_ID=${PROJECT}"
chmod 644 "${WORK}/.config/two-lab/scaleway.env"
chmod 644 "${WORK}/.config/labctl/scaleway.env"
run_lab_without_env_credentials && fail "plan a réussi"
grep -q "chmod 600" "${WORK}/out.log" || fail "pas de consigne de droits"
[[ -s "${WORK}/calls.log" ]] && fail "appel réseau avec un fichier exposé"
@ -892,9 +892,9 @@ test_no_zone_with_stock_is_refused_without_creation () {
test_down_and_status_cover_every_candidate_zone () {
setup "down et status : serveurs de lab de toutes les zones candidates"
mutate ".servers[\"lab-ams\"] = {id: \"lab-ams\", name: \"two-lab\", project_id: \"${PROJECT}\", tags: [\"two-lab\"],
mutate ".servers[\"lab-ams\"] = {id: \"lab-ams\", name: \"labctl\", project_id: \"${PROJECT}\", tags: [\"labctl\"],
status: \"ready\", install: {status: \"completed\"}, ips: [], zone: \"nl-ams-2\", offer_name: \"EM-B420E-NVME\", created_at: \"now\"}"
mutate ".servers[\"lab-par\"] = {id: \"lab-par\", name: \"two-lab\", project_id: \"${PROJECT}\", tags: [\"two-lab\"],
mutate ".servers[\"lab-par\"] = {id: \"lab-par\", name: \"labctl\", project_id: \"${PROJECT}\", tags: [\"labctl\"],
status: \"ready\", install: {status: \"completed\"}, ips: [], offer_name: \"EM-B212X-SSD\", created_at: \"now\"}"
LAB_ZONES="fr-par-1 nl-ams-2" run_lab status
grep -q '^nl-ams-2 lab-ams' "${WORK}/out.log" || fail "status : $(cat "${WORK}/out.log")"