From 91b71fcbbac9f2e14e2ec4a634b3e04264fca25e Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 20 Nov 2014 09:37:59 +0100 Subject: [PATCH] Add nspawn test to boot-and-services autopkgtest --- debian/changelog | 1 + debian/tests/boot-and-services | 40 ++++++++++++++++++++++++++++++++++ debian/tests/control | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 26ea0c242..84b090b62 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ systemd (215-7) UNRELEASED; urgency=medium * Add boot-and-services autopkgtest: Check booting with systemd-sysv and that the most crucial services behave as expected. * logind autopkgtest: Fix stderr output in waiting loop for scsi_debug. + * Add nspawn test to boot-and-services autopkgtest. [ Jon Severinsson] * Add /run/shm -> /dev/shm symlink in debian/tmpfiles.d/debian.conf. This diff --git a/debian/tests/boot-and-services b/debian/tests/boot-and-services index 5e0f43059..a7344c21c 100755 --- a/debian/tests/boot-and-services +++ b/debian/tests/boot-and-services @@ -7,6 +7,8 @@ import sys import os import unittest import subprocess +import tempfile +import shutil class ServicesTest(unittest.TestCase): @@ -99,6 +101,44 @@ class JournalTest(unittest.TestCase): self.assertNotIn(b'systemd:', out) +class NspawnTest(unittest.TestCase): + '''Check nspawn''' + + @classmethod + def setUpClass(kls): + '''Build a bootable busybox mini-container''' + + kls.td_c_busybox = tempfile.TemporaryDirectory(prefix='c_busybox.') + kls.c_busybox = kls.td_c_busybox.name + for d in ['etc/init.d', 'bin', 'sbin']: + os.makedirs(os.path.join(kls.c_busybox, d)) + shutil.copy('/bin/busybox', os.path.join(kls.c_busybox, 'bin')) + shutil.copy('/etc/os-release', os.path.join(kls.c_busybox, 'etc')) + os.symlink('busybox', os.path.join(kls.c_busybox, 'bin', 'sh')) + os.symlink('../bin/busybox', os.path.join(kls.c_busybox, 'sbin/init')) + with open(os.path.join(kls.c_busybox, 'etc/init.d/rcS'), 'w') as f: + f.write('''#!/bin/sh +echo fake container started +ps aux +poweroff\n''') + os.fchmod(f.fileno(), 0o755) + + def setUp(self): + self.workdir = tempfile.TemporaryDirectory() + + def test_boot(self): + cont = os.path.join(self.workdir.name, 'c1') + shutil.copytree(self.c_busybox, cont, symlinks=True) + shutil.copytree(self.c_busybox, '/tmp/cont', symlinks=True) + out = subprocess.check_output(['systemd-nspawn', '-D', cont, '-b'], + timeout=60, stderr=subprocess.STDOUT) + self.assertIn(b'Spawning container c1', out) + self.assertIn(b'fake container started', out) + self.assertRegex(out, b'\n\s+1\s+0\s+init[\r\n]') + self.assertRegex(out, b'\n\s+2+\s+0\s.*rcS[\r\n]') + self.assertRegex(out, b'Container c1.*shut down') + + def boot_with_systemd(): '''Reboot with systemd as init diff --git a/debian/tests/control b/debian/tests/control index e04309694..501052ed9 100644 --- a/debian/tests/control +++ b/debian/tests/control @@ -9,5 +9,5 @@ Tests: python3 Depends: python3-systemd Tests: boot-and-services -Depends: lightdm, cron, network-manager +Depends: lightdm, cron, network-manager, busybox-static Restrictions: needs-root, isolation-machine, needs-recommends, breaks-testbed