f-62: e2e: MAC fournie par le harnais, VM à MAC arbitraire, interface sans mac refusée #62

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-19 21:27:53 +02:00
commit 11eb7f22a9
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
6 changed files with 46 additions and 18 deletions

View file

@ -155,6 +155,14 @@ test_vrf_members_lists_interface_names () {
teardown
}
test_mac_for_ip_uses_the_last_three_octets () {
setup "mac_for_ip : 52:54:00 suivi des trois derniers octets de l'IP, en hexadécimal"
[[ $(node 'mac_for_ip 10.25.1.30') == 52:54:00:19:01:1e ]] || fail "$(node 'mac_for_ip 10.25.1.30')"
[[ $(node 'mac_for_ip 10.25.2.30') == 52:54:00:19:02:1e ]] || fail "même rang, subnet voisin : $(node 'mac_for_ip 10.25.2.30')"
[[ $(node 'mac_for_ip 10.255.255.255') == 52:54:00:ff:ff:ff ]] || fail "$(node 'mac_for_ip 10.255.255.255')"
teardown
}
test_vm_create_is_idempotent () {
setup "vm_create : VM déjà en running, rien n'est copié ni envoyé"
[[ $(node 'api_state () { echo running; }; cp () { echo COPIE; }; api_post () { echo POST; }; vm_create v sn 10.0.0.10 && echo OK') == OK ]] \
@ -341,7 +349,7 @@ test_api_field_reads_one_field_or_nothing () {
test_vm_body_builds_the_create_request () {
setup "vm_body : requête de création, disque par défaut, métadonnées et dev"
[[ $(node 'vm_body t11-a sn-t11a 10.11.1.10') == '{"name":"t11-a","memory":1024,"cpus":1,"metadata":{},"interfaces":[{"subnet":"sn-t11a","ip":"10.11.1.10","primary":true}],"storage":[{"path":"/var/lib/two/volumes/t11-a.qcow2","dev":"vda"}]}' ]] \
[[ $(node 'vm_body t11-a sn-t11a 10.11.1.10') == '{"name":"t11-a","memory":1024,"cpus":1,"metadata":{},"interfaces":[{"subnet":"sn-t11a","ip":"10.11.1.10","mac":"52:54:00:0b:01:0a","primary":true}],"storage":[{"path":"/var/lib/two/volumes/t11-a.qcow2","dev":"vda"}]}' ]] \
|| fail "défaut : $(node 'vm_body t11-a sn-t11a 10.11.1.10')"
[[ $(node 'vm_body t11-b sn-t11a 10.11.1.11 /x.qcow2 "{\"user_data\":\"YQ==\"}" sdb | jq -c "[.metadata.user_data, .storage[0].path, .storage[0].dev]"') == '["YQ==","/x.qcow2","sdb"]' ]] \
|| fail "options : $(node 'vm_body t11-b sn-t11a 10.11.1.11 /x.qcow2 "{\"user_data\":\"YQ==\"}" sdb')"
@ -352,10 +360,12 @@ test_vm_json_builds_nics_disks_metadata_and_uefi () {
setup "vm_json : NIC (la première primaire), disques, métadonnées, uefi"
local out
out=$(node 'vm_json t25-m --disk vda=/v/a.qcow2 --nic sn-a=10.0.1.10 --nic sn-b=10.0.2.10 --disk sda=/v/b.qcow2 --sshkey "ssh-ed25519 AAAA x" --password "\$6\$s\$h" --user-data "I2Nsb3Vk" --uefi')
[[ "${out}" == '{"name":"t25-m","memory":1024,"cpus":1,"metadata":{"sshkey":"ssh-ed25519 AAAA x","password":"$6$s$h","user_data":"I2Nsb3Vk"},"interfaces":[{"subnet":"sn-a","ip":"10.0.1.10","primary":true},{"subnet":"sn-b","ip":"10.0.2.10","primary":false}],"storage":[{"path":"/v/a.qcow2","dev":"vda"},{"path":"/v/b.qcow2","dev":"sda"}],"uefi":true}' ]] \
[[ "${out}" == '{"name":"t25-m","memory":1024,"cpus":1,"metadata":{"sshkey":"ssh-ed25519 AAAA x","password":"$6$s$h","user_data":"I2Nsb3Vk"},"interfaces":[{"subnet":"sn-a","ip":"10.0.1.10","mac":"52:54:00:00:01:0a","primary":true},{"subnet":"sn-b","ip":"10.0.2.10","mac":"52:54:00:00:02:0a","primary":false}],"storage":[{"path":"/v/a.qcow2","dev":"vda"},{"path":"/v/b.qcow2","dev":"sda"}],"uefi":true}' ]] \
|| fail "complet : ${out}"
out=$(node 'vm_json t21-a --nic sn-a=10.0.1.10')
[[ "${out}" == '{"name":"t21-a","memory":1024,"cpus":1,"metadata":{},"interfaces":[{"subnet":"sn-a","ip":"10.0.1.10","primary":true}],"storage":[],"uefi":false}' ]] || fail "minimal : ${out}"
[[ "${out}" == '{"name":"t21-a","memory":1024,"cpus":1,"metadata":{},"interfaces":[{"subnet":"sn-a","ip":"10.0.1.10","mac":"52:54:00:00:01:0a","primary":true}],"storage":[],"uefi":false}' ]] || fail "minimal : ${out}"
out=$(node 'vm_json t21-m --nic sn-a=10.0.1.12=02:de:ad:be:ef:01 | jq -c ".interfaces[0] | [.ip, .mac]"')
[[ "${out}" == '["10.0.1.12","02:de:ad:be:ef:01"]' ]] || fail "mac forcée : ${out}"
[[ $(node 'vm_json t || echo NON' 2>&1) == '{"name":"t","memory":1024,"cpus":1,"metadata":{},"interfaces":[],"storage":[],"uefi":false}' ]] || fail "vide"
[[ $(node 'vm_json t --inconnue x || echo NON') == *NON ]] || fail "option inconnue acceptée"
teardown