libvirt_cloud/Makefile

254 lines
9.6 KiB
Makefile
Raw Normal View History

2023-12-26 01:44:16 +01:00
ROLES=base proxy toxcore
SHELLCHECK_OPTS=SC2003,SC2006,SC2010,SC2039,SC2181,SC2046,SC2086,SC2048,SC2162,SC2034,SC2030,SC2166,SC2242,SC2223,SC2319,SC3009,SC3011,SC3030,SC3043,SC3054,SC2009,SC1090,SC2164,SC3044
2023-12-29 20:40:31 +01:00
# FixMe
ANSIBLE_PLUGINS=/usr/local/lib/python3.11/site-packages/ansible-2.9.22-py3.11.egg/ansible/plugins
2023-12-26 01:44:16 +01:00
2023-12-29 20:40:31 +01:00
# Edit this to be one of pentoo or devuan depending on your host platform
# Find the corresponding host in hosts.yml and edit the settings, then
# change this to be that hostname
LOCALHOST=`cat /etc/hostname`
2023-12-26 01:44:16 +01:00
2023-12-29 20:40:31 +01:00
# set this to the name linux_local_group host in hosts.yml
LOCAL_HOSTS_NAME=pentoo
# set this to the name linux_chroot_group host in hosts.yml
YAML_CHROOT_NAME=linuxGentoo
# set this to the libvirt name of the linux_libvirt_group host in hosts.yml
2024-01-05 12:12:55 +01:00
OVERLAY_HOSTS_NAME=gentoo_overlay-2
BOX_NBD_BASE_QCOW="`/usr/local/bin/ansible_get_inventory.bash BOX_NBD_BASE_QCOW ${OVERLAY_HOSTS_NAME}`"
BOX_NBD_OVERLAY_DIR="`/usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAT_DIR ${OVERLAY_HOSTS_NAME}`"
BOX_NBD_OVERLAY_QCOW="`/usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAT_QCOW ${OVERLAY_HOSTS_NAME}`"
BOX_NBD_OVERLAY_XML=${BOX_NBD_OVERLAY_DIR}/xml/${OVERLAY_HOSTS_NAME}.xml
BOX_NBD_OVERLAY_NAME="`/usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_NAME ${OVERLAY_HOSTS_NAME}`"
2023-12-26 01:44:16 +01:00
2023-12-29 20:40:31 +01:00
PWD=/o/var/local/src/play_tox/
2024-01-05 12:12:55 +01:00
NETWORK=Whonix-External
2023-12-29 20:40:31 +01:00
VERBOSE=2
all: install lint build check run test
2023-12-26 01:44:16 +01:00
lint::
2023-12-29 20:40:31 +01:00
@sudo xmllint -noout roles/ansible-gentoo_install/templates/etc/libvirt/qemu/gentoo.xml
@yamllint -c .yamllint.yml -f standard *.yml roles/*/*s/*yml 2>&1| \
2023-12-26 01:44:16 +01:00
grep -v 'truthy\|indentation' | \
sed -e '/^$$/d' | tee .yamllint.out | \
grep -B 2 error | tee .yamllint.err || true
grep Error .yamllint.out || true
2024-01-01 02:04:40 +01:00
# groddy but works for me
install:: lint
# ( /usr/local/src ; ansible-galaxy collection install \
# file:///usr/local/src/community.general )
[ -e $(ANSIBLE_PLUGINS)/connection/libvirt_qemu.py ] \
|| ln -s ${PWD}/lib/plugins/libvirt_qemu.py \
$(ANSIBLE_PLUGINS)/connection/q || true
@[ -f ${BOX_NBD_BASE_QCOW} ] || { \
echo ERROR: not created BOX_NBD_DEV="${BOX_NBD_DEV}" - use ; \
echo qemu-img create -f qcow2 "${BOX_NBD_BASE_QCOW}" 20G ; \
exit 2 ; }
@( ps ax | grep -v grep | \
grep "qemu-nbd.*/dev/nbd.*${BOX_NBD_BASE_QCOW}" ) || { \
echo ERROR: not mounted BOX_NBD_DEV="${BOX_NBD_DEV}" - use ; \
echo qemu-nbd -n -f qcow2 -c /dev/nbd1 ${BOX_NBD_BASE_QCOW} ;\
exit 1 ; }
build::
sudo $(MAKE) -$(MAKEFLAGS) build_base
2023-12-29 20:40:31 +01:00
sudo $(MAKE) -$(MAKEFLAGS) build_overlay
2024-01-01 02:04:40 +01:00
build_base:: install
echo INFO: $@ "${BOX_NBD_BASE_QCOW}"
2023-12-29 20:40:31 +01:00
echo INFO running the toxcore role will build ${BOX_NBD_BASE_QCOW}
sudo sh ansible_local.bash --diff -i ${PWD}/hosts.yml \
-l ${LOCALHOST} -c local --verbose ${VERBOSE} \
$(ROLES) > .$@-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
[ -f ${BOX_NBD_BASE_QCOW} ]
build_overlay::
2024-01-05 12:12:55 +01:00
@virsh list | grep "${OVERLAY_HOSTS_NAME}.*running" && \
virsh destroy ${OVERLAY_HOSTS_NAME} ; true
# @virsh list | grep "${OVERLAY_HOSTS_NAME}.*running" && exit 1
@virsh list --all | grep ${OVERLAY_HOSTS_NAME} && \
virsh undefine ${OVERLAY_HOSTS_NAME} && \
2024-01-02 03:13:28 +01:00
rm -f \
2024-01-05 12:12:55 +01:00
${BOX_NBD_OVERLAY_XML} \
${BOX_NBD_OVERLAY_QCOW} ; true
2024-01-02 03:13:28 +01:00
# /a/tmp/GentooImgr/create-vm/xml/gentoo1.xml
2024-01-05 12:12:55 +01:00
# ! virsh list --all | grep "${OVERLAY_HOSTS_NAME}" && exit 2
[ ! -f ${BOX_NBD_OVERLAY_QCOW} ] || { \
2024-01-02 03:13:28 +01:00
echo WARN delete this file to continue; \
2024-01-05 12:12:55 +01:00
echo rm -f ${BOX_NBD_OVERLAY_QCOW} ; \
2023-12-29 20:40:31 +01:00
exit 3 ; }
2024-01-05 12:12:55 +01:00
[ ! -f ${BOX_NBD_OVERLAY_XML} ] || { \
2024-01-02 03:13:28 +01:00
echo WARN delete this file to continue ; \
2024-01-05 12:12:55 +01:00
echo rm -f ${BOX_NBD_OVERLAY_XML} ; \
2023-12-29 20:40:31 +01:00
exit 4 ; }
2024-01-02 03:13:28 +01:00
PLAY_ANSIBLE_SRC=${PWD} bash bin/toxcore_build_overlay_qcow.bash
2024-01-05 12:12:55 +01:00
[ -f ${BOX_NBD_OVERLAY_XML} ]
xmllint -noout ${BOX_NBD_OVERLAY_XML}
2023-12-29 20:40:31 +01:00
check::
grep -n 'shell: *$$' roles/*/tasks/*.yml && { echo ERROR: "shell: in .yml" ; false ; } || true
grep -n '^[a-z ]*: {{' roles/*/tasks/*.yml && { echo WARN: "{{ in .yml" ; false ; } || true
@bash .pylint.sh ; cat .pylint.err ; true
@shellcheck -s bash -W 0 -x -a -e ${SHELLCHECK_OPTS} bin/*sh || true
$(MAKE) -$(MAKEFLAGS) check_base
@[ -d /mnt/gentoo/lost+found ] && \
sudo $(MAKE) -$(MAKEFLAGS) $@_chroot
2024-01-05 12:12:55 +01:00
@[ -f ${BOX_NBD_OVERLAY_QCOW} ] && \
2023-12-29 20:40:31 +01:00
sudo $(MAKE) -$(MAKEFLAGS) $@_overlay
check_localhost::
sudo sh ansible_local.bash --diff -i hosts.yml -l ${LOCALHOST} \
--check -c local --verbose ${VERBOSE} \
$(ROLES) > .$@-$@-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
check_base::
ls ${BOX_NBD_BASE_QCOW}
2024-01-05 12:12:55 +01:00
ls ${BOX_NBD_OVERLAY_QCOW}
ls ${BOX_NBD_OVERLAY_XML}
ps axf | grep 'qemu-system-x86_64 -name guest='${OVERLAY_HOSTS_NAME} ; \
2023-12-29 20:40:31 +01:00
true
check_chroot::
[ -d /mnt/gentoo/lost+found ] || exit 0
ansible -c chroot -l ${YAML_CHROOT_NAME} -i hosts.yml \
-m setup -vvv ${YAML_CHROOT_NAME}
sudo sh ansible_local.bash --diff -i hosts.yml -l ${YAML_CHROOT_NAME} \
--check -c chroot --verbose ${VERBOSE} \
$(ROLES) > .$@-${YAML_CHROOT_NAME}-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
check_overlay::
2024-01-05 12:12:55 +01:00
sudo /usr/local/sbin/toxcore_libvirt_test_ga.bash ${OVERLAY_HOSTS_NAME} ls /
sudo /usr/local/sbin/toxcore_libvirt_test_ga.bash ${OVERLAY_HOSTS_NAME}
2023-12-29 20:40:31 +01:00
# domain-*-gentoo/org.qemu.guest_agent.0 || true
2024-01-05 12:12:55 +01:00
sudo virsh list | grep -q ${OVERLAY_HOSTS_NAME} || exit 0
2023-12-29 20:40:31 +01:00
sudo find /var/lib/libvirt/qemu/channel/target/ | \
grep org.qemu.guest_agent.0
sudo find /var/lib/libvirt/qemu/channel/target/ -type s | \
2024-01-05 12:12:55 +01:00
grep ${OVERLAY_HOSTS_NAME}
ansible -c libvirt_qemu -l ${OVERLAY_HOSTS_NAME} -i hosts.yml \
-m setup -vvv ${OVERLAY_HOSTS_NAME}
sudo sh ansible_local.bash --diff -i hosts.yml -l ${OVERLAY_HOSTS_NAME} \
2023-12-29 20:40:31 +01:00
--check -c libvirt_qemu --verbose ${VERBOSE} \
2024-01-05 12:12:55 +01:00
$(ROLES) > .$@-${OVERLAY_HOSTS_NAME}-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
# Edit hosts.yml and customize this target if you are on a Debianish
devuan::
sudo sh ansible_local.bash --diff -i ${PWD}/hosts.yml \
-l devuan -c local --verbose ${VERBOSE} $(ROLES) \
> .$@-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
# Edit hosts.yml and customize this target if you are on a Gentoo
pentoo::
sudo sh ansible_local.bash --diff -i ${PWD}/hosts.yml \
-l pentoo -c local --verbose ${VERBOSE} $(ROLES) \
> .$@-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
run::
@[ ! -f ${BOX_NBD_BASE_QCOW} ] && \
$(MAKE) -$(MAKEFLAGS) $@_local
@[ -d /mnt/gentoo/lost+found ] && \
sudo $(MAKE) -$(MAKEFLAGS) $@_chroot
2024-01-05 12:12:55 +01:00
@[ ! -f ${BOX_NBD_OVERLAY_QCOW} ] && \
sudo $(MAKE) -$(MAKEFLAGS) $@_overlay
2023-12-29 20:40:31 +01:00
run_local:: lint
A=`grep nbd /proc/partitions | wc -l`
@[ $${A} -eq 0 ] && echo WARN looks like theres no nbd mount && \
exit 0
@[ -f ${BOX_NBD_BASE_QCOW} ] && \
echo WARN ${BOX_NBD_BASE_QCOW} exists - delete or rename \
&& exit 0
BOX_NBD_DEV=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_DEV $BOX)
A=`grep $BOX_NBD_DEV /proc/partitions | wc -l`
@[ $${A} -eq 0 ] && echo WARN looks like theres no $BOX_NBD_DEV nbd mount && \
exit 0
sudo sh ansible_local.bash --diff -i hosts.yml -l ${LOCALHOST} \
-c local --verbose ${VERBOSE} $(ROLES) \
> .$@-$@-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
run_chroot::
[ -d /mnt/gentoo/lost+found ] || exit 0
sudo sh ansible_local.bash --diff -i hosts.yml -l ${YAML_CHROOT_NAME} \
-c chroot --verbose ${VERBOSE} $(ROLES) \
> .$@-${YAML_CHROOT_NAME}-${LOCALHOST} 2>&1
2024-01-05 12:12:55 +01:00
install_libvirt::
2023-12-29 20:40:31 +01:00
@virsh net-list | grep "${NETWORK}.*active" || \
2024-01-05 12:12:55 +01:00
sudo virsh net-start "${NETWORK}" || { \
echo WARN: error virsh net-start "${NETWORK}" ; }
[ -f ${BOX_NBD_OVERLAY_XML} ]
# xmlstarlet sel -t -v
A=$(grep 'source file=' ${BOX_NBD_OVERLAY_XML} | sed -e 's@.*file=.@@' -e "s@'.*@@" )
[ -n "${A}" ] && [ -f "${A}" ]
@virsh list --all | grep ${OVERLAY_HOSTS_NAME} || \
virsh define ${BOX_NBD_OVERLAY_XML}
@virsh list | grep "${OVERLAY_HOSTS_NAME}.*running" || \
{ virsh start ${OVERLAY_HOSTS_NAME} ; sleep 40 ; }
run_overlay:: install_libvirt
[ -f ${BOX_NBD_OVERLAY_QCOW} ] || { \
echo WARN ${BOX_NBD_OVERLAY_QCOW} doesnt exist - make build_overlay ; \
exit 1 ; }
sh ansible_local.bash --diff -i hosts.yml -l ${OVERLAY_HOSTS_NAME} \
2023-12-29 20:40:31 +01:00
-c libvirt_qemu --verbose ${VERBOSE} $(ROLES) \
2024-01-05 12:12:55 +01:00
> .run-${OVERLAY_HOSTS_NAME}-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
# hourly is quick tests, weekly is medium tests, monthly is long tests
weekly:: test
2023-12-29 20:40:31 +01:00
test::
2024-01-05 12:12:55 +01:00
# bash .pyanal.sh &
2023-12-29 20:40:31 +01:00
@[ -d /mnt/gentoo/lost+found ] && \
sudo $(MAKE) -$(MAKEFLAGS) $@_local
2024-01-05 12:12:55 +01:00
@[ -f ${BOX_NBD_OVERLAY_QCOW} ] && \
sudo $(MAKE) -$(MAKEFLAGS) $@_overlay
test_local::
bash .pyanal.sh &
sudo sh ansible_local.bash --diff -i ${PWD}/hosts.yml -l ${LOCALHOST} \
-c local \
--verbose ${VERBOSE} -t weekly \
$(ROLES) > .$@-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
2024-01-05 12:12:55 +01:00
test_overlay:: install_libvirt
! sudo virsh list | grep -q ${OVERLAY_HOSTS_NAME} && exit 0
2023-12-29 20:40:31 +01:00
sudo sh ansible_local.bash --diff -i ${PWD}/hosts.yml \
2024-01-05 12:12:55 +01:00
-l ${OVERLAY_HOSTS_NAME} -c libvirt_qemu \
2023-12-29 20:40:31 +01:00
--verbose ${VERBOSE} -t weekly \
$(ROLES) > .$@-${LOCALHOST} 2>&1
2023-12-29 20:40:31 +01:00
2024-01-05 12:12:55 +01:00
# this is a special test target to test a copy of the base qcow2
VM_HOSTS_NAME=gentoo_vm-2
VM_XML=/etc/libvirt/qemu/${VM_HOSTS_NAME}.xml
A="`grep 'source file=.*qcow2' ${VM_XML} | sed -e 's@.*file=.@@' -e "s@'.*@@"`"
install_vm::
@virsh net-list | grep "${NETWORK}.*active" || \
sudo virsh net-start "${NETWORK}" || { \
echo WARN: error virsh net-start "${NETWORK}" ; }
[ -f ${VM_XML} ]
@virsh list --all | grep ${VM_HOSTS_NAME} || { \
echo ERROR virsh define ${VM_XML} ; exit 8 ; }
# xmlstarlet sel -t -v
[ -n "${A}" ] && [ -f "${A}" ]
@virsh list | grep "${VM_HOSTS_NAME}.*running" || \
{ virsh start ${VM_HOSTS_NAME} ; sleep 40 ; }
test_vm:: install_vm
sudo sh ansible_local.bash --diff -i ${PWD}/hosts.yml \
-l ${VM_HOSTS_NAME} -c libvirt_qemu \
--check --verbose ${VERBOSE} -t daily \
$(ROLES) > .$@-${LOCALHOST} 2>&1
sudo sh ansible_local.bash --diff -i ${PWD}/hosts.yml \
-l ${VM_HOSTS_NAME} -c libvirt_qemu \
--verbose ${VERBOSE} -t daily \
$(ROLES) > .$@-${LOCALHOST} 2>&1
veryclean:: clean
rm -f .run* .check*
2023-12-26 01:44:16 +01:00
clean::
find . -name \*~ -delete
2023-12-30 13:52:24 +01:00
rm roles/*/vars/*.txt
2024-01-04 15:53:42 +01:00
rm -rf roles/toxcore/overlay/Linux/usr/local/src/_Old