Browse Source

Merge "Allow setting other fields on discovery"

master
Zuul 4 days ago
committed by Gerrit Code Review
parent
commit
c1fa28a9f8
5 changed files with 41 additions and 4 deletions
  1. +10
    -3
      doc/source/user/usage.rst
  2. +2
    -0
      ironic_inspector/conf/discovery.py
  3. +1
    -1
      ironic_inspector/plugins/discovery.py
  4. +23
    -0
      ironic_inspector/test/unit/test_plugins_discovery.py
  5. +5
    -0
      releasenotes/notes/enroll-node-fields-3f4e22213fd90307.yaml

+ 10
- 3
doc/source/user/usage.rst View File

@@ -274,9 +274,16 @@ Ironic first.

For discovery, the configuration file option ``node_not_found_hook`` should be
set to load the hook called ``enroll``. This hook will enroll the unidentified
node into Ironic using the ``fake-hardware`` hardware type. (This is
a configurable option; set ``enroll_node_driver``, in the **ironic-inspector**
configuration file, to the Ironic hardware type or classic driver you want.)
node into Ironic using the ``fake-hardware`` hardware type. This is
a configurable option: set ``enroll_node_driver`` in the **ironic-inspector**
configuration file to the hardware type you want. You can also configure
arbitrary fields to set on discovery, for example:

.. code-block:: ini

[discovery]
enroll_node_driver = ipmi
enroll_node_fields = management_interface:noop,resource_class:baremetal

The ``enroll`` hook will also set the ``ipmi_address`` property on the new
node, if its available in the introspection data we received,


+ 2
- 0
ironic_inspector/conf/discovery.py View File

@@ -21,6 +21,8 @@ _OPTS = [
default='fake-hardware',
help=_('The name of the Ironic driver used by the enroll '
'hook when creating a new node in Ironic.')),
cfg.DictOpt('enroll_node_fields', default={},
help=_('Additional fields to set on newly discovered nodes.')),
cfg.ListOpt('enabled_bmc_address_version',
default=['4', '6'],
help=_('IP version of BMC address that will be '


+ 1
- 1
ironic_inspector/plugins/discovery.py View File

@@ -62,7 +62,7 @@ def _check_existing_nodes(introspection_data, node_driver_info, ironic):


def enroll_node_not_found_hook(introspection_data, **kwargs):
node_attr = {}
node_attr = CONF.discovery.enroll_node_fields.copy()
ironic = ir_utils.get_client()

node_driver_info = _extract_node_driver_info(introspection_data)


+ 23
- 0
ironic_inspector/test/unit/test_plugins_discovery.py View File

@@ -117,6 +117,29 @@ class TestEnrollNodeNotFoundHook(test_base.NodeTest):
{}, {}, self.ironic)
self.assertEqual({'auto_discovered': True}, introspection_data)

@mock.patch.object(node_cache, 'create_node', autospec=True)
@mock.patch.object(ir_utils, 'get_client', autospec=True)
@mock.patch.object(discovery, '_check_existing_nodes', autospec=True)
def test_enroll_with_fields(self, mock_check_existing,
mock_client, mock_create_node):
mock_client.return_value = self.ironic
discovery.CONF.set_override('enroll_node_fields',
{'power_interface': 'other'},
'discovery')
mock_check_existing = copy_call_args(mock_check_existing)
introspection_data = {}

discovery.enroll_node_not_found_hook(introspection_data)

mock_create_node.assert_called_once_with('fake-hardware',
ironic=self.ironic,
driver_info={},
provision_state='enroll',
power_interface='other')
mock_check_existing.assert_called_once_with(
{}, {}, self.ironic)
self.assertEqual({'auto_discovered': True}, introspection_data)

def test__check_existing_nodes_new_mac(self):
self.ironic.ports.return_value = []
introspection_data = {'macs': self.macs}


+ 5
- 0
releasenotes/notes/enroll-node-fields-3f4e22213fd90307.yaml View File

@@ -0,0 +1,5 @@
---
features:
- |
Adds a new configuration option ``[discovery]enroll_node_fields`` that
specifies additional fields to set on a node (e.g. driver interfaces).

Loading…
Cancel
Save