From 72245529a22a5dea8575c7bd8d5b288f8208d21a Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sat, 6 May 2023 12:41:01 +0000 Subject: [PATCH] Add lab-build snippets and executing them in 'create'. Refactor create/destroy/pristine; also, only virsh destroy VMs if they are 'running' --- .../host1-0/root/lab-build/disable-vpp | 6 +++++ .../host1-0/root/lab-build/perms | 5 ++++ .../host1-0/root/lab-build/test | 4 +++ .../host1-1/root/lab-build/disable-vpp | 6 +++++ .../host1-1/root/lab-build/perms | 5 ++++ .../host1-1/root/lab-build/test | 4 +++ .../tap1-0/root/lab-build/perms | 5 ++++ .../vpp1-0/root/lab-build/perms | 5 ++++ .../vpp1-1/root/lab-build/perms | 5 ++++ .../vpp1-2/root/lab-build/perms | 5 ++++ .../vpp1-3/root/lab-build/perms | 5 ++++ create | 27 +++++++++---------- destroy | 12 ++++++--- overlays/bird/common/root/lab-build/perms | 6 +++++ overlays/bird/host/root/lab-build/disable-vpp | 6 +++++ pristine | 12 ++++++--- virshall | 8 ++++-- 17 files changed, 102 insertions(+), 24 deletions(-) create mode 100644 build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/disable-vpp create mode 100644 build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/perms create mode 100644 build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/test create mode 100644 build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/disable-vpp create mode 100644 build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/perms create mode 100644 build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/test create mode 100644 build/default/hvn1.lab.ipng.ch/tap1-0/root/lab-build/perms create mode 100644 build/default/hvn1.lab.ipng.ch/vpp1-0/root/lab-build/perms create mode 100644 build/default/hvn1.lab.ipng.ch/vpp1-1/root/lab-build/perms create mode 100644 build/default/hvn1.lab.ipng.ch/vpp1-2/root/lab-build/perms create mode 100644 build/default/hvn1.lab.ipng.ch/vpp1-3/root/lab-build/perms create mode 100644 overlays/bird/common/root/lab-build/perms create mode 100644 overlays/bird/host/root/lab-build/disable-vpp diff --git a/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/disable-vpp b/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/disable-vpp new file mode 100644 index 0000000..a33b2ad --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/disable-vpp @@ -0,0 +1,6 @@ +#!/bin/sh + +echo " * Disabling VPP, Bird and FRR" +for i in vpp vppcfg bird-dataplane frr; do + ln -sf /dev/null /etc/systemd/system/multi-user.target.wants/${i}.service +done \ No newline at end of file diff --git a/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/perms b/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/perms new file mode 100644 index 0000000..beb167f --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/perms @@ -0,0 +1,5 @@ +#!/bin/bash + +echo " * Fixing permissions" +chown -R root. /root/ +chown -R ipng. /home/ipng/ diff --git a/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/test b/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/test new file mode 100644 index 0000000..3b172e3 --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/host1-0/root/lab-build/test @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Testing build snippets" +date diff --git a/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/disable-vpp b/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/disable-vpp new file mode 100644 index 0000000..a33b2ad --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/disable-vpp @@ -0,0 +1,6 @@ +#!/bin/sh + +echo " * Disabling VPP, Bird and FRR" +for i in vpp vppcfg bird-dataplane frr; do + ln -sf /dev/null /etc/systemd/system/multi-user.target.wants/${i}.service +done \ No newline at end of file diff --git a/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/perms b/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/perms new file mode 100644 index 0000000..beb167f --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/perms @@ -0,0 +1,5 @@ +#!/bin/bash + +echo " * Fixing permissions" +chown -R root. /root/ +chown -R ipng. /home/ipng/ diff --git a/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/test b/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/test new file mode 100644 index 0000000..3b172e3 --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/host1-1/root/lab-build/test @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Testing build snippets" +date diff --git a/build/default/hvn1.lab.ipng.ch/tap1-0/root/lab-build/perms b/build/default/hvn1.lab.ipng.ch/tap1-0/root/lab-build/perms new file mode 100644 index 0000000..beb167f --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/tap1-0/root/lab-build/perms @@ -0,0 +1,5 @@ +#!/bin/bash + +echo " * Fixing permissions" +chown -R root. /root/ +chown -R ipng. /home/ipng/ diff --git a/build/default/hvn1.lab.ipng.ch/vpp1-0/root/lab-build/perms b/build/default/hvn1.lab.ipng.ch/vpp1-0/root/lab-build/perms new file mode 100644 index 0000000..beb167f --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/vpp1-0/root/lab-build/perms @@ -0,0 +1,5 @@ +#!/bin/bash + +echo " * Fixing permissions" +chown -R root. /root/ +chown -R ipng. /home/ipng/ diff --git a/build/default/hvn1.lab.ipng.ch/vpp1-1/root/lab-build/perms b/build/default/hvn1.lab.ipng.ch/vpp1-1/root/lab-build/perms new file mode 100644 index 0000000..beb167f --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/vpp1-1/root/lab-build/perms @@ -0,0 +1,5 @@ +#!/bin/bash + +echo " * Fixing permissions" +chown -R root. /root/ +chown -R ipng. /home/ipng/ diff --git a/build/default/hvn1.lab.ipng.ch/vpp1-2/root/lab-build/perms b/build/default/hvn1.lab.ipng.ch/vpp1-2/root/lab-build/perms new file mode 100644 index 0000000..beb167f --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/vpp1-2/root/lab-build/perms @@ -0,0 +1,5 @@ +#!/bin/bash + +echo " * Fixing permissions" +chown -R root. /root/ +chown -R ipng. /home/ipng/ diff --git a/build/default/hvn1.lab.ipng.ch/vpp1-3/root/lab-build/perms b/build/default/hvn1.lab.ipng.ch/vpp1-3/root/lab-build/perms new file mode 100644 index 0000000..beb167f --- /dev/null +++ b/build/default/hvn1.lab.ipng.ch/vpp1-3/root/lab-build/perms @@ -0,0 +1,5 @@ +#!/bin/bash + +echo " * Fixing permissions" +chown -R root. /root/ +chown -R ipng. /home/ipng/ diff --git a/create b/create index 2aab79f..89d063b 100755 --- a/create +++ b/create @@ -24,18 +24,17 @@ LABDIR=/var/lab STAGING=$LABDIR/staging HVN="hvn${LAB}.lab.ipng.ch" -echo "* Cloning base" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; mkdir -p $STAGING/\$VM; zfs clone $BASE ssd-vol0/\$VM; done" -sleep 1 +VMS=$(ls -1 build/${BUILD}/${HVN}/) -echo "* Mounting in staging" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; mount /dev/zvol/ssd-vol0/\$VM-part1 $STAGING/\$VM; done" - -echo "* Rsyncing build" -rsync -aIcgv build/$BUILD/$HVN/ root@hvn${LAB}.lab.ipng.ch:$STAGING - -echo "* Setting permissions" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; chown -R root. $STAGING/\$VM/root; done" - -echo "* Unmounting and snapshotting pristine state" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; umount $STAGING/\$VM; zfs snapshot ssd-vol0/\${VM}@pristine; done" +for VM in $VMS; do + echo "[$VM] Cloning base" + ssh root@$HVN "mkdir -p $STAGING/$VM; zfs clone $BASE ssd-vol0/$VM" + echo "[$VM] Mounting in staging" + ssh root@$HVN "mount /dev/zvol/ssd-vol0/$VM-part1 $STAGING/$VM" + echo "[$VM] Rsyncing build" + rsync -aIcg build/$BUILD/$HVN/$VM/ root@${HVN}:$STAGING/$VM/ + echo "[$VM] Running lab-build snippets" + ssh root@$HVN "cd $STAGING/$VM; for s in root/lab-build/*; do chroot $STAGING/$VM /bin/bash /\$s; done" + echo "[$VM] Unmounting and snapshotting pristine state" + ssh root@$HVN "umount $STAGING/$VM; zfs snapshot ssd-vol0/${VM}@pristine" +done diff --git a/destroy b/destroy index e77d26a..ce0c8de 100755 --- a/destroy +++ b/destroy @@ -10,13 +10,17 @@ ## * Recursively delete any matching ZFS datasets BASE=${BASE:=ssd-vol0/hvn0.chbtl0.ipng.ch/ssd-vol0/vpp-proto-disk0@20221018-release} +BUILD=${BUILD:=default} LAB=${LAB:=0} ## Do not touch below this line HVN="hvn${LAB}.lab.ipng.ch" -echo "* Destroying VMs" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; virsh destroy \$VM; done" +VMS=$(ls -1 build/${BUILD}/${HVN}/) -echo "* Destroying ZFS datasets" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; zfs destroy -r ssd-vol0/\$VM; done" +for VM in $VMS; do + echo "[$VM] Destroying VM" + ssh root@$HVN "/usr/bin/virsh list --all | grep $VM.*running >/dev/null && virsh destroy $VM" + echo "[$VM] Destroying ZFS datasets" + ssh root@$HVN "zfs destroy -r ssd-vol0/$VM" +done diff --git a/overlays/bird/common/root/lab-build/perms b/overlays/bird/common/root/lab-build/perms new file mode 100644 index 0000000..9e3a9d4 --- /dev/null +++ b/overlays/bird/common/root/lab-build/perms @@ -0,0 +1,6 @@ +#!/bin/bash + +echo " * Fixing permissions" +chown -R root. /root/ +chown -R ipng. /home/ipng/ + diff --git a/overlays/bird/host/root/lab-build/disable-vpp b/overlays/bird/host/root/lab-build/disable-vpp new file mode 100644 index 0000000..13bbeb9 --- /dev/null +++ b/overlays/bird/host/root/lab-build/disable-vpp @@ -0,0 +1,6 @@ +#!/bin/sh + +echo " * Disabling VPP, Bird and FRR" +for i in vpp vppcfg bird-dataplane frr; do + ln -sf /dev/null /etc/systemd/system/multi-user.target.wants/${i}.service +done diff --git a/pristine b/pristine index 887d3b1..f1ea8e0 100755 --- a/pristine +++ b/pristine @@ -1,10 +1,14 @@ #!/bin/sh - +BUILD=${BUILD:=default} LAB=${LAB:=0} ## Do not touch below this line HVN="hvn${LAB}.lab.ipng.ch" +VMS=$(ls -1 build/${BUILD}/${HVN}/) -## Destroy the VMs and bring them back into pristine state -echo "* Restarting VMs from pristine snapshot" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; virsh destroy \$VM; zfs rollback ssd-vol0/\${VM}@pristine; done" +for VM in $VMS; do + echo "[$VM] Destroying VM" + ssh root@$HVN "/usr/bin/virsh list --all | grep $VM.*running >/dev/null && virsh destroy $VM" + echo "[$VM] Rolling VM back to pristine snapshot" + ssh root@$HVN "zfs rollback ssd-vol0/${VM}@pristine" +done diff --git a/virshall b/virshall index dd1f6df..be78ca7 100755 --- a/virshall +++ b/virshall @@ -13,8 +13,12 @@ CMD=$1 exit } -echo "* Executing $CMD against all VMs on lab $LAB" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; virsh $CMD \$VM; done" +VMS=$(ls -1 build/${BUILD}/${HVN}/) + +for VM in $VMS; do + echo "[$VM] Executing $CMD against VMs on lab $LAB" + ssh root@$HVN "virsh $CMD $VM" +done [ "$CMD" = "start" ] && { echo "* Committing OVS config"