Completely stop using the "fake" classic driver in unit tests

This change makes "fake-hardware" the default driver for test nodes
and makes enabled_drivers empty in the base test class.

Note that some unit test coverage for classic drivers is lost because
of this change. It is fine, because the classic drivers themselves
are deprecated and will be removed soon.

Change-Id: I06acb5aed24ef952db3f9e6987e5a90c81e96401
This commit is contained in:
Dmitry Tantsur 2018-05-25 16:09:35 +02:00
parent d69dc019cb
commit 7fcca34de6
23 changed files with 581 additions and 1196 deletions

View File

@ -129,11 +129,27 @@ class TestCase(oslo_test_base.BaseTestCase):
group='neutron')
self.config(rescuing_network=uuidutils.generate_uuid(),
group='neutron')
self.config(enabled_drivers=['fake'])
self.config(enabled_hardware_types=['fake-hardware'])
self.config(enabled_network_interfaces=['flat', 'noop', 'neutron'])
self.config(enabled_drivers=[])
self.config(enabled_hardware_types=['fake-hardware',
'manual-management'])
for iface in drivers_base.ALL_INTERFACES:
self.config(**{'default_%s_interface' % iface: None})
# Restore some reasonable defaults
if iface == 'network':
values = ['flat', 'noop', 'neutron']
else:
values = ['fake']
if iface == 'deploy':
values.extend(['iscsi', 'direct'])
elif iface == 'boot':
values.append('pxe')
elif iface == 'storage':
values.append('noop')
elif iface not in {'network', 'power', 'management'}:
values.append('no-%s' % iface)
self.config(**{'enabled_%s_interfaces' % iface: values,
'default_%s_interface' % iface: None})
self.set_defaults(host='fake-mini',
debug=True)
self.set_defaults(connection="sqlite://",

View File

@ -449,7 +449,7 @@ class TestListDrivers(base.BaseApiTest):
driver._RAID_PROPERTIES = {}
self.register_fake_conductors()
disk_prop_mock.side_effect = exception.UnsupportedDriverExtension(
extension='raid', driver='fake')
extension='raid', driver='fake-hardware')
path = '/drivers/%s/raid/logical_disk_properties' % self.d1
ret = self.get_json(path,
headers={api_base.Version.string: "1.12"},
@ -467,7 +467,7 @@ class TestDriverProperties(base.BaseApiTest):
def test_driver_properties_fake(self, mock_topic, mock_properties):
# Can get driver properties for fake driver.
driver._DRIVER_PROPERTIES = {}
driver_name = 'fake'
driver_name = 'test'
mock_topic.return_value = 'fake_topic'
mock_properties.return_value = {'prop1': 'Property 1. Required.'}
data = self.get_json('/drivers/%s/properties' % driver_name)
@ -501,12 +501,17 @@ class TestDriverProperties(base.BaseApiTest):
# only one RPC-conductor call will be made and the info cached
# for subsequent requests
driver._DRIVER_PROPERTIES = {}
driver_name = 'fake'
driver_name = 'manual-management'
mock_topic.return_value = 'fake_topic'
mock_properties.return_value = {'prop1': 'Property 1. Required.'}
data = self.get_json('/drivers/%s/properties' % driver_name)
data = self.get_json('/drivers/%s/properties' % driver_name)
data = self.get_json('/drivers/%s/properties' % driver_name)
with mock.patch.object(self.dbapi, 'get_active_hardware_type_dict',
autospec=True) as mock_hw_type:
mock_hw_type.return_value = {driver_name: 'fake_topic'}
data = self.get_json('/drivers/%s/properties' % driver_name)
data = self.get_json('/drivers/%s/properties' % driver_name)
data = self.get_json('/drivers/%s/properties' % driver_name)
self.assertEqual(mock_properties.return_value, data)
mock_topic.assert_called_once_with(driver_name)
mock_properties.assert_called_once_with(mock.ANY, driver_name,

View File

@ -1178,17 +1178,17 @@ class TestListNodes(test_api_base.BaseApiTest):
def test_get_nodes_by_driver(self):
node = obj_utils.create_test_node(self.context,
uuid=uuidutils.generate_uuid(),
driver='pxe_ipmitool')
driver='ipmi')
node1 = obj_utils.create_test_node(self.context,
uuid=uuidutils.generate_uuid(),
driver='fake')
driver='fake-hardware')
data = self.get_json('/nodes?driver=pxe_ipmitool',
data = self.get_json('/nodes?driver=ipmi',
headers={api_base.Version.string: "1.16"})
uuids = [n['uuid'] for n in data['nodes']]
self.assertIn(node.uuid, uuids)
self.assertNotIn(node1.uuid, uuids)
data = self.get_json('/nodes?driver=fake',
data = self.get_json('/nodes?driver=fake-hardware',
headers={api_base.Version.string: "1.16"})
uuids = [n['uuid'] for n in data['nodes']]
self.assertIn(node1.uuid, uuids)
@ -1215,11 +1215,9 @@ class TestListNodes(test_api_base.BaseApiTest):
node = obj_utils.create_test_node(self.context,
uuid=uuidutils.generate_uuid(),
driver='fake',
resource_class='foo')
node1 = obj_utils.create_test_node(self.context,
uuid=uuidutils.generate_uuid(),
driver='fake',
resource_class='bar')
data = self.get_json(base_url % 'foo',
@ -2317,7 +2315,6 @@ class TestPost(test_api_base.BaseApiTest):
def setUp(self):
super(TestPost, self).setUp()
self.config(enabled_drivers=['fake'])
self.chassis = obj_utils.create_test_chassis(self.context)
p = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for')
self.mock_gtf = p.start()
@ -2421,22 +2418,8 @@ class TestPost(test_api_base.BaseApiTest):
expect_errors=True)
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_int)
def test_create_node_classic_driver_specify_interface(self):
headers = {api_base.Version.string: '1.31'}
for field in api_utils.V31_FIELDS:
node = {
'uuid': uuidutils.generate_uuid(),
field: 'fake',
}
ndict = test_api_utils.post_get_test_node(**node)
response = self.post_json('/nodes', ndict,
headers=headers,
expect_errors=True)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_node_explicit_storage_interface(self):
self.config(enabled_storage_interfaces=['cinder', 'noop', 'fake'])
headers = {api_base.Version.string: '1.33'}
result = self._test_create_node(headers=headers,
storage_interface='cinder')
@ -3961,7 +3944,7 @@ class TestPut(test_api_base.BaseApiTest):
raid_config = {'logical_disks': [{'size_gb': 100, 'raid_level': 1}]}
set_raid_config_mock.side_effect = (
exception.UnsupportedDriverExtension(extension='raid',
driver='fake'))
driver='fake-hardware'))
ret = self.put_json(
'/nodes/%s/states/raid' % self.node.uuid, raid_config,
headers={api_base.Version.string: "1.12"},

View File

@ -35,7 +35,6 @@ class FakeEp(object):
class DriverLoadTestCase(db_base.DbTestCase):
def _fake_init_name_err(self, *args, **kwargs):
kwargs['on_load_failure_callback'](None, FakeEp, NameError('aaa'))
@ -97,43 +96,6 @@ class DriverLoadTestCase(db_base.DbTestCase):
driver_factory.HardwareTypesFactory._extension_manager.names())
self.assertTrue(mock_warn.called)
@mock.patch.object(driver_factory.LOG, 'warning', autospec=True)
def test_classic_drivers_unsupported(self, mock_warn):
self.config(enabled_drivers=['fake'])
driver_factory.DriverFactory._init_extension_manager()
self.assertTrue(mock_warn.called)
def test_build_driver_for_task(self):
node = obj_utils.create_test_node(self.context, driver='fake')
with task_manager.acquire(self.context, node.id) as task:
for iface in drivers_base.ALL_INTERFACES:
impl = getattr(task.driver, iface)
if iface in ['bios', 'rescue']:
self.assertIsNone(impl)
else:
self.assertIsNotNone(impl)
@mock.patch.object(drivers_base.BaseDriver, 'supported', True)
@mock.patch.object(driver_factory, '_attach_interfaces_to_driver',
autospec=True)
@mock.patch.object(driver_factory.LOG, 'warning', autospec=True)
def test_build_driver_for_task_incorrect(self, mock_warn, mock_attach):
# Cannot set these node interfaces for classic driver
no_set_interfaces = (drivers_base.ALL_INTERFACES
- set(['network', 'storage']))
for iface in no_set_interfaces:
iface_name = '%s_interface' % iface
node_kwargs = {'uuid': uuidutils.generate_uuid(),
iface_name: 'fake'}
node = obj_utils.create_test_node(self.context, driver='fake',
**node_kwargs)
with task_manager.acquire(self.context, node.id) as task:
mock_warn.assert_called_once_with(mock.ANY, mock.ANY)
mock_warn.reset_mock()
mock_attach.assert_called_once_with(mock.ANY, task.node,
mock.ANY)
mock_attach.reset_mock()
class WarnUnsupportedDriversTestCase(base.TestCase):
@mock.patch.object(driver_factory.LOG, 'warning', autospec=True)
@ -154,23 +116,13 @@ class WarnUnsupportedDriversTestCase(base.TestCase):
self._test__warn_if_unsupported(False)
class GetDriverTestCase(base.TestCase):
def test_get_driver_known(self):
driver = driver_factory.get_driver('fake')
self.assertIsInstance(driver, drivers_base.BaseDriver)
def test_get_driver_unknown(self):
self.assertRaises(exception.DriverNotFound,
driver_factory.get_driver, 'unknown_driver')
class NetworkInterfaceFactoryTestCase(db_base.DbTestCase):
@mock.patch.object(driver_factory, '_warn_if_unsupported', autospec=True)
def test_build_driver_for_task(self, mock_warn):
# flat, neutron, and noop network interfaces are enabled in base test
# case
factory = driver_factory.NetworkInterfaceFactory
node = obj_utils.create_test_node(self.context, driver='fake',
node = obj_utils.create_test_node(self.context,
network_interface='flat')
with task_manager.acquire(self.context, node.id) as task:
extension_mgr = factory._extension_manager
@ -188,38 +140,11 @@ class NetworkInterfaceFactoryTestCase(db_base.DbTestCase):
# each activated interface or driver causes the number to increment.
self.assertTrue(mock_warn.called)
def test_build_driver_for_task_default_is_none(self):
# flat, neutron, and noop network interfaces are enabled in base test
# case
factory = driver_factory.NetworkInterfaceFactory
self.config(dhcp_provider='none', group='dhcp')
node = obj_utils.create_test_node(self.context, driver='fake')
with task_manager.acquire(self.context, node.id) as task:
extension_mgr = factory._extension_manager
self.assertIn('flat', extension_mgr)
self.assertIn('neutron', extension_mgr)
self.assertIn('noop', extension_mgr)
self.assertEqual(extension_mgr['noop'].obj, task.driver.network)
def test_build_driver_for_task_default_network_interface_is_set(self):
# flat, neutron, and noop network interfaces are enabled in base test
# case
factory = driver_factory.NetworkInterfaceFactory
self.config(dhcp_provider='none', group='dhcp')
self.config(default_network_interface='flat')
node = obj_utils.create_test_node(self.context, driver='fake')
with task_manager.acquire(self.context, node.id) as task:
extension_mgr = factory._extension_manager
self.assertIn('flat', extension_mgr)
self.assertIn('neutron', extension_mgr)
self.assertIn('noop', extension_mgr)
self.assertEqual(extension_mgr['flat'].obj, task.driver.network)
def test_build_driver_for_task_default_is_flat(self):
# flat, neutron, and noop network interfaces are enabled in base test
# case
factory = driver_factory.NetworkInterfaceFactory
node = obj_utils.create_test_node(self.context, driver='fake')
node = obj_utils.create_test_node(self.context)
with task_manager.acquire(self.context, node.id) as task:
extension_mgr = factory._extension_manager
self.assertIn('flat', extension_mgr)
@ -228,7 +153,7 @@ class NetworkInterfaceFactoryTestCase(db_base.DbTestCase):
self.assertEqual(extension_mgr['flat'].obj, task.driver.network)
def test_build_driver_for_task_unknown_network_interface(self):
node = obj_utils.create_test_node(self.context, driver='fake',
node = obj_utils.create_test_node(self.context,
network_interface='meow')
self.assertRaises(exception.InterfaceNotFoundInEntrypoint,
task_manager.acquire, self.context, node.id)
@ -236,16 +161,10 @@ class NetworkInterfaceFactoryTestCase(db_base.DbTestCase):
class StorageInterfaceFactoryTestCase(db_base.DbTestCase):
def setUp(self):
super(StorageInterfaceFactoryTestCase, self).setUp()
driver_factory.DriverFactory._extension_manager = None
driver_factory.StorageInterfaceFactory._extension_manager = None
self.config(enabled_drivers=['fake'])
def test_build_interface_for_task(self):
"""Validate a node has no default storage interface."""
factory = driver_factory.StorageInterfaceFactory
node = obj_utils.create_test_node(self.context, driver='fake')
node = obj_utils.create_test_node(self.context, driver='fake-hardware')
with task_manager.acquire(self.context, node.id) as task:
manager = factory._extension_manager
self.assertIn('noop', manager)
@ -265,71 +184,36 @@ class NewFactoryTestCase(db_base.DbTestCase):
class CheckAndUpdateNodeInterfacesTestCase(db_base.DbTestCase):
def test_no_network_interface(self):
node = obj_utils.get_test_node(self.context, driver='fake')
node = obj_utils.get_test_node(self.context)
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
self.assertEqual('flat', node.network_interface)
def test_none_network_interface(self):
node = obj_utils.get_test_node(self.context, driver='fake',
network_interface=None)
node = obj_utils.get_test_node(self.context, network_interface=None)
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
self.assertEqual('flat', node.network_interface)
def test_no_network_interface_default_from_conf(self):
self.config(default_network_interface='noop')
node = obj_utils.get_test_node(self.context, driver='fake')
node = obj_utils.get_test_node(self.context)
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
self.assertEqual('noop', node.network_interface)
def test_no_network_interface_default_from_dhcp(self):
self.config(dhcp_provider='none', group='dhcp')
node = obj_utils.get_test_node(self.context, driver='fake')
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
# "none" dhcp provider corresponds to "noop" network_interface
self.assertEqual('noop', node.network_interface)
def test_create_node_classic_driver_valid_interfaces(self):
node = obj_utils.get_test_node(self.context, driver='fake',
def test_create_node_valid_interfaces(self):
node = obj_utils.get_test_node(self.context,
network_interface='noop',
storage_interface='noop')
self.assertFalse(driver_factory.check_and_update_node_interfaces(node))
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
self.assertEqual('noop', node.network_interface)
self.assertEqual('noop', node.storage_interface)
def test_create_node_classic_driver_invalid_network_interface(self):
node = obj_utils.get_test_node(self.context, driver='fake',
def test_create_node_invalid_network_interface(self):
node = obj_utils.get_test_node(self.context,
network_interface='banana')
self.assertRaises(exception.InterfaceNotFoundInEntrypoint,
driver_factory.check_and_update_node_interfaces,
node)
def test_create_node_classic_driver_not_allowed_interfaces_set(self):
# Cannot set these node interfaces for classic driver
no_set_interfaces = (drivers_base.ALL_INTERFACES
- set(['network', 'storage']))
for iface in no_set_interfaces:
iface_name = '%s_interface' % iface
node_kwargs = {'uuid': uuidutils.generate_uuid(),
iface_name: 'fake'}
node = obj_utils.get_test_node(self.context, driver='fake',
**node_kwargs)
self.assertRaisesRegex(
exception.InvalidParameterValue,
'driver fake.*%s' % iface_name,
driver_factory.check_and_update_node_interfaces, node)
def test_create_node_classic_driver_no_interfaces_set(self):
no_set_interfaces = (drivers_base.ALL_INTERFACES
- set(['network', 'storage']))
node_kwargs = {'uuid': uuidutils.generate_uuid()}
node = obj_utils.get_test_node(self.context, driver='fake',
**node_kwargs)
driver_factory.check_and_update_node_interfaces(node)
for iface in no_set_interfaces:
iface_name = '%s_interface' % iface
self.assertIsNone(getattr(node, iface_name))
def _get_valid_default_interface_name(self, iface):
i_name = 'fake'
# there is no 'fake' network interface
@ -344,15 +228,6 @@ class CheckAndUpdateNodeInterfacesTestCase(db_base.DbTestCase):
'default_%s_interface' % iface: i_name}
self.config(**config_kwarg)
def test_create_node_dynamic_driver_invalid_network_interface(self):
self._set_config_interface_options_hardware_type()
node = obj_utils.get_test_node(self.context, driver='fake-hardware',
network_interface='banana')
self.assertRaises(exception.InterfaceNotFoundInEntrypoint,
driver_factory.check_and_update_node_interfaces,
node)
def test_create_node_dynamic_driver_interfaces_set(self):
self._set_config_interface_options_hardware_type()
@ -366,101 +241,6 @@ class CheckAndUpdateNodeInterfacesTestCase(db_base.DbTestCase):
driver_factory.check_and_update_node_interfaces(node)
self.assertEqual(i_name, getattr(node, iface_name))
def test_update_node_set_classic_driver_and_not_allowed_interfaces(self):
"""Update driver to classic and interfaces specified"""
not_allowed_interfaces = (drivers_base.ALL_INTERFACES
- set(['network', 'storage']))
self.config(enabled_drivers=['fake', 'fake_agent'])
for iface in not_allowed_interfaces:
iface_name = '%s_interface' % iface
node_kwargs = {'uuid': uuidutils.generate_uuid()}
node = obj_utils.create_test_node(self.context, driver='fake',
**node_kwargs)
setattr(node, iface_name, 'fake')
node.driver = 'fake_agent'
self.assertRaisesRegex(
exception.InvalidParameterValue,
'driver fake.*%s' % iface_name,
driver_factory.check_and_update_node_interfaces, node)
def test_update_node_set_classic_driver_and_allowed_interfaces(self):
"""Update driver to classic and interfaces specified"""
self._set_config_interface_options_hardware_type()
self.config(enabled_drivers=['fake', 'fake_agent'])
for iface in ['network', 'storage']:
iface_name = '%s_interface' % iface
node_kwargs = {'uuid': uuidutils.generate_uuid()}
node = obj_utils.create_test_node(self.context, driver='fake',
**node_kwargs)
i_name = self._get_valid_default_interface_name(iface)
setattr(node, iface_name, i_name)
node.driver = 'fake_agent'
driver_factory.check_and_update_node_interfaces(node)
self.assertEqual(i_name, getattr(node, iface_name))
def test_update_node_set_classic_driver_unset_interfaces(self):
"""Update driver to classic and set interfaces to None"""
no_set_interfaces = (drivers_base.ALL_INTERFACES
- set(['network', 'storage']))
self.config(enabled_drivers=['fake', 'fake_agent'])
for iface in no_set_interfaces:
iface_name = '%s_interface' % iface
node_kwargs = {'uuid': uuidutils.generate_uuid()}
node = obj_utils.create_test_node(self.context, driver='fake',
**node_kwargs)
setattr(node, iface_name, None)
node.driver = 'fake_agent'
driver_factory.check_and_update_node_interfaces(node)
self.assertEqual('fake_agent', node.driver)
self.assertIsNone(getattr(node, iface_name))
def test_update_node_classic_driver_unset_interfaces(self):
"""Update interfaces to None for node with classic driver"""
no_set_interfaces = (drivers_base.ALL_INTERFACES
- set(['network', 'storage']))
self.config(enabled_drivers=['fake', 'fake_agent'])
for iface in no_set_interfaces:
iface_name = '%s_interface' % iface
node_kwargs = {'uuid': uuidutils.generate_uuid()}
node = obj_utils.create_test_node(self.context, driver='fake',
**node_kwargs)
setattr(node, iface_name, None)
driver_factory.check_and_update_node_interfaces(node)
self.assertIsNone(getattr(node, iface_name))
def test_update_node_set_classic_driver_no_interfaces(self):
"""Update driver to classic no interfaces specified"""
self._set_config_interface_options_hardware_type()
no_set_interfaces = (drivers_base.ALL_INTERFACES
- set(['network', 'storage']))
for iface in no_set_interfaces:
iface_name = '%s_interface' % iface
node_kwargs = {'uuid': uuidutils.generate_uuid()}
node_kwargs[iface_name] = 'fake'
node = obj_utils.create_test_node(self.context,
driver='fake-hardware',
**node_kwargs)
node.driver = 'fake'
driver_factory.check_and_update_node_interfaces(node)
self.assertEqual('fake', node.driver)
self.assertIsNone(getattr(node, iface_name))
self.assertEqual('noop', node.network_interface)
def test_update_node_set_dynamic_driver_and_interfaces(self):
"""Update driver to dynamic and interfaces specified"""
self._set_config_interface_options_hardware_type()
for iface in drivers_base.ALL_INTERFACES:
iface_name = '%s_interface' % iface
node_kwargs = {'uuid': uuidutils.generate_uuid()}
node = obj_utils.create_test_node(self.context, driver='fake',
**node_kwargs)
i_name = self._get_valid_default_interface_name(iface)
setattr(node, iface_name, i_name)
node.driver = 'fake-hardware'
driver_factory.check_and_update_node_interfaces(node)
self.assertEqual(i_name, getattr(node, iface_name))
def test_node_update_dynamic_driver_set_interfaces(self):
"""Update interfaces for node with dynamic driver"""
self._set_config_interface_options_hardware_type()
@ -480,8 +260,7 @@ class CheckAndUpdateNodeInterfacesTestCase(db_base.DbTestCase):
class DefaultInterfaceTestCase(db_base.DbTestCase):
def setUp(self):
super(DefaultInterfaceTestCase, self).setUp()
self.config(enabled_hardware_types=['manual-management'],
enabled_drivers=['fake'])
self.config(enabled_hardware_types=['manual-management'])
self.driver = driver_factory.get_hardware_type('manual-management')
def test_from_config(self):
@ -501,22 +280,6 @@ class DefaultInterfaceTestCase(db_base.DbTestCase):
iface = driver_factory.default_interface(self.driver, 'network')
self.assertEqual('neutron', iface)
def test_network_from_additional_defaults(self):
self.config(default_network_interface=None)
self.config(dhcp_provider='none', group='dhcp')
iface = driver_factory.default_interface(
driver_factory.get_driver_or_hardware_type('fake'),
'network')
self.assertEqual('noop', iface)
def test_network_from_additional_defaults_neutron_dhcp(self):
self.config(default_network_interface=None)
self.config(dhcp_provider='neutron', group='dhcp')
iface = driver_factory.default_interface(
driver_factory.get_driver_or_hardware_type('fake'),
'network')
self.assertEqual('flat', iface)
def test_calculated_with_one(self):
self.config(default_deploy_interface=None)
self.config(enabled_deploy_interfaces=['direct'])
@ -655,14 +418,16 @@ class HardwareTypeLoadTestCase(db_base.DbTestCase):
self.assertIsInstance(hw_type, fake_hardware.FakeHardware)
def test_get_hardware_type_missing(self):
self.config(enabled_drivers=['fake_agent'])
self.assertRaises(exception.DriverNotFound,
# "fake" is a classic driver
driver_factory.get_hardware_type, 'fake')
# "fake_agent" is a classic driver
driver_factory.get_hardware_type, 'fake_agent')
def test_get_driver_or_hardware_type(self):
self.config(enabled_drivers=['fake_agent'])
hw_type = driver_factory.get_driver_or_hardware_type('fake-hardware')
self.assertIsInstance(hw_type, fake_hardware.FakeHardware)
driver = driver_factory.get_driver_or_hardware_type('fake')
driver = driver_factory.get_driver_or_hardware_type('fake_agent')
self.assertNotIsInstance(driver, fake_hardware.FakeHardware)
def test_get_driver_or_hardware_type_missing(self):
@ -745,12 +510,12 @@ class HardwareTypeLoadTestCase(db_base.DbTestCase):
task_manager.acquire, self.context, node.id)
def test_no_storage_interface(self):
node = obj_utils.get_test_node(self.context, driver='fake')
node = obj_utils.get_test_node(self.context)
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
self.assertEqual('noop', node.storage_interface)
def test_none_storage_interface(self):
node = obj_utils.get_test_node(self.context, driver='fake',
node = obj_utils.get_test_node(self.context,
storage_interface=None)
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
self.assertEqual('noop', node.storage_interface)
@ -758,22 +523,17 @@ class HardwareTypeLoadTestCase(db_base.DbTestCase):
def test_no_storage_interface_default_from_conf(self):
self.config(enabled_storage_interfaces=['noop', 'fake'])
self.config(default_storage_interface='fake')
node = obj_utils.get_test_node(self.context, driver='fake')
node = obj_utils.get_test_node(self.context)
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
self.assertEqual('fake', node.storage_interface)
def test_invalid_storage_interface(self):
node = obj_utils.get_test_node(self.context, driver='fake',
node = obj_utils.get_test_node(self.context,
storage_interface='scoop')
self.assertRaises(exception.InterfaceNotFoundInEntrypoint,
driver_factory.check_and_update_node_interfaces,
node)
def test_none_rescue_interface(self):
node = obj_utils.get_test_node(self.context, driver='fake')
self.assertTrue(driver_factory.check_and_update_node_interfaces(node))
self.assertIsNone(node.rescue_interface)
def test_no_rescue_interface_default_from_conf(self):
self.config(enabled_rescue_interfaces=['fake'])
self.config(default_rescue_interface='fake')

View File

@ -48,7 +48,7 @@ class TestNetwork(db_base.DbTestCase):
port1 = db_utils.create_test_port(node_id=self.node.id,
address='aa:bb:cc:dd:ee:ff',
uuid=uuidutils.generate_uuid(),
driver='fake', **kwargs1)
**kwargs1)
expected = {'portgroups': {},
'ports': {port1.uuid: 'test-vif-A'}}
with task_manager.acquire(self.context, self.node.uuid) as task:
@ -91,11 +91,11 @@ class TestNetwork(db_base.DbTestCase):
port1 = db_utils.create_test_port(node_id=self.node.id,
address='aa:bb:cc:dd:ee:ff',
uuid=uuidutils.generate_uuid(),
driver='fake', **kwargs1)
**kwargs1)
port2 = db_utils.create_test_port(node_id=self.node.id,
address='dd:ee:ff:aa:bb:cc',
uuid=uuidutils.generate_uuid(),
driver='fake', **kwargs2)
**kwargs2)
expected = {'portgroups': {},
'ports': {port1.uuid: 'test-vif-A',
port2.uuid: 'test-vif-B'}}
@ -201,9 +201,8 @@ class TestRemoveVifsTestCase(db_base.DbTestCase):
class GetPortgroupByIdTestCase(db_base.DbTestCase):
def test_portgroup_by_id(self):
node = object_utils.create_test_node(self.context, driver='fake')
node = object_utils.create_test_node(self.context)
portgroup = object_utils.create_test_portgroup(self.context,
node_id=node.id)
object_utils.create_test_portgroup(self.context,
@ -216,7 +215,7 @@ class GetPortgroupByIdTestCase(db_base.DbTestCase):
self.assertEqual(portgroup.id, res.id)
def test_portgroup_by_id_no_such_portgroup(self):
node = object_utils.create_test_node(self.context, driver='fake')
node = object_utils.create_test_node(self.context)
object_utils.create_test_portgroup(self.context, node_id=node.id)
with task_manager.acquire(self.context, node.uuid) as task:
portgroup_id = 'invalid-portgroup-id'
@ -227,7 +226,7 @@ class GetPortgroupByIdTestCase(db_base.DbTestCase):
class GetPortsByPortgroupIdTestCase(db_base.DbTestCase):
def test_ports_by_portgroup_id(self):
node = object_utils.create_test_node(self.context, driver='fake')
node = object_utils.create_test_node(self.context)
portgroup = object_utils.create_test_portgroup(self.context,
node_id=node.id)
port = object_utils.create_test_port(self.context, node_id=node.id,
@ -240,7 +239,7 @@ class GetPortsByPortgroupIdTestCase(db_base.DbTestCase):
self.assertEqual([port.id], [p.id for p in res])
def test_ports_by_portgroup_id_empty(self):
node = object_utils.create_test_node(self.context, driver='fake')
node = object_utils.create_test_node(self.context)
portgroup = object_utils.create_test_portgroup(self.context,
node_id=node.id)
with task_manager.acquire(self.context, node.uuid) as task:
@ -251,20 +250,20 @@ class GetPortsByPortgroupIdTestCase(db_base.DbTestCase):
class GetPhysnetsForNodeTestCase(db_base.DbTestCase):
def test_get_physnets_for_node_no_ports(self):
node = object_utils.create_test_node(self.context, driver='fake')
node = object_utils.create_test_node(self.context)
with task_manager.acquire(self.context, node.uuid) as task:
res = network.get_physnets_for_node(task)
self.assertEqual(set(), res)
def test_get_physnets_for_node_excludes_None(self):
node = object_utils.create_test_node(self.context, driver='fake')
node = object_utils.create_test_node(self.context)
object_utils.create_test_port(self.context, node_id=node.id)
with task_manager.acquire(self.context, node.uuid) as task:
res = network.get_physnets_for_node(task)
self.assertEqual(set(), res)
def test_get_physnets_for_node_multiple_ports(self):
node = object_utils.create_test_node(self.context, driver='fake')
node = object_utils.create_test_node(self.context)
object_utils.create_test_port(self.context, node_id=node.id,
physical_network='physnet1')
object_utils.create_test_port(self.context, node_id=node.id,
@ -280,7 +279,7 @@ class GetPhysnetsByPortgroupID(db_base.DbTestCase):
def setUp(self):
super(GetPhysnetsByPortgroupID, self).setUp()
self.node = object_utils.create_test_node(self.context, driver='fake')
self.node = object_utils.create_test_node(self.context)
self.portgroup = object_utils.create_test_portgroup(
self.context, node_id=self.node.id)

View File

@ -30,6 +30,8 @@ from ironic.tests.unit.objects import utils as object_utils
CONF = cfg.CONF
# Prevent /httpboot validation on creating the node
@mock.patch('ironic.drivers.modules.pxe.PXEBoot.__init__', lambda self: None)
class TestPXEUtils(db_base.DbTestCase):
def setUp(self):

View File

@ -180,8 +180,7 @@ class RaidPublicMethodsTestCase(db_base.DbTestCase):
def _test_update_raid_info(self, current_config,
capabilities=None):
node = obj_utils.create_test_node(self.context,
driver='fake')
node = obj_utils.create_test_node(self.context)
if capabilities:
properties = node.properties
properties['capabilities'] = capabilities

View File

@ -22,7 +22,6 @@ import mock
from oslo_utils import strutils
from oslo_utils import uuidutils
from ironic.common import driver_factory
from ironic.common import exception
from ironic.common import states
from ironic.conductor import manager
@ -126,25 +125,10 @@ class ServiceSetUpMixin(object):
def setUp(self):
super(ServiceSetUpMixin, self).setUp()
self.hostname = 'test-host'
self.config(enabled_drivers=['fake'])
self.config(node_locked_retry_attempts=1, group='conductor')
self.config(node_locked_retry_interval=0, group='conductor')
self.config(enabled_hardware_types=['fake-hardware',
'manual-management'])
self.config(enabled_boot_interfaces=['fake', 'pxe'])
self.config(enabled_console_interfaces=['fake', 'no-console'])
self.config(enabled_deploy_interfaces=['fake', 'iscsi'])
self.config(enabled_inspect_interfaces=['fake', 'no-inspect'])
self.config(enabled_management_interfaces=['fake'])
self.config(enabled_power_interfaces=['fake'])
self.config(enabled_raid_interfaces=['fake', 'no-raid'])
self.config(enabled_rescue_interfaces=['fake', 'no-rescue'])
self.config(enabled_vendor_interfaces=['fake', 'no-vendor'])
self.config(enabled_bios_interfaces=['fake', 'no-bios'])
self.service = manager.ConductorManager(self.hostname, 'test-topic')
self.driver = driver_factory.get_driver('fake')
def _stop_service(self):
try:

View File

@ -175,11 +175,6 @@ class StartStopTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
'options enabled_boot_interfaces',
self.service.init_host)
def test_starts_without_enabled_hardware_types(self):
self.config(enabled_hardware_types=[])
self.config(enabled_boot_interfaces=[])
self._start_service()
@mock.patch.object(base_manager, 'LOG')
@mock.patch.object(driver_factory, 'HardwareTypesFactory')
@mock.patch.object(driver_factory, 'DriverFactory')
@ -208,20 +203,6 @@ class StartStopTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
df_mock.assert_called_with()
self.assertFalse(del_mock.called)
@mock.patch.object(base_manager, 'LOG')
@mock.patch.object(base_manager.BaseConductorManager, 'del_host',
autospec=True)
@mock.patch.object(driver_factory, 'HardwareTypesFactory')
def test_starts_with_only_classic_drivers(self, ht_mock, del_mock,
log_mock):
# don't load any dynamic drivers
driver_factory_mock = mock.MagicMock(names=[])
ht_mock.return_value = driver_factory_mock
self.service.init_host()
self.assertFalse(log_mock.error.called)
ht_mock.assert_called_with()
self.assertFalse(del_mock.called)
@mock.patch.object(base_manager, 'LOG')
@mock.patch.object(base_manager.BaseConductorManager,
'_register_and_validate_hardware_interfaces')

View File

@ -548,7 +548,7 @@ class UpdateNodeTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
self._test_associate_node(states.POWER_ON)
def test_update_node_invalid_driver(self):
existing_driver = 'fake'
existing_driver = 'fake-hardware'
wrong_driver = 'wrong-driver'
node = obj_utils.create_test_node(self.context,
driver=existing_driver,
@ -577,7 +577,7 @@ class UpdateNodeTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
'power_interface': UpdateInterfaces(None, 'fake'),
'raid_interface': UpdateInterfaces(None, 'fake'),
'rescue_interface': UpdateInterfaces(None, 'no-rescue'),
'storage_interface': UpdateInterfaces('noop', 'cinder'),
'storage_interface': UpdateInterfaces('noop', 'fake'),
}
def _create_node_with_interfaces(self, prov_state, maintenance=False):
@ -721,10 +721,10 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
@mock.patch.object(task_manager.TaskManager, 'upgrade_lock')
@mock.patch.object(task_manager.TaskManager, 'spawn_after')
def _test_vendor_passthru_async(self, driver, vendor_iface, mock_spawn,
mock_upgrade):
node = obj_utils.create_test_node(self.context, driver=driver,
vendor_interface=vendor_iface)
def test_vendor_passthru_async(self, mock_spawn,
mock_upgrade):
node = obj_utils.create_test_node(self.context,
vendor_interface='fake')
info = {'bar': 'baz'}
self._start_service()
@ -747,12 +747,6 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
# Verify reservation has been cleared.
self.assertIsNone(node.reservation)
def test_vendor_passthru_async(self):
self._test_vendor_passthru_async('fake', None)
def test_vendor_passthru_async_hw_type(self):
self._test_vendor_passthru_async('fake-hardware', 'fake')
@mock.patch.object(task_manager.TaskManager, 'upgrade_lock')
@mock.patch.object(task_manager.TaskManager, 'spawn_after')
def test_vendor_passthru_sync(self, mock_spawn, mock_upgrade):
@ -876,26 +870,6 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
# Verify reservation has been cleared.
self.assertIsNone(node.reservation)
def test_vendor_passthru_vendor_interface_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(self.context, driver='fake')
info = {'bar': 'baz'}
self.driver.vendor = None
self._start_service()
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.vendor_passthru,
self.context, node.uuid,
'whatever_method', 'POST', info)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
node.refresh()
# Verify reservation has been cleared.
self.assertIsNone(node.reservation)
def test_vendor_passthru_worker_pool_full(self):
node = obj_utils.create_test_node(self.context, driver='fake-hardware')
info = {'bar': 'baz'}
@ -936,30 +910,13 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
del fake_routes['test_method']['func']
self.assertEqual(fake_routes, data)
def test_get_node_vendor_passthru_methods_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(self.context, driver='fake')
self.driver.vendor = None
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.get_node_vendor_passthru_methods,
self.context, node.uuid)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
@mock.patch.object(driver_factory, 'get_interface')
@mock.patch.object(manager.ConductorManager, '_spawn_worker')
def _test_driver_vendor_passthru_sync(self, is_hw_type, mock_spawn,
mock_get_if):
def test_driver_vendor_passthru_sync(self, mock_spawn, mock_get_if):
expected = {'foo': 'bar'}
vendor_mock = mock.Mock(spec=drivers_base.VendorInterface)
if is_hw_type:
mock_get_if.return_value = vendor_mock
driver_name = 'fake-hardware'
else:
self.driver.vendor = vendor_mock
driver_name = 'fake'
mock_get_if.return_value = vendor_mock
driver_name = 'fake-hardware'
test_method = mock.MagicMock(return_value=expected)
vendor_mock.driver_routes = {
'test_method': {'func': test_method,
@ -984,14 +941,7 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
test_method.assert_called_once_with(self.context, **vendor_args)
# No worker was spawned
self.assertFalse(mock_spawn.called)
if is_hw_type:
mock_get_if.assert_called_once_with(mock.ANY, 'vendor', 'fake')
def test_driver_vendor_passthru_sync(self):
self._test_driver_vendor_passthru_sync(False)
def test_driver_vendor_passthru_sync_hw_type(self):
self._test_driver_vendor_passthru_sync(True)
mock_get_if.assert_called_once_with(mock.ANY, 'vendor', 'fake')
@mock.patch.object(driver_factory, 'get_interface', autospec=True)
@mock.patch.object(manager.ConductorManager, '_spawn_worker')
@ -1033,20 +983,6 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
self.assertEqual(exception.InvalidParameterValue,
exc.exc_info[0])
def test_driver_vendor_passthru_vendor_interface_not_supported(self):
# Test for when no vendor interface is set at all
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
self.driver.vendor = None
self.service.init_host()
exc = self.assertRaises(messaging.ExpectedException,
self.service.driver_vendor_passthru,
self.context, 'fake', 'test_method',
'POST', {})
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
def test_driver_vendor_passthru_method_not_supported(self):
# Test for when the vendor interface is set, but hasn't passed a
# driver_passthru_mapping to MixinVendorInterface
@ -1085,16 +1021,11 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
self.assertEqual(exception.NoValidDefaultForInterface,
exc.exc_info[0])
@mock.patch.object(driver_factory, 'get_interface')
def _test_get_driver_vendor_passthru_methods(self, is_hw_type,
mock_get_if):
@mock.patch.object(driver_factory, 'get_interface', autospec=True)
def test_get_driver_vendor_passthru_methods(self, mock_get_if):
vendor_mock = mock.Mock(spec=drivers_base.VendorInterface)
if is_hw_type:
mock_get_if.return_value = vendor_mock
driver_name = 'fake-hardware'
else:
self.driver.vendor = vendor_mock
driver_name = 'fake'
mock_get_if.return_value = vendor_mock
driver_name = 'fake-hardware'
fake_routes = {'test_method': {'async': True,
'description': 'foo',
'http_methods': ['POST'],
@ -1111,29 +1042,7 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
del fake_routes['test_method']['func']
self.assertEqual(fake_routes, data)
if is_hw_type:
mock_get_if.assert_called_once_with(mock.ANY, 'vendor', 'fake')
else:
mock_get_if.assert_not_called()
def test_get_driver_vendor_passthru_methods(self):
self._test_get_driver_vendor_passthru_methods(False)
def test_get_driver_vendor_passthru_methods_hw_type(self):
self._test_get_driver_vendor_passthru_methods(True)
def test_get_driver_vendor_passthru_methods_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
self.service.init_host()
self.driver.vendor = None
exc = self.assertRaises(
messaging.rpc.ExpectedException,
self.service.get_driver_vendor_passthru_methods,
self.context, 'fake')
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
mock_get_if.assert_called_once_with(mock.ANY, 'vendor', 'fake')
@mock.patch.object(driver_factory, 'default_interface', autospec=True)
def test_get_driver_vendor_passthru_methods_no_default_interface(
@ -3089,21 +2998,6 @@ class DoNodeRescueTestCase(mgr_utils.CommonMixIn, mgr_utils.ServiceSetUpMixin,
def test_do_node_rescue_when_network_validate_fail(self, mock_validate):
self._test_do_node_rescue_when_validate_fail(mock_validate)
def test_do_node_rescue_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(
self.context, driver='fake',
provision_state=states.ACTIVE,
network_interface='noop',
target_provision_state=states.NOSTATE,
instance_info={})
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.do_node_rescue,
self.context, node.uuid, "password")
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0], str(exc.exc_info))
def test_do_node_rescue_maintenance(self):
node = obj_utils.create_test_node(
self.context, driver='fake-hardware',
@ -3225,19 +3119,6 @@ class DoNodeRescueTestCase(mgr_utils.CommonMixIn, mgr_utils.ServiceSetUpMixin,
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.InstanceUnrescueFailure, exc.exc_info[0])
def test_do_node_unrescue_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(
self.context, driver='fake',
provision_state=states.RESCUE,
instance_info={})
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.do_node_unrescue,
self.context, node.uuid)
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
def test_do_node_unrescue_maintenance(self):
node = obj_utils.create_test_node(
self.context, driver='fake-hardware',
@ -3497,32 +3378,6 @@ class MiscTestCase(mgr_utils.ServiceSetUpMixin, mgr_utils.CommonMixIn,
self.assertEqual(expected, ret)
mock_iwdi.assert_called_once_with(self.context, node.instance_info)
@mock.patch.object(images, 'is_whole_disk_image')
def test_validate_driver_interfaces_classic_driver(self, mock_iwdi):
mock_iwdi.return_value = False
target_raid_config = {'logical_disks': [{'size_gb': 1,
'raid_level': '1'}]}
node = obj_utils.create_test_node(
self.context, driver='fake',
target_raid_config=target_raid_config,
network_interface='noop')
ret = self.service.validate_driver_interfaces(self.context,
node.uuid)
reason = ('not supported')
expected = {'console': {'result': True},
'power': {'result': True},
'inspect': {'result': True},
'management': {'result': True},
'boot': {'result': True},
'raid': {'result': True},
'deploy': {'result': True},
'network': {'result': True},
'storage': {'result': True},
'rescue': {'reason': reason, 'result': None}}
self.assertEqual(expected, ret)
mock_iwdi.assert_called_once_with(self.context, node.instance_info)
@mock.patch.object(fake.FakeDeploy, 'validate', autospec=True)
@mock.patch.object(images, 'is_whole_disk_image')
def test_validate_driver_interfaces_validation_fail(self, mock_iwdi,
@ -3664,23 +3519,6 @@ class ConsoleTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
mock.call(mock.ANY, 'console_set',
obj_fields.NotificationStatus.END)])
def test_set_console_mode_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(self.context, driver='fake',
last_error=None)
self._start_service()
# null the console interface
self.driver.console = None
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.set_console_mode, self.context,
node.uuid, True)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
self._stop_service()
node.refresh()
@mock.patch.object(fake.FakeConsole, 'validate', autospec=True)
def test_set_console_mode_validation_fail(self, mock_val):
node = obj_utils.create_test_node(self.context, driver='fake-hardware',
@ -3742,17 +3580,16 @@ class ConsoleTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
self.assertFalse(mock_sc.called)
self.assertFalse(mock_notify.called)
@mock.patch.object(fake.FakeConsole, 'stop_console', autospec=True)
@mock.patch.object(notification_utils, 'emit_console_notification')
def test_disable_console_already_disabled(self, mock_notify):
def test_disable_console_already_disabled(self, mock_notify, mock_sc):
node = obj_utils.create_test_node(self.context, driver='fake-hardware',
console_enabled=False)
self._start_service()
with mock.patch.object(self.driver.console,
'stop_console') as mock_sc:
self.service.set_console_mode(self.context, node.uuid, False)
self._stop_service()
self.assertFalse(mock_sc.called)
self.assertFalse(mock_notify.called)
self.service.set_console_mode(self.context, node.uuid, False)
self._stop_service()
self.assertFalse(mock_sc.called)
self.assertFalse(mock_notify.called)
@mock.patch.object(fake.FakeConsole, 'get_console', autospec=True)
def test_get_console(self, mock_gc):
@ -3764,20 +3601,6 @@ class ConsoleTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
node.uuid)
self.assertEqual(console_info, data)
def test_get_console_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(self.context, driver='fake',
console_enabled=True)
# null the console interface
self.driver.console = None
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.get_console_information,
self.context, node.uuid)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
def test_get_console_disabled(self):
node = obj_utils.create_test_node(self.context, driver='fake-hardware',
console_enabled=False)
@ -4288,17 +4111,14 @@ class SensorsTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
CONF.set_override('send_sensor_data', True, group='conductor')
task = acquire_mock.return_value.__enter__.return_value
task.driver = self.driver
task.node.maintenance = False
with mock.patch.object(self.driver.management,
'get_sensors_data') as get_sensors_data_mock:
with mock.patch.object(self.driver.management,
'validate') as validate_mock:
get_sensors_data_mock.return_value = 'fake-sensor-data'
self.service._sensors_nodes_task(self.context, nodes)
self.assertEqual(5, acquire_mock.call_count)
self.assertEqual(5, validate_mock.call_count)
self.assertEqual(5, get_sensors_data_mock.call_count)
get_sensors_data_mock = task.driver.management.get_sensors_data
validate_mock = task.driver.management.validate
get_sensors_data_mock.return_value = 'fake-sensor-data'
self.service._sensors_nodes_task(self.context, nodes)
self.assertEqual(5, acquire_mock.call_count)
self.assertEqual(5, validate_mock.call_count)
self.assertEqual(5, get_sensors_data_mock.call_count)
@mock.patch.object(task_manager, 'acquire')
def test_send_sensor_task_shutdown(self, acquire_mock):
@ -4319,20 +4139,13 @@ class SensorsTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
self._start_service()
self.driver.management = None
task = acquire_mock.return_value.__enter__.return_value
task.driver = self.driver
task.node.maintenance = False
task.driver.management = None
with mock.patch.object(fake.FakeManagement, 'get_sensors_data',
autospec=True) as get_sensors_data_mock:
with mock.patch.object(fake.FakeManagement, 'validate',
autospec=True) as validate_mock:
self.service._sensors_nodes_task(self.context, nodes)
self.service._sensors_nodes_task(self.context, nodes)
self.assertTrue(acquire_mock.called)
self.assertFalse(get_sensors_data_mock.called)
self.assertFalse(validate_mock.called)
@mock.patch.object(manager.LOG, 'debug', autospec=True)
@mock.patch.object(task_manager, 'acquire', autospec=True)
@ -4343,17 +4156,15 @@ class SensorsTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
CONF.set_override('send_sensor_data', True, group='conductor')
task = acquire_mock.return_value.__enter__.return_value
task.driver = self.driver
task.node.maintenance = True
with mock.patch.object(self.driver.management,
'get_sensors_data') as get_sensors_data_mock:
with mock.patch.object(self.driver.management,
'validate') as validate_mock:
self.service._sensors_nodes_task(self.context, nodes)
self.assertTrue(acquire_mock.called)
self.assertFalse(validate_mock.called)
self.assertFalse(get_sensors_data_mock.called)
self.assertTrue(debug_log.called)
get_sensors_data_mock = task.driver.management.get_sensors_data
validate_mock = task.driver.management.validate
self.service._sensors_nodes_task(self.context, nodes)
self.assertTrue(acquire_mock.called)
self.assertFalse(validate_mock.called)
self.assertFalse(get_sensors_data_mock.called)
self.assertTrue(debug_log.called)
@mock.patch.object(manager.ConductorManager, '_spawn_worker')
@mock.patch.object(manager.ConductorManager, '_mapped_to_this_conductor')
@ -4434,19 +4245,6 @@ class BootDeviceTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.NodeLocked, exc.exc_info[0])
def test_set_boot_device_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(self.context, driver='fake')
# null the console interface
self.driver.management = None
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.set_boot_device,
self.context, node.uuid, boot_devices.DISK)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
@mock.patch.object(fake.FakeManagement, 'validate', autospec=True)
def test_set_boot_device_validate_fail(self, mock_val):
node = obj_utils.create_test_node(self.context, driver='fake-hardware')
@ -4472,19 +4270,6 @@ class BootDeviceTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.NodeLocked, exc.exc_info[0])
def test_get_boot_device_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(self.context, driver='fake')
# null the management interface
self.driver.management = None
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.get_boot_device,
self.context, node.uuid)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
@mock.patch.object(fake.FakeManagement, 'validate', autospec=True)
def test_get_boot_device_validate_fail(self, mock_val):
node = obj_utils.create_test_node(self.context, driver='fake-hardware')
@ -4501,19 +4286,6 @@ class BootDeviceTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
node.uuid)
self.assertEqual([boot_devices.PXE], bootdevs)
def test_get_supported_boot_devices_iface_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(self.context, driver='fake')
# null the management interface
self.driver.management = None
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.get_supported_boot_devices,
self.context, node.uuid)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
@mgr_utils.mock_record_keepalive
class NmiTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
@ -4535,19 +4307,6 @@ class NmiTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.NodeLocked, exc.exc_info[0])
def test_inject_nmi_not_supported(self):
# TODO(dtantsur): remove this test when classic drivers are removed
# (interfaces in dynamic drivers cannot be None).
node = obj_utils.create_test_node(self.context, driver='fake')
# null the management interface
self.driver.management = None
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.inject_nmi,
self.context, node.uuid)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.UnsupportedDriverExtension,
exc.exc_info[0])
@mock.patch.object(fake.FakeManagement, 'validate', autospec=True)
def test_inject_nmi_validate_invalid_param(self, mock_val):
node = obj_utils.create_test_node(self.context, driver='fake-hardware')
@ -4897,7 +4656,7 @@ class UpdatePortgroupTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
@mgr_utils.mock_record_keepalive
class RaidTestCases(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
driver_name = 'fake'
driver_name = 'fake-hardware'
raid_interface = None
def setUp(self):
@ -4914,14 +4673,6 @@ class RaidTestCases(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
self.assertIn('raid_level', properties)
self.assertIn('size_gb', properties)
def test_get_raid_logical_disk_properties_iface_not_supported(self):
self.driver.raid = None
self._start_service()
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.get_raid_logical_disk_properties,
self.context, self.driver_name)
self.assertEqual(exception.UnsupportedDriverExtension, exc.exc_info[0])
def test_set_target_raid_config(self):
raid_config = {'logical_disks': [{'size_gb': 100, 'raid_level': '1'}]}
self.service.set_target_raid_config(
@ -4938,18 +4689,6 @@ class RaidTestCases(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
self.node.refresh()
self.assertEqual({}, self.node.target_raid_config)
def test_set_target_raid_config_iface_not_supported(self):
raid_config = {'logical_disks': [{'size_gb': 100, 'raid_level': '1'}]}
self.driver.raid = None
exc = self.assertRaises(
messaging.rpc.ExpectedException,
self.service.set_target_raid_config,
self.context, self.node.uuid, raid_config)
self.node.refresh()
self.assertEqual({}, self.node.target_raid_config)
self.assertEqual(exception.UnsupportedDriverExtension, exc.exc_info[0])
self.assertIn(self.driver_name, six.text_type(exc.exc_info[1]))
def test_set_target_raid_config_invalid_parameter_value(self):
# Missing raid_level in the below raid config.
raid_config = {'logical_disks': [{'size_gb': 100}]}
@ -7597,7 +7336,7 @@ class DoNodeInspectAbortTestCase(mgr_utils.CommonMixIn,
task = task_manager.TaskManager(self.context, node.uuid)
mock_acquire.side_effect = self._get_acquire_side_effect(task)
mock_abort.side_effect = exception.UnsupportedDriverExtension(
driver='fake', extension='inspect')
driver='fake-hardware', extension='inspect')
self._start_service()
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.do_provisioning_action,

View File

@ -85,7 +85,7 @@ class TaskManagerTestCase(db_base.DbTestCase):
reserve_mock, release_mock, node_get_mock):
node2 = obj_utils.create_test_node(self.context,
uuid=uuidutils.generate_uuid(),
driver='fake')
driver='fake-hardware')
reserve_mock.return_value = self.node
get_ports_mock.return_value = mock.sentinel.ports1

File diff suppressed because it is too large Load Diff

View File

@ -179,7 +179,7 @@ def get_test_node(**kw):
'last_error': kw.get('last_error'),
'instance_uuid': kw.get('instance_uuid'),
'instance_info': kw.get('instance_info', fake_instance_info),
'driver': kw.get('driver', 'fake'),
'driver': kw.get('driver', 'fake-hardware'),
'driver_info': kw.get('driver_info', fake_driver_info),
'driver_internal_info': kw.get('driver_internal_info',
fake_internal_info),

View File

@ -31,7 +31,6 @@ class TestDHCPFactory(base.TestCase):
def setUp(self):
super(TestDHCPFactory, self).setUp()
self.config(enabled_drivers=['fake'])
self.config(url='test-url',
url_timeout=30,
group='neutron')

View File

@ -55,10 +55,10 @@ class AnsibleDeployTestCaseBase(db_base.DbTestCase):
def setUp(self):
super(AnsibleDeployTestCaseBase, self).setUp()
self.config(enabled_hardware_types='manual-management',
enabled_deploy_interfaces='ansible',
enabled_power_interfaces='fake',
enabled_management_interfaces='fake')
self.config(enabled_hardware_types=['manual-management'],
enabled_deploy_interfaces=['ansible'],
enabled_power_interfaces=['fake'],
enabled_management_interfaces=['fake'])
node = {
'driver': 'manual-management',
'instance_info': INSTANCE_INFO,

View File

@ -29,7 +29,6 @@ class TestCommonFunctions(db_base.DbTestCase):
def setUp(self):
super(TestCommonFunctions, self).setUp()
self.config(enabled_drivers=['fake'])
self.node = obj_utils.create_test_node(self.context,
network_interface='neutron')
self.port = obj_utils.create_test_port(
@ -436,7 +435,6 @@ class TestVifPortIDMixin(db_base.DbTestCase):
def setUp(self):
super(TestVifPortIDMixin, self).setUp()
self.config(enabled_drivers=['fake'])
self.interface = common.VIFPortIDMixin()
self.node = obj_utils.create_test_node(self.context,
network_interface='neutron')
@ -660,7 +658,6 @@ class TestNeutronVifPortIDMixin(db_base.DbTestCase):
def setUp(self):
super(TestNeutronVifPortIDMixin, self).setUp()
self.config(enabled_drivers=['fake'])
self.interface = common.NeutronVIFPortIDMixin()
self.node = obj_utils.create_test_node(self.context,
network_interface='neutron')

View File

@ -30,7 +30,6 @@ class TestFlatInterface(db_base.DbTestCase):
def setUp(self):
super(TestFlatInterface, self).setUp()
self.config(enabled_drivers=['fake'])
self.interface = flat_interface.FlatNetwork()
self.node = utils.create_test_node(self.context)
self.port = utils.create_test_port(

View File

@ -20,7 +20,6 @@ class NoopInterfaceTestCase(db_base.DbTestCase):
def setUp(self):
super(NoopInterfaceTestCase, self).setUp()
self.config(enabled_drivers=['fake'])
self.interface = noop.NoopNetwork()
self.node = utils.create_test_node(self.context,
network_interface='noop')

View File

@ -35,13 +35,15 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
self.config(action_retries=3,
action_retry_interval=0,
group='cinder')
self.config(enabled_storage_interfaces=['noop', 'cinder'])
self.config(enabled_boot_interfaces=['fake'],
enabled_storage_interfaces=['noop', 'cinder'])
self.interface = cinder.CinderStorage()
self.node = object_utils.create_test_node(self.context,
boot_interface='fake',
storage_interface='cinder')
@mock.patch.object(cinder, 'LOG', autospec=True)
def test__fail_validation(self, mock_log):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
"""Ensure the validate helper logs and raises exceptions."""
fake_error = 'a error!'
expected = ("Failed to validate cinder storage interface for node "
@ -55,8 +57,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test__generate_connector_raises_with_insufficent_data(self, mock_log):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
with task_manager.acquire(self.context, self.node.id) as task:
self.assertRaises(exception.StorageError,
self.interface._generate_connector,
@ -64,8 +64,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
self.assertTrue(mock_log.error.called)
def test__generate_connector_iscsi(self):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
expected = {
'initiator': 'iqn.address',
'ip': 'ip.address',
@ -84,8 +82,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test__generate_connector_iscsi_and_unknown(self, mock_log):
"""Validate we return and log with valid and invalid connectors."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
expected = {
'initiator': 'iqn.address',
'host': self.node.uuid,
@ -104,8 +100,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test__generate_connector_unknown_raises_excption(self, mock_log):
"""Validate an exception is raised with only an invalid connector."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='foo',
connector_id='bar')
@ -119,8 +113,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
def test__generate_connector_single_path(self):
"""Validate an exception is raised with only an invalid connector."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
expected = {
'initiator': 'iqn.address',
'host': self.node.uuid}
@ -132,8 +124,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
self.assertDictEqual(expected, return_value)
def test__generate_connector_multiple_fc_wwns(self):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
"""Validate handling of WWPNs and WWNNs."""
expected = {
'wwpns': ['wwpn1', 'wwpn2'],
@ -171,8 +161,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder.CinderStorage, '_fail_validation', autospec=True)
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_success_no_settings(self, mock_log, mock_fail):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
with task_manager.acquire(self.context, self.node.id) as task:
self.interface.validate(task)
self.assertFalse(mock_fail.called)
@ -180,9 +168,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_failure_if_iscsi_boot_no_connectors(self, mock_log):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
valid_types = ', '.join(cinder.VALID_ISCSI_TYPES)
expected_msg = ("Failed to validate cinder storage interface for node "
"%(id)s. In order to enable the 'iscsi_boot' "
@ -200,8 +185,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_failure_if_fc_boot_no_connectors(self, mock_log):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
valid_types = ', '.join(cinder.VALID_FC_TYPES)
expected_msg = ("Failed to validate cinder storage interface for node "
"%(id)s. In order to enable the 'fibre_channel_boot' "
@ -222,8 +205,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_success_iscsi_connector(self, mock_log, mock_fail):
"""Perform validate with only an iSCSI connector in place."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='iqn',
connector_id='iqn.address')
@ -236,8 +217,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_success_fc_connectors(self, mock_log, mock_fail):
"""Perform validate with only FC connectors in place"""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='wwpn',
connector_id='wwpn.address', uuid=uuidutils.generate_uuid())
@ -253,8 +232,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_success_connectors_and_boot(self, mock_log, mock_fail):
"""Perform validate with volume connectors and boot capabilities."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='iqn',
connector_id='iqn.address', uuid=uuidutils.generate_uuid())
@ -277,8 +254,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_success_iscsi_targets(self, mock_log, mock_fail):
"""Validate success with full iscsi scenario."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='iqn',
connector_id='iqn.address', uuid=uuidutils.generate_uuid())
@ -295,8 +270,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_success_fc_targets(self, mock_log, mock_fail):
"""Validate success with full fc scenario."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='wwpn',
connector_id='fc.address', uuid=uuidutils.generate_uuid())
@ -318,8 +291,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
def test_validate_fails_with_ipxe_not_enabled(self, mock_log):
"""Ensure a validation failure is raised when iPXE not enabled."""
self.config(ipxe_enabled=False, group='pxe')
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='iqn',
connector_id='foo.address')
@ -336,8 +307,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_fails_when_fc_connectors_unequal(self, mock_log):
"""Validate should fail with only wwnn FC connector in place"""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='wwnn',
connector_id='wwnn.address')
@ -350,8 +319,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_fail_on_unknown_volume_types(self, mock_log):
"""Ensure exception is raised when connector/target do not match."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='iqn',
connector_id='foo.address')
@ -368,8 +335,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_fails_iscsi_conn_fc_target(self, mock_log):
"""Validate failure of iSCSI connectors with FC target."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='iqn',
connector_id='foo.address')
@ -386,8 +351,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_validate_fails_fc_conn_iscsi_target(self, mock_log):
"""Validate failure of FC connectors with iSCSI target."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_connector(
self.context, node_id=self.node.id, type='fibre_channel',
connector_id='foo.address')
@ -408,8 +371,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG')
def test_attach_detach_volumes_no_volumes(self, mock_log,
mock_attach, mock_detach):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
with task_manager.acquire(self.context, self.node.id) as task:
self.interface.attach_volumes(task)
self.interface.detach_volumes(task)
@ -424,8 +385,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
mock_attach,
mock_detach):
"""Without connectors, attach and detach should fail."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_target(
self.context, node_id=self.node.id, volume_type='iscsi',
boot_index=0, volume_id='1234')
@ -447,8 +406,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
mock_log,
mock_attach,
mock_detach):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
target_uuid = uuidutils.generate_uuid()
test_volume_target = object_utils.create_test_volume_target(
self.context, node_id=self.node.id, volume_type='iscsi',
@ -481,9 +438,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_attach_volumes_failure(self, mock_log, mock_attach, mock_detach):
"""Verify detach is called upon attachment failing."""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_target(
self.context, node_id=self.node.id, volume_type='iscsi',
boot_index=0, volume_id='1234')
@ -516,8 +470,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
Volume attachment fails if the number of attachments completed
does not match the number of configured targets.
"""
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_target(
self.context, node_id=self.node.id, volume_type='iscsi',
boot_index=0, volume_id='1234')
@ -538,8 +490,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
@mock.patch.object(cinder_common, 'detach_volumes', autospec=True)
@mock.patch.object(cinder, 'LOG', autospec=True)
def test_detach_volumes_failure(self, mock_log, mock_detach):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_target(
self.context, node_id=self.node.id, volume_type='iscsi',
boot_index=0, volume_id='1234')
@ -568,8 +518,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
def test_detach_volumes_failure_raises_exception(self,
mock_log,
mock_detach):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_target(
self.context, node_id=self.node.id, volume_type='iscsi',
boot_index=0, volume_id='1234')
@ -589,8 +537,6 @@ class CinderInterfaceTestCase(db_base.DbTestCase):
self.assertEqual(4, mock_detach.call_count)
def test_should_write_image(self):
self.node = object_utils.create_test_node(self.context,
storage_interface='cinder')
object_utils.create_test_volume_target(
self.context, node_id=self.node.id, volume_type='iscsi',
boot_index=0, volume_id='1234')

View File

@ -975,7 +975,8 @@ class GetPxeBootConfigTestCase(db_base.DbTestCase):
def setUp(self):
super(GetPxeBootConfigTestCase, self).setUp()
self.node = obj_utils.get_test_node(self.context, driver='fake')
self.node = obj_utils.get_test_node(self.context,
driver='fake-hardware')
self.config(pxe_bootfile_name='bios-bootfile', group='pxe')
self.config(uefi_pxe_bootfile_name='uefi-bootfile', group='pxe')
self.config(pxe_config_template='bios-template', group='pxe')
@ -1308,7 +1309,8 @@ class ParseInstanceInfoCapabilitiesTestCase(tests_base.TestCase):
def setUp(self):
super(ParseInstanceInfoCapabilitiesTestCase, self).setUp()
self.node = obj_utils.get_test_node(self.context, driver='fake')
self.node = obj_utils.get_test_node(self.context,
driver='fake-hardware')
def test_parse_instance_info_capabilities_string(self):
self.node.instance_info = {'capabilities': '{"cat": "meow"}'}
@ -1440,7 +1442,8 @@ class TrySetBootDeviceTestCase(db_base.DbTestCase):
def setUp(self):
super(TrySetBootDeviceTestCase, self).setUp()
self.node = obj_utils.create_test_node(self.context, driver="fake")
self.node = obj_utils.create_test_node(self.context,
driver="fake-hardware")
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
def test_try_set_boot_device_okay(self, node_set_boot_device_mock):
@ -2380,7 +2383,8 @@ class TestStorageInterfaceUtils(db_base.DbTestCase):
def setUp(self):
super(TestStorageInterfaceUtils, self).setUp()
self.node = obj_utils.create_test_node(self.context,
driver='fake')
driver='fake-hardware')
self.config(enabled_storage_interfaces=['noop', 'fake', 'cinder'])
def test_check_interface_capability(self):
class fake_driver(object):
@ -2415,18 +2419,14 @@ class TestStorageInterfaceUtils(db_base.DbTestCase):
self.context, self.node.uuid, shared=False) as task:
self.assertIsNone(utils.get_remote_boot_volume(task))
@mock.patch.object(fake, 'FakeBoot', autospec=True)
@mock.patch.object(fake, 'FakeDeploy', autospec=True)
@mock.patch.object(fake.FakeBoot, 'capabilities',
['iscsi_volume_boot'], create=True)
@mock.patch.object(fake.FakeDeploy, 'capabilities',
['iscsi_volume_deploy'], create=True)
@mock.patch.object(cinder.CinderStorage, 'should_write_image',
autospec=True)
def test_populate_storage_driver_internal_info_iscsi(self,
mock_should_write,
mock_deploy,
mock_boot):
mock_deploy.return_value = mock.Mock(
capabilities=['iscsi_volume_deploy'])
mock_boot.return_value = mock.Mock(
capabilities=['iscsi_volume_boot'])
mock_should_write):
mock_should_write.return_value = True
vol_uuid = uuidutils.generate_uuid()
obj_utils.create_test_volume_target(
@ -2453,18 +2453,14 @@ class TestStorageInterfaceUtils(db_base.DbTestCase):
task.node.driver_internal_info.get('boot_from_volume_deploy',
None))
@mock.patch.object(fake, 'FakeBoot', autospec=True)
@mock.patch.object(fake, 'FakeDeploy', autospec=True)
@mock.patch.object(fake.FakeBoot, 'capabilities',
['fibre_channel_volume_boot'], create=True)
@mock.patch.object(fake.FakeDeploy, 'capabilities',
['fibre_channel_volume_deploy'], create=True)
@mock.patch.object(cinder.CinderStorage, 'should_write_image',
autospec=True)
def test_populate_storage_driver_internal_info_fc(self,
mock_should_write,
mock_deploy,
mock_boot):
mock_deploy.return_value = mock.Mock(
capabilities=['fibre_channel_volume_deploy'])
mock_boot.return_value = mock.Mock(
capabilities=['fibre_channel_volume_boot'])
mock_should_write):
mock_should_write.return_value = True
self.node.storage_interface = "cinder"
self.node.save()
@ -2487,15 +2483,11 @@ class TestStorageInterfaceUtils(db_base.DbTestCase):
task.node.driver_internal_info.get('boot_from_volume_deploy',
None))
@mock.patch.object(fake, 'FakeBoot', autospec=True)
@mock.patch.object(fake, 'FakeDeploy', autospec=True)
def test_populate_storage_driver_internal_info_error(
self, mock_deploy, mock_boot):
mock_deploy.return_value = mock.Mock(
capabilities=['fibre_channel_volume_deploy'])
mock_boot.return_value = mock.Mock(
capabilities=['fibre_channel_volume_boot'])
@mock.patch.object(fake.FakeBoot, 'capabilities',
['fibre_channel_volume_boot'], create=True)
@mock.patch.object(fake.FakeDeploy, 'capabilities',
['fibre_channel_volume_deploy'], create=True)
def test_populate_storage_driver_internal_info_error(self):
obj_utils.create_test_volume_target(
self.context, node_id=self.node.id, volume_type='iscsi',
boot_index=0, volume_id='1234')

View File

@ -17,28 +17,24 @@
"""Test class for Fake driver."""
import mock
from ironic.common import boot_devices
from ironic.common import driver_factory
from ironic.common import exception
from ironic.common import states
from ironic.conductor import task_manager
from ironic.drivers import base as driver_base
from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.objects import utils as obj_utils
from ironic.tests.unit.db import utils as db_utils
class FakeDriverTestCase(db_base.DbTestCase):
class FakeHardwareTestCase(db_base.DbTestCase):
def setUp(self):
super(FakeDriverTestCase, self).setUp()
self.driver = driver_factory.get_driver("fake")
self.node = obj_utils.get_test_node(self.context)
self.task = mock.MagicMock(spec=task_manager.TaskManager)
self.task.shared = False
self.task.node = self.node
self.task.driver = self.driver
super(FakeHardwareTestCase, self).setUp()
self.node = db_utils.create_test_node()
self.task = task_manager.acquire(self.context, self.node.id)
self.addCleanup(self.task.release_resources)
self.driver = self.task.driver
def test_driver_interfaces(self):
self.assertIsInstance(self.driver.power, driver_base.PowerInterface)
@ -49,7 +45,7 @@ class FakeDriverTestCase(db_base.DbTestCase):
driver_base.ConsoleInterface)
def test_get_properties(self):
expected = ['A1', 'A2', 'B1', 'B2']
expected = ['B1', 'B2']
properties = self.driver.get_properties()
self.assertEqual(sorted(expected), sorted(properties))

View File

@ -34,8 +34,7 @@ class ManualManagementHardwareTestCase(db_base.DbTestCase):
super(ManualManagementHardwareTestCase, self).setUp()
self.config(enabled_hardware_types=['manual-management'],
enabled_power_interfaces=['fake'],
enabled_management_interfaces=['fake'],
enabled_inspect_interfaces=['no-inspect'])
enabled_management_interfaces=['fake'])
self.config(enabled=True, group='inspector')
def test_default_interfaces(self):
@ -50,7 +49,8 @@ class ManualManagementHardwareTestCase(db_base.DbTestCase):
self.assertIsInstance(task.driver.raid, noop.NoRAID)
def test_supported_interfaces(self):
self.config(enabled_inspect_interfaces=['inspector', 'no-inspect'])
self.config(enabled_inspect_interfaces=['inspector', 'no-inspect'],
enabled_raid_interfaces=['agent'])
node = obj_utils.create_test_node(self.context,
driver='manual-management',
deploy_interface='direct',

View File

@ -20,7 +20,6 @@ import mock
from oslo_config import cfg
from oslo_utils import timeutils
from ironic.common import driver_factory
from ironic.common import exception
from ironic.common import swift
from ironic.conductor import task_manager
@ -37,32 +36,8 @@ class UtilsTestCase(db_base.DbTestCase):
def setUp(self):
super(UtilsTestCase, self).setUp()
self.driver = driver_factory.get_driver("fake")
self.node = obj_utils.create_test_node(self.context)
def test_vendor_interface_get_properties(self):
expected = {'A1': 'A1 description. Required.',
'A2': 'A2 description. Optional.',
'B1': 'B1 description. Required.',
'B2': 'B2 description. Required.'}
props = self.driver.vendor.get_properties()
self.assertEqual(expected, props)
@mock.patch.object(fake.FakeVendorA, 'validate', autospec=True)
def test_vendor_interface_validate_valid_methods(self,
mock_fakea_validate):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.vendor.validate(task, method='first_method')
mock_fakea_validate.assert_called_once_with(
self.driver.vendor.mapping['first_method'],
task, method='first_method')
def test_vendor_interface_validate_bad_method(self):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.InvalidParameterValue,
self.driver.vendor.validate,
task, method='fake_method')
def test_get_node_mac_addresses(self):
ports = []
ports.append(
@ -378,3 +353,41 @@ class UtilsRamdiskLogsTestCase(tests_base.TestCase):
mock_makedirs.assert_called_once_with(log_path)
mock_logs_name.assert_called_once_with(self.node, label=None)
class MixinVendorInterfaceTestCase(db_base.DbTestCase):
def setUp(self):
super(MixinVendorInterfaceTestCase, self).setUp()
self.a = fake.FakeVendorA()
self.b = fake.FakeVendorB()
self.mapping = {'first_method': self.a,
'second_method': self.b,
'third_method_sync': self.b,
'fourth_method_shared_lock': self.b}
self.vendor = driver_utils.MixinVendorInterface(self.mapping)
self.node = obj_utils.create_test_node(self.context,
driver='fake-hardware')
def test_vendor_interface_get_properties(self):
expected = {'A1': 'A1 description. Required.',
'A2': 'A2 description. Optional.',
'B1': 'B1 description. Required.',
'B2': 'B2 description. Required.'}
props = self.vendor.get_properties()
self.assertEqual(expected, props)
@mock.patch.object(fake.FakeVendorA, 'validate', autospec=True)
def test_vendor_interface_validate_valid_methods(self,
mock_fakea_validate):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.vendor.validate(task, method='first_method')
mock_fakea_validate.assert_called_once_with(
self.vendor.mapping['first_method'],
task, method='first_method')
def test_vendor_interface_validate_bad_method(self):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.InvalidParameterValue,
self.vendor.validate,
task, method='fake_method')