Bug#1059903: autopkgtest: Add Incus support

2024-01-03 Thread Paul Gevers

Hi

On 03-01-2024 12:44, Colin Watson wrote:

While at some point you might want to do a bit more abstraction to
reduce code duplication, I think the simplest approach would be to copy
autopkgtest-{build,virt}-lxd to autopkgtest-{build,virt}-incus and do a
little bit of search-and-replace.  I've filed
https://salsa.debian.org/ci-team/autopkgtest/-/merge_requests/272 for
this.  To help with review, here's the diff against the LXD versions.


Yes, please let's not do this. src:autopkgtest already has a huge 
technical dept, I don't want to add such a copy/paste thing to it. I 
suggest you declare a variable at the start and use that everywhere 
where you now have a diff. And suggest a way how that script can take 
the option (e.g. make the current script a wrapper to a new cloned 
script with the behavior it gets lxd, while the new script requires you 
to define it, or something).


Paul


OpenPGP_signature.asc
Description: OpenPGP digital signature


Bug#1059903: autopkgtest: Add Incus support

2024-01-03 Thread Colin Watson
Package: autopkgtest
Version: 5.31.2
Severity: wishlist
Tags: patch

Recent actions by Canonical have resulted in the Incus project being
forked from LXD; see https://bugs.debian.org/1042989 and
https://bugs.debian.org/1058592 for background.  It isn't yet in Debian,
but there are efforts in progress to package it.  I'm using the Zabbly
packages (https://github.com/zabbly/incus) until such time as it's
properly in Debian.

We've been discussing using Incus in debusine
(https://salsa.debian.org/freexian-team/debusine); debusine uses
autopkgtest, and autopkgtest includes LXD integration, hence this bug
report.

While at some point you might want to do a bit more abstraction to
reduce code duplication, I think the simplest approach would be to copy
autopkgtest-{build,virt}-lxd to autopkgtest-{build,virt}-incus and do a
little bit of search-and-replace.  I've filed
https://salsa.debian.org/ci-team/autopkgtest/-/merge_requests/272 for
this.  To help with review, here's the diff against the LXD versions.

--- tools/autopkgtest-build-lxd 2024-01-03 11:12:52.376824948 +
+++ tools/autopkgtest-build-incus   2024-01-03 11:24:24.368817982 +
@@ -1,10 +1,10 @@
 #!/bin/sh
-# autopkgtest-build-lxd is part of autopkgtest
+# autopkgtest-build-incus is part of autopkgtest
 # autopkgtest is a tool for testing Debian binary packages
 #
 # autopkgtest is Copyright (C) 2006-2015 Canonical Ltd.
 #
-# Build or update an LXD image autopkgtest/// with
+# Build or update an Incus image autopkgtest/// with
 # autopkgtest customizations from an arbitrary existing image.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -29,7 +29,7 @@
 generate_container_name() {
 while true; do
 CONTAINER=$(mktemp autopkgtest-prepare-XXX -u)
-lxc info "$CONTAINER" >/dev/null 2>&1 || break
+incus info "$CONTAINER" >/dev/null 2>&1 || break
 done
 }
 
@@ -43,7 +43,7 @@
 if echo "${proxy:-}" | egrep -q '(localhost|127\.0\.0\.[0-9]*)'; then
 # translate proxy address to one that can be accessed from the
 # running container
-local bridge_interface=$(lxc profile show default | sed -n 
'/parent:/ { s/^.*: *//; p; q }') || true
+local bridge_interface=$(incus profile show default | sed -n 
'/parent:/ { s/^.*: *//; p; q }') || true
 if [ -n "$bridge_interface" ]; then
 local bridge_ip=$(ip -4 a show dev "$bridge_interface" | awk 
'/ inet / {sub(/\/.*$/, "", $2); print $2}') || true
 if [ -n "$bridge_ip" ]; then
@@ -63,22 +63,22 @@
 setup() {
 # set up apt proxy for the container
 if [ -n "$AUTOPKGTEST_APT_PROXY" ] && [ "$AUTOPKGTEST_APT_PROXY" != "none" 
]; then
-echo "Acquire::http::Proxy \"$AUTOPKGTEST_APT_PROXY\";" | lxc file 
push - "$CONTAINER/etc/apt/apt.conf.d/01proxy"
+echo "Acquire::http::Proxy \"$AUTOPKGTEST_APT_PROXY\";" | incus file 
push - "$CONTAINER/etc/apt/apt.conf.d/01proxy"
 # work around LP#1548878
-lxc exec "$CONTAINER" -- chmod 644 /etc/apt/apt.conf.d/01proxy
+incus exec "$CONTAINER" -- chmod 644 /etc/apt/apt.conf.d/01proxy
 fi
 
 sleep 5
-if lxc exec "$CONTAINER" -- systemctl mask serial-getty@getty.service; then
-   lxc exec "$CONTAINER" -- reboot
+if incus exec "$CONTAINER" -- systemctl mask serial-getty@getty.service; 
then
+   incus exec "$CONTAINER" -- reboot
 fi
 
-# wait until it is booted: lxc exec works and we get a numeric runlevel
+# wait until it is booted: incus exec works and we get a numeric runlevel
 timeout=60
 while [ $timeout -ge 0 ]; do
 timeout=$((timeout - 1))
 sleep 1
-O=`lxc exec "$CONTAINER" runlevel 2>/dev/null /dev/null &2
 exit 1
 fi
 
-ARCH=$(lxc exec "$CONTAINER" -- dpkg --print-architecture /dev/null || . 
/etc/os-release; echo "${NAME% *}"' /dev/null || 
awk "/^deb/ {sub(/\\[.*\\]/, \"\", \$0); print \$3; exit}" 
/etc/apt/sources.list' /dev/null || 
. /etc/os-release; echo "${NAME% *}"' /dev/null 
|| awk "/^deb/ {sub(/\\[.*\\]/, \"\", \$0); print \$3; exit}" 
/etc/apt/sources.list' = 1000 && $3 <= 5) { print $1; exit } }'"]
 out = VirtSubproc.execute_timeout(None, 10, cmd,
@@ -115,11 +115,11 @@
 def hook_open():
 global args, container_name, capabilities
 
-extra_lxcargs = args.lxcargs
+extra_incusargs = args.incusargs
 if args.vm:
 adtlog.debug('will start a VM (with isolation-machine capability)')
 capabilities.append('isolation-machine')
-extra_lxcargs += ['--vm']
+extra_incusargs += ['--vm']
 else:
 adtlog.debug('will start a container (with isolation-container 
capability)')
 capabilities.append('isolation-container')
@@ -127,7 +127,7 @@
 container_name = args.remote + get_available_container_name()
 adtlog.debug('using container name %s' % container_name)
 VirtSubproc.check_exec(
-['lxc', 'launch', '--ephemera