Ejemplo n.º 1
0
 def test_set_partition_type_gpt(self):
     image = Image(self.img, MiB(6), VolumeSchema.gpt)
     image.partition(offset=MiB(1), size=MiB(1))
     self.assertEqual(len(image.disk.partitions), 1)
     image.set_parition_type(1, '21686148-6449-6E6F-744E-656564454649')
     disk_info = image.diagnostics()
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['type'],
                      '21686148-6449-6E6F-744E-656564454649')
     image.set_parition_type(1, '00000000-0000-0000-0000-0000DEADBEEF')
     disk_info = image.diagnostics()
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['type'],
                      '00000000-0000-0000-0000-0000DEADBEEF')
Ejemplo n.º 2
0
 def test_set_partition_type_mbr(self):
     image = Image(self.img, MiB(6), VolumeSchema.mbr)
     image.partition(offset=MiB(1), size=MiB(1))
     self.assertEqual(len(image.disk.partitions), 1)
     image.set_parition_type(1, '83')
     disk_info = image.diagnostics()
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['type'],
                      '83')
     image.set_parition_type(1, 'da')
     disk_info = image.diagnostics()
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['type'],
                      'da')
Ejemplo n.º 3
0
 def test_set_partition_type_mbr(self):
     image = Image(self.img, MiB(6), VolumeSchema.mbr)
     image.partition(offset=MiB(1), size=MiB(1))
     self.assertEqual(len(image.disk.partitions), 1)
     image.set_parition_type(1, '83')
     disk_info = image.diagnostics()
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['type'],
                      '83')
     image.set_parition_type(1, 'da')
     disk_info = image.diagnostics()
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['type'],
                      'da')
Ejemplo n.º 4
0
 def test_set_partition_type_gpt(self):
     image = Image(self.img, MiB(6), VolumeSchema.gpt)
     image.partition(offset=MiB(1), size=MiB(1))
     self.assertEqual(len(image.disk.partitions), 1)
     image.set_parition_type(1, '21686148-6449-6E6F-744E-656564454649')
     disk_info = image.diagnostics()
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['type'],
                      '21686148-6449-6E6F-744E-656564454649')
     image.set_parition_type(1, '00000000-0000-0000-0000-0000DEADBEEF')
     disk_info = image.diagnostics()
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['type'],
                      '00000000-0000-0000-0000-0000DEADBEEF')
Ejemplo n.º 5
0
 def test_partition(self):
     # Create BIOS boot partition
     #
     # The partition is 1MiB in size, as recommended by various
     # partitioning guides.  The actual required size is much, much
     # smaller.
     image = Image(self.img, MiB(10))
     image.partition(new='1:4MiB:+1MiB')
     image.partition(typecode='1:21686148-6449-6E6F-744E-656564454649')
     image.partition(change_name='1:grub')
     mbr = image.diagnostics(Diagnostics.mbr)
     # We should see that the disk size is 10MiB.
     self.assertRegex(mbr, '10.0 MiB')
     gpt = image.diagnostics(Diagnostics.gpt)
     # We should see that there is 1 partition named grub.
     self.assertRegex(gpt, 'grub')
Ejemplo n.º 6
0
 def test_small_partition_size_and_offset(self):
     # LP: #1630709 - structure parts with size and offset < 1MB.
     image = Image(self.img, MiB(2), VolumeSchema.mbr)
     image.partition(offset=256, size=512)
     disk_info = image.diagnostics()
     # Even though the offset and size are set at 256 bytes and 512 bytes
     # respectively, the minimum granularity is one sector (i.e. 512
     # bytes).  The start and size returned by diagnostics() are in sector
     # units.
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['start'],
                      1)
     self.assertEqual(disk_info['partitiontable']['partitions'][0]['size'],
                      1)
Ejemplo n.º 7
0
 def test_small_partition_size_and_offset(self):
     # LP: #1630709 - structure parts with size and offset < 1MB.
     image = Image(self.img, MiB(2), VolumeSchema.mbr)
     image.partition(offset=256, size=512)
     disk_info = image.diagnostics()
     # Even though the offset and size are set at 256 bytes and 512 bytes
     # respectively, the minimum granularity is one sector (i.e. 512
     # bytes).  The start and size returned by diagnostics() are in sector
     # units.
     self.assertEqual(
         disk_info['partitiontable']['partitions'][0]['start'],
         1)
     self.assertEqual(
         disk_info['partitiontable']['partitions'][0]['size'],
         1)
Ejemplo n.º 8
0
 def test_gpt_image_partitions(self):
     image = Image(self.img, MiB(10), VolumeSchema.gpt)
     image.partition(offset=MiB(4), size=MiB(1), name='grub')
     self.assertEqual(len(image.disk.partitions), 1)
     image.partition(offset=MiB(5), size=MiB(4))
     self.assertEqual(len(image.disk.partitions), 2)
     image.set_parition_type(1, '21686148-6449-6E6F-744E-656564454649')
     image.set_parition_type(2, '0FC63DAF-8483-4772-8E79-3D69D8477DE4')
     # Use an external tool for checking the partition table to be sure
     # that it's indeed correct as suspected.
     disk_info = image.diagnostics()
     partitions = disk_info['partitiontable']
     # The device id is unpredictable.
     partitions.pop('id')
     # Newer sfdisk displays an additional field of 'sectorsize' that
     # we're not really interested in.
     partitions.pop('sectorsize', None)
     # The partition uuids as well.
     [p.pop('uuid') for p in partitions['partitions']]
     self.maxDiff = None
     self.assertEqual(
         partitions, {
             'label':
             'gpt',
             'device':
             self.img,
             'unit':
             'sectors',
             'firstlba':
             34,
             'lastlba':
             20446,
             'partitions': [{
                 'node': '{}1'.format(self.img),
                 'start': 8192,
                 'size': 2048,
                 'type': '21686148-6449-6E6F-744E-656564454649',
                 'name': 'grub',
             }, {
                 'node': '{}2'.format(self.img),
                 'start': 10240,
                 'size': 8192,
                 'type': '0FC63DAF-8483-4772-8E79-3D69D8477DE4',
             }],
         })
Ejemplo n.º 9
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',
             }],
         })
Ejemplo n.º 10
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',
             }],
         })
Ejemplo n.º 11
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',
             }],
         })
Ejemplo n.º 12
0
 def test_gpt_image_partitions(self):
     image = Image(self.img, MiB(10), VolumeSchema.gpt)
     image.partition(offset=MiB(4), size=MiB(1), name='grub')
     self.assertEqual(len(image.disk.partitions), 1)
     image.partition(offset=MiB(5), size=MiB(4))
     self.assertEqual(len(image.disk.partitions), 2)
     image.set_parition_type(1, '21686148-6449-6E6F-744E-656564454649')
     image.set_parition_type(2, '0FC63DAF-8483-4772-8E79-3D69D8477DE4')
     # Use an external tool for checking the partition table to be sure
     # that it's indeed correct as suspected.
     disk_info = image.diagnostics()
     partitions = disk_info['partitiontable']
     # The device id is unpredictable.
     partitions.pop('id')
     # The partition uuids as well.
     [p.pop('uuid') for p in partitions['partitions']]
     self.maxDiff = None
     self.assertEqual(partitions, {
         'label': 'gpt',
         'device': self.img,
         'unit': 'sectors',
         'firstlba': 34,
         'lastlba': 20446,
         'partitions': [{
             'node': '{}1'.format(self.img),
             'start': 8192,
             'size': 2048,
             'type': '21686148-6449-6E6F-744E-656564454649',
             'name': 'grub',
             }, {
             'node': '{}2'.format(self.img),
             'start': 10240,
             'size': 8192,
             'type': '0FC63DAF-8483-4772-8E79-3D69D8477DE4',
             }],
         })
Ejemplo n.º 13
0
image.partition(new='1:4MiB:+1MiB')
image.partition(typecode='1:21686148-6449-6E6F-744E-656564454649')
image.partition(change_name='1:grub')
image.copy_blob('blobs/img.bios-boot',
                bs='1MiB', seek=4, count=1, conv='notrunc')

# Create EFI system partition
#
# TODO: switch to 512MiB as recommended by the standard
image.partition(new='2:5MiB:+64MiB')
image.partition(typecode='2:C12A7328-F81F-11D2-BA4B-00A0C93EC93B')
image.partition(change_name='2:system-boot')
image.copy_blob('blobs/img.system-boot',
                bs='1MB', seek=4, count=64, conv='notrunc')

# Create main snappy writable partition
image.partition(new='3:72MiB:+3646MiB')
image.partition(typecode='3:0FC63DAF-8483-4772-8E79-3D69D8477DE4')
image.partition(change_name='3:writable')
image.copy_blob('blobs/img.writable',
                bs='1MiB', seek=72, count=3646, conv='notrunc')

# TODO: the partition needs to be populated with skeleton directory layout
# TODO: the partition needs to have all the snaps copied to a
# firstboot-specific location
# TODO: (assertions and side infos)

# Show what we have
print(image.diagnostics(Diagnostics.mbr))
print(image.diagnostics(Diagnostics.gpt))
Ejemplo n.º 14
0
# Create EFI system partition
#
# TODO: switch to 512MiB as recommended by the standard
image.partition(new='2:5MiB:+64MiB')
image.partition(typecode='2:C12A7328-F81F-11D2-BA4B-00A0C93EC93B')
image.partition(change_name='2:system-boot')
image.copy_blob('blobs/img.system-boot',
                bs='1MB',
                seek=4,
                count=64,
                conv='notrunc')

# Create main snappy writable partition
image.partition(new='3:72MiB:+3646MiB')
image.partition(typecode='3:0FC63DAF-8483-4772-8E79-3D69D8477DE4')
image.partition(change_name='3:writable')
image.copy_blob('blobs/img.writable',
                bs='1MiB',
                seek=72,
                count=3646,
                conv='notrunc')

# TODO: the partition needs to be populated with skeleton directory layout
# TODO: the partition needs to have all the snaps copied to a
# firstboot-specific location
# TODO: (assertions and side infos)

# Show what we have
print(image.diagnostics(Diagnostics.mbr))
print(image.diagnostics(Diagnostics.gpt))