summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-11-28 05:39:23 +0000
committerGerrit Code Review <review@openstack.org>2018-11-28 05:39:23 +0000
commitf7079e9acccfedc6b1bf5a1269869d39da80a700 (patch)
treeb39384c3cab1200a69f8fb76a536c0110cdebdef
parentc3b8463bb79d7a8f86e3fd3f5b30b65f861b5ded (diff)
parenta1c44d29e67339a05abde733d24315326c23e685 (diff)
Merge "Support IPv6 address when validating interfaces"
-rw-r--r--ironic_inspector/plugins/standard.py13
-rw-r--r--ironic_inspector/test/unit/test_plugins_standard.py44
-rw-r--r--releasenotes/notes/validate-ipv6-address-fda29c929754352e.yaml9
3 files changed, 62 insertions, 4 deletions
diff --git a/ironic_inspector/plugins/standard.py b/ironic_inspector/plugins/standard.py
index 123d062..cfaeb37 100644
--- a/ironic_inspector/plugins/standard.py
+++ b/ironic_inspector/plugins/standard.py
@@ -13,7 +13,6 @@
13 13
14"""Standard set of plugins.""" 14"""Standard set of plugins."""
15 15
16
17from ironic_lib import utils as il_utils 16from ironic_lib import utils as il_utils
18import netaddr 17import netaddr
19from oslo_config import cfg 18from oslo_config import cfg
@@ -27,7 +26,6 @@ from ironic_inspector import utils
27 26
28CONF = cfg.CONF 27CONF = cfg.CONF
29 28
30
31LOG = utils.getProcessingLogger('ironic_inspector.plugins.standard') 29LOG = utils.getProcessingLogger('ironic_inspector.plugins.standard')
32 30
33 31
@@ -162,7 +160,13 @@ class ValidateInterfacesHook(base.ProcessingHook):
162 for iface in inventory['interfaces']: 160 for iface in inventory['interfaces']:
163 name = iface.get('name') 161 name = iface.get('name')
164 mac = iface.get('mac_address') 162 mac = iface.get('mac_address')
165 ip = iface.get('ipv4_address') 163 ipv4_address = iface.get('ipv4_address')
164 ipv6_address = iface.get('ipv6_address')
165 # NOTE(kaifeng) ipv6 address may in the form of fd00::1%enp2s0,
166 # which is not supported by netaddr, remove the suffix if exists.
167 if ipv6_address and '%' in ipv6_address:
168 ipv6_address = ipv6_address.split('%')[0]
169 ip = ipv4_address or ipv6_address
166 client_id = iface.get('client_id') 170 client_id = iface.get('client_id')
167 171
168 if not name: 172 if not name:
@@ -221,7 +225,8 @@ class ValidateInterfacesHook(base.ProcessingHook):
221 LOG.debug('Skipping interface %s as it was not PXE booting', 225 LOG.debug('Skipping interface %s as it was not PXE booting',
222 name, data=data) 226 name, data=data)
223 continue 227 continue
224 elif CONF.processing.add_ports != 'all' and not ip: 228 elif CONF.processing.add_ports != 'all' and (
229 not ip or netaddr.IPAddress(ip).is_link_local()):
225 LOG.debug('Skipping interface %s as it did not have ' 230 LOG.debug('Skipping interface %s as it did not have '
226 'an IP address assigned during the ramdisk run', 231 'an IP address assigned during the ramdisk run',
227 name, data=data) 232 name, data=data)
diff --git a/ironic_inspector/test/unit/test_plugins_standard.py b/ironic_inspector/test/unit/test_plugins_standard.py
index b1d4a78..5a355aa 100644
--- a/ironic_inspector/test/unit/test_plugins_standard.py
+++ b/ironic_inspector/test/unit/test_plugins_standard.py
@@ -188,6 +188,50 @@ class TestValidateInterfacesHookBeforeProcessing(test_base.NodeTest):
188 self.assertRaisesRegex(utils.Error, 'No suitable interfaces found', 188 self.assertRaisesRegex(utils.Error, 'No suitable interfaces found',
189 self.hook.before_processing, self.data) 189 self.hook.before_processing, self.data)
190 190
191 def test_skipped_interfaces_with_local_address(self):
192 CONF.set_override('add_ports', 'active', 'processing')
193 self.inventory['interfaces'] = [
194 # local interface (by IPv4 address)
195 {'name': 'em1', 'mac_address': '22:22:22:22:22:22',
196 'ipv4_address': '127.0.0.1'},
197 # local interface (by IPv6 address)
198 {'name': 'em2', 'mac_address': '33:33:33:33:33:33',
199 'ipv6_address': '::1'},
200 # interface only with local-link address
201 {'name': 'em3', 'mac_address': '44:44:44:44:44:44',
202 'ipv6_address': 'fe80::4644:44ff:fe44:4444'},
203 # interface only with local-link address with suffix
204 {'name': 'em4', 'mac_address': '55:55:55:55:55:55',
205 'ipv6_address': 'fe80::5755:55ff:fe55:5555%em4'},
206 ]
207 self.assertRaisesRegex(utils.Error, 'No suitable interfaces found',
208 self.hook.before_processing, self.data)
209
210 def test_interfaces_with_ipv6_addresses_only(self):
211 CONF.set_override('add_ports', 'all', 'processing')
212 self.inventory['interfaces'] = [
213 # loopback interface (by IPv6 address)
214 {'name': 'em2', 'mac_address': '33:33:33:33:33:33',
215 'ipv6_address': '::1'},
216 # interface with local-link address
217 {'name': 'em3', 'mac_address': '44:44:44:44:44:44',
218 'ipv6_address': 'fe80::4644:44ff:fe44:4444'},
219 # interface with local-link address with suffix
220 {'name': 'em4', 'mac_address': '55:55:55:55:55:55',
221 'ipv6_address': 'fe80::5755:55ff:fe55:5555%em4'},
222 # interface with ULA address
223 {'name': 'em5', 'mac_address': '66:66:66:66:66:66',
224 'ipv6_address': 'fd00::1111:2222:6666'},
225 ]
226 self.hook.before_processing(self.data)
227 interfaces = self.data['interfaces']
228 self.assertEqual(interfaces['em3']['mac'], '44:44:44:44:44:44')
229 self.assertEqual(interfaces['em3']['ip'], 'fe80::4644:44ff:fe44:4444')
230 self.assertEqual(interfaces['em4']['mac'], '55:55:55:55:55:55')
231 self.assertEqual(interfaces['em4']['ip'], 'fe80::5755:55ff:fe55:5555')
232 self.assertEqual(interfaces['em5']['mac'], '66:66:66:66:66:66')
233 self.assertEqual(interfaces['em5']['ip'], 'fd00::1111:2222:6666')
234
191 235
192@mock.patch.object(node_cache.NodeInfo, 'delete_port', autospec=True) 236@mock.patch.object(node_cache.NodeInfo, 'delete_port', autospec=True)
193@mock.patch.object(node_cache.NodeInfo, 'create_ports', autospec=True) 237@mock.patch.object(node_cache.NodeInfo, 'create_ports', autospec=True)
diff --git a/releasenotes/notes/validate-ipv6-address-fda29c929754352e.yaml b/releasenotes/notes/validate-ipv6-address-fda29c929754352e.yaml
new file mode 100644
index 0000000..2d82e8d
--- /dev/null
+++ b/releasenotes/notes/validate-ipv6-address-fda29c929754352e.yaml
@@ -0,0 +1,9 @@
1---
2fixes:
3 - |
4 Fixes the issue that ports were not collected when there were only IPv6
5 addresses (no IPv4), and the configuration option
6 ``[processing]add_ports`` was not set to ``all``. Inspector will report
7 "No suitable interfaces found" if no interface is collected. For more
8 information see
9 `Story 1744073 <https://storyboard.openstack.org/#!/story/1744073>`_