Skip to content

Commit

Permalink
tests: Remove udevadm settle from test_60_partitioning
Browse files Browse the repository at this point in the history
Should not be necessary anymore now that we're more predictable.
Added proper wipe on cleanup though.
  • Loading branch information
tbzatek committed Feb 4, 2022
1 parent fd3045c commit 727a1fb
Showing 1 changed file with 19 additions and 36 deletions.
55 changes: 19 additions & 36 deletions src/tests/dbus-tests/test_60_partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def _remove_format(self, device):
try:
device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
except dbus.exceptions.DBusException:
self.udev_settle()
time.sleep(5)
device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
pass

def _create_format(self, device, ftype):
device.Format(ftype, self.no_options, dbus_interface=self.iface_prefix + '.Block')
Expand All @@ -28,9 +26,7 @@ def _remove_partition(self, part):
try:
part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')
except dbus.exceptions.DBusException:
self.udev_settle()
time.sleep(5)
part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')
pass

def test_create_mbr_partition(self):
disk = self.get_object('/block_devices/' + os.path.basename(self.vdevs[0]))
Expand All @@ -39,6 +35,7 @@ def test_create_mbr_partition(self):
# create msdos partition table
self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

pttype = self.get_property(disk, '.PartitionTable', 'Type')
pttype.assertEqual('dos')
Expand All @@ -55,7 +52,6 @@ def test_create_mbr_partition(self):
# create partition
path1 = disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(100 * 1024**2), part_type, '',
self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

part = self.bus.get_object(self.iface_prefix, path1)
self.assertIsNotNone(part)
Expand Down Expand Up @@ -103,7 +99,6 @@ def test_create_mbr_partition(self):
# create another partition
path2 = disk.CreatePartition(dbus.UInt64(1024**2 + (1024**2 + 100 * 1024**2)), dbus.UInt64(100 * 1024**2),
part_type, '', self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

part = self.bus.get_object(self.iface_prefix, path2)
self.assertIsNotNone(part)
Expand All @@ -113,7 +108,6 @@ def test_create_mbr_partition(self):
# create yet another partition
path3 = disk.CreatePartition(dbus.UInt64(1024**2 + 2 * (1024**2 + 100 * 1024**2)), dbus.UInt64(100 * 1024**2),
part_type, '', self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

part = self.bus.get_object(self.iface_prefix, path3)
self.assertIsNotNone(part)
Expand All @@ -136,11 +130,11 @@ def create_extended_partition(self, ext_options, log_options, part_type=''):
# create msdos partition table
self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

# create extended partition
ext_path = disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(150 * 1024**2), part_type, '',
ext_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

ext_part = self.bus.get_object(self.iface_prefix, ext_path)
self.assertIsNotNone(ext_part)
Expand All @@ -163,7 +157,6 @@ def create_extended_partition(self, ext_options, log_options, part_type=''):
# create logical partition
log_path = disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(50 * 1024**2), '', '',
log_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

log_part = self.bus.get_object(self.iface_prefix, log_path)
self.assertIsNotNone(log_part)
Expand All @@ -180,7 +173,6 @@ def create_extended_partition(self, ext_options, log_options, part_type=''):
# create one more logical partition
log_path2 = disk.CreatePartition(dbus.UInt64(dbus_offset.value + dbus_size.value), dbus.UInt64(50 * 1024**2), '', '',
log_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

log_part2 = self.bus.get_object(self.iface_prefix, log_path2)
self.assertIsNotNone(log_part2)
Expand All @@ -202,6 +194,7 @@ def test_fill_with_primary_partitions(self):
# create msdos partition table
self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

options = dbus.Dictionary({'partition-type': 'primary'}, signature='sv')
offset = 1024**2
Expand All @@ -210,7 +203,6 @@ def test_fill_with_primary_partitions(self):
# create primary partition
path = disk.CreatePartition(dbus.UInt64(offset + i * (offset + size)), dbus.UInt64(size), '', '',
options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

part = self.bus.get_object(self.iface_prefix, path)
self.assertIsNotNone(part)
Expand All @@ -232,6 +224,7 @@ def test_create_gpt_partition(self):
pttype.assertEqual('gpt')

self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

gpt_name = 'home'
gpt_type = '933ac7e1-2eb4-4f13-b844-0e14e2aef915'
Expand All @@ -241,7 +234,6 @@ def test_create_gpt_partition(self):
gpt_type, gpt_name,
self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable')

self.udev_settle()
part = self.bus.get_object(self.iface_prefix, path)
self.assertIsNotNone(part)

Expand Down Expand Up @@ -290,6 +282,7 @@ def test_create_with_format(self):
self._create_format(disk, 'dos')

self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

# create partition with xfs format
path = disk.CreatePartitionAndFormat(dbus.UInt64(1024**2), dbus.UInt64(100 * 1024**2), '', '',
Expand Down Expand Up @@ -345,6 +338,7 @@ def test_create_with_format_auto_type_mbr(self):
self._create_format(disk, 'dos')

self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

# create partition with udf format and automatically set partition type
# it should be 0x07
Expand Down Expand Up @@ -376,10 +370,11 @@ def test_create_with_format_auto_type_gpt(self):
disk = self.get_object('/block_devices/' + os.path.basename(self.vdevs[0]))
self.assertIsNotNone(disk)

# create msdos partition table
# create gpt partition table
self._create_format(disk, 'gpt')

self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

# create partition with udf format and automatically set partition type
# it should be ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
Expand Down Expand Up @@ -414,9 +409,7 @@ def _remove_format(self, device):
try:
device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
except dbus.exceptions.DBusException:
self.udev_settle()
time.sleep(5)
device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
pass

def _create_format(self, device, ftype):
device.Format(ftype, self.no_options, dbus_interface=self.iface_prefix + '.Block')
Expand All @@ -425,9 +418,7 @@ def _remove_partition(self, part):
try:
part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')
except dbus.exceptions.DBusException:
self.udev_settle()
time.sleep(5)
part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')
pass

def _create_partition(self, disk, start=1024**2, size=100 * 1024**2, fmt='xfs', type=''):
if fmt:
Expand All @@ -439,7 +430,6 @@ def _create_partition(self, disk, start=1024**2, size=100 * 1024**2, fmt='xfs',
self.no_options,
dbus_interface=self.iface_prefix + '.PartitionTable')

self.udev_settle()
part = self.bus.get_object(self.iface_prefix, path)
self.assertIsNotNone(part)

Expand All @@ -451,14 +441,13 @@ def test_delete(self):

self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
path = str(part.object_path)

part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

part_name = path.split('/')[-1]
disk_name = os.path.basename(self.vdevs[0])
part_syspath = '/sys/block/%s/%s' % (disk_name, part_name)
Expand All @@ -481,6 +470,7 @@ def test_dos_flags(self):

self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
self.addCleanup(self._remove_partition, part)
Expand All @@ -491,7 +481,6 @@ def test_dos_flags(self):
# set boot flag (10000000(2), 128(10), 0x80(16))
part.SetFlags(dbus.UInt64(128), self.no_options,
dbus_interface=self.iface_prefix + '.Partition')
self.udev_settle()

# test flags value on types
dbus_flags = self.get_property(part, '.Partition', 'Flags')
Expand All @@ -510,6 +499,7 @@ def test_gpt_flags(self):

self._create_format(disk, 'gpt')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk, fmt=False, type=esp_guid)
self.addCleanup(self._remove_partition, part)
Expand All @@ -531,7 +521,6 @@ def test_gpt_flags(self):
# set legacy BIOS bootable flag (100(2), 4(10), 0x4(16))
part.SetFlags(dbus.UInt64(4), self.no_options,
dbus_interface=self.iface_prefix + '.Partition')
self.udev_settle()

# test flags value on types
dbus_flags = self.get_property(part, '.Partition', 'Flags')
Expand All @@ -555,6 +544,7 @@ def test_gpt_type(self):

self._create_format(disk, 'gpt')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
self.addCleanup(self._remove_partition, part)
Expand All @@ -572,7 +562,6 @@ def test_gpt_type(self):
home_guid = '933ac7e1-2eb4-4f13-b844-0e14e2aef915'
part.SetType(home_guid, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')
self.udev_settle()

# test flags value on types
dbus_type = self.get_property(part, '.Partition', 'Type')
Expand All @@ -589,6 +578,7 @@ def test_dos_type(self):

self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
self.addCleanup(self._remove_partition, part)
Expand All @@ -606,7 +596,6 @@ def test_dos_type(self):
part_type = '0x8e' # 'Linux LVM' type, see https://en.wikipedia.org/wiki/Partition_type#PID_8Eh
part.SetType(part_type, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')
self.udev_settle()

# test flags value on types
dbus_type = self.get_property(part, '.Partition', 'Type')
Expand All @@ -624,6 +613,7 @@ def test_resize(self):

self._create_format(disk, 'gpt')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

disk_size = self.get_property(disk, '.Block', 'Size')

Expand All @@ -649,8 +639,6 @@ def test_resize(self):
part.Resize(0, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

part_offset.assertEqual(initial_offset)
max_size = part_size.value
part_size.assertGreater(initial_size)
Expand All @@ -660,8 +648,6 @@ def test_resize(self):
part.Resize(new_size, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

part_offset.assertEqual(initial_offset)
# resize should guarantee at least the requested size
part_size.assertGreater(new_size - 1)
Expand All @@ -671,8 +657,6 @@ def test_resize(self):
part.Resize(max_size, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

part_offset.assertEqual(initial_offset)
part_size.assertGreater(max_size - 1)
part_size.assertLess(disk_size.value)
Expand All @@ -683,6 +667,7 @@ def test_name(self):

self._create_format(disk, 'gpt')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
self.addCleanup(self._remove_partition, part)
Expand All @@ -700,8 +685,6 @@ def test_name(self):
part.SetName('test', self.no_options,
dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

# test flags value on types
dbus_name = self.get_property(part, '.Partition', 'Name')
dbus_name.assertEqual('test')
Expand Down

0 comments on commit 727a1fb

Please sign in to comment.