~wesley-wiedenmeier/curtin/curtin-1543263

« back to all changes in this revision

Viewing changes to curtin/commands/block_meta.py

  • Committer: Wesley Wiedenmeier
  • Date: 2016-02-12 03:00:44 UTC
  • Revision ID: wesley.wiedenmeier@gmail.com-20160212030044-r00uy4b0g1ne98yl
Add function find_previous_partition to find correct previous partition number
even if configuration requests partition numbers to be skipped.

Resolves LP: 1543263

Show diffs side-by-side

added added

removed removed

Lines of Context:
503
503
    return logicaldisks
504
504
 
505
505
 
 
506
def find_previous_partition(disk_id, part_id, storage_config):
 
507
    last_partnum = 0
 
508
    for item_id, command in storage_config.items():
 
509
        print('item_id: %s last=%s' % (item_id, last_partnum))
 
510
        if item_id == part_id:
 
511
            print("found last partition for %s was %s" %
 
512
                  (part_id, last_partnum))
 
513
            return last_partnum
 
514
        if command['type'] == 'partition' and command['device'] == disk_id:
 
515
            if 'number' in item_id:
 
516
                last_partnum = item_id['number']
 
517
            else:
 
518
                last_partnum += 1
 
519
    return None
 
520
 
 
521
 
506
522
def partition_handler(info, storage_config):
507
523
    device = info.get('device')
508
524
    size = info.get('size')
528
544
    except:
529
545
        logical_block_size_bytes = 512
530
546
 
 
547
    print("disk=%s\npartnumber=%s\n" % (disk, partnumber))
531
548
    if partnumber > 1:
532
549
        if partnumber == 5 and disk_ptable == "msdos":
533
550
            for key, item in storage_config.items():
540
557
            previous_partition = "/sys/block/%s/%s%s/" % \
541
558
                (disk_kname, disk_kname, extended_part_no)
542
559
        else:
 
560
            pnum = find_previous_partition(device, info['id'], storage_config)
543
561
            previous_partition = "/sys/block/%s/%s%s/" % \
544
 
                (disk_kname, disk_kname, partnumber - 1)
 
562
                (disk_kname, disk_kname, pnum)
545
563
        with open(os.path.join(previous_partition, "size"), "r") as fp:
546
564
            previous_size = int(fp.read())
547
565
        with open(os.path.join(previous_partition, "start"), "r") as fp: