def test_polymorphism(self): environment = storage.Environment(True, storage.ProbeMode_NONE, storage.TargetMode_DIRECT) s = storage.Storage(environment) devicegraph = storage.Devicegraph(s) sda = storage.Disk.create(devicegraph, "/dev/sda") gpt = sda.create_partition_table(storage.PtType_GPT) self.assertEqual(sda.get_sid(), 42) self.assertEqual(gpt.get_sid(), 43) tmp1 = devicegraph.find_device(42) self.assertTrue(storage.is_disk(tmp1)) self.assertTrue(storage.to_disk(tmp1)) self.assertFalse(storage.is_partition_table(tmp1)) self.assertRaises(storage.DeviceHasWrongType, lambda: storage.to_partition_table(tmp1)) self.assertRaises(storage.Exception, lambda: storage.to_partition_table(tmp1)) self.assertEqual(storage.downcast(tmp1).__class__, storage.Disk) tmp2 = devicegraph.find_device(43) self.assertTrue(storage.is_partition_table(tmp2)) self.assertTrue(storage.to_partition_table(tmp2)) self.assertFalse(storage.is_disk(tmp2)) self.assertRaises(storage.DeviceHasWrongType, lambda: storage.to_disk(tmp2)) self.assertRaises(storage.Exception, lambda: storage.to_disk(tmp2)) self.assertEqual(storage.downcast(tmp2).__class__, storage.Gpt) tmp3 = devicegraph.find_holder(42, 43) self.assertTrue(storage.is_user(tmp3)) self.assertTrue(storage.to_user(tmp3)) self.assertFalse(storage.is_filesystem_user(tmp3)) self.assertRaises(storage.HolderHasWrongType, lambda: storage.to_filesystem_user(tmp3)) self.assertRaises(storage.Exception, lambda: storage.to_filesystem_user(tmp3)) self.assertEqual(storage.downcast(tmp3).__class__, storage.User)
def test_polymorphism(self): environment = storage.Environment(True, storage.ProbeMode_NONE, storage.TargetMode_DIRECT) s = storage.Storage(environment) devicegraph = storage.Devicegraph(s) sda = storage.Disk.create(devicegraph, "/dev/sda") gpt = sda.create_partition_table(storage.PtType_GPT) self.assertEqual(sda.get_sid(), 42) self.assertEqual(gpt.get_sid(), 43) tmp1 = devicegraph.find_device(42) self.assertTrue(storage.is_disk(tmp1)) self.assertTrue(storage.to_disk(tmp1)) self.assertFalse(storage.is_partition_table(tmp1)) self.assertRaises(storage.DeviceHasWrongType, lambda: storage.to_partition_table(tmp1)) tmp2 = devicegraph.find_device(43) self.assertTrue(storage.is_partition_table(tmp2)) self.assertTrue(storage.to_partition_table(tmp2)) self.assertFalse(storage.is_disk(tmp2)) self.assertRaises(storage.DeviceHasWrongType, lambda: storage.to_disk(tmp2))
sda = storage.Disk.create(devicegraph, "/dev/sda") gpt = sda.create_partition_table(storage.GPT) sda1 = gpt.create_partition("/dev/sda1") sda2 = gpt.create_partition("/dev/sda2") print devicegraph print "partitions on gpt:" for partition in gpt.get_partitions(): print " %s %s" % (partition, partition.get_number()) print print "descendants of sda:" for device in sda.get_descendants(False): partition_table = storage.to_partition_table(device) if partition_table: print " %s is partition table" % partition_table partition = storage.to_partition(device) if partition: print " %s %s is partition" % (partition, partition.get_number()) print
gpt = sda.create_partition_table(storage.PtType_GPT) sda1 = gpt.create_partition("/dev/sda1", storage.Region(0, 100, 262144), storage.PRIMARY) sda2 = gpt.create_partition("/dev/sda2", storage.Region(100, 100, 262144), storage.PRIMARY) print devicegraph print "partitions on gpt:" for partition in gpt.get_partitions(): print " %s %s" % (partition, partition.get_number()) print print "descendants of sda:" for device in sda.get_descendants(False): try: partition_table = storage.to_partition_table(device) print " %s is partition table" % partition_table except storage.DeviceHasWrongType: pass try: partition = storage.to_partition(device) print " %s %s is partition" % (partition, partition.get_number()) except storage.DeviceHasWrongType: pass print