Diff comments:
> diff --git a/curtin/block/__init__.py b/curtin/block/__init__.py
> index a7fe22f..97596e1 100644
> --- a/curtin/block/__init__.py
> +++ b/curtin/block/__init__.py
> @@ -248,46 +248,47 @@ def _lsblock(args=None):
> return _lsblock_pairs_to_dict(out)
>
>
> -def _sfdisk_parse(lines):
> - info = {}
> - for line in lines:
> - if ':' not in line:
> - continue
> - lhs, _, rhs = line.partition(':')
> - key = lhs.strip()
> - value = rhs.strip()
> - if "," in rhs:
> - value = dict((item.split('=')
> - for item in rhs.replace(' ', '').split(',')))
> - info[key] = value
> -
> - return info
> -
> -
> def sfdisk_info(devpath):
> ''' returns dict of sfdisk info about disk partitions
> {
> - "/dev/vda1": {
> - "size": "20744159",
> - "start": "227328",
> - "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
> - "uuid": "29983666-2A66-4F14-8533-7CE13B715462"
> - },
> - "device": "/dev/vda",
> - "first-lba": "34",
> - "label": "gpt",
> - "label-id": "E94FCCFE-953D-4D4B-9511-451BBCC17A9A",
> - "last-lba": "20971486",
> - "unit": "sectors"
> + "label": "gpt",
> + "id": "877716F7-31D0-4D56-A1ED-4D566EFE418E",
> + "device": "/dev/vda",
> + "unit": "sectors",
> + "firstlba": 34,
> + "lastlba": 41943006,
> + "partitions": [
> + {"node": "/dev/vda1", "start": 227328, "size": 41715679,
> + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
> + "uuid": "60541CAF-E2AC-48CD-BF89-AF16051C833F"},
> + ]
> + }
> + {
> + "label":"dos",
> + "id":"0xb0dbdde1",
> + "device":"/dev/vdb",
> + "unit":"sectors",
> + "partitions": [
> + {"node":"/dev/vdb1", "start":2048, "size":8388608,
> + "type":"83", "bootable":true},
> + {"node":"/dev/vdb2", "start":8390656, "size":8388608, "type":"83"},
> + {"node":"/dev/vdb3", "start":16779264, "size":62914560, "type":"5"},
> + {"node":"/dev/vdb5", "start":16781312, "size":31457280,
> "type":"83"},
> + {"node":"/dev/vdb6", "start":48240640, "size":10485760,
> "type":"83"},
> + {"node":"/dev/vdb7", "start":58728448, "size":20965376, "type":"83"}
> + ]
> }
> '''
> (parent, partnum) = get_blockdev_for_partition(devpath)
> try:
> - (out, _err) = util.subp(['sfdisk', '--dump', parent], capture=True)
> + (out, _err) = util.subp(['sfdisk', '--json', parent], capture=True)
At least for now; it is not an issue. Subiquity is the only user of the
'preserve' flag; MAAS does not have such use-case; and for now the
partition_verify() which utilizes this code-path is only triggered for a
preserve scenario (which is also Ubuntu only).
Alternatively, we could also fix the existing code and use it as a fallback if
--json output failed.
> except util.ProcessExecutionError as e:
> + out = None
> LOG.exception(e)
> - out = ""
> - return _sfdisk_parse(out.splitlines())
> + if out is not None:
> + return util.load_json(out).get('partitiontable', {})
> +
> + return {}
>
>
> def dmsetup_info(devname):
> diff --git a/curtin/commands/block_meta.py b/curtin/commands/block_meta.py
> index 1ad49b7..52eae94 100644
> --- a/curtin/commands/block_meta.py
> +++ b/curtin/commands/block_meta.py
> @@ -715,8 +721,28 @@ def verify_exists(devpath):
> raise RuntimeError("Device %s does not exist" % devpath)
>
>
> -def verify_size(devpath, expected_size_bytes):
> - found_size_bytes = block.read_sys_block_size_bytes(devpath)
> +def _sfdisk_get_partition_info(devpath, sfdisk_info=None):
> + if not sfdisk_info:
> + sfdisk_info = block.sfdisk_info(devpath)
> +
> + entry = [part for part in sfdisk_info['partitions']
> + if part['node'] == devpath]
> + if len(entry) != 1:
> + raise RuntimeError('Device %s not present in sfdisk dump:\n%s' %
> + devpath, util.json_dumps(sfdisk_info))
> + return entry.pop()
> +
> +
> +def verify_size(devpath, expected_size_bytes, sfdisk_info=None):
> + if not sfdisk_info:
> + sfdisk_info = block.sfdisk_info(devpath)
> +
> + part_info = _sfdisk_get_partition_info(devpath, sfdisk_info=sfdisk_info)
> + # FIXME: stuff this list of msdos extended partition type codes elsewhere
+1
> + if part_info.get('type') in ('5', 'f', '85', 'c5'):
> + found_size_bytes = int(part_info['size']) * 512
> + else:
> + found_size_bytes = block.read_sys_block_size_bytes(devpath)
> msg = (
> 'Verifying %s size, expecting %s bytes, found %s bytes' % (
> devpath, expected_size_bytes, found_size_bytes))
> @@ -725,19 +751,30 @@ def verify_size(devpath, expected_size_bytes):
> raise RuntimeError(msg)
>
>
> -def verify_ptable_flag(devpath, expected_flag):
> - if not SGDISK_FLAGS.get(expected_flag):
> +def verify_ptable_flag(devpath, expected_flag, sfdisk_info=None):
> + if expected_flag not in (list(SGDISK_FLAGS.keys()) +
Yes, will fix.
> + list(MSDOS_FLAGS.keys())):
> raise RuntimeError(
> - 'Cannot verify unknown partition flag: %s', expected_flag)
> + 'Cannot verify unknown partition flag: %s' % expected_flag)
>
> - info = block.sfdisk_info(devpath)
> - if devpath not in info:
> - raise RuntimeError('Device %s not present in sfdisk dump:\n%s' %
> - devpath, util.json_dumps(info))
> + if not sfdisk_info:
> + sfdisk_info = block.sfdisk_info(devpath)
> + if not sfdisk_info:
> + raise RuntimeError('Failed to extract sfdisk info from %s' % devpath)
For block-meta, I'll move this check to partition_verify which is the entry to
the verify partition code paths. We then pass the asserted value info to the
sub functions which will reuse this info without a second invocation.
>
> - entry = info[devpath]
> + entry = _sfdisk_get_partition_info(devpath, sfdisk_info=sfdisk_info)
> LOG.debug("Device %s ptable entry: %s", devpath, util.json_dumps(entry))
> - (found_flag, code) = ptable_uuid_to_flag_entry(entry['type'])
> + found_flag = None
> + if (sfdisk_info['label'] in ('dos', 'msdos')):
> + if expected_flag == 'boot':
> + found_flag = 'boot' if entry.get('bootable') is True else None
> + elif expected_flag == 'extended':
> + (found_flag, _code) = ptable_uuid_to_flag_entry(entry['type'])
> + elif expected_flag == 'logical':
> + (_parent, partnumber) = block.get_blockdev_for_partition(devpath)
> + found_flag = 'logical' if int(partnumber) > 4 else None
> + else:
> + (found_flag, _code) = ptable_uuid_to_flag_entry(entry['type'])
> msg = (
> 'Verifying %s partition flag, expecting %s, found %s' % (
> devpath, expected_flag, found_flag))
> diff --git a/curtin/storage_config.py b/curtin/storage_config.py
> index eccb96b..c0e351d 100644
> --- a/curtin/storage_config.py
> +++ b/curtin/storage_config.py
> @@ -1234,13 +1238,18 @@ def ptable_uuid_to_flag_entry(guid):
> '9E1A2D38-C612-4316-AA26-8B49521E5A8B': ('prep', '4200'),
> 'A19D880F-05FC-4D3B-A006-743F0F84911E': ('raid', 'fd00'),
> '0657FD6D-A4AB-43C4-84E5-0933C84B4F4F': ('swap', '8200'),
> - '0X83': ('linux', '83'),
> '0XF': ('extended', 'f'),
> '0X5': ('extended', 'f'),
> + '0X80': ('boot', '80'),
> + '0X83': ('linux', '83'),
> '0X85': ('extended', 'f'),
> '0XC5': ('extended', 'f'),
> }
> name = code = None
> +
> + # prefix non-uuid guid values with 0x
> + if guid and '-' not in guid and not guid.upper().startswith('0X'):
> + guid = '0x' + guid
we .upper() the value anyhow? Either is fine.
> if guid and guid.upper() in guid_map:
> name, code = guid_map[guid.upper()]
>
--
https://code.launchpad.net/~raharper/curtin/+git/curtin/+merge/383180
Your team curtin developers is subscribed to branch curtin:master.
--
Mailing list: https://launchpad.net/~curtin-dev
Post to : curtin-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~curtin-dev
More help : https://help.launchpad.net/ListHelp