Skip to content

Commit

Permalink
tests: Add tests for resolving partlabel/partuuid
Browse files Browse the repository at this point in the history
  • Loading branch information
tbzatek committed Oct 17, 2022
1 parent ed17dc9 commit cf47eee
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/tests/dbus-tests/test_10_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,31 @@ def _wipe(self, device, retry=True):
def test_60_resolve_device(self):
manager = self.get_interface(self.manager_obj, '.Manager')

# empty/invalid devspec supplied
spec = dbus.Dictionary({}, signature='sv')
msg = r'Invalid device specification provided'
with six.assertRaisesRegex(self, 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):
manager.ResolveDevice(spec, self.no_options)

# try some non-existing device first
spec = dbus.Dictionary({'path': '/dev/i-dont-exist'}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
self.assertEqual(len(devices), 0)
spec = dbus.Dictionary({'uuid': 'I-DONT-EXIST'}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
self.assertEqual(len(devices), 0)
spec = dbus.Dictionary({'label': 'I-DONT-EXIST'}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
self.assertEqual(len(devices), 0)
spec = dbus.Dictionary({'partuuid': 'I-DONT-EXIST'}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
self.assertEqual(len(devices), 0)
spec = dbus.Dictionary({'partlabel': 'I-DONT-EXIST'}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
self.assertEqual(len(devices), 0)

# get our first virtual disk by path
spec = dbus.Dictionary({'path': self.vdevs[0]}, signature='sv')
Expand Down Expand Up @@ -297,6 +318,34 @@ def test_60_resolve_device(self):
self.assertEqual(len(devices), 1)
self.assertIn(object_path, devices)

# create a partition on another device
disk = self.get_object('/block_devices/' + os.path.basename(self.vdevs[2]))
self.assertIsNotNone(disk)
disk.Format('gpt', self.no_options, dbus_interface=self.iface_prefix + '.Block')
self.addCleanup(self._wipe, self.vdevs[2])
part_label = 'PRTLBLX'
path = disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(100 * 1024**2),
'', part_label, self.no_options,
dbus_interface=self.iface_prefix + '.PartitionTable')
part = self.bus.get_object(self.iface_prefix, path)
self.assertIsNotNone(part)
part_uuid = self.get_property_raw(part, '.Partition', 'UUID')
self.assertIsNotNone(part_uuid)
part_name_val = self.get_property_raw(part, '.Partition', 'Name')
self.assertEquals(part_name_val, part_label)

# check that partlabel and partuuid can be resolved
spec = dbus.Dictionary({'partlabel': part_label}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
object_path = '%s/block_devices/%s1' % (self.path_prefix, os.path.basename(self.vdevs[2]))
self.assertEqual(len(devices), 1)
self.assertIn(object_path, devices)
spec = dbus.Dictionary({'partuuid': part_uuid}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
object_path = '%s/block_devices/%s1' % (self.path_prefix, os.path.basename(self.vdevs[2]))
self.assertEqual(len(devices), 1)
self.assertIn(object_path, devices)

def test_80_device_presence(self):
'''Test the debug devices are present on the bus'''
for d in self.vdevs:
Expand Down

0 comments on commit cf47eee

Please sign in to comment.