2015-02-11 17:51:31 +01:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
|
|
# implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""Gather root device hint from recognized block devices."""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2015-05-26 07:47:55 +02:00
|
|
|
from ironic_inspector.common.i18n import _LI, _LW
|
|
|
|
from ironic_inspector.plugins import base
|
2015-02-11 17:51:31 +01:00
|
|
|
|
|
|
|
|
2015-05-26 07:47:55 +02:00
|
|
|
LOG = logging.getLogger('ironic_inspector.plugins.root_device_hint')
|
2015-02-11 17:51:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RootDeviceHintHook(base.ProcessingHook):
|
2015-05-26 07:47:55 +02:00
|
|
|
"""Processing hook for learning the root device after RAID creation.
|
2015-02-11 17:51:31 +01:00
|
|
|
|
|
|
|
The plugin can figure out the root device in 2 runs. First, it saves the
|
|
|
|
discovered block device serials in node.extra. The second run will check
|
|
|
|
the difference between the recently discovered block devices and the
|
|
|
|
previously saved ones. After saving the root device in node.properties, it
|
|
|
|
will delete the temporarily saved block device serials in node.extra.
|
|
|
|
|
|
|
|
This way, it helps to figure out the root device hint in cases when
|
|
|
|
otherwise Ironic doesn't have enough information to do so. Such a usecase
|
|
|
|
is DRAC RAID configuration where the BMC doesn't provide any useful
|
|
|
|
information about the created RAID disks. Using this plugin immediately
|
|
|
|
before and after creating the root RAID device will solve the issue of root
|
|
|
|
device hints.
|
2015-05-27 11:14:15 +02:00
|
|
|
|
|
|
|
In cases where there's no RAID volume on the node, the standard plugin will
|
|
|
|
fail due to the missing local_gb value. This plugin fakes the missing
|
|
|
|
value, until it's corrected during later runs. Note, that for this to work
|
|
|
|
the plugin needs to take precedence over the standard plugin.
|
2015-02-11 17:51:31 +01:00
|
|
|
"""
|
|
|
|
|
2015-05-27 11:14:15 +02:00
|
|
|
def before_processing(self, node_info):
|
|
|
|
"""Adds fake local_gb value if it's missing from node_info."""
|
|
|
|
if not node_info.get('local_gb'):
|
|
|
|
LOG.info(_LI('No volume is found on the node. Adding a fake '
|
|
|
|
'value for "local_gb"'))
|
|
|
|
node_info['local_gb'] = 1
|
|
|
|
|
2015-02-11 17:51:31 +01:00
|
|
|
def before_update(self, node, ports, node_info):
|
2015-02-12 15:15:11 +01:00
|
|
|
if 'block_devices' not in node_info:
|
2015-02-16 04:05:49 +00:00
|
|
|
LOG.warning(_LW('No block device was received from ramdisk'))
|
2015-02-12 15:15:11 +01:00
|
|
|
return [], {}
|
|
|
|
|
2015-02-11 17:51:31 +01:00
|
|
|
if 'root_device' in node.properties:
|
2015-02-16 04:05:49 +00:00
|
|
|
LOG.info(_LI('Root device is already known for the node'))
|
2015-02-11 17:51:31 +01:00
|
|
|
return [], {}
|
|
|
|
|
|
|
|
if 'block_devices' in node.extra:
|
|
|
|
# Compare previously discovered devices with the current ones
|
|
|
|
previous_devices = node.extra['block_devices']['serials']
|
|
|
|
current_devices = node_info['block_devices']['serials']
|
|
|
|
new_devices = [device for device in current_devices
|
|
|
|
if device not in previous_devices]
|
|
|
|
|
|
|
|
if len(new_devices) > 1:
|
2015-02-16 04:05:49 +00:00
|
|
|
LOG.warning(_LW('Root device cannot be identified because '
|
|
|
|
'multiple new devices were found'))
|
2015-02-11 17:51:31 +01:00
|
|
|
return [], {}
|
|
|
|
elif len(new_devices) == 0:
|
2015-02-16 04:05:49 +00:00
|
|
|
LOG.warning(_LW('No new devices were found'))
|
2015-02-11 17:51:31 +01:00
|
|
|
return [], {}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{'op': 'remove',
|
|
|
|
'path': '/extra/block_devices'},
|
|
|
|
{'op': 'add',
|
|
|
|
'path': '/properties/root_device',
|
|
|
|
'value': {'serial': new_devices[0]}}
|
|
|
|
], {}
|
|
|
|
|
|
|
|
else:
|
2015-05-26 07:47:55 +02:00
|
|
|
# No previously discovered devices - save the inspector block
|
2015-02-11 17:51:31 +01:00
|
|
|
# devices in node.extra
|
|
|
|
return [
|
|
|
|
{'op': 'add',
|
|
|
|
'path': '/extra/block_devices',
|
|
|
|
'value': node_info['block_devices']}
|
|
|
|
], {}
|