Use the device hints matching mechanism from ironic-lib

This patch is replacing the ironic-inspector own implementation for
validating the root device hints in favor of the standard one from
ironic-lib.

The implementation in ironic-lib is flexible enough and fits in
ironic-inspector well so no big updates to functional or unittests
are needed.

A new dependency for ironic-lib was added to requirements.txt.

Change-Id: I0f2b8f463232d0d5b42d0b6e343d5c6e336d32c7
Closes-Bug: #1648133
This commit is contained in:
Lucas Alvares Gomes 2016-12-08 10:41:35 +00:00
parent 01b83595d5
commit 891639612b
4 changed files with 25 additions and 31 deletions

View File

@ -15,6 +15,7 @@
import sys
from ironic_lib import utils as il_utils
import netaddr
from oslo_config import cfg
from oslo_utils import netutils
@ -47,41 +48,27 @@ class RootDiskSelectionHook(base.ProcessingHook):
node_info=node_info, data=introspection_data)
return
if 'size' in hints:
# Special case to match IPA behaviour
try:
hints['size'] = int(hints['size'])
except (TypeError, ValueError):
raise utils.Error(_('Invalid root device size hint, expected '
'an integer, got %s') % hints['size'],
node_info=node_info, data=introspection_data)
inventory = utils.get_inventory(introspection_data,
node_info=node_info)
for disk in inventory['disks']:
properties = disk.copy()
# Root device hints are in GiB, data from IPA is in bytes
properties['size'] //= units.Gi
try:
device = il_utils.match_root_device_hints(inventory['disks'],
hints)
except (TypeError, ValueError) as e:
raise utils.Error(
_('No disks could be found using the root device hints '
'%(hints)s because they failed to validate. '
'Error: %(error)s') % {'hints': hints, 'error': e},
node_info=node_info, data=introspection_data)
for name, value in hints.items():
actual = properties.get(name)
if actual != value:
LOG.debug('Disk %(disk)s does not satisfy hint '
'%(name)s=%(value)s, actual value is %(actual)s',
{'disk': disk.get('name'), 'name': name,
'value': value, 'actual': actual},
if not device:
raise utils.Error(_('No disks satisfied root device hints'),
node_info=node_info, data=introspection_data)
break
else:
LOG.debug('Disk %(disk)s of size %(size)s satisfies '
'root device hints',
{'disk': disk.get('name'), 'size': disk['size']},
node_info=node_info, data=introspection_data)
introspection_data['root_disk'] = disk
return
raise utils.Error(_('No disks satisfied root device hints'),
node_info=node_info, data=introspection_data)
LOG.debug('Disk %(disk)s of size %(size)s satisfies '
'root device hints',
{'disk': device.get('name'), 'size': device['size']},
node_info=node_info, data=introspection_data)
introspection_data['root_disk'] = device
class SchedulerHook(base.ProcessingHook):

View File

@ -307,7 +307,7 @@ class TestRootDiskSelection(test_base.NodeTest):
for bad_size in ('foo', None, {}):
self.node.properties['root_device'] = {'size': bad_size}
self.assertRaisesRegex(utils.Error,
'Invalid root device size hint',
'No disks could be found',
self.hook.before_update,
self.data, self.node_info)

View File

@ -0,0 +1,6 @@
---
features:
- Adds support for using operators with the root device hints mechanism.
The supported operators are ``=``, ``==``, ``!=``, ``>=``,
``<=``, ``>``, ``<``, ``s==``, ``s!=``, ``s>=``, ``s>``,
``s<=``, ``s<``, ``<in>``, ``<all-in>`` and ``<or>``.

View File

@ -7,6 +7,7 @@ Babel>=2.3.4 # BSD
eventlet!=0.18.3,>=0.18.2 # MIT
Flask!=0.11,<1.0,>=0.10 # BSD
futurist!=0.15.0,>=0.11.0 # Apache-2.0
ironic-lib>=2.2.0 # Apache-2.0
jsonpath-rw<2.0,>=1.2.0 # Apache-2.0
jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT
keystoneauth1>=2.16.0 # Apache-2.0