From 3312522af2297beee7ff5d8150737d0e249d8043 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Mon, 8 Dec 2014 20:45:15 +0100 Subject: [PATCH] Refactoring: consolidate standard plugins in one module Introduces module ironic_discoverd.plugins.standard. Moves currently unused handling of ramdisk error to a plugin. Change-Id: I3dff43e27e5354b3f4155f005b7bc66897f81ec4 --- ironic_discoverd/discoverd.py | 5 -- ironic_discoverd/plugins/scheduler.py | 48 ------------------- .../{validate_interfaces.py => standard.py} | 45 ++++++++++++++++- ironic_discoverd/test.py | 2 +- setup.py | 5 +- 5 files changed, 47 insertions(+), 58 deletions(-) delete mode 100644 ironic_discoverd/plugins/scheduler.py rename ironic_discoverd/plugins/{validate_interfaces.py => standard.py} (57%) diff --git a/ironic_discoverd/discoverd.py b/ironic_discoverd/discoverd.py index 196db2fd8..02e0183fe 100644 --- a/ironic_discoverd/discoverd.py +++ b/ironic_discoverd/discoverd.py @@ -33,11 +33,6 @@ def process(node_info): for hook_ext in hooks: hook_ext.obj.pre_discover(node_info) - if node_info.get('error'): - LOG.error('Error happened during discovery: %s', - node_info['error']) - raise utils.DiscoveryFailed(node_info['error']) - bmc_address = node_info.get('ipmi_address') cached_node = node_cache.pop_node(bmc_address=bmc_address, diff --git a/ironic_discoverd/plugins/scheduler.py b/ironic_discoverd/plugins/scheduler.py deleted file mode 100644 index c37ebc808..000000000 --- a/ironic_discoverd/plugins/scheduler.py +++ /dev/null @@ -1,48 +0,0 @@ -# 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. - -"""Nova scheduler required properties.""" - -import logging - -from ironic_discoverd.plugins import base -from ironic_discoverd import utils - - -LOG = logging.getLogger('ironic_discoverd.plugins.scheduler') - - -class SchedulerHook(base.ProcessingHook): - KEYS = ('cpus', 'cpu_arch', 'memory_mb', 'local_gb') - - def pre_discover(self, node_info): - """Validate that required properties are provided by the ramdisk.""" - missing = [key for key in self.KEYS if not node_info.get(key)] - if missing: - LOG.error('The following required parameters are missing: %s', - missing) - raise utils.DiscoveryFailed( - 'The following required parameters are missing: %s' % - missing) - - LOG.info('Discovered data: CPUs: %(cpus)s %(cpu_arch)s, ' - 'memory %(memory_mb)s MiB, disk %(local_gb)s GiB', - {key: node_info.get(key) for key in self.KEYS}) - - def post_discover(self, node, ports, discovered_data): - """Update node with scheduler properties.""" - patch = [{'op': 'add', 'path': '/properties/%s' % key, - 'value': str(discovered_data[key])} - for key in self.KEYS - if not node.properties.get(key)] - return patch, {} diff --git a/ironic_discoverd/plugins/validate_interfaces.py b/ironic_discoverd/plugins/standard.py similarity index 57% rename from ironic_discoverd/plugins/validate_interfaces.py rename to ironic_discoverd/plugins/standard.py index ca4f653e3..e493212e7 100644 --- a/ironic_discoverd/plugins/validate_interfaces.py +++ b/ironic_discoverd/plugins/standard.py @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Hook to validate network interfaces.""" +"""Standard set of plugins.""" import logging @@ -20,10 +20,40 @@ from ironic_discoverd.plugins import base from ironic_discoverd import utils -LOG = logging.getLogger('ironic_discoverd.plugins.validate_interfaces') +LOG = logging.getLogger('ironic_discoverd.plugins.standard') + + +class SchedulerHook(base.ProcessingHook): + """Nova scheduler required properties.""" + + KEYS = ('cpus', 'cpu_arch', 'memory_mb', 'local_gb') + + def pre_discover(self, node_info): + """Validate that required properties are provided by the ramdisk.""" + missing = [key for key in self.KEYS if not node_info.get(key)] + if missing: + LOG.error('The following required parameters are missing: %s', + missing) + raise utils.DiscoveryFailed( + 'The following required parameters are missing: %s' % + missing) + + LOG.info('Discovered data: CPUs: %(cpus)s %(cpu_arch)s, ' + 'memory %(memory_mb)s MiB, disk %(local_gb)s GiB', + {key: node_info.get(key) for key in self.KEYS}) + + def post_discover(self, node, ports, discovered_data): + """Update node with scheduler properties.""" + patch = [{'op': 'add', 'path': '/properties/%s' % key, + 'value': str(discovered_data[key])} + for key in self.KEYS + if not node.properties.get(key)] + return patch, {} class ValidateInterfacesHook(base.ProcessingHook): + """Hook to validate network interfaces.""" + def pre_discover(self, node_info): bmc_address = node_info.get('ipmi_address') @@ -54,3 +84,14 @@ class ValidateInterfacesHook(base.ProcessingHook): node_info['interfaces'] = valid_interfaces node_info['macs'] = valid_macs + + +class RamdiskErrorHook(base.ProcessingHook): + """Hook to process error send from the ramdisk.""" + + def pre_discover(self, node_info): + if not node_info.get('error'): + return + + LOG.error('Error happened during discovery: %s', node_info['error']) + raise utils.DiscoveryFailed(node_info['error']) diff --git a/ironic_discoverd/test.py b/ironic_discoverd/test.py index 5c05c2076..0fae7c7c4 100644 --- a/ironic_discoverd/test.py +++ b/ironic_discoverd/test.py @@ -97,7 +97,7 @@ class TestProcess(BaseTest): post_mock): plugins_base._HOOKS_MGR = None conf.CONF.set('discoverd', 'processing_hooks', - 'scheduler,validate_interfaces,example') + 'ramdisk_error,scheduler,validate_interfaces,example') cli = client_mock.return_value diff --git a/setup.py b/setup.py index ddde80c46..778957893 100644 --- a/setup.py +++ b/setup.py @@ -22,8 +22,9 @@ setup( "ironic-discoverd = ironic_discoverd.main:main" ], 'ironic_discoverd.hooks': [ - "scheduler = ironic_discoverd.plugins.scheduler:SchedulerHook", - "validate_interfaces = ironic_discoverd.plugins.validate_interfaces:ValidateInterfacesHook", + "scheduler = ironic_discoverd.plugins.standard:SchedulerHook", + "validate_interfaces = ironic_discoverd.plugins.standard:ValidateInterfacesHook", + "ramdisk_error = ironic_discoverd.plugins.standard:RamdiskErrorHook", "example = ironic_discoverd.plugins.example:ExampleProcessingHook", ], },