Package: systemd Version: 241-5 Severity: normal Tags: patch User: ubuntu-de...@lists.ubuntu.com Usertags: origin-ubuntu eoan ubuntu-patch
Dear Maintainer, 'storage' test fails on some archs/releases trying to modprobe and/or rmmod scsi_debug. -- Package-specific info: * d/t/storage: - fix handling of scsi_debug module, test drives (LP: #1829347) Thanks for considering the patch. -- System Information: Debian Release: buster/sid APT prefers disco-updates APT policy: (500, 'disco-updates'), (500, 'disco-security'), (500, 'disco'), (100, 'disco-backports') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 5.0.0-13-generic (SMP w/24 CPU cores) Kernel taint flags: TAINT_WARN Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled Versions of packages systemd is related to: pn dracut <none> ii initramfs-tools 0.131ubuntu19 ii udev 240-6ubuntu5
diff -Nru systemd-241/debian/tests/storage systemd-241/debian/tests/storage --- systemd-241/debian/tests/storage 2019-05-24 16:58:59.000000000 -0400 +++ systemd-241/debian/tests/storage 2019-05-29 11:52:19.000000000 -0400 @@ -12,40 +12,69 @@ from glob import glob -@unittest.skipIf(os.path.isdir('/sys/module/scsi_debug'), - 'The scsi_debug module is already loaded') +SCSI_DEBUG_DIR='/sys/bus/pseudo/drivers/scsi_debug' + class FakeDriveTestBase(unittest.TestCase): @classmethod def setUpClass(klass): - # create a fake SCSI hard drive - subprocess.check_call(['modprobe', 'scsi_debug', 'dev_size_mb=32']) + if not os.path.isdir(SCSI_DEBUG_DIR): + subprocess.call(['modprobe', 'scsi_debug', 'dev_size_mb=32'], + stderr=subprocess.DEVNULL) + # if still not available, we can't run any of our tests + if not os.path.isdir(SCSI_DEBUG_DIR): + klass.skipTest('scsi_debug module not loaded') + + def setUp(self): + # remove any existing drives, then add back one for us to use + self.remove_scsi_debug_drives() + with open(os.path.join(SCSI_DEBUG_DIR, 'add_host'), 'r+') as f: + print('Adding scsi_debug drive') + f.write('1') + for wait in range(10): + f.seek(0) + if f.read().strip() == '1': + break + time.sleep(0.1) + else: + self.skipTest('Could not add scsi_debug drive to test') # wait until drive got created sys_dirs = [] - while not sys_dirs: - sys_dirs = glob('/sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block') + for tries in range(100): + sys_dirs = glob(os.path.join(SCSI_DEBUG_DIR, + 'adapter*/host*/target*/*:*/block')) + if sys_dirs: + break time.sleep(0.1) - assert len(sys_dirs) == 1 + if len(sys_dirs) < 1: + self.skipTest('could not find scsi_debug block device') + elif len(sys_dirs) > 1: + self.skipTest('too many scsi_debug block devices (%s)' % len(sys_dirs)) devs = os.listdir(sys_dirs[0]) assert len(devs) == 1 - klass.device = '/dev/' + devs[0] - - @classmethod - def tearDownClass(klass): - # create a fake SCSI hard drive - subprocess.check_call(['rmmod', 'scsi_debug']) + self.device = '/dev/' + devs[0] def tearDown(self): - # clear drive - with open(self.device, 'wb') as f: - block = b'0' * 1048576 - try: - while True: - f.write(block) - except OSError: - pass + self.remove_scsi_debug_drives() subprocess.check_call(['udevadm', 'settle']) subprocess.check_call(['systemctl', 'daemon-reload']) + def remove_scsi_debug_drives(self): + with open(os.path.join(SCSI_DEBUG_DIR, 'add_host'), 'r+') as f: + n = f.read().strip() + f.seek(0) + if n == '0': + return + print('Removing %s scsi_debug test drive(s)' % n) + f.write('-%s' % n) + for wait in range(50): + f.seek(0) + n = f.read().strip() + if n == '0': + break + time.sleep(0.1) + else: + self.skipTest('Could not remove %s scsi_debug drives' % n) + class CryptsetupTest(FakeDriveTestBase): def setUp(self): @@ -215,6 +244,7 @@ self.format_luks() with open('/etc/crypttab', 'w') as f: f.write('%s %s none luks,tmp\n' % (self.plaintext_name, self.device)) + self.apply('cryptsetup.target') mountpoint = '/run/crypt1.systemdtest' os.mkdir(mountpoint) @@ -230,17 +260,15 @@ self.apply('local-fs.target') # should be mounted - found = False with open('/proc/mounts') as f: for line in f: fields = line.split() if fields[0] == self.plaintext_dev: self.assertEqual(fields[1], mountpoint) self.assertEqual(fields[2], 'ext2') - found = True break - if not found: - self.fail('%s is not mounted' % self.plaintext_dev) + else: + self.fail('%s is not mounted' % self.plaintext_dev) if __name__ == '__main__':