diff options
author | Dmitry Tantsur <divius.inside@gmail.com> | 2016-11-04 17:43:17 +0100 |
---|---|---|
committer | Dmitry Tantsur <divius.inside@gmail.com> | 2016-11-10 16:52:06 +0100 |
commit | 7591dcedfb1bc4e2f443af6445afb0319ec07ba5 (patch) | |
tree | 59dd91800862c89645680aa0cb092995d7a0602d /ironic/tests/unit/drivers/modules/test_noop.py | |
parent | 565a0ed6b940df2d45172065840700bbc3802c99 (diff) | |
download | ironic-7591dcedfb1bc4e2f443af6445afb0319ec07ba5.tar.gz |
Create dummy interfaces for use with hardware types
A new module is created containing "noop" implementations of all
interfaces we consider optional. These can be used as default
implementation for hardware types that don't support a particular
interface or just don't want it enabled by default.
Partial-Bug: #1524745
Change-Id: I2abe2ff5449ac2671020f309b27c4e738fa017b5
Diffstat (limited to 'ironic/tests/unit/drivers/modules/test_noop.py')
-rw-r--r-- | ironic/tests/unit/drivers/modules/test_noop.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/ironic/tests/unit/drivers/modules/test_noop.py b/ironic/tests/unit/drivers/modules/test_noop.py new file mode 100644 index 000000000..ec6f21776 --- /dev/null +++ b/ironic/tests/unit/drivers/modules/test_noop.py @@ -0,0 +1,66 @@ +# Copyright 2016 Red Hat, Inc. +# +# 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. + +import mock +import stevedore + +from ironic.common import exception +from ironic.drivers.modules import noop +from ironic.tests import base + + +# TODO(dtantsur): move to ironic.common.driver_factory +def hardware_interface_extension_manager(interface): + """Get a Stevedore extension manager for given hardware interface.""" + return stevedore.extension.ExtensionManager( + 'ironic.hardware.interfaces.%s' % interface, + invoke_on_load=True) + + +class NoInterfacesTestCase(base.TestCase): + iface_types = ['console', 'inspect', 'raid', 'rescue', 'vendor'] + task = mock.Mock(node=mock.Mock(driver='pxe_foobar', spec=['driver']), + spec=['node']) + + def test_console(self): + for method in ('start_console', 'stop_console', 'get_console'): + self.assertRaises(exception.UnsupportedDriverExtension, + getattr(noop.NoConsole(), method), + self.task) + + def test_rescue(self): + for method in ('rescue', 'unrescue'): + self.assertRaises(exception.UnsupportedDriverExtension, + getattr(noop.NoRescue(), method), + self.task) + + def test_vendor(self): + self.assertRaises(exception.UnsupportedDriverExtension, + noop.NoVendor().validate, + self.task, 'method') + self.assertRaises(exception.UnsupportedDriverExtension, + noop.NoVendor().driver_validate, + 'method') + + def test_inspect(self): + self.assertRaises(exception.UnsupportedDriverExtension, + noop.NoInspect().inspect_hardware, self.task) + + def test_load_by_name(self): + for iface_type in self.iface_types: + mgr = hardware_interface_extension_manager(iface_type) + inst = mgr['no-%s' % iface_type].obj + self.assertEqual({}, inst.get_properties()) + self.assertRaises(exception.UnsupportedDriverExtension, + inst.validate, self.task) |