Merge lp:~wesley-wiedenmeier/curtin/trusty-preserve into lp:~curtin-dev/curtin/trunk

Proposed by Wesley Wiedenmeier
Status: Merged
Merged at revision: 403
Proposed branch: lp:~wesley-wiedenmeier/curtin/trusty-preserve
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 51 lines (+24/-14)
1 file modified
curtin/commands/block_meta.py (+24/-14)
To merge this branch: bzr merge lp:~wesley-wiedenmeier/curtin/trusty-preserve
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Needs Fixing
Review via email: mp+296588@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Hi Wesley,

Do you think we should use a lsb_release value to look up which tool to use to discover the partition instead of using the fallback?

If we're running an install (or preserve) on a Trusty system, won't blkid _always_ fail?
If so, then there's little point in exec'ing blkid when we know it will fail.

Does that make sense? Maybe look at the block/mkfs.py for one of those mappings for
extracting the right command for checking ptable state?

review: Needs Fixing
Revision history for this message
Scott Moser (smoser) wrote :

I think what you're fixing is the determination of the partition table on a block device.
I think it would be generally nicer then to do:

class pttypes
def get_partition_table_type(block_device):
    """Return the block partition table type for block_device
       Raise OSError on unexpected Error.
       return values of 'gpt', 'dos' or None"""

I'd put that method into curtin/block and use it from there, as it is seemingly a useful bit of function all by itself.
Then, some other thoughts:
a.) growpart in cloud-utils does this for all ubuntu releases as seen in 'get_table_format' in
http://bazaar.launchpad.net/~cloud-utils-dev/cloud-utils/trunk/view/head:/bin/growpart#L650

b.) it would be nice to have some less error prone way or like to identify valid values of partition types in the code, more than checking the string 'gpt' or 'mbr'.

You can't use Enum in python 2 without additional module, but you could do something like
  tests/vmtests/releases.py does with _Releases

class PartitionTableTypes(object):
   MBR = "MBR"
   GPT = "GPT"
   NONE = "Unpartitioned"

then always refer to types as
  from block import PartitionTableTypes
  return PartitionTableTypes.MBR

Revision history for this message
Wesley Wiedenmeier (wesley-wiedenmeier) wrote :

That makes sense.

It would definitely be nice to have all of the logic for getting information about the partition table somewhere in block because a lot of that si repeated throughout block_meta and I'm sure there are more bugs like this where I didn't accomodate for blkid failing on trusty in block meta.

I can move this logic into block this afternoon, probably in a new file (something like block.disk_info) because block.__init__ is getting pretty long.

It definitely would be nice to have constants defined as well for most of the storage config stuff because there are a lot of places in block meta where I used string comparison that could break. I'll get that added in as well

Revision history for this message
Wesley Wiedenmeier (wesley-wiedenmeier) wrote :

I moved the _nameset class from curtin.reporter.events into curtin.util.NameSet and created entries in that format for all of the differetn types of storage config commands, filesystem types, and partition table types and made the substitutions in block meta.

I think it would be nice to have a simple object model of the storage config that supports filtering storage config items and does preprocessing on the storage config to get the partition numbers sorted out, so I did all of this in a different branch that I should have ready to merge soon.

lp:~wesley-wiedenmeier/curtin/storage-config/

That will also let me rip out some of the ad-hoc storage config manipulation stuff I wrote last summer and replace it with code that is easy to test, that should get rid of some bugs.

I'll start on getting the disk information gathering stuff consolidated into a file in block and making sure that the functions all have fallbacks for trusty and switch to the fallback automatically so they don't exec anything they don't have to.

348. By Wesley Wiedenmeier

Remove \ and better format comments in disk handle

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'curtin/commands/block_meta.py'
--- curtin/commands/block_meta.py 2016-06-08 21:58:29 +0000
+++ curtin/commands/block_meta.py 2016-07-18 18:59:02 +0000
@@ -452,23 +452,33 @@
452 # Don't need to check state, return452 # Don't need to check state, return
453 return453 return
454454
455 # Check state of current ptable455 # Check state of current ptable, try to do this using blkid, but if
456 # blkid fails then try to fall back to using parted.
457 _possible_errors = (util.ProcessExecutionError, StopIteration,
458 IndexError, AttributeError)
456 try:459 try:
457 (out, _err) = util.subp(["blkid", "-o", "export", disk],460 (out, _err) = util.subp(["blkid", "-o", "export", disk],
458 capture=True)461 capture=True)
459 except util.ProcessExecutionError:462 current_ptable = next(l.split('=')[1] for l in out.splitlines()
460 raise ValueError("disk '%s' has no readable partition table or \463 if 'TYPE' in l)
461 cannot be accessed, but preserve is set to true, so cannot \464 except _possible_errors:
462 continue")465 try:
463 current_ptable = list(filter(lambda x: "PTTYPE" in x,466 (out, _err) = util.subp(["parted", disk, "--script", "print"],
464 out.splitlines()))[0].split("=")[-1]467 capture=True)
465 if current_ptable == "dos" and ptable != "msdos" or \468 current_ptable = next(l.split()[-1] for l in out.splitlines()
466 current_ptable == "gpt" and ptable != "gpt":469 if "Partition Table" in l)
467 raise ValueError("disk '%s' does not have correct \470 except _possible_errors:
468 partition table, but preserve is set to true, so not \471 raise ValueError("disk '%s' has no readable partition table "
469 creating table, so not creating table." % info.get('id'))472 "or cannot be accessed, but preserve is set "
470 LOG.info("disk '%s' marked to be preserved, so keeping partition \473 "to true, so cannot continue" % disk)
471 table")474 if not (current_ptable == ptable or
475 (current_ptable == "dos" and ptable == "msdos")):
476 raise ValueError("disk '%s' does not have correct "
477 "partition table, but preserve is "
478 "set to true, so not creating table."
479 % info.get('id'))
480 LOG.info("disk '%s' marked to be preserved, so keeping partition "
481 "table" % disk)
472 return482 return
473483
474 # Wipe the disk484 # Wipe the disk

Subscribers

People subscribed via source and target branches