Add support for root device hints with operators
This patch is updating IPA to use the match_root_device_hints() method provided by ironic-lib version 2.2.0. Partial-Bug: #1561137 Depends-On: I1d9dc7a57ea391a3419710c289242b39a4201463 Change-Id: Id93dd0360137df600f5a656348279e56c6b84bf9
This commit is contained in:
parent
4d26be6e98
commit
cca1cd48ef
ironic_python_agent
@ -20,12 +20,11 @@ import shlex
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from ironic_lib import disk_utils
|
from ironic_lib import disk_utils
|
||||||
|
from ironic_lib import utils as il_utils
|
||||||
import netifaces
|
import netifaces
|
||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_utils import strutils
|
|
||||||
from oslo_utils import units
|
|
||||||
import pint
|
import pint
|
||||||
import psutil
|
import psutil
|
||||||
import pyudev
|
import pyudev
|
||||||
@ -627,66 +626,27 @@ class GenericHardwareManager(HardwareManager):
|
|||||||
if not root_device_hints:
|
if not root_device_hints:
|
||||||
return utils.guess_root_disk(block_devices).name
|
return utils.guess_root_disk(block_devices).name
|
||||||
else:
|
else:
|
||||||
|
serialized_devs = [dev.serialize() for dev in block_devices]
|
||||||
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:
|
try:
|
||||||
hint_value = int(hint_value)
|
device = il_utils.match_root_device_hints(serialized_devs,
|
||||||
except (ValueError, TypeError):
|
root_device_hints)
|
||||||
LOG.warning(
|
except ValueError as e:
|
||||||
'Root device hint "size" is not an integer. '
|
# NOTE(lucasagomes): Just playing on the safe side
|
||||||
'Current value: "%(value)s"; and type: "%(type)s"',
|
# here, this exception should never be raised because
|
||||||
{'value': hint_value, 'type': type(hint_value)})
|
# Ironic should validate the root device hints before the
|
||||||
return False
|
# 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})
|
||||||
|
|
||||||
if hint_value != current_value:
|
if not device:
|
||||||
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:
|
|
||||||
raise errors.DeviceNotFound(
|
raise errors.DeviceNotFound(
|
||||||
"No suitable device was found for "
|
"No suitable device was found for "
|
||||||
"deployment using these hints %s" % root_device_hints)
|
"deployment using these hints %s" % root_device_hints)
|
||||||
|
|
||||||
|
return device['name']
|
||||||
|
|
||||||
def get_system_vendor_info(self):
|
def get_system_vendor_info(self):
|
||||||
product_name = None
|
product_name = None
|
||||||
serial_number = None
|
serial_number = None
|
||||||
|
@ -531,13 +531,10 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
|
|||||||
self._get_os_install_device_root_device_hints(
|
self._get_os_install_device_root_device_hints(
|
||||||
{'size': '10'}, '/dev/sdb')
|
{'size': '10'}, '/dev/sdb')
|
||||||
|
|
||||||
@mock.patch.object(hardware.LOG, 'warning')
|
def test_get_os_install_device_root_device_hints_size_not_int(self):
|
||||||
def test_get_os_install_device_root_device_hints_size_not_int(
|
|
||||||
self, mock_log):
|
|
||||||
self.assertRaises(errors.DeviceNotFound,
|
self.assertRaises(errors.DeviceNotFound,
|
||||||
self._get_os_install_device_root_device_hints,
|
self._get_os_install_device_root_device_hints,
|
||||||
{'size': 'not-int'}, '/dev/sdb')
|
{'size': 'not-int'}, '/dev/sdb')
|
||||||
self.assertTrue(mock_log.called)
|
|
||||||
|
|
||||||
def test_get_os_install_device_root_device_hints_vendor(self):
|
def test_get_os_install_device_root_device_hints_vendor(self):
|
||||||
self._get_os_install_device_root_device_hints(
|
self._get_os_install_device_root_device_hints(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user