Skip to content

Commit

Permalink
tests: add support for testing updates of Archlinux template
Browse files Browse the repository at this point in the history
  • Loading branch information
marmarek committed Jan 21, 2025
1 parent f1896ae commit 2ecc6a2
Showing 1 changed file with 85 additions and 3 deletions.
88 changes: 85 additions & 3 deletions qubes/tests/integ/vm_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ class VmUpdatesMixin(object):
),
]

ARCH_PACKAGE = [
(b"pkgname=test-pkg\n"
b"pkgver=1.0\n"
b"pkgrel=1\n"
b"arch=(any)\n"
b"options=(\"!debug\")\n"
),
(b"pkgname=test-pkg\n"
b"pkgver=1.1\n"
b"pkgrel=1\n"
b"arch=(any)\n"
b"options=(\"!debug\")\n"
),
]

@classmethod
def setUpClass(cls):
super(VmUpdatesMixin, cls).setUpClass()
Expand Down Expand Up @@ -202,7 +217,7 @@ def setUp(self):
"""
if not self.template.count("debian") and not self.template.count(
"fedora"
):
) and not self.template.count("archlinux"):
self.skipTest(
"Template {} not supported by this test".format(self.template)
)
Expand Down Expand Up @@ -235,6 +250,14 @@ def setUp(self):
self.install_test_cmd = "rpm -q {}"
self.upgrade_test_cmd = "rpm -q {} | grep 1.1"
self.ret_code_ok = [0, 100]
elif self.template.count("archlinux"):
self.update_cmd = "pacman -Syy"
self.upgrade_cmd = "pacman -Syu --noconfirm"
self.install_cmd = "pacman -Sy --noconfirm {}"
self.install_test_cmd = "pacman -Q {}"
self.upgrade_test_cmd = "pacman -Q {} | grep 1.1"
self.ret_code_ok = [0]


self.init_default_template(self.template)
self.init_networking()
Expand Down Expand Up @@ -381,6 +404,33 @@ def create_repo_yum(self, version=0):
self.netvm_repo.run_for_stdio("createrepo_c /tmp/yum-repo")
)

def create_repo_arch(self, version=0):
"""
:type self: qubes.tests.SystemTestCase | VmUpdatesMixin
:type version: int
"""
self.loop.run_until_complete(
self.netvm_repo.run_for_stdio(
"""mkdir -p /tmp/pkg \
&& cd /tmp/pkg \
&& cat > PKGBUILD \
&& makepkg""",
input=self.ARCH_PACKAGE[version]
))
pkg_file_name = "test-pkg-1.{}-1-any.pkg.tar.zst".format(version)
self.loop.run_until_complete(
self.netvm_repo.run_for_stdio(
"""
mkdir -p /tmp/arch-repo \
&& cd /tmp/arch-repo \
&& cp /tmp/pkg/{0} ./ \
&& repo-add ./testrepo.db.tar.zst {0}
""".format(
pkg_file_name
),
)
)

def create_repo_and_serve(self):
"""
:type self: qubes.tests.SystemTestCase | VmUpdatesMixin
Expand All @@ -405,6 +455,16 @@ def create_repo_and_serve(self):
stderr=subprocess.DEVNULL,
)
)
elif self.template.count("archlinux"):
self.create_repo_arch()
self.repo_proc = self.loop.run_until_complete(
self.netvm_repo.run(
"cd /tmp/arch-repo && python3 -m http.server 8080",
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
)
else:
# not reachable...
self.skipTest(
Expand All @@ -426,6 +486,8 @@ def add_update_to_repo(self):
self.create_repo_apt(1)
elif self.template.count("fedora"):
self.create_repo_yum(1)
elif self.template.count("archlinux"):
self.create_repo_arch(1)

def configure_test_repo(self):
"""
Expand Down Expand Up @@ -458,6 +520,18 @@ def configure_test_repo(self):
user="root",
)
)
elif self.template.count("archlinux"):
self.loop.run_until_complete(
self.testvm1.run_for_stdio(
"rm -f /etc/pacman.d/*.conf &&"
"echo '[testrepo]' > /etc/pacman.d/70-test.conf &&"
"echo 'SigLevel = Optional TrustAll'"
" >> /etc/pacman.d/70-test.conf &&"
"echo 'Server = http://localhost:8080/'"
" >> /etc/pacman.d/70-test.conf",
user="root",
)
)
else:
# not reachable...
self.skipTest(
Expand Down Expand Up @@ -744,19 +818,27 @@ def test_121_updates_available_notification_qubes_vm_update_cli(self):
)

def test_130_no_network_qubes_vm_update(self):
expected_ret_codes = (23,)
if self.template.count("archlinux"):
# updater on Arch doesn't have separate metadata refresh step
expected_ret_codes = (23,24,)
self.update_via_proxy_qubes_vm_update_impl(
method="qubes-vm-update",
options=(),
expected_ret_codes=(23,),
expected_ret_codes=expected_ret_codes,
break_repo=True,
expect_updated=False,
)

def test_131_no_network_qubes_vm_update_cli(self):
expected_ret_codes = (23,)
if self.template.count("archlinux"):
# updater on Arch doesn't have separate metadata refresh step
expected_ret_codes = (23,24,)
self.update_via_proxy_qubes_vm_update_impl(
method="qubes-vm-update",
options=("--no-progress",),
expected_ret_codes=(23,),
expected_ret_codes=expected_ret_codes,
break_repo=True,
expect_updated=False,
)
Expand Down

0 comments on commit 2ecc6a2

Please sign in to comment.