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
1=== modified file 'curtin/commands/block_meta.py'
2--- curtin/commands/block_meta.py 2016-06-08 21:58:29 +0000
3+++ curtin/commands/block_meta.py 2016-07-18 18:59:02 +0000
4@@ -452,23 +452,33 @@
5 # Don't need to check state, return
6 return
7
8- # Check state of current ptable
9+ # Check state of current ptable, try to do this using blkid, but if
10+ # blkid fails then try to fall back to using parted.
11+ _possible_errors = (util.ProcessExecutionError, StopIteration,
12+ IndexError, AttributeError)
13 try:
14 (out, _err) = util.subp(["blkid", "-o", "export", disk],
15 capture=True)
16- except util.ProcessExecutionError:
17- raise ValueError("disk '%s' has no readable partition table or \
18- cannot be accessed, but preserve is set to true, so cannot \
19- continue")
20- current_ptable = list(filter(lambda x: "PTTYPE" in x,
21- out.splitlines()))[0].split("=")[-1]
22- if current_ptable == "dos" and ptable != "msdos" or \
23- current_ptable == "gpt" and ptable != "gpt":
24- raise ValueError("disk '%s' does not have correct \
25- partition table, but preserve is set to true, so not \
26- creating table, so not creating table." % info.get('id'))
27- LOG.info("disk '%s' marked to be preserved, so keeping partition \
28- table")
29+ current_ptable = next(l.split('=')[1] for l in out.splitlines()
30+ if 'TYPE' in l)
31+ except _possible_errors:
32+ try:
33+ (out, _err) = util.subp(["parted", disk, "--script", "print"],
34+ capture=True)
35+ current_ptable = next(l.split()[-1] for l in out.splitlines()
36+ if "Partition Table" in l)
37+ except _possible_errors:
38+ raise ValueError("disk '%s' has no readable partition table "
39+ "or cannot be accessed, but preserve is set "
40+ "to true, so cannot continue" % disk)
41+ if not (current_ptable == ptable or
42+ (current_ptable == "dos" and ptable == "msdos")):
43+ raise ValueError("disk '%s' does not have correct "
44+ "partition table, but preserve is "
45+ "set to true, so not creating table."
46+ % info.get('id'))
47+ LOG.info("disk '%s' marked to be preserved, so keeping partition "
48+ "table" % disk)
49 return
50
51 # Wipe the disk

Subscribers

People subscribed via source and target branches