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
This commit is contained in:
Dmitry Tantsur 2014-12-08 20:45:15 +01:00
parent 4f209bb1e2
commit 3312522af2
5 changed files with 47 additions and 58 deletions

View File

@ -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,

View File

@ -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, {}

View File

@ -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'])

View File

@ -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

View File

@ -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",
],
},