Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few small test improvements #1254

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/tests/dbus-tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/python3

from __future__ import print_function

import os
import sys
import time
Expand All @@ -14,7 +12,6 @@
import tempfile
import pdb
import re
import six
import atexit
import traceback
import yaml
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions src/tests/dbus-tests/test_10_basic.py
Original file line number Diff line number Diff line change
@@ -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'''

Expand Down Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/tests/dbus-tests/test_19_lsm.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import re
import six
import dbus
import unittest
import tempfile
import shutil

import udiskstestcase


class UdisksLSMTestCase(udiskstestcase.UdisksTestCase):
"""
Provide as much LSM module code coverage as possible using the libstoragemgmt 'sim' plugin.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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')
12 changes: 5 additions & 7 deletions src/tests/dbus-tests/test_20_LVM.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import re
import time
import unittest
import six
import sys
import glob

from packaging.version import Version
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')

Expand Down
16 changes: 7 additions & 9 deletions src/tests/dbus-tests/test_30_iscsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import glob
import os
import re
import six
import time
import shutil
import unittest

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/tests/dbus-tests/test_40_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import dbus
import glob
import os
import six
import unittest
import udiskstestcase


Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
1 change: 0 additions & 1 deletion src/tests/dbus-tests/test_50_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import fcntl
import os
import time
import unittest

import udiskstestcase

Expand Down
11 changes: 5 additions & 6 deletions src/tests/dbus-tests/test_60_partitioning.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import dbus
import os
import six
import time
import uuid

Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions src/tests/dbus-tests/test_70_encrypted.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand All @@ -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')

Expand Down Expand Up @@ -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')

Expand All @@ -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')

Expand Down
Loading
Loading