Commit 91b71fcb authored by Martin Pitt's avatar Martin Pitt
Browse files

Add nspawn test to boot-and-services autopkgtest

parent 457f782e
......@@ -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
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment