Exemplo n.º 1
0
 def test_sector_conversion(self):
     # For empty non-partitioned images we default to a 512 sector size.
     image = Image(self.img, MiB(1))
     self.assertEqual(image.sector(10), 5120)
     # In case of using partitioning, be sure we use the sector size as
     # returned by pyparted.
     image = Image(self.img, MiB(5), VolumeSchema.mbr)
     self.assertEqual(image.sector(10), 10 * image.device.sectorSize)
Exemplo n.º 2
0
 def test_sector_conversion(self):
     # For empty non-partitioned images we default to a 512 sector size.
     image = Image(self.img, MiB(1))
     self.assertEqual(image.sector(10), 5120)
     # In case of using partitioning, be sure we use the sector size as
     # returned by pyparted.
     image = Image(self.img, MiB(5), VolumeSchema.mbr)
     self.assertEqual(image.sector(10), 10 * image.device.sectorSize)
Exemplo n.º 3
0
 def test_mbr_image_partitions(self):
     image = Image(self.img, MiB(2), VolumeSchema.mbr)
     # Create the first partition.
     image.partition(offset=image.sector(33),
                     size=image.sector(3000),
                     is_bootable=True)
     self.assertEqual(len(image.disk.partitions), 1)
     # Append the next one.
     image.partition(offset=image.sector(3033), size=image.sector(1000))
     self.assertEqual(len(image.disk.partitions), 2)
     image.set_parition_type(1, '83')
     image.set_parition_type(2, 'dd')
     disk_info = image.diagnostics()
     partitions = disk_info['partitiontable']
     # The device id is unpredictable.
     partitions.pop('id')
     # XXX: In later versions of pyparted the partitiontable structure
     #  added a 'grain' entry that we're not really interested in.
     #  Remove it so we can have the tests working for all series.
     if 'grain' in partitions:
         partitions.pop('grain')
     # Newer sfdisk displays an additional field of 'sectorsize' that
     # we're not really interested in.
     partitions.pop('sectorsize', None)
     self.assertEqual(
         partitions, {
             'label':
             'dos',
             'device':
             self.img,
             'unit':
             'sectors',
             'partitions': [{
                 'node': '{}1'.format(self.img),
                 'start': 33,
                 'size': 3000,
                 'type': '83',
                 'bootable': True,
             }, {
                 'node': '{}2'.format(self.img),
                 'start': 3033,
                 'size': 1000,
                 'type': 'dd',
             }],
         })
Exemplo n.º 4
0
 def test_mbr_image_partitions(self):
     image = Image(self.img, MiB(2), VolumeSchema.mbr)
     # Create the first partition.
     image.partition(offset=image.sector(33),
                     size=image.sector(3000),
                     is_bootable=True)
     self.assertEqual(len(image.disk.partitions), 1)
     # Append the next one.
     image.partition(offset=image.sector(3033),
                     size=image.sector(1000))
     self.assertEqual(len(image.disk.partitions), 2)
     image.set_parition_type(1, '83')
     image.set_parition_type(2, 'dd')
     disk_info = image.diagnostics()
     partitions = disk_info['partitiontable']
     # The device id is unpredictable.
     partitions.pop('id')
     # XXX: In later versions of pyparted the partitiontable structure
     #  added a 'grain' entry that we're not really interested in.
     #  Remove it so we can have the tests working for all series.
     if 'grain' in partitions:
         partitions.pop('grain')
     self.assertEqual(partitions, {
         'label': 'dos',
         'device': self.img,
         'unit': 'sectors',
         'partitions': [{
             'node': '{}1'.format(self.img),
             'start': 33,
             'size': 3000,
             'type': '83',
             'bootable': True,
             }, {
             'node': '{}2'.format(self.img),
             'start': 3033,
             'size': 1000,
             'type': 'dd',
             }],
         })
Exemplo n.º 5
0
 def test_mbr_image_partitions(self):
     image = Image(self.img, MiB(2), VolumeSchema.mbr)
     # Create the first partition.
     image.partition(offset=image.sector(33),
                     size=image.sector(3000),
                     is_bootable=True)
     self.assertEqual(len(image.disk.partitions), 1)
     # Append the next one.
     image.partition(offset=image.sector(3033), size=image.sector(1000))
     self.assertEqual(len(image.disk.partitions), 2)
     image.set_parition_type(1, '83')
     image.set_parition_type(2, 'dd')
     disk_info = image.diagnostics()
     partitions = disk_info['partitiontable']
     # The device id is unpredictable.
     partitions.pop('id')
     self.assertEqual(
         partitions, {
             'label':
             'dos',
             'device':
             self.img,
             'unit':
             'sectors',
             'partitions': [{
                 'node': '{}1'.format(self.img),
                 'start': 33,
                 'size': 3000,
                 'type': '83',
                 'bootable': True,
             }, {
                 'node': '{}2'.format(self.img),
                 'start': 3033,
                 'size': 1000,
                 'type': 'dd',
             }],
         })