diff --git a/src/tests/dbus-tests/run_tests.py b/src/tests/dbus-tests/run_tests.py index 3d681401c..b0d7c4b68 100755 --- a/src/tests/dbus-tests/run_tests.py +++ b/src/tests/dbus-tests/run_tests.py @@ -1,7 +1,5 @@ #!/usr/bin/python3 -from __future__ import print_function - import os import sys import time @@ -14,7 +12,6 @@ import tempfile import pdb import re -import six import atexit import traceback import yaml @@ -161,7 +158,7 @@ def _get_test_tags(test): # in the test file, just return empty list and let it fail # with python2 the loader will raise an exception directly without returning # a "fake" FailedTest test case - if six.PY3 and isinstance(test, unittest.loader._FailedTest): + if isinstance(test, unittest.loader._FailedTest): return tags test_fn = getattr(test, test._testMethodName) diff --git a/src/tests/dbus-tests/test_10_basic.py b/src/tests/dbus-tests/test_10_basic.py index 73ad08a42..5157177e9 100644 --- a/src/tests/dbus-tests/test_10_basic.py +++ b/src/tests/dbus-tests/test_10_basic.py @@ -1,11 +1,11 @@ import udiskstestcase import dbus import os -import six import shutil from config_h import UDISKS_MODULES_ENABLED + class UdisksBaseTest(udiskstestcase.UdisksTestCase): '''This is a base test suite''' @@ -48,7 +48,7 @@ def test_20_enable_modules(self): self.udisks2_conf_contents = None try: self.udisks2_conf_contents = self.read_file(self._get_udisks2_conf_path()) - except FileNotFoundError as e: + except FileNotFoundError: # no existing udisks2.conf, simply remove the file once finished pass @@ -73,20 +73,20 @@ def test_21_enable_single_module(self): with self.assertRaises(dbus.exceptions.DBusException): manager.EnableModule(module, dbus.Boolean(False)) manager.EnableModule(module, dbus.Boolean(True)) - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, - r'cannot open shared object file: No such file or directory'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, + r'cannot open shared object file: No such file or directory'): manager.EnableModule("non-exist_ent", dbus.Boolean(True)) - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, - r'Module unloading is not currently supported.'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, + r'Module unloading is not currently supported.'): manager.EnableModule("nonexistent", dbus.Boolean(False)) - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, - r'Requested module name .* is not a valid udisks2 module name.'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, + r'Requested module name .* is not a valid udisks2 module name.'): manager.EnableModule("inváálěd", dbus.Boolean(True)) - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, - r'Requested module name .* is not a valid udisks2 module name.'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, + r'Requested module name .* is not a valid udisks2 module name.'): manager.EnableModule("inváálěd", dbus.Boolean(False)) - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, - r'Requested module name .* is not a valid udisks2 module name.'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, + r'Requested module name .* is not a valid udisks2 module name.'): manager.EnableModule("module/../intruder", dbus.Boolean(True)) def test_30_supported_filesystems(self): @@ -218,10 +218,10 @@ def test_60_resolve_device(self): # empty/invalid devspec supplied spec = dbus.Dictionary({}, signature='sv') msg = r'Invalid device specification provided' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): manager.ResolveDevice(spec, self.no_options) spec = dbus.Dictionary({'PATH': '/dev/i-dont-exist'}, signature='sv') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): manager.ResolveDevice(spec, self.no_options) # try some non-existing device first diff --git a/src/tests/dbus-tests/test_19_lsm.py b/src/tests/dbus-tests/test_19_lsm.py index cbb55c63d..d78ff133d 100644 --- a/src/tests/dbus-tests/test_19_lsm.py +++ b/src/tests/dbus-tests/test_19_lsm.py @@ -1,6 +1,5 @@ import os import re -import six import dbus import unittest import tempfile @@ -8,6 +7,7 @@ import udiskstestcase + class UdisksLSMTestCase(udiskstestcase.UdisksTestCase): """ Provide as much LSM module code coverage as possible using the libstoragemgmt 'sim' plugin. @@ -164,7 +164,7 @@ def test_drive_lsm_local(self): for method_name in UdisksLSMTestCase._LED_CONTROL_METHOD_NAMES: method = drive_lsm_local.get_dbus_method(method_name) msg = r'(Specified disk does not support this action|Unable to find block device for drive)' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): method(self.no_options) def test_drive_lsm(self): @@ -199,5 +199,5 @@ def test_drive_lsm(self): self.assertEqual(self.get_property_raw(drive, '.Drive.LSM', 'RaidDiskCount'), 2) else: # no .Drive.LSM interface should be present on other objects - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, r'org.freedesktop.DBus.Error.InvalidArgs: No such interface'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, r'org.freedesktop.DBus.Error.InvalidArgs: No such interface'): self.get_property_raw(drive_lsm, '.Drive.LSM', 'IsOK') diff --git a/src/tests/dbus-tests/test_20_LVM.py b/src/tests/dbus-tests/test_20_LVM.py index 9095dfa03..4ed05b892 100644 --- a/src/tests/dbus-tests/test_20_LVM.py +++ b/src/tests/dbus-tests/test_20_LVM.py @@ -3,8 +3,6 @@ import re import time import unittest -import six -import sys import glob from packaging.version import Version @@ -204,7 +202,7 @@ def assertSegs(pvs): # Attempt to resize the LV to the whole VG, but specify only # the original PVS. This is expected to fail. msg = "Insufficient free space" - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): lv.Resize(dbus.UInt64(new_vgsize.value), dbus.Dictionary({'pvs': devs}, signature='sv'), dbus_interface=self.iface_prefix + '.LogicalVolume') @@ -906,18 +904,18 @@ def _init_stack(self, name): def _check_torn_down_stack(self, name): # check that all created objects don't exist anymore msg = r'Object does not exist at path|No such interface' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): luks_block = self.get_object(self.luks_block_path) self.get_property_raw(luks_block, '.Block', 'DeviceNumber') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): lv_block = self.get_object(self.lv_block_path) self.get_property_raw(lv_block, '.Block', 'DeviceNumber') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): # the lvm2 udisks module is not fully synchronous, see https://github.com/storaged-project/udisks/pull/814 time.sleep(2) lv = self.get_object(self.lv_path) self.get_property_raw(lv, '.LogicalVolume', 'Name') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): vg = self.get_object(self.vg_path) self.get_property_raw(vg, '.VolumeGroup', 'Name') diff --git a/src/tests/dbus-tests/test_30_iscsi.py b/src/tests/dbus-tests/test_30_iscsi.py index 7e71c4bf8..bc45e1bf6 100644 --- a/src/tests/dbus-tests/test_30_iscsi.py +++ b/src/tests/dbus-tests/test_30_iscsi.py @@ -4,8 +4,6 @@ import glob import os import re -import six -import time import shutil import unittest @@ -52,7 +50,7 @@ def _set_initiator_name(self): try: initiatorname_backup = self.read_file(INITIATOR_FILE) self.addCleanup(self.write_file, INITIATOR_FILE, initiatorname_backup) - except FileNotFoundError as e: + except FileNotFoundError: # no existing file, simply remove it once finished self.addCleanup(self.remove_file, INITIATOR_FILE, True) @@ -166,13 +164,13 @@ def test_login_chap_auth(self): msg = r'Login failed: initiator reported error \(24 - iSCSI login failed due to authorization failure\)' # missing auth info - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): manager.Login(iqn, tpg, host, port, iface, self.no_options, dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator', timeout=self.iscsi_timeout) # wrong password - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): options['password'] = '12345' manager.Login(iqn, tpg, host, port, iface, options, dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator', @@ -340,13 +338,13 @@ def test_login_noauth_badauth(self): options['node.session.auth.chap_algs'] = 'SHA3-256,SHA256,SHA1' # disallow MD5 options['username'] = self.initiator msg = r'Login failed: initiator reported error \((19 - encountered non-retryable iSCSI login failure|24 - iSCSI login failed due to authorization failure)\)' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): options['password'] = '12345' manager.Login(iqn, tpg, host, port, iface, options, dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator', timeout=self.iscsi_timeout) - # second atttempt - no password + # second attempt - no password manager.Login(iqn, tpg, host, port, iface, self.no_options, dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator', timeout=self.iscsi_timeout) @@ -383,7 +381,7 @@ def test_ibft(self): if not os.path.exists('/sys/firmware/acpi/tables/iBFT'): udiskstestcase.UdisksTestCase.tearDownClass() self.skipTest('No iBFT ACPI table detected') - ret, out = udiskstestcase.run_command('modprobe iscsi_ibft') + ret, _out = udiskstestcase.run_command('modprobe iscsi_ibft') if ret != 0: udiskstestcase.UdisksTestCase.tearDownClass() self.skipTest('iscsi_ibft kernel module unavailable') @@ -422,7 +420,7 @@ def test_ibft(self): # second attempt - wrong password msg = r'Login failed: initiator reported error \((19 - encountered non-retryable iSCSI login failure|24 - iSCSI login failed due to authorization failure)\)' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): options['username'] = 'nonsenseuser' options['password'] = '12345' manager.Login(iqn, tpg, host, port, iface, options, diff --git a/src/tests/dbus-tests/test_40_drive.py b/src/tests/dbus-tests/test_40_drive.py index ca9ffb2ad..4f13f8a4f 100644 --- a/src/tests/dbus-tests/test_40_drive.py +++ b/src/tests/dbus-tests/test_40_drive.py @@ -2,8 +2,6 @@ import dbus import glob import os -import six -import unittest import udiskstestcase @@ -54,8 +52,8 @@ def test_10_eject(self): dev = self.get_device(self.vdevs[0]) drive = self.get_drive(dev) - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, - r'is not hot-pluggable device|is not ejectable device'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, + r'is not hot-pluggable device|is not ejectable device'): drive.Eject(self.no_options) dev = self.get_device(self.cd_dev) @@ -70,8 +68,8 @@ def test_20_poweroff(self): # check should fail since device cannot be powered off # sadly this is so far the only way we can test this function - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, - 'Failed: No usb device'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, + 'Failed: No usb device'): drive.PowerOff(self.no_options) def test_30_setconfiguration(self): diff --git a/src/tests/dbus-tests/test_50_block.py b/src/tests/dbus-tests/test_50_block.py index ee11aec43..82d8a84c8 100644 --- a/src/tests/dbus-tests/test_50_block.py +++ b/src/tests/dbus-tests/test_50_block.py @@ -4,7 +4,6 @@ import fcntl import os import time -import unittest import udiskstestcase diff --git a/src/tests/dbus-tests/test_60_partitioning.py b/src/tests/dbus-tests/test_60_partitioning.py index db479e645..de3531457 100644 --- a/src/tests/dbus-tests/test_60_partitioning.py +++ b/src/tests/dbus-tests/test_60_partitioning.py @@ -1,6 +1,5 @@ import dbus import os -import six import time import uuid @@ -49,7 +48,7 @@ def test_create_mbr_partition(self): # first try to create partition with name -> should fail because mbr # doesn't support partition names msg = 'MBR partition table does not support names' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(100 * 1024**2), part_type, 'name', self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable') @@ -565,7 +564,7 @@ def test_gpt_type(self): # first try some invalid guid msg = 'org.freedesktop.UDisks2.Error.Failed: .* is not a valid UUID' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): part.SetType('aaaa', self.no_options, dbus_interface=self.iface_prefix + '.Partition') @@ -599,7 +598,7 @@ def test_dos_type(self): # try to set part type to an extended partition type -- should fail msg = 'Refusing to change partition type to that of an extended partition' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): part.SetType('0x05', self.no_options, dbus_interface=self.iface_prefix + '.Partition') @@ -693,7 +692,7 @@ def test_name(self): # first try some invalid name (longer than 36 characters) msg = 'Max partition name length is 36 characters' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): part.SetName('a' * 37, self.no_options, dbus_interface=self.iface_prefix + '.Partition') @@ -746,7 +745,7 @@ def test_uuid(self): msg = 'Provided UUID is not a valid RFC-4122 UUID' for uu in ['garbage', str(uuid.uuid4()) + 'garbage', '12345678-zzzz-xxxx-yyyy-567812345678', 'ABCD-EFGH']: - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): part.SetUUID(uu, self.no_options, dbus_interface=self.iface_prefix + '.Partition') # set new valid UUID diff --git a/src/tests/dbus-tests/test_70_encrypted.py b/src/tests/dbus-tests/test_70_encrypted.py index b986054c6..e008b4cf0 100644 --- a/src/tests/dbus-tests/test_70_encrypted.py +++ b/src/tests/dbus-tests/test_70_encrypted.py @@ -1,12 +1,9 @@ import dbus import os import re -import six import shutil import tarfile import tempfile -import time -import unittest import configparser import gi @@ -156,13 +153,13 @@ def test_close_open(self): # no password msg = 'org.freedesktop.UDisks2.Error.Failed: No key available.*' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.Unlock("", self.no_options, dbus_interface=self.iface_prefix + '.Encrypted') # wrong password msg = 'org.freedesktop.UDisks2.Error.Failed: Error unlocking %s *' % self.vdevs[0] - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.Unlock('abcdefghijklmn', self.no_options, dbus_interface=self.iface_prefix + '.Encrypted') @@ -304,7 +301,7 @@ def test_mount(self): # should not be possible to close mounted luks msg = 'org.freedesktop.UDisks2.Error.Failed: Error locking' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.Lock(self.no_options, dbus_interface=self.iface_prefix + '.Encrypted') # now unmount it and try to close it again @@ -326,7 +323,7 @@ def test_password_change(self): # old password, should fail msg = 'org.freedesktop.UDisks2.Error.Failed: Error unlocking %s *' % self.vdevs[0] - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.Unlock(self.PASSPHRASE, self.no_options, dbus_interface=self.iface_prefix + '.Encrypted') @@ -531,7 +528,7 @@ def test_resize(self): # kernel keyring support and no passphrase for LUKS 2 given = fail if self._get_key_location('/dev/' + clear_dev) == 'keyring': msg = 'org.freedesktop.UDisks2.Error.Failed: Error resizing encrypted device /dev/dm-[0-9]+: Insufficient (permissions|persmissions) to resize device. *' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): device.Resize(dbus.UInt64(100*1024*1024), self.no_options, dbus_interface=self.iface_prefix + '.Encrypted') @@ -540,7 +537,7 @@ def test_resize(self): d['passphrase'] = 'wrongpassphrase' msg = 'org.freedesktop.UDisks2.Error.Failed: Error resizing encrypted device /dev/dm-[0-9]+: '\ 'Failed to activate device: (Operation not permitted|Incorrect passphrase)' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): device.Resize(dbus.UInt64(100*1024*1024), d, dbus_interface=self.iface_prefix + '.Encrypted') diff --git a/src/tests/dbus-tests/test_80_filesystem.py b/src/tests/dbus-tests/test_80_filesystem.py index 18c8011d1..60b4e67c5 100644 --- a/src/tests/dbus-tests/test_80_filesystem.py +++ b/src/tests/dbus-tests/test_80_filesystem.py @@ -2,7 +2,6 @@ import os import errno import re -import six import shutil import uuid import random @@ -254,7 +253,7 @@ def _invalid_uuid(self, block): msg = r'org.freedesktop.UDisks2.Error.Failed: (Provided UUID is not a valid RFC-4122 UUID.|UUID for .* filesystem must be a hexadecimal number.|.*volume ID must be a hexadecimal number|UUID for .* filesystem must be .* characters long.)' for u in ['garbage', self._gen_uuid() + 'garbage', '12345678-zzzz-xxxx-yyyy-567812345678', 'ABCD-EFGH']: - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): block.SetUUID(u, self.no_options, dbus_interface=self.iface_prefix + '.Filesystem') def test_uuid(self): @@ -529,7 +528,7 @@ def test_readonly(self, should_be_readonly, config_file_contents, udev_rules_con mnt_path = block_fs.Mount(dd, dbus_interface=self.iface_prefix + '.Filesystem') self.assertTrue(os.path.ismount(mnt_path)) if should_be_readonly: - with six.assertRaisesRegex(self, OSError, "Read-only file system"): + with self.assertRaisesRegex(OSError, "Read-only file system"): fd, _tmpfile = tempfile.mkstemp(dir=mnt_path) os.close(fd) else: @@ -556,7 +555,7 @@ def test_custom_option(self, should_fail, dbus_option, should_be_present, config msg="org.freedesktop.UDisks2.Error.OptionNotPermitted: Mount option `%s' is not allowed" % dbus_option else: msg="org.freedesktop.UDisks2.Error.OptionNotPermitted: Mount option `.*' is not allowed" - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): mnt_path = block_fs.Mount(dd, dbus_interface=self.iface_prefix + '.Filesystem') else: mnt_path = block_fs.Mount(dd, dbus_interface=self.iface_prefix + '.Filesystem') @@ -998,7 +997,7 @@ def test_protective_part_overwrite(self): # attempt to create another filesystem on the partition msg = 'This partition cannot be modified because it contains a partition table; please reinitialize layout of the whole device.' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): part.Format(self._fs_signature, self.no_options, dbus_interface=self.iface_prefix + '.Block') @udiskstestcase.tag_test(udiskstestcase.TestTags.UNSAFE) @@ -1022,7 +1021,7 @@ def test_protective_part_overwrite_mounted(self): # now try formatting the master block device msg = r"Error wiping device:.*Failed to open the device|Error synchronizing after initial wipe: Timed out waiting for object" - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.Format(self._fs_signature, self.no_options, dbus_interface=self.iface_prefix + '.Block') part.Unmount(self.no_options, dbus_interface=self.iface_prefix + '.Filesystem') @@ -1151,7 +1150,7 @@ def test_mount_as_user(self): # try to mount it now: first with a nonexistent user d['as-user'] = 'nonexistent' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, "User with name nonexistent does not exist"): + with self.assertRaisesRegex(dbus.exceptions.DBusException, "User with name nonexistent does not exist"): block_fs.Mount(d, dbus_interface=self.iface_prefix + '.Filesystem') # now mount it with the actual user @@ -1182,7 +1181,7 @@ class Ext2TestCase(UdisksFSTestCase): def _invalid_label(self, disk): label = 'a' * 17 # at most 16 characters, longer should be truncated msg = 'org.freedesktop.UDisks2.Error.Failed: Label for ext filesystem must be at most 16 characters long.' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.SetLabel(label, self.no_options, dbus_interface=self.iface_prefix + '.Filesystem') @@ -1314,7 +1313,7 @@ def test_create_format_mkfs_args(self): options = dbus.Dictionary(signature='sv') options['mkfs-args'] = ['-O', 'nonexistent'] - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, 'Invalid filesystem option set: nonexistent'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, 'Invalid filesystem option set: nonexistent'): self._create_format(disk, options=options) options['mkfs-args'] = ['-O', 'encrypt'] @@ -1328,7 +1327,7 @@ class XFSTestCase(UdisksFSTestCase): def _invalid_label(self, disk): label = 'a a' # space not allowed msg = 'org.freedesktop.UDisks2.Error.Failed: Label for XFS filesystem cannot contain spaces.' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.SetLabel(label, self.no_options, dbus_interface=self.iface_prefix + '.Filesystem') @@ -1636,7 +1635,7 @@ class VFATTestCase(NonPOSIXTestCase): def _invalid_label(self, disk): label = 'a' * 12 # at most 11 characters msg = 'org.freedesktop.UDisks2.Error.Failed: Label for VFAT filesystem must be at most 11 characters long.' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.SetLabel(label, self.no_options, dbus_interface=self.iface_prefix + '.Filesystem') def _gen_uuid(self): @@ -1781,7 +1780,7 @@ def test_create_format(self): # try to create some nonexisting filesystem msg = 'org.freedesktop.UDisks2.Error.NotSupported: Filesystem \'definitely-nonexisting-fs\' is not supported.' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.Format('definitely-nonexisting-fs', self.no_options, dbus_interface=self.iface_prefix + '.Block') @@ -1798,7 +1797,7 @@ def test_relabel(self): self.addCleanup(self.wipe_fs, self.vdevs[0]) msg = "org.freedesktop.UDisks2.Error.Failed: Setting the label of filesystem 'f2fs' is not supported." - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.SetLabel('test', self.no_options, dbus_interface=self.iface_prefix + '.Filesystem') def test_mount_auto(self): @@ -1818,7 +1817,7 @@ def test_mount_auto(self): d['fstype'] = 'xfs' msg = '[Ww]rong fs type' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): mnt_path = disk.Mount(d, dbus_interface=self.iface_prefix + '.Filesystem') self.assertIsNone(mnt_path) @@ -1828,14 +1827,14 @@ def test_mount_auto(self): msg = 'org.freedesktop.UDisks2.Error.OptionNotPermitted: Mount option '\ '`definitely-nonexisting-option\' is not allowed' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): mnt_path = disk.Mount(d, dbus_interface=self.iface_prefix + '.Filesystem') self.assertIsNone(mnt_path) # should not be mounted -- so lets try to unmount it msg = 'org.freedesktop.UDisks2.Error.NotMounted: Device `%s\' is not '\ 'mounted' % self.vdevs[0] - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): disk.Unmount(self.no_options, dbus_interface=self.iface_prefix + '.Filesystem') diff --git a/src/tests/dbus-tests/test_btrfs.py b/src/tests/dbus-tests/test_btrfs.py index be781ef06..85996925b 100644 --- a/src/tests/dbus-tests/test_btrfs.py +++ b/src/tests/dbus-tests/test_btrfs.py @@ -1,6 +1,5 @@ import dbus import os -import six import shutil import re import tempfile @@ -122,7 +121,7 @@ def test_create_raid(self): # invalid raid level msg = '[uU]nknown .* profile raidN' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): manager.CreateVolume([dev.obj_path for dev in devs], 'test_raidN', 'raidN', 'raidN', self.no_options, @@ -181,7 +180,7 @@ def test_subvolumes(self): # not mounted, should fail msg = 'org.freedesktop.UDisks2.Error.NotMounted: Volume not mounted' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): dev.obj.CreateSubvolume('test_sub1', self.no_options, dbus_interface=self.iface_prefix + '.Filesystem.BTRFS') @@ -227,7 +226,7 @@ def test_add_remove_device(self): # shouldn't be possible to remove only device with self._temp_mount(dev1.path): msg = 'unable to remove the only writeable device' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): dev1.obj.RemoveDevice(dev1.obj_path, self.no_options, dbus_interface=self.iface_prefix + '.Filesystem.BTRFS') diff --git a/src/tests/dbus-tests/test_drive_ata.py b/src/tests/dbus-tests/test_drive_ata.py index 37740c60b..2f5aaba9a 100644 --- a/src/tests/dbus-tests/test_drive_ata.py +++ b/src/tests/dbus-tests/test_drive_ata.py @@ -49,6 +49,7 @@ def _get_sata_disks(): else: smart_unsupported.add(disk) + class UdisksDriveAtaTest(udiskstestcase.UdisksTestCase): '''Noninvasive tests for the Drive.Ata interface''' @@ -88,7 +89,6 @@ def get_attrs(self, disk): return attrs - @unittest.skipUnless(smart_supported, "No disks supporting S.M.A.R.T. available") def test_iface_present(self): for disk in smart_supported: diff --git a/src/tests/dbus-tests/test_loop.py b/src/tests/dbus-tests/test_loop.py index 1954b4275..78417f0cd 100644 --- a/src/tests/dbus-tests/test_loop.py +++ b/src/tests/dbus-tests/test_loop.py @@ -71,6 +71,7 @@ def test_40_setupbyuid(self): uid = self.get_property(self.device, '.Loop', 'SetupByUID') uid.assertEqual(0) # uid should be 0 since device is not created by Udisks + class UdisksManagerLoopDeviceTest(udiskstestcase.UdisksTestCase): """Unit tests for the loop-related methods of the Manager object""" diff --git a/src/tests/dbus-tests/test_mdraid.py b/src/tests/dbus-tests/test_mdraid.py index 0a8f5277e..76fe60b94 100644 --- a/src/tests/dbus-tests/test_mdraid.py +++ b/src/tests/dbus-tests/test_mdraid.py @@ -91,7 +91,6 @@ def _array_create(self, array_name, bitmap=None, version=None): manager = self.get_object('/Manager') with wait_for_action('resync'): - array_path = manager.MDRaidCreate(dbus.Array(m.obj for m in self.members), self.level, array_name, self.chunk_size, d, dbus_interface=self.iface_prefix + '.Manager') diff --git a/src/tests/dbus-tests/test_nvme.py b/src/tests/dbus-tests/test_nvme.py index ced60833b..ef60a41d8 100644 --- a/src/tests/dbus-tests/test_nvme.py +++ b/src/tests/dbus-tests/test_nvme.py @@ -1,10 +1,7 @@ import os import stat -import re -import six import tempfile import time -import sys import shutil import json import uuid @@ -104,6 +101,7 @@ def _check_subsys(subsys, ns_dev_paths): return ns_dev_paths + def setup_nvme_target(dev_paths, subnqn): """ Sets up a new NVMe target loop device (using nvmetcli) on top of the @@ -186,13 +184,13 @@ def setUpClass(cls): if not shutil.which("nvmetcli"): udiskstestcase.UdisksTestCase.tearDownClass() raise unittest.SkipTest("nvmetcli executable not found in $PATH, skipping.") - ret, out = udiskstestcase.run_command("modprobe nvme-fabrics") + ret, _out = udiskstestcase.run_command("modprobe nvme-fabrics") if ret != 0: raise unittest.SkipTest("nvme-fabrics kernel module unavailable, skipping.") cls.dev_files = [] - for i in range(cls.NUM_NS): + for _ in range(cls.NUM_NS): with tempfile.NamedTemporaryFile(prefix="udisks_test", delete=False, mode='w+b', dir='/var/tmp') as temp: temp.truncate(cls.NS_SIZE) cls.dev_files += [temp.name] @@ -231,7 +229,6 @@ def tearDownClass(cls): pass udiskstestcase.UdisksTestCase.tearDownClass() - def test_controller_info(self): self._nvme_connect() self.addCleanup(self._nvme_disconnect, self.SUBNQN, ignore_errors=True) @@ -280,7 +277,6 @@ def test_controller_info(self): unalloc_cap = self.get_property_raw(drive_obj, '.NVMe.Controller', 'UnallocatedCapacity') self.assertEqual(unalloc_cap, 0) - def test_namespace_info(self): self._nvme_connect() self.addCleanup(self._nvme_disconnect, self.SUBNQN, ignore_errors=True) @@ -326,7 +322,6 @@ def test_namespace_info(self): format_progress = self.get_property_raw(ns, '.NVMe.Namespace', 'FormatPercentRemaining') self.assertEqual(format_progress, -1) - def test_health_info(self): self._nvme_connect() self.addCleanup(self._nvme_disconnect, self.SUBNQN, ignore_errors=True) @@ -379,15 +374,14 @@ def test_health_info(self): # Try trigerring a self-test operation msg = 'The NVMe controller has no support for self-test operations' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): drive_obj.SmartSelftestStart('xxx', self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Controller') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): drive_obj.SmartSelftestStart('short', self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Controller') msg = 'NVMe Device Self-test command error: Invalid Command Opcode' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): drive_obj.SmartSelftestAbort(self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Controller') - def test_sanitize(self): self._nvme_connect() self.addCleanup(self._nvme_disconnect, self.SUBNQN, ignore_errors=True) @@ -414,17 +408,16 @@ def test_sanitize(self): # Try trigerring a sanitize operation msg = 'Unknown sanitize action xxx' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): drive_obj.SanitizeStart('xxx', self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Controller') msg = r'The NVMe controller has no support for the .* sanitize operation' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): drive_obj.SanitizeStart('block-erase', self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Controller') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): drive_obj.SanitizeStart('crypto-erase', self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Controller') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): drive_obj.SanitizeStart('overwrite', self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Controller') - def test_format_ns(self): self._nvme_connect() self.addCleanup(self._nvme_disconnect, self.SUBNQN, ignore_errors=True) @@ -444,50 +437,50 @@ def test_format_ns(self): state.assertEqual('live', timeout=10) msg = 'Format NVM command error: Invalid Command Opcode: A reserved coded value or an unsupported value in the command opcode field' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): ns.FormatNamespace(self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Namespace') d = dbus.Dictionary(signature='sv') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, 'Unknown secure erase type xxx'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, 'Unknown secure erase type xxx'): d['secure_erase'] = 'xxx' ns.FormatNamespace(d, dbus_interface=self.iface_prefix + '.NVMe.Namespace') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): d['secure_erase'] = 'user_data' ns.FormatNamespace(d, dbus_interface=self.iface_prefix + '.NVMe.Namespace') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): d['secure_erase'] = 'crypto_erase' ns.FormatNamespace(d, dbus_interface=self.iface_prefix + '.NVMe.Namespace') d = dbus.Dictionary(signature='sv') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): d['lba_data_size'] = 0 ns.FormatNamespace(d, dbus_interface=self.iface_prefix + '.NVMe.Namespace') lbaf_curr = self.get_property_raw(ns, '.NVMe.Namespace', 'FormattedLBASize') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): d['lba_data_size'] = lbaf_curr[0] ns.FormatNamespace(d, dbus_interface=self.iface_prefix + '.NVMe.Namespace') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): d['lba_data_size'] = lbaf_curr[0] d['metadata_size'] = lbaf_curr[1] ns.FormatNamespace(d, dbus_interface=self.iface_prefix + '.NVMe.Namespace') msg = "Couldn't match desired LBA data block size in a device supported LBA format data sizes" - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): d['lba_data_size'] = dbus.UInt16(666) ns.FormatNamespace(d, dbus_interface=self.iface_prefix + '.NVMe.Namespace') - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): d['lba_data_size'] = lbaf_curr[0] d['metadata_size'] = dbus.UInt16(5) ns.FormatNamespace(d, dbus_interface=self.iface_prefix + '.NVMe.Namespace') def test_fabrics_connect(self): manager = self.get_interface("/Manager", ".Manager.NVMe") - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, 'Invalid value specified for the transport address argument'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, 'Invalid value specified for the transport address argument'): manager.Connect(self.str_to_ay(self.SUBNQN), "notransport", "", self.no_options) msg = r'Error connecting the controller: failed to write to nvme-fabrics device' - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): manager.Connect(self.str_to_ay(self.SUBNQN), "loop", "127.0.0.1", self.no_options) - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg): + with self.assertRaisesRegex(dbus.exceptions.DBusException, msg): manager.Connect(self.str_to_ay("unknownsubnqn"), "loop", "", self.no_options) d = dbus.Dictionary(signature='sv') @@ -511,10 +504,9 @@ def test_fabrics_connect(self): ctrl.Disconnect(self.no_options, dbus_interface=self.iface_prefix + '.NVMe.Fabrics') ctrl = self.get_object(ctrl_obj_path) - with six.assertRaisesRegex(self, dbus.exceptions.DBusException, r'Object does not exist at path .*|No such interface'): + with self.assertRaisesRegex(dbus.exceptions.DBusException, r'Object does not exist at path .*|No such interface'): self.get_property_raw(ctrl, '.NVMe.Fabrics', 'HostNQN') - def test_hostnqn(self): HOSTNQN_PATH = '/etc/nvme/hostnqn' HOSTID_PATH = '/etc/nvme/hostid' diff --git a/src/tests/dbus-tests/udiskstestcase.py b/src/tests/dbus-tests/udiskstestcase.py index 33b883833..867f956c4 100644 --- a/src/tests/dbus-tests/udiskstestcase.py +++ b/src/tests/dbus-tests/udiskstestcase.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import dbus import subprocess @@ -10,11 +8,7 @@ from datetime import datetime from enum import Enum from systemd import journal - -if sys.version_info.major == 3 and sys.version_info.minor >= 3: - from time import monotonic -else: - from monotonic import monotonic +from time import monotonic import gi gi.require_version('GUdev', '1.0') @@ -23,6 +17,7 @@ test_devs = None FLIGHT_RECORD_FILE = "flight_record.log" + def run_command(command): res = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -34,6 +29,7 @@ def run_command(command): output = out.decode().strip() return (res.returncode, output) + def get_call_long(call): def call_long(*args, **kwargs): """Do an async call with a very long timeout (unless specified otherwise)""" @@ -95,52 +91,6 @@ def get_version(): return (distro, version) -def skip_on(skip_on_distros, skip_on_version="", reason=""): - """A function returning a decorator to skip some test on a given distribution-version combination - - :param skip_on_distros: distro(s) to skip the test on - :type skip_on_distros: str or tuple of str - :param str skip_on_version: version of distro(s) to skip the tests on (only - checked on distribution match) - - """ - if isinstance(skip_on_distros, str): - skip_on_distros = (skip_on_distros,) - - distro, version = get_version() - - def decorator(func): - if distro in skip_on_distros and (not skip_on_version or skip_on_version == version): - msg = "not supported on this distribution in this version" + (": %s" % reason if reason else "") - return unittest.skip(msg)(func) - else: - return func - - return decorator - -def unstable_test(test): - """Decorator for unstable tests - - Failures of tests decorated with this decorator are silently ignored unless - the ``UNSTABLE_TESTS_FATAL`` environment variable is defined. - """ - - def decorated_test(*args): - try: - test(*args) - except unittest.SkipTest: - # make sure skipped tests are just skipped as usual - raise - except Exception as e: - # and swallow everything else, just report a failure of an unstable - # test, unless told otherwise - if "UNSTABLE_TESTS_FATAL" in os.environ: - raise - print("unstable-fail: Ignoring exception '%s'\n" % e, end="", file=sys.stderr) - - return decorated_test - - class DBusProperty(object): TIMEOUT = 5 @@ -218,7 +168,6 @@ def assertAlmostEqual(self, value, delta, timeout=TIMEOUT, getter=None): raise AssertionError('%s is not almost equal to %s (delta = %s)' % (self._value, value, delta)) - def assertGreater(self, value, timeout=TIMEOUT): check_fn = lambda x: x > value ret = self._check(timeout, check_fn) @@ -293,6 +242,7 @@ def assertContains(self, member, timeout=TIMEOUT): if not ret: raise AssertionError('%s does not contain %s' % (self._value, member)) + class UdisksTestCase(unittest.TestCase): iface_prefix = None path_prefix = None @@ -301,7 +251,6 @@ class UdisksTestCase(unittest.TestCase): distro = (None, None, None) # (project, distro_name, version) no_options = dbus.Dictionary(signature="sv") - @classmethod def setUpClass(self): self.iface_prefix = 'org.freedesktop.UDisks2' @@ -315,15 +264,13 @@ def setUpClass(self): self.bus.call_async = get_call_long(self._orig_call_async) self.bus.call_blocking = get_call_long(self._orig_call_blocking) self.vdevs = test_devs - assert len(self.vdevs) > 3; - + assert len(self.vdevs) > 3 @classmethod def tearDownClass(self): self.bus.call_async = self._orig_call_async self.bus.call_blocking = self._orig_call_blocking - def run(self, *args): record = [] now = datetime.now() @@ -371,12 +318,10 @@ def get_interface(self, obj, iface_suffix): obj = self.get_object(obj) return dbus.Interface(obj, self.iface_prefix + iface_suffix) - @classmethod def get_property(self, obj, iface_suffix, prop): return DBusProperty(obj, self.iface_prefix + iface_suffix, prop) - @classmethod def get_property_raw(self, obj, iface_suffix, prop): res = obj.Get(self.iface_prefix + iface_suffix, prop, dbus_interface=dbus.PROPERTIES_IFACE) @@ -426,7 +371,6 @@ def read_file(self, filename): content = f.read() return content - @classmethod def write_file(self, filename, content, ignore_nonexistent=False, binary=False): try: @@ -534,7 +478,7 @@ def assertHasIface(self, obj, iface): for _ in range(20): obj_intro = dbus.Interface(obj, "org.freedesktop.DBus.Introspectable") intro_data = obj_intro.Introspect() - if ('interface name="%s"' % iface) in intro_data: + if 'interface name="%s"' % iface in intro_data: return time.sleep(0.5) @@ -582,6 +526,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): # given as arguments was not handled return False + class CmdFlightRecorder(FlightRecorder): """Flight recorder running a command and gathering its standard and error output""" @@ -610,6 +555,7 @@ def _save(self): rec = '<<<<< ' + self._desc + ' >>>>>' + '\n' + out.decode() + '\n\n' self._store.append(rec) + class JournalRecorder(FlightRecorder): """Flight recorder for gathering logs (journal)"""