Get root device hints from the node object

In order to support a more complex syntax for root device hints (e.g
operators: greater than, less than, in, etc...) we need to stop relying
on the kernel command line for passing the root device hints. This patch
changes this approach by getting the root device hints from a cached
node object that was set in the hardware module.

Two new functions: "cache_node" and "get_cached_node" were added to the
hardware module. The idea is to facilitate the access to a node object
representation from the hardware extension methods without changing
method signatures, which would break compatibility with out-of-tree
hardware managers.

Note that the new "get_cached_node" is just a guard function to
facilitate the tests for the code.

The function parse_root_device_hints() and its tests were removed since
it's not used/needed anymore.

Partial-Bug: #1561137
Change-Id: I830fe7da1a59b46e348213b6f451c2ee55f6008c
This commit is contained in:
Lucas Alvares Gomes
2016-05-19 10:48:02 +01:00
parent 962ee1afb5
commit 33535cd572
7 changed files with 57 additions and 90 deletions

@ -233,44 +233,6 @@ def normalize(string):
return parse.unquote(string).lower().strip()
def parse_root_device_hints():
"""Parse the root device hints.
Parse the root device hints given by Ironic via kernel cmdline
or vmedia.
:returns: A dict with the hints or an empty dict if no hints are
passed.
:raises: DeviceNotFound if there are unsupported hints.
"""
root_device = get_agent_params().get('root_device')
if not root_device:
return {}
hints = dict((item.split('=') for item in root_device.split(',')))
# Find invalid hints for logging
not_supported = set(hints) - SUPPORTED_ROOT_DEVICE_HINTS
if not_supported:
error_msg = ('No device can be found because the following hints: '
'"%(not_supported)s" are not supported by this version '
'of IPA. Supported hints are: "%(supported)s"',
{'not_supported': ', '.join(not_supported),
'supported': ', '.join(SUPPORTED_ROOT_DEVICE_HINTS)})
raise errors.DeviceNotFound(error_msg)
# Normalise the values
hints = {k: normalize(v) for k, v in hints.items()}
if 'size' in hints:
# NOTE(lucasagomes): Ironic should validate before passing to
# the deploy ramdisk
hints['size'] = int(hints['size'])
return hints
class AccumulatedFailures(object):
"""Object to accumulate failures without raising exception."""