Exemplo n.º 1
0
    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']
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
 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'])
Exemplo n.º 5
0
 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'])
Exemplo n.º 6
0
 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"])
Exemplo n.º 7
0
 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'])
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
 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"])
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 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'])
Exemplo n.º 12
0
 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"])
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
 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'])
Exemplo n.º 15
0
 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"])
Exemplo n.º 16
0
 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"])
Exemplo n.º 17
0
 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"])
Exemplo n.º 18
0
 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"])
Exemplo n.º 19
0
 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'])
Exemplo n.º 20
0
 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'])
Exemplo n.º 21
0
 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)
Exemplo n.º 22
0
 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)