Skip to content

Commit b787b01

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Remove compatibility with old bash-based introspection ramdisk"
2 parents 2334605 + 10bff0a commit b787b01

File tree

3 files changed

+10
-155
lines changed

3 files changed

+10
-155
lines changed

ironic_python_agent/inspector.py

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
import os
1717
import time
1818

19-
import netaddr
2019
from oslo_concurrency import processutils
2120
from oslo_config import cfg
2221
from oslo_log import log as logging
2322
from oslo_serialization import jsonutils
2423
from oslo_utils import excutils
25-
from oslo_utils import units
2624
import requests
2725
import stevedore
2826

@@ -157,67 +155,6 @@ def setup_ipmi_credentials(resp):
157155
LOG.info('successfully set IPMI credentials: user %s', user)
158156

159157

160-
def discover_network_properties(inventory, data, failures):
161-
"""Discover network and BMC related properties.
162-
163-
This logic should eventually move to inspector itself.
164-
165-
:param inventory: hardware inventory from a hardware manager
166-
:param data: mutable data that we'll send to inspector
167-
:param failures: AccumulatedFailures object
168-
"""
169-
data.setdefault('interfaces', {})
170-
for iface in inventory['interfaces']:
171-
is_loopback = (iface.ipv4_address and
172-
netaddr.IPAddress(iface.ipv4_address).is_loopback())
173-
if iface.name == 'lo' or is_loopback:
174-
LOG.debug('ignoring local network interface %s', iface.name)
175-
continue
176-
177-
LOG.debug('found network interface %s', iface.name)
178-
179-
if not iface.mac_address:
180-
LOG.debug('no link information for interface %s', iface.name)
181-
continue
182-
183-
if not iface.ipv4_address:
184-
LOG.debug('no IP address for interface %s', iface.name)
185-
186-
data['interfaces'][iface.name] = {'mac': iface.mac_address,
187-
'ip': iface.ipv4_address}
188-
189-
if data['interfaces']:
190-
LOG.info('network interfaces: %s', data['interfaces'])
191-
else:
192-
failures.add('no network interfaces found')
193-
194-
195-
def discover_scheduling_properties(inventory, data, root_disk=None):
196-
"""Discover properties required for nova scheduler.
197-
198-
This logic should eventually move to inspector itself.
199-
200-
:param inventory: hardware inventory from a hardware manager
201-
:param data: mutable data that we'll send to inspector
202-
:param root_disk: root device (if it can be detected)
203-
"""
204-
data['cpus'] = inventory['cpu'].count
205-
data['cpu_arch'] = inventory['cpu'].architecture
206-
data['memory_mb'] = inventory['memory'].physical_mb
207-
if root_disk is not None:
208-
# -1 is required to give Ironic some spacing for partitioning
209-
data['local_gb'] = root_disk.size / units.Gi - 1
210-
211-
for key in ('cpus', 'local_gb', 'memory_mb'):
212-
try:
213-
data[key] = int(data[key])
214-
except (KeyError, ValueError, TypeError):
215-
LOG.warning('value for %s is missing or malformed: %s',
216-
key, data.get(key))
217-
else:
218-
LOG.info('value for %s is %s', key, data[key])
219-
220-
221158
def _normalize_mac(mac):
222159
"""Convert MAC to a well-known format aa:bb:cc:dd:ee:ff."""
223160
if '-' in mac:
@@ -274,12 +211,10 @@ def wait_for_dhcp():
274211
def collect_default(data, failures):
275212
"""The default inspection collector.
276213
277-
This is the only collector that is called by default. It is designed to be
278-
both backward and future compatible:
279-
1. it collects exactly the same data as the old bash-based ramdisk
280-
2. it also posts the whole inventory which we'll eventually use.
214+
This is the only collector that is called by default. It collects
215+
the whole inventory as returned by the hardware manager(s).
281216
282-
In both cases it tries to get BMC address, PXE boot device and the expected
217+
It also tries to get BMC address, PXE boot device and the expected
283218
root device.
284219
285220
:param data: mutable data that we'll send to inspector
@@ -288,9 +223,6 @@ def collect_default(data, failures):
288223
wait_for_dhcp()
289224
inventory = hardware.dispatch_to_managers('list_hardware_info')
290225

291-
# In the future we will only need the current version of inventory,
292-
# a guessed root disk, PXE boot interface and IPMI address.
293-
# Everything else will be done by inspector itself and its plugins.
294226
data['inventory'] = inventory
295227
# Replicate the same logic as in deploy. We need to make sure that when
296228
# root device hints are not set, inspector will use the same root disk as
@@ -310,11 +242,6 @@ def collect_default(data, failures):
310242
data['ipmi_address'] = inventory.get('bmc_address')
311243
LOG.debug('BMC IP address: %s', data['ipmi_address'])
312244

313-
# These 2 calls are required for backward compatibility and should be
314-
# dropped after inspector is ready (probably in Mitaka cycle).
315-
discover_network_properties(inventory, data, failures)
316-
discover_scheduling_properties(inventory, data, root_disk)
317-
318245

319246
def collect_logs(data, failures):
320247
"""Collect system logs from the ramdisk.

ironic_python_agent/tests/unit/test_inspector.py

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -262,77 +262,10 @@ def setUp(self):
262262
self.data = {}
263263

264264

265-
class TestDiscoverNetworkProperties(BaseDiscoverTest):
266-
def test_no_network_interfaces(self):
267-
self.inventory['interfaces'] = [
268-
hardware.NetworkInterface(name='lo',
269-
mac_addr='aa:bb:cc:dd:ee:ff',
270-
ipv4_address='127.0.0.1'),
271-
hardware.NetworkInterface(name='local-2',
272-
mac_addr='aa:bb:cc:dd:ee:ff',
273-
ipv4_address='127.0.1.42'),
274-
]
275-
276-
inspector.discover_network_properties(self.inventory, self.data,
277-
self.failures)
278-
279-
self.assertIn('no network interfaces found', self.failures.get_error())
280-
self.assertFalse(self.data['interfaces'])
281-
282-
def test_ok(self):
283-
inspector.discover_network_properties(self.inventory, self.data,
284-
self.failures)
285-
286-
self.assertEqual({'em1': {'mac': 'aa:bb:cc:dd:ee:ff',
287-
'ip': '1.1.1.1'},
288-
'em2': {'mac': '11:22:33:44:55:66',
289-
'ip': None}},
290-
self.data['interfaces'])
291-
self.assertFalse(self.failures)
292-
293-
def test_missing(self):
294-
self.inventory['interfaces'] = [
295-
hardware.NetworkInterface(name='em1',
296-
mac_addr='aa:bb:cc:dd:ee:ff'),
297-
hardware.NetworkInterface(name='em2',
298-
mac_addr=None,
299-
ipv4_address='1.2.1.2'),
300-
]
301-
302-
inspector.discover_network_properties(self.inventory, self.data,
303-
self.failures)
304-
305-
self.assertEqual({'em1': {'mac': 'aa:bb:cc:dd:ee:ff', 'ip': None}},
306-
self.data['interfaces'])
307-
self.assertFalse(self.failures)
308-
309-
310-
class TestDiscoverSchedulingProperties(BaseDiscoverTest):
311-
def test_ok(self):
312-
inspector.discover_scheduling_properties(
313-
self.inventory, self.data,
314-
root_disk=self.inventory['disks'][2])
315-
316-
self.assertEqual({'cpus': 4, 'cpu_arch': 'x86_64', 'local_gb': 464,
317-
'memory_mb': 12288}, self.data)
318-
319-
def test_no_local_gb(self):
320-
# Some DRAC servers do not have any visible hard drive until RAID is
321-
# built
322-
323-
inspector.discover_scheduling_properties(self.inventory, self.data)
324-
325-
self.assertEqual({'cpus': 4, 'cpu_arch': 'x86_64', 'memory_mb': 12288},
326-
self.data)
327-
328-
329265
@mock.patch.object(inspector, 'wait_for_dhcp', autospec=True)
330-
@mock.patch.object(inspector, 'discover_scheduling_properties', autospec=True)
331-
@mock.patch.object(inspector, 'discover_network_properties', autospec=True)
332266
@mock.patch.object(hardware, 'dispatch_to_managers', autospec=True)
333267
class TestCollectDefault(BaseDiscoverTest):
334-
def test_ok(self, mock_dispatch, mock_discover_net, mock_discover_sched,
335-
mock_wait_for_dhcp):
268+
def test_ok(self, mock_dispatch, mock_wait_for_dhcp):
336269
mock_dispatch.return_value = self.inventory
337270

338271
inspector.collect_default(self.data, self.failures)
@@ -346,15 +279,9 @@ def test_ok(self, mock_dispatch, mock_discover_net, mock_discover_sched,
346279
self.data['root_disk'].name)
347280

348281
mock_dispatch.assert_called_once_with('list_hardware_info')
349-
mock_discover_net.assert_called_once_with(self.inventory, self.data,
350-
self.failures)
351-
mock_discover_sched.assert_called_once_with(
352-
self.inventory, self.data,
353-
root_disk=self.inventory['disks'][0])
354282
mock_wait_for_dhcp.assert_called_once_with()
355283

356-
def test_no_root_disk(self, mock_dispatch, mock_discover_net,
357-
mock_discover_sched, mock_wait_for_dhcp):
284+
def test_no_root_disk(self, mock_dispatch, mock_wait_for_dhcp):
358285
mock_dispatch.return_value = self.inventory
359286
self.inventory['disks'] = []
360287

@@ -368,10 +295,6 @@ def test_no_root_disk(self, mock_dispatch, mock_discover_net,
368295
self.assertNotIn('root_disk', self.data)
369296

370297
mock_dispatch.assert_called_once_with('list_hardware_info')
371-
mock_discover_net.assert_called_once_with(self.inventory, self.data,
372-
self.failures)
373-
mock_discover_sched.assert_called_once_with(
374-
self.inventory, self.data, root_disk=None)
375298
mock_wait_for_dhcp.assert_called_once_with()
376299

377300

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
other:
3+
- |
4+
Introspection data no longer contains keys used for compatibility with
5+
the old introspection ramdisk.

0 commit comments

Comments
 (0)