Allow setting other fields on discovery
Adds a new option to set arbitrary fields on newly discovered nodes, which is useful to e.g. set non-default driver interfaces. Change-Id: I2e23fde9c5aae00ed39bd60c204e7c3eb029586a Story: #2007771 Task: #40091
This commit is contained in:
parent
52138f2c54
commit
f78229f659
@ -274,9 +274,16 @@ Ironic first.
|
|||||||
|
|
||||||
For discovery, the configuration file option ``node_not_found_hook`` should be
|
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
|
set to load the hook called ``enroll``. This hook will enroll the unidentified
|
||||||
node into Ironic using the ``fake-hardware`` hardware type. (This is
|
node into Ironic using the ``fake-hardware`` hardware type. This is
|
||||||
a configurable option; set ``enroll_node_driver``, in the **ironic-inspector**
|
a configurable option: set ``enroll_node_driver`` in the **ironic-inspector**
|
||||||
configuration file, to the Ironic hardware type or classic driver you want.)
|
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
|
The ``enroll`` hook will also set the ``ipmi_address`` property on the new
|
||||||
node, if its available in the introspection data we received,
|
node, if its available in the introspection data we received,
|
||||||
|
@ -21,6 +21,8 @@ _OPTS = [
|
|||||||
default='fake-hardware',
|
default='fake-hardware',
|
||||||
help=_('The name of the Ironic driver used by the enroll '
|
help=_('The name of the Ironic driver used by the enroll '
|
||||||
'hook when creating a new node in Ironic.')),
|
'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',
|
cfg.ListOpt('enabled_bmc_address_version',
|
||||||
default=['4', '6'],
|
default=['4', '6'],
|
||||||
help=_('IP version of BMC address that will be '
|
help=_('IP version of BMC address that will be '
|
||||||
|
@ -62,7 +62,7 @@ def _check_existing_nodes(introspection_data, node_driver_info, ironic):
|
|||||||
|
|
||||||
|
|
||||||
def enroll_node_not_found_hook(introspection_data, **kwargs):
|
def enroll_node_not_found_hook(introspection_data, **kwargs):
|
||||||
node_attr = {}
|
node_attr = CONF.discovery.enroll_node_fields.copy()
|
||||||
ironic = ir_utils.get_client()
|
ironic = ir_utils.get_client()
|
||||||
|
|
||||||
node_driver_info = _extract_node_driver_info(introspection_data)
|
node_driver_info = _extract_node_driver_info(introspection_data)
|
||||||
|
@ -117,6 +117,29 @@ class TestEnrollNodeNotFoundHook(test_base.NodeTest):
|
|||||||
{}, {}, self.ironic)
|
{}, {}, self.ironic)
|
||||||
self.assertEqual({'auto_discovered': True}, introspection_data)
|
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):
|
def test__check_existing_nodes_new_mac(self):
|
||||||
self.ironic.ports.return_value = []
|
self.ironic.ports.return_value = []
|
||||||
introspection_data = {'macs': self.macs}
|
introspection_data = {'macs': self.macs}
|
||||||
|
@ -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…
Reference in New Issue
Block a user