Remove compatibility with old bash-based introspection ramdisk

Inspector is using inventory directly, so we can remove the bits sending
processed network and scheduling properties.

Change-Id: I6c58bc3c5ea78fd2dbda82b38515f332ce2e8d4a
This commit is contained in:
Dmitry Tantsur 2017-01-09 14:10:47 +01:00
parent a6b09f2fa8
commit 10bff0a518
3 changed files with 10 additions and 155 deletions

View File

@ -16,13 +16,11 @@
import os
import time
import netaddr
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import excutils
from oslo_utils import units
import requests
import stevedore
@ -157,67 +155,6 @@ def setup_ipmi_credentials(resp):
LOG.info('successfully set IPMI credentials: user %s', user)
def discover_network_properties(inventory, data, failures):
"""Discover network and BMC related properties.
This logic should eventually move to inspector itself.
:param inventory: hardware inventory from a hardware manager
:param data: mutable data that we'll send to inspector
:param failures: AccumulatedFailures object
"""
data.setdefault('interfaces', {})
for iface in inventory['interfaces']:
is_loopback = (iface.ipv4_address and
netaddr.IPAddress(iface.ipv4_address).is_loopback())
if iface.name == 'lo' or is_loopback:
LOG.debug('ignoring local network interface %s', iface.name)
continue
LOG.debug('found network interface %s', iface.name)
if not iface.mac_address:
LOG.debug('no link information for interface %s', iface.name)
continue
if not iface.ipv4_address:
LOG.debug('no IP address for interface %s', iface.name)
data['interfaces'][iface.name] = {'mac': iface.mac_address,
'ip': iface.ipv4_address}
if data['interfaces']:
LOG.info('network interfaces: %s', data['interfaces'])
else:
failures.add('no network interfaces found')
def discover_scheduling_properties(inventory, data, root_disk=None):
"""Discover properties required for nova scheduler.
This logic should eventually move to inspector itself.
:param inventory: hardware inventory from a hardware manager
:param data: mutable data that we'll send to inspector
:param root_disk: root device (if it can be detected)
"""
data['cpus'] = inventory['cpu'].count
data['cpu_arch'] = inventory['cpu'].architecture
data['memory_mb'] = inventory['memory'].physical_mb
if root_disk is not None:
# -1 is required to give Ironic some spacing for partitioning
data['local_gb'] = root_disk.size / units.Gi - 1
for key in ('cpus', 'local_gb', 'memory_mb'):
try:
data[key] = int(data[key])
except (KeyError, ValueError, TypeError):
LOG.warning('value for %s is missing or malformed: %s',
key, data.get(key))
else:
LOG.info('value for %s is %s', key, data[key])
def _normalize_mac(mac):
"""Convert MAC to a well-known format aa:bb:cc:dd:ee:ff."""
if '-' in mac:
@ -274,12 +211,10 @@ def wait_for_dhcp():
def collect_default(data, failures):
"""The default inspection collector.
This is the only collector that is called by default. It is designed to be
both backward and future compatible:
1. it collects exactly the same data as the old bash-based ramdisk
2. it also posts the whole inventory which we'll eventually use.
This is the only collector that is called by default. It collects
the whole inventory as returned by the hardware manager(s).
In both cases it tries to get BMC address, PXE boot device and the expected
It also tries to get BMC address, PXE boot device and the expected
root device.
:param data: mutable data that we'll send to inspector
@ -288,9 +223,6 @@ def collect_default(data, failures):
wait_for_dhcp()
inventory = hardware.dispatch_to_managers('list_hardware_info')
# In the future we will only need the current version of inventory,
# a guessed root disk, PXE boot interface and IPMI address.
# Everything else will be done by inspector itself and its plugins.
data['inventory'] = inventory
# Replicate the same logic as in deploy. We need to make sure that when
# root device hints are not set, inspector will use the same root disk as
@ -310,11 +242,6 @@ def collect_default(data, failures):
data['ipmi_address'] = inventory.get('bmc_address')
LOG.debug('BMC IP address: %s', data['ipmi_address'])
# These 2 calls are required for backward compatibility and should be
# dropped after inspector is ready (probably in Mitaka cycle).
discover_network_properties(inventory, data, failures)
discover_scheduling_properties(inventory, data, root_disk)
def collect_logs(data, failures):
"""Collect system logs from the ramdisk.

View File

@ -262,77 +262,10 @@ class BaseDiscoverTest(test_base.BaseTestCase):
self.data = {}
class TestDiscoverNetworkProperties(BaseDiscoverTest):
def test_no_network_interfaces(self):
self.inventory['interfaces'] = [
hardware.NetworkInterface(name='lo',
mac_addr='aa:bb:cc:dd:ee:ff',
ipv4_address='127.0.0.1'),
hardware.NetworkInterface(name='local-2',
mac_addr='aa:bb:cc:dd:ee:ff',
ipv4_address='127.0.1.42'),
]
inspector.discover_network_properties(self.inventory, self.data,
self.failures)
self.assertIn('no network interfaces found', self.failures.get_error())
self.assertFalse(self.data['interfaces'])
def test_ok(self):
inspector.discover_network_properties(self.inventory, self.data,
self.failures)
self.assertEqual({'em1': {'mac': 'aa:bb:cc:dd:ee:ff',
'ip': '1.1.1.1'},
'em2': {'mac': '11:22:33:44:55:66',
'ip': None}},
self.data['interfaces'])
self.assertFalse(self.failures)
def test_missing(self):
self.inventory['interfaces'] = [
hardware.NetworkInterface(name='em1',
mac_addr='aa:bb:cc:dd:ee:ff'),
hardware.NetworkInterface(name='em2',
mac_addr=None,
ipv4_address='1.2.1.2'),
]
inspector.discover_network_properties(self.inventory, self.data,
self.failures)
self.assertEqual({'em1': {'mac': 'aa:bb:cc:dd:ee:ff', 'ip': None}},
self.data['interfaces'])
self.assertFalse(self.failures)
class TestDiscoverSchedulingProperties(BaseDiscoverTest):
def test_ok(self):
inspector.discover_scheduling_properties(
self.inventory, self.data,
root_disk=self.inventory['disks'][2])
self.assertEqual({'cpus': 4, 'cpu_arch': 'x86_64', 'local_gb': 464,
'memory_mb': 12288}, self.data)
def test_no_local_gb(self):
# Some DRAC servers do not have any visible hard drive until RAID is
# built
inspector.discover_scheduling_properties(self.inventory, self.data)
self.assertEqual({'cpus': 4, 'cpu_arch': 'x86_64', 'memory_mb': 12288},
self.data)
@mock.patch.object(inspector, 'wait_for_dhcp', autospec=True)
@mock.patch.object(inspector, 'discover_scheduling_properties', autospec=True)
@mock.patch.object(inspector, 'discover_network_properties', autospec=True)
@mock.patch.object(hardware, 'dispatch_to_managers', autospec=True)
class TestCollectDefault(BaseDiscoverTest):
def test_ok(self, mock_dispatch, mock_discover_net, mock_discover_sched,
mock_wait_for_dhcp):
def test_ok(self, mock_dispatch, mock_wait_for_dhcp):
mock_dispatch.return_value = self.inventory
inspector.collect_default(self.data, self.failures)
@ -346,15 +279,9 @@ class TestCollectDefault(BaseDiscoverTest):
self.data['root_disk'].name)
mock_dispatch.assert_called_once_with('list_hardware_info')
mock_discover_net.assert_called_once_with(self.inventory, self.data,
self.failures)
mock_discover_sched.assert_called_once_with(
self.inventory, self.data,
root_disk=self.inventory['disks'][0])
mock_wait_for_dhcp.assert_called_once_with()
def test_no_root_disk(self, mock_dispatch, mock_discover_net,
mock_discover_sched, mock_wait_for_dhcp):
def test_no_root_disk(self, mock_dispatch, mock_wait_for_dhcp):
mock_dispatch.return_value = self.inventory
self.inventory['disks'] = []
@ -368,10 +295,6 @@ class TestCollectDefault(BaseDiscoverTest):
self.assertNotIn('root_disk', self.data)
mock_dispatch.assert_called_once_with('list_hardware_info')
mock_discover_net.assert_called_once_with(self.inventory, self.data,
self.failures)
mock_discover_sched.assert_called_once_with(
self.inventory, self.data, root_disk=None)
mock_wait_for_dhcp.assert_called_once_with()

View File

@ -0,0 +1,5 @@
---
other:
- |
Introspection data no longer contains keys used for compatibility with
the old introspection ramdisk.