add disabled option to VALID_ADD_PORTS_VALUES

This allows inspector to create nodes without creating ports for the node.

Change-Id: Ife4c06d20e9217f0a308fef19177884596c6cf2d
Closes-Bug: #1693892
This commit is contained in:
Chris Krelle 2017-06-03 17:49:24 -07:00
parent 8b2e7d16b5
commit f61a75aaa0
6 changed files with 41 additions and 3 deletions

View File

@ -47,6 +47,11 @@ Usual hardware introspection flow is as follows:
created for all detected NIC's, and all other ports will be deleted.
Refer to the `Ironic inspection documentation`_ for details.
Ironic inspector can also be configured to not create any ports. This is
done by setting ``add_ports=disabled``. If setting ``add_ports`` to disabled
the ``keep_ports`` option should be also set to ``all``. This will ensure
no manually added ports will be deleted.
* Separate API (see :ref:`usage` and :ref:`api`) can be used to query
introspection results for a given node.

View File

@ -723,7 +723,7 @@
# IP addresses), pxe (only MAC address of NIC node PXE booted from,
# falls back to "active" if PXE MAC is not supplied by the ramdisk).
# (string value)
# Allowed values: all, active, pxe
# Allowed values: all, active, pxe, disabled
#add_ports = pxe
# Which ports (already present on a node) to keep after introspection.

View File

@ -21,7 +21,7 @@ MIN_VERSION_HEADER = 'X-OpenStack-Ironic-Inspector-API-Minimum-Version'
MAX_VERSION_HEADER = 'X-OpenStack-Ironic-Inspector-API-Maximum-Version'
VERSION_HEADER = 'X-OpenStack-Ironic-Inspector-API-Version'
VALID_ADD_PORTS_VALUES = ('all', 'active', 'pxe')
VALID_ADD_PORTS_VALUES = ('all', 'active', 'pxe', 'disabled')
VALID_KEEP_PORTS_VALUES = ('all', 'present', 'added')
VALID_STORE_DATA_VALUES = ('none', 'swift')

View File

@ -124,6 +124,15 @@ class SchedulerHook(base.ProcessingHook):
class ValidateInterfacesHook(base.ProcessingHook):
"""Hook to validate network interfaces."""
def __init__(self):
# Some configuration checks
if (CONF.processing.add_ports == 'disabled' and
CONF.processing.keep_ports == 'added'):
msg = _("Configuration error: add_ports set to disabled "
"and keep_ports set to added. Please change keep_ports "
"to all.")
raise utils.Error(msg)
def _get_interfaces(self, data=None):
"""Convert inventory to a dict with interfaces.
@ -237,6 +246,7 @@ class ValidateInterfacesHook(base.ProcessingHook):
def before_update(self, introspection_data, node_info, **kwargs):
"""Create new ports and drop ports that are not present in the data."""
interfaces = introspection_data.get('interfaces')
if CONF.processing.add_ports != 'disabled':
node_info.create_ports(list(interfaces.values()))
if CONF.processing.keep_ports == 'present':

View File

@ -173,6 +173,24 @@ class TestValidateInterfacesHookBeforeProcessing(test_base.NodeTest):
sorted(self.data['macs']))
self.assertEqual(self.all_interfaces, self.data['all_interfaces'])
@mock.patch.object(node_cache.NodeInfo, 'create_ports')
def test_disabled_bad_conf(self, mock_create_port):
CONF.set_override('add_ports', 'disabled', 'processing')
CONF.set_override('keep_ports', 'added', 'processing')
self.assertRaisesRegex(utils.Error, 'Configuration error:',
self.hook.__init__)
mock_create_port.assert_not_called()
@mock.patch.object(node_cache.NodeInfo, 'create_ports')
def test_disabled(self, mock_create_port):
CONF.set_override('add_ports', 'disabled', 'processing')
CONF.set_override('keep_ports', 'all', 'processing')
self.hook.before_processing(self.data)
self.assertEqual(self.active_interfaces, self.data['interfaces'])
mock_create_port.assert_not_called()
def test_malformed_interfaces(self):
self.inventory['interfaces'] = [
# no name

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``disabled`` option to add_ports, so discovered nodes can be created
without create ports.