Merge lp:~smoser/curtin/trunk.lp1523779 into lp:~curtin-dev/curtin/trunk

Proposed by Scott Moser
Status: Merged
Merged at revision: 332
Proposed branch: lp:~smoser/curtin/trunk.lp1523779
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 137 lines (+51/-31)
2 files modified
curtin/commands/block_meta.py (+19/-18)
curtin/commands/curthooks.py (+32/-13)
To merge this branch: bzr merge lp:~smoser/curtin/trunk.lp1523779
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Approve
Review via email: mp+281000@code.launchpad.net

Commit message

fix bug in install_grub to partition when storage_config provided.

when installing with a storage config and grub is to be installed
on a partition (as it is in powerpc) we were not able to look
up the device that was to be installed on.

This puts a temporary bit of code in place that finds that device
via imports from commands.block_meta. The result is that
storage_config now works for lvm on power8 systems.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:322
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~smoser/curtin/trunk.lp1523779/+merge/281000/+edit-commit-message

https://server-team-jenkins.canonical.com/job/curtin-ci/70/
Executed test runs:
    None: https://server-team-jenkins.canonical.com/job/generic-update-mp/67/console

Click here to trigger a rebuild:
https://server-team-jenkins.canonical.com/job/curtin-ci/70/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) :
Revision history for this message
Scott Moser (smoser) wrote :

The change as it is right now is to add a method 'extract_storage_ordered_dict' to get an ordered dictionary, where that code was being done inside 'meta_custom' directly.

The reason for doing that is that we need to use it from curthooks.
Previously, if custom storage was used and 'grub_device' existed on a partition it woudl fail.
That was because we could only look up by serial or path.

Now, we use extract_storage_ordered_dict method to get an ordered dictionary and then get a path to that volume (or partition) via get_path_to_storage_volume.

I dont like the inline import : i've done that here only because I dont like importing from block_meta at all. I'd rather move all this to curtin.block but I dont think its ready to go there yet.

I could add another method in block_meta that
  get_path_to_storage_voulme_with_config_id() or seomthing like that and then only use one method from curthooks.

Revision history for this message
Ryan Harper (raharper) wrote :

That makes sense. I don't think it'd be too much trouble to put the wrapper in... but which ever method reminds use we need to migrate that into block is fine with me.

Revision history for this message
Ryan Harper (raharper) wrote :

Via IRC, missing grub_device in storage config will fallback to grub_install on mounted devices. That's sufficient for now.

review: Approve
lp:~smoser/curtin/trunk.lp1523779 updated
324. By Scott Moser

explain the no-grub-dev found path a bit

325. By Scott Moser

some cleanup and doc and FIXME

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:325
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~smoser/curtin/trunk.lp1523779/+merge/281000/+edit-commit-message

https://server-team-jenkins.canonical.com/job/curtin-ci/72/
Executed test runs:
    None: https://server-team-jenkins.canonical.com/job/generic-update-mp/69/console

Click here to trigger a rebuild:
https://server-team-jenkins.canonical.com/job/curtin-ci/72/rebuild

review: Needs Fixing (continuous-integration)
lp:~smoser/curtin/trunk.lp1523779 updated
326. By Scott Moser

fix keyerror if no install_devices

327. By Scott Moser

handle lvm devices

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:327
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~smoser/curtin/trunk.lp1523779/+merge/281000/+edit-commit-message

https://server-team-jenkins.canonical.com/job/curtin-ci/75/
Executed test runs:
    None: https://server-team-jenkins.canonical.com/job/generic-update-mp/72/console

Click here to trigger a rebuild:
https://server-team-jenkins.canonical.com/job/curtin-ci/75/rebuild

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 2015-12-08 01:23:09 +0000
3+++ curtin/commands/block_meta.py 2015-12-18 22:14:07 +0000
4@@ -1070,6 +1070,21 @@
5 not supported")
6
7
8+def extract_storage_ordered_dict(config):
9+ storage_config = config.get('storage', {})
10+ if not storage_config:
11+ raise ValueError("no 'storage' entry in config")
12+ scfg = storage_config.get('config')
13+ if not scfg:
14+ raise ValueError("invalid storage config data")
15+
16+ # Since storage config will often have to be searched for a value by its
17+ # id, and this can become very inefficient as storage_config grows, a dict
18+ # will be generated with the id of each component of the storage_config as
19+ # its index and the component of storage_config as its value
20+ return OrderedDict((d["id"], d) for (i, d) in enumerate(scfg))
21+
22+
23 def meta_custom(args):
24 """Does custom partitioning based on the layout provided in the config
25 file. Section with the name storage contains information on which
26@@ -1092,23 +1107,9 @@
27 state = util.load_command_environment()
28 cfg = config.load_command_config(args, state)
29
30- storage_config = cfg.get('storage', {})
31- if not storage_config:
32- raise Exception("storage configuration is required by mode '%s' "
33- "but not provided in the config file" % CUSTOM)
34- storage_config_data = storage_config.get('config')
35-
36- if not storage_config_data:
37- raise ValueError("invalid storage config data")
38-
39- # Since storage config will often have to be searched for a value by its
40- # id, and this can become very inefficient as storage_config grows, a dict
41- # will be generated with the id of each component of the storage_config as
42- # its index and the component of storage_config as its value
43- storage_config_dict = OrderedDict((d["id"], d) for (i, d) in
44- enumerate(storage_config_data))
45-
46- for command in storage_config_data:
47+ storage_config_dict = extract_storage_ordered_dict(cfg)
48+
49+ for item_id, command in storage_config_dict.items():
50 handler = command_handlers.get(command['type'])
51 if not handler:
52 raise ValueError("unknown command type '%s'" % command['type'])
53@@ -1116,7 +1117,7 @@
54 handler(command, storage_config_dict)
55 except Exception as error:
56 LOG.error("An error occured handling '%s': %s - %s" %
57- (command.get('id'), type(error).__name__, error))
58+ (item_id, type(error).__name__, error))
59 raise
60
61 return 0
62
63=== modified file 'curtin/commands/curthooks.py'
64--- curtin/commands/curthooks.py 2015-12-17 18:25:51 +0000
65+++ curtin/commands/curthooks.py 2015-12-18 22:14:07 +0000
66@@ -282,27 +282,37 @@
67
68 def setup_grub(cfg, target):
69 # target is the path to the mounted filesystem
70+
71+ # FIXME: these methods need moving to curtin.block
72+ # and using them from there rather than commands.block_meta
73+ from curtin.commands.block_meta import (extract_storage_ordered_dict,
74+ get_path_to_storage_volume)
75+
76 grubcfg = cfg.get('grub', {})
77
78 # copy legacy top level name
79 if 'grub_install_devices' in cfg and 'install_devices' not in grubcfg:
80 grubcfg['install_devices'] = cfg['grub_install_devices']
81
82- if 'storage' in cfg:
83+ # if there is storage config, look for devices tagged with 'grub_device'
84+ storage_cfg_odict = None
85+ try:
86+ storage_cfg_odict = extract_storage_ordered_dict(cfg)
87+ except ValueError as e:
88+ pass
89+
90+ if storage_cfg_odict:
91 storage_grub_devices = []
92- for item in cfg.get('storage').get('config'):
93- if item.get('grub_device'):
94- if item.get('serial'):
95- storage_grub_devices.append(
96- block.lookup_disk(item.get('serial')))
97- elif item.get('path'):
98- storage_grub_devices.append(item.get('path'))
99- else:
100- raise ValueError("setup_grub cannot find path to disk \
101- '%s'" % item.get('id'))
102+ for item_id, item in storage_cfg_odict.items():
103+ if not item.get('grub_device'):
104+ continue
105+ LOG.debug("checking: %s", item)
106+ storage_grub_devices.append(
107+ get_path_to_storage_volume(item_id, storage_cfg_odict))
108 if len(storage_grub_devices) > 0:
109 grubcfg['install_devices'] = storage_grub_devices
110
111+ LOG.debug("install_devices: %s", grubcfg.get('install_devices'))
112 if 'install_devices' in grubcfg:
113 instdevs = grubcfg.get('install_devices')
114 if isinstance(instdevs, str):
115@@ -310,11 +320,20 @@
116 if instdevs is None:
117 LOG.debug("grub installation disabled by config")
118 else:
119+ # If there were no install_devices found then we try to do the right
120+ # thing. That right thing is basically installing on all block
121+ # devices that are mounted. On powerpc, though it means finding PrEP
122+ # partitions.
123 devs = block.get_devices_for_mp(target)
124 blockdevs = set()
125 for maybepart in devs:
126- (blockdev, part) = block.get_blockdev_for_partition(maybepart)
127- blockdevs.add(blockdev)
128+ try:
129+ (blockdev, part) = block.get_blockdev_for_partition(maybepart)
130+ blockdevs.add(blockdev)
131+ except ValueError as e:
132+ # if there is no syspath for this device such as a lvm
133+ # or raid device, then a ValueError is raised here.
134+ LOG.debug("failed to find block device for %s", maybepart)
135
136 if platform.machine().startswith("ppc64"):
137 # assume we want partitions that are 4100 (PReP). The snippet here

Subscribers

People subscribed via source and target branches