def get_os_install_device(self): cached_node = get_cached_node() root_device_hints = None if cached_node is not None: root_device_hints = cached_node['properties'].get('root_device') block_devices = self.list_block_devices() 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}) if not device: raise errors.DeviceNotFound( "No suitable device was found for " "deployment using these hints %s" % root_device_hints) return device['name']
def _process_root_device_hints(self, introspection_data, node_info, inventory): """Detect root disk from root device hints and IPA inventory.""" hints = node_info.node().properties.get('root_device') if not hints: LOG.debug('Root device hints are not provided', node_info=node_info, data=introspection_data) return 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) if not device: 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
def before_update(self, introspection_data, node_info, **kwargs): """Detect root disk from root device hints and IPA inventory.""" hints = node_info.node().properties.get('root_device') if not hints: LOG.debug('Root device hints are not provided', node_info=node_info, data=introspection_data) return inventory = utils.get_inventory(introspection_data, node_info=node_info) 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) if not device: 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
def test_match_root_device_hints_multiple_hints2(self): root_device_hints = { 'size': '<= 20', 'model': '<or> model 5 <or> foomodel <or> small model <or>', 'serial': 's== veryveryfakeserial' } dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual('/dev/sdc', dev['name'])
def test_match_root_device_hints_multiple_hints(self): root_device_hints = { 'size': '>= 50', 'model': 's==big model', 'serial': 's==veryfakeserial' } dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual('/dev/sdb', dev['name'])
def test_match_root_device_hints_multiple_hints2(self): root_device_hints = { "size": "<= 20", "model": "<or> model 5 <or> foomodel <or> small model <or>", "serial": "s== veryveryfakeserial", } dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual("/dev/sdc", dev["name"])
def test_match_root_device_hints_no_operators(self): root_device_hints = { 'size': '120', 'model': 'big model', 'serial': 'veryfakeserial' } dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual('/dev/sdb', dev['name'])
def get_os_install_device(self): cached_node = get_cached_node() root_device_hints = None if cached_node is not None: root_device_hints = cached_node['properties'].get('root_device') LOG.debug('Looking for a device matching root hints %s', root_device_hints) block_devices = self.list_block_devices() if not root_device_hints: dev_name = 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}) if not device: raise errors.DeviceNotFound( "No suitable device was found for " "deployment using these hints %s" % root_device_hints) dev_name = device['name'] LOG.info('Picked root device %(dev)s for node %(node)s based on ' 'root device hints %(hints)s', {'dev': dev_name, 'hints': root_device_hints, 'node': cached_node['uuid'] if cached_node else None}) return dev_name
def test_match_root_device_hints_one_hint(self): root_device_hints = {"size": ">= 70"} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual("/dev/sdb", dev["name"])
def test_match_root_device_hints_empty_device_attribute(self, mock_warn): empty_dev = [{"name": "/dev/sda", "model": " "}] dev = utils.match_root_device_hints(empty_dev, {"model": "foo"}) self.assertIsNone(dev) self.assertTrue(mock_warn.called)
def test_match_root_device_hints_rotational(self): root_device_hints = {'rotational': False} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual('/dev/sdc', dev['name'])
def test_match_root_device_hints_no_operators(self): root_device_hints = {"size": "120", "model": "big model", "serial": "veryfakeserial"} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual("/dev/sdb", dev["name"])
def test_match_root_device_hints_no_device_found(self): root_device_hints = {"size": ">=50", "model": "s==foo"} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertIsNone(dev)
def test_match_root_device_hints_rotational_convert_devices_bool(self): root_device_hints = {'size': '>=100', 'rotational': True} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual('/dev/sdb', dev['name'])
def test_match_root_device_hints_multiple_hints3(self): root_device_hints = {"rotational": False, "model": "<in> small"} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual("/dev/sdc", dev["name"])
def test_match_root_device_hints_rotational_convert_devices_bool(self): root_device_hints = {"size": ">=100", "rotational": True} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual("/dev/sdb", dev["name"])
def test_match_root_device_hints_multiple_hints(self): root_device_hints = {"size": ">= 50", "model": "s==big model", "serial": "s==veryfakeserial"} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual("/dev/sdb", dev["name"])
def test_match_root_device_hints_rotational(self): root_device_hints = {"rotational": False} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual("/dev/sdc", dev["name"])
def test_match_root_device_hints_one_hint(self): root_device_hints = {'size': '>= 70'} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual('/dev/sdb', dev['name'])
def test_match_root_device_hints_multiple_hints3(self): root_device_hints = {'rotational': False, 'model': '<in> small'} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertEqual('/dev/sdc', dev['name'])
def test_match_root_device_hints_empty_device_attribute(self, mock_warn): empty_dev = [{'name': '/dev/sda', 'model': ' '}] dev = utils.match_root_device_hints(empty_dev, {'model': 'foo'}) self.assertIsNone(dev) self.assertTrue(mock_warn.called)
def test_match_root_device_hints_no_device_found(self): root_device_hints = {'size': '>=50', 'model': 's==foo'} dev = utils.match_root_device_hints(self.devices, root_device_hints) self.assertIsNone(dev)