From f61a75aaa0293db909b3b062ef62f7ed8dbf53bc Mon Sep 17 00:00:00 2001 From: Chris Krelle Date: Sat, 3 Jun 2017 17:49:24 -0700 Subject: [PATCH] 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 --- doc/source/workflow.rst | 5 +++++ example.conf | 2 +- ironic_inspector/conf.py | 2 +- ironic_inspector/plugins/standard.py | 12 +++++++++++- .../test/unit/test_plugins_standard.py | 18 ++++++++++++++++++ ...d-option-to-add-ports-f8c6c9b3e6797652.yaml | 5 +++++ 6 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/add-disabled-option-to-add-ports-f8c6c9b3e6797652.yaml diff --git a/doc/source/workflow.rst b/doc/source/workflow.rst index 912117502..fe629cf6a 100644 --- a/doc/source/workflow.rst +++ b/doc/source/workflow.rst @@ -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. diff --git a/example.conf b/example.conf index 82185aab8..76312314a 100644 --- a/example.conf +++ b/example.conf @@ -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. diff --git a/ironic_inspector/conf.py b/ironic_inspector/conf.py index 97f13609f..1a8b9dc1a 100644 --- a/ironic_inspector/conf.py +++ b/ironic_inspector/conf.py @@ -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') diff --git a/ironic_inspector/plugins/standard.py b/ironic_inspector/plugins/standard.py index 3d0e464b9..37089e77d 100644 --- a/ironic_inspector/plugins/standard.py +++ b/ironic_inspector/plugins/standard.py @@ -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,7 +246,8 @@ 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') - node_info.create_ports(list(interfaces.values())) + if CONF.processing.add_ports != 'disabled': + node_info.create_ports(list(interfaces.values())) if CONF.processing.keep_ports == 'present': expected_macs = { diff --git a/ironic_inspector/test/unit/test_plugins_standard.py b/ironic_inspector/test/unit/test_plugins_standard.py index 07aa33f60..3a579b182 100644 --- a/ironic_inspector/test/unit/test_plugins_standard.py +++ b/ironic_inspector/test/unit/test_plugins_standard.py @@ -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 diff --git a/releasenotes/notes/add-disabled-option-to-add-ports-f8c6c9b3e6797652.yaml b/releasenotes/notes/add-disabled-option-to-add-ports-f8c6c9b3e6797652.yaml new file mode 100644 index 000000000..6f648566f --- /dev/null +++ b/releasenotes/notes/add-disabled-option-to-add-ports-f8c6c9b3e6797652.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``disabled`` option to add_ports, so discovered nodes can be created + without create ports.