Merge lp:~wesley-wiedenmeier/curtin/curtin-fix-sysfs-partition-data into lp:~curtin-dev/curtin/trunk

Proposed by Wesley Wiedenmeier
Status: Work in progress
Proposed branch: lp:~wesley-wiedenmeier/curtin/curtin-fix-sysfs-partition-data
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 63 lines (+20/-17)
1 file modified
curtin/block/__init__.py (+20/-17)
To merge this branch: bzr merge lp:~wesley-wiedenmeier/curtin/curtin-fix-sysfs-partition-data
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Needs Fixing
Review via email: mp+296626@code.launchpad.net

Description of the change

The current implementation of sysfs_partition_data only works when a blockdev to a whole disk is specified. It does not work when the blockdev for a partition is specified or when only a sysfs path is specified. This function is used quite a decent bit by the storage tests in
lp:~wesley-wiedenmeier/curtin/partial-testing so the fix is useful even though it doesn't look like it will fix any current bugs.

See: http://paste.ubuntu.com/17082198/
Output with fix: http://paste.ubuntu.com/17082212/

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 :

This is good improvement. Comments on simplifying below.

review: Needs Fixing
380. By Wesley Wiedenmeier

Improve code for sysfs_partition_data by ensuring that both blockdev and
sysfs_path will be set.

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

Makes sense, I just switched it over and it looks much nicer this way

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
381. By Wesley Wiedenmeier

Cleanup to partnum assignment in sysfs_partition_data() based on diff comments
from:
https://code.launchpad.net/~wesley-wiedenmeier/curtin/partial-testing/+merge/297958

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)
382. By Wesley Wiedenmeier

Merge from trunk

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
383. By Wesley Wiedenmeier

Merge from trunk

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

Moving to WIP

Unmerged revisions

383. By Wesley Wiedenmeier

Merge from trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/block/__init__.py'
2--- curtin/block/__init__.py 2016-07-31 01:17:53 +0000
3+++ curtin/block/__init__.py 2016-08-23 00:02:14 +0000
4@@ -558,31 +558,33 @@
5 def sysfs_partition_data(blockdev=None, sysfs_path=None):
6 # given block device or sysfs_path, return a list of tuples
7 # of (kernel_name, number, offset, size)
8- if blockdev is None and sysfs_path is None:
9- raise ValueError("Blockdev and sysfs_path cannot both be None")
10-
11 if blockdev:
12+ blockdev = os.path.normpath(blockdev)
13 sysfs_path = sys_block_path(blockdev)
14-
15- ptdata = []
16- # /sys/class/block/dev has entries of 'kname' for each partition
17+ elif sysfs_path:
18+ # use normpath to ensure that paths with trailing slash work
19+ sysfs_path = os.path.normpath(sysfs_path)
20+ blockdev = os.path.join('/dev', os.path.basename(sysfs_path))
21+ else:
22+ raise ValueError("Blockdev and sysfs_path cannot both be None")
23
24 # queue property is only on parent devices, ie, we can't read
25 # /sys/class/block/vda/vda1/queue/* as queue is only on the
26 # parent device
27+ sysfs_prefix = sysfs_path
28 (parent, partnum) = get_blockdev_for_partition(blockdev)
29- sysfs_prefix = sysfs_path
30 if partnum:
31 sysfs_prefix = sys_block_path(parent)
32-
33- block_size = int(util.load_file(os.path.join(sysfs_prefix,
34- 'queue/logical_block_size')))
35-
36- block_size = int(
37- util.load_file(os.path.join(sysfs_path, 'queue/logical_block_size')))
38+ partnum = int(partnum)
39+
40+ block_size = int(util.load_file(os.path.join(
41+ sysfs_prefix, 'queue/logical_block_size')))
42 unit = block_size
43- for d in os.listdir(sysfs_path):
44- partd = os.path.join(sysfs_path, d)
45+
46+ # /sys/class/block/dev has entries of 'kname' for each partition
47+ ptdata = []
48+ for d in os.listdir(sysfs_prefix):
49+ partd = os.path.join(sysfs_prefix, d)
50 data = {}
51 for sfile in ('partition', 'start', 'size'):
52 dfile = os.path.join(partd, sfile)
53@@ -591,8 +593,9 @@
54 data[sfile] = int(util.load_file(dfile))
55 if 'partition' not in data:
56 continue
57- ptdata.append((d, data['partition'], data['start'] * unit,
58- data['size'] * unit,))
59+ if partnum is None or data['partition'] == partnum:
60+ ptdata.append((d, data['partition'], data['start'] * unit,
61+ data['size'] * unit,))
62
63 return ptdata
64

Subscribers

People subscribed via source and target branches