summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-10-14 18:31:04 +0000
committerGerrit Code Review <review@openstack.org>2016-10-14 18:31:04 +0000
commitdca181a47ca1eaec4a56385bce994c12763426cb (patch)
treef3badec00ddb9eaa9bfdf94f6242389a20a4db1b /ironic_python_agent
parent772ff4e7e67a1d1a07890e74f240ad4cb615d486 (diff)
parentcca1cd48efb544df54054b4538d1dae4a182facf (diff)
downloadironic-python-agent-dca181a47ca1eaec4a56385bce994c12763426cb.tar.gz
Merge "Add support for root device hints with operators"
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/hardware.py74
-rw-r--r--ironic_python_agent/tests/unit/test_hardware.py5
2 files changed, 18 insertions, 61 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index 80e007e0..bafd8a5f 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -20,12 +20,11 @@ import shlex
import time
from ironic_lib import disk_utils
+from ironic_lib import utils as il_utils
import netifaces
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_log import log
-from oslo_utils import strutils
-from oslo_utils import units
import pint
import psutil
import pyudev
@@ -627,66 +626,27 @@ class GenericHardwareManager(HardwareManager):
if not root_device_hints:
return utils.guess_root_disk(block_devices).name
else:
+ serialized_devs = [dev.serialize() for dev in block_devices]
+ try:
+ device = il_utils.match_root_device_hints(serialized_devs,
+ root_device_hints)
+ except ValueError as e:
+ # NOTE(lucasagomes): Just playing on the safe side
+ # here, this exception should never be raised because
+ # Ironic should validate the root device hints before the
+ # deployment starts.
+ raise errors.DeviceNotFound(
+ 'No devices could be found using the root device hints '
+ '%(hints)s because they failed to validate. Error: '
+ '%(error)s' % {'hints': root_device_hints, 'error': e})
- def match(hint, current_value, device):
- hint_value = root_device_hints[hint]
-
- if hint == 'rotational':
- hint_value = strutils.bool_from_string(hint_value)
-
- elif hint == 'size':
- try:
- hint_value = int(hint_value)
- except (ValueError, TypeError):
- LOG.warning(
- 'Root device hint "size" is not an integer. '
- 'Current value: "%(value)s"; and type: "%(type)s"',
- {'value': hint_value, 'type': type(hint_value)})
- return False
-
- if hint_value != current_value:
- LOG.debug("Root device hint %(hint)s=%(value)s does not "
- "match the device %(device)s value of "
- "%(current)s", {
- 'hint': hint,
- 'value': hint_value, 'device': device,
- 'current': current_value})
- return False
- return True
-
- def check_device_attrs(device):
- for key in ('model', 'wwn', 'serial', 'vendor',
- 'wwn_with_extension', 'wwn_vendor_extension',
- 'name', 'rotational', 'size'):
- if key not in root_device_hints:
- continue
-
- value = getattr(device, key)
- if value is None:
- return False
-
- if isinstance(value, six.string_types):
- value = utils.normalize(value)
-
- if key == 'size':
- # Since we don't support units yet we expect the size
- # in GiB for now
- value = value / units.Gi
-
- if not match(key, value, device.name):
- return False
-
- return True
-
- for dev in block_devices:
- if check_device_attrs(dev):
- return dev.name
-
- else:
+ if not device:
raise errors.DeviceNotFound(
"No suitable device was found for "
"deployment using these hints %s" % root_device_hints)
+ return device['name']
+
def get_system_vendor_info(self):
product_name = None
serial_number = None
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py
index 548c850c..c4b33f01 100644
--- a/ironic_python_agent/tests/unit/test_hardware.py
+++ b/ironic_python_agent/tests/unit/test_hardware.py
@@ -531,13 +531,10 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
self._get_os_install_device_root_device_hints(
{'size': '10'}, '/dev/sdb')
- @mock.patch.object(hardware.LOG, 'warning')
- def test_get_os_install_device_root_device_hints_size_not_int(
- self, mock_log):
+ def test_get_os_install_device_root_device_hints_size_not_int(self):
self.assertRaises(errors.DeviceNotFound,
self._get_os_install_device_root_device_hints,
{'size': 'not-int'}, '/dev/sdb')
- self.assertTrue(mock_log.called)
def test_get_os_install_device_root_device_hints_vendor(self):
self._get_os_install_device_root_device_hints(