diff --git a/ironic/drivers/fake.py b/ironic/drivers/fake.py deleted file mode 100644 index 16c90b66b1..0000000000 --- a/ironic/drivers/fake.py +++ /dev/null @@ -1,193 +0,0 @@ -# -*- encoding: utf-8 -*- -# -# Copyright 2013 Hewlett-Packard Development Company, L.P. -# -# 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. -""" -Fake drivers used in testing. -""" - -from oslo_utils import importutils - -from ironic.common import exception -from ironic.common.i18n import _ -from ironic.drivers import base -from ironic.drivers.modules.cimc import management as cimc_mgmt -from ironic.drivers.modules.cimc import power as cimc_power -from ironic.drivers.modules.drac import inspect as drac_inspect -from ironic.drivers.modules.drac import management as drac_mgmt -from ironic.drivers.modules.drac import power as drac_power -from ironic.drivers.modules.drac import raid as drac_raid -from ironic.drivers.modules.drac import vendor_passthru as drac_vendor -from ironic.drivers.modules import fake -from ironic.drivers.modules.ilo import inspect as ilo_inspect -from ironic.drivers.modules.ilo import management as ilo_management -from ironic.drivers.modules.ilo import power as ilo_power -from ironic.drivers.modules.irmc import inspect as irmc_inspect -from ironic.drivers.modules.irmc import management as irmc_management -from ironic.drivers.modules.irmc import power as irmc_power -from ironic.drivers.modules import iscsi_deploy -from ironic.drivers.modules.oneview import management as oneview_management -from ironic.drivers.modules.oneview import power as oneview_power -from ironic.drivers.modules.ucs import management as ucs_mgmt -from ironic.drivers.modules.ucs import power as ucs_power - - -class FakeIloDriver(base.BaseDriver): - """Fake iLO driver, used in testing.""" - - def __init__(self): - if not importutils.try_import('proliantutils'): - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to import proliantutils library")) - self.power = ilo_power.IloPower() - self.deploy = fake.FakeDeploy() - self.management = ilo_management.IloManagement() - self.inspect = ilo_inspect.IloInspect() - - @classmethod - def to_hardware_type(cls): - return 'fake-hardware', { - 'boot': 'fake', - 'deploy': 'fake', - 'inspect': 'ilo', - 'management': 'ilo', - 'power': 'ilo' - } - - -class FakeDracDriver(base.BaseDriver): - """Fake Drac driver.""" - - def __init__(self): - if not importutils.try_import('dracclient'): - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_('Unable to import python-dracclient library')) - - self.power = drac_power.DracPower() - self.deploy = iscsi_deploy.ISCSIDeploy() - self.management = drac_mgmt.DracManagement() - self.raid = drac_raid.DracRAID() - self.vendor = drac_vendor.DracVendorPassthru() - self.inspect = drac_inspect.DracInspect() - - @classmethod - def to_hardware_type(cls): - return 'fake-hardware', { - 'boot': 'fake', - # NOTE(dtantsur): the classic driver uses boot=None and - # deploy=iscsi. This cannot work, so correcting it based on the - # intended purpose of these fake drivers. - 'deploy': 'fake', - 'inspect': 'idrac', - 'management': 'idrac', - 'power': 'idrac', - 'raid': 'idrac', - 'vendor': 'idrac' - } - - -class FakeIRMCDriver(base.BaseDriver): - """Fake iRMC driver.""" - - def __init__(self): - if not importutils.try_import('scciclient'): - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to import python-scciclient library")) - self.power = irmc_power.IRMCPower() - self.deploy = fake.FakeDeploy() - self.management = irmc_management.IRMCManagement() - self.inspect = irmc_inspect.IRMCInspect() - - @classmethod - def to_hardware_type(cls): - return 'fake-hardware', { - 'boot': 'fake', - 'deploy': 'fake', - 'inspect': 'irmc', - 'management': 'irmc', - 'power': 'irmc' - } - - -class FakeUcsDriver(base.BaseDriver): - """Fake UCS driver.""" - - def __init__(self): - if not importutils.try_import('UcsSdk'): - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to import UcsSdk library")) - self.power = ucs_power.Power() - self.deploy = fake.FakeDeploy() - self.management = ucs_mgmt.UcsManagement() - - @classmethod - def to_hardware_type(cls): - return 'fake-hardware', { - 'boot': 'fake', - 'deploy': 'fake', - 'management': 'ucsm', - 'power': 'ucsm' - } - - -class FakeCIMCDriver(base.BaseDriver): - """Fake CIMC driver.""" - - def __init__(self): - if not importutils.try_import('ImcSdk'): - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to import ImcSdk library")) - self.power = cimc_power.Power() - self.deploy = fake.FakeDeploy() - self.management = cimc_mgmt.CIMCManagement() - - @classmethod - def to_hardware_type(cls): - return 'fake-hardware', { - 'boot': 'fake', - 'deploy': 'fake', - 'management': 'cimc', - 'power': 'cimc' - } - - -class FakeOneViewDriver(base.BaseDriver): - """Fake OneView driver. For testing purposes.""" - - def __init__(self): - if not importutils.try_import('hpOneView.oneview_client'): - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to import hpOneView library")) - - self.power = oneview_power.OneViewPower() - self.management = oneview_management.OneViewManagement() - self.boot = fake.FakeBoot() - self.deploy = fake.FakeDeploy() - self.inspect = fake.FakeInspect() - - @classmethod - def to_hardware_type(cls): - return 'fake-hardware', { - 'boot': 'fake', - 'deploy': 'fake', - 'inspect': 'fake', - 'management': 'oneview', - 'power': 'oneview' - } diff --git a/ironic/tests/unit/drivers/modules/cimc/test_common.py b/ironic/tests/unit/drivers/modules/cimc/test_common.py index 0d9d1e107d..bf42d540f6 100644 --- a/ironic/tests/unit/drivers/modules/cimc/test_common.py +++ b/ironic/tests/unit/drivers/modules/cimc/test_common.py @@ -35,10 +35,12 @@ class CIMCBaseTestCase(db_base.DbTestCase): def setUp(self): super(CIMCBaseTestCase, self).setUp() - self.config(enabled_drivers=['fake_cimc']) + self.config(enabled_hardware_types=['cisco-ucs-standalone'], + enabled_power_interfaces=['cimc', 'fake'], + enabled_management_interfaces=['cimc', 'fake']) self.node = obj_utils.create_test_node( self.context, - driver='fake_cimc', + driver='cisco-ucs-standalone', driver_info=INFO_DICT, instance_uuid=uuidutils.generate_uuid()) CONF.set_override('max_retry', 2, 'cimc') diff --git a/ironic/tests/unit/drivers/modules/drac/test_bios.py b/ironic/tests/unit/drivers/modules/drac/test_bios.py index 3fc7e220e1..b032eaea45 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_bios.py +++ b/ironic/tests/unit/drivers/modules/drac/test_bios.py @@ -25,20 +25,18 @@ import mock from ironic.common import exception from ironic.conductor import task_manager from ironic.drivers.modules.drac import common as drac_common -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.drac import utils as test_utils from ironic.tests.unit.objects import utils as obj_utils -INFO_DICT = db_utils.get_test_drac_info() +INFO_DICT = test_utils.INFO_DICT -class DracBIOSConfigurationTestCase(db_base.DbTestCase): +class DracBIOSConfigurationTestCase(test_utils.BaseDracTest): def setUp(self): super(DracBIOSConfigurationTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) patch_get_drac_client = mock.patch.object( diff --git a/ironic/tests/unit/drivers/modules/drac/test_common.py b/ironic/tests/unit/drivers/modules/drac/test_common.py index e79edc143f..f8eb47d62b 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_common.py +++ b/ironic/tests/unit/drivers/modules/drac/test_common.py @@ -20,18 +20,17 @@ import mock from ironic.common import exception from ironic.drivers.modules.drac import common as drac_common -from ironic.tests.unit.db import base as db_base from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.drac import utils as test_utils from ironic.tests.unit.objects import utils as obj_utils INFO_DICT = db_utils.get_test_drac_info() -class DracCommonMethodsTestCase(db_base.DbTestCase): - +class DracCommonMethodsTestCase(test_utils.BaseDracTest): def test_parse_driver_info(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) info = drac_common.parse_driver_info(node) self.assertEqual(INFO_DICT['drac_address'], info['drac_address']) @@ -47,7 +46,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): driver_info['drac_host'] = '4.5.6.7' driver_info.pop('drac_address') node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=driver_info) info = drac_common.parse_driver_info(node) self.assertEqual('4.5.6.7', info['drac_address']) @@ -59,7 +58,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): driver_info = db_utils.get_test_drac_info() driver_info['drac_host'] = '4.5.6.7' node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=driver_info) info = drac_common.parse_driver_info(node) self.assertEqual('4.5.6.7', driver_info['drac_host']) @@ -68,7 +67,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): def test_parse_driver_info_missing_host(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) del node.driver_info['drac_address'] self.assertRaises(exception.InvalidParameterValue, @@ -76,7 +75,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): def test_parse_driver_info_missing_port(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) del node.driver_info['drac_port'] @@ -85,7 +84,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): def test_parse_driver_info_invalid_port(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) node.driver_info['drac_port'] = 'foo' self.assertRaises(exception.InvalidParameterValue, @@ -93,7 +92,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): def test_parse_driver_info_missing_path(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) del node.driver_info['drac_path'] @@ -102,7 +101,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): def test_parse_driver_info_missing_protocol(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) del node.driver_info['drac_protocol'] @@ -111,7 +110,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): def test_parse_driver_info_invalid_protocol(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) node.driver_info['drac_protocol'] = 'foo' @@ -120,7 +119,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): def test_parse_driver_info_missing_username(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) del node.driver_info['drac_username'] self.assertRaises(exception.InvalidParameterValue, @@ -128,7 +127,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): def test_parse_driver_info_missing_password(self): node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) del node.driver_info['drac_password'] self.assertRaises(exception.InvalidParameterValue, @@ -139,7 +138,7 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): expected_call = mock.call('1.2.3.4', 'admin', 'fake', 443, '/wsman', 'https') node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) drac_common.get_drac_client(node) diff --git a/ironic/tests/unit/drivers/modules/drac/test_inspect.py b/ironic/tests/unit/drivers/modules/drac/test_inspect.py index 92bc6013ed..2c6b259360 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_inspect.py +++ b/ironic/tests/unit/drivers/modules/drac/test_inspect.py @@ -24,21 +24,18 @@ from ironic.conductor import task_manager from ironic.drivers.modules.drac import common as drac_common from ironic.drivers.modules.drac import inspect as drac_inspect from ironic import objects -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils from ironic.tests.unit.drivers.modules.drac import utils as test_utils from ironic.tests.unit.objects import utils as obj_utils -INFO_DICT = db_utils.get_test_drac_info() +INFO_DICT = test_utils.INFO_DICT -class DracInspectionTestCase(db_base.DbTestCase): +class DracInspectionTestCase(test_utils.BaseDracTest): def setUp(self): super(DracInspectionTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) memory = [{'id': 'DIMM.Socket.A1', 'size_mb': 16384, diff --git a/ironic/tests/unit/drivers/modules/drac/test_job.py b/ironic/tests/unit/drivers/modules/drac/test_job.py index aba89ccfef..fd72668a3f 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_job.py +++ b/ironic/tests/unit/drivers/modules/drac/test_job.py @@ -22,23 +22,20 @@ from ironic.common import exception from ironic.conductor import task_manager from ironic.drivers.modules.drac import common as drac_common from ironic.drivers.modules.drac import job as drac_job -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils from ironic.tests.unit.drivers.modules.drac import utils as test_utils from ironic.tests.unit.objects import utils as obj_utils -INFO_DICT = db_utils.get_test_drac_info() +INFO_DICT = test_utils.INFO_DICT @mock.patch.object(drac_common, 'get_drac_client', spec_set=True, autospec=True) -class DracJobTestCase(db_base.DbTestCase): +class DracJobTestCase(test_utils.BaseDracTest): def setUp(self): super(DracJobTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) self.job_dict = { 'id': 'JID_001436912645', @@ -117,13 +114,12 @@ class DracJobTestCase(db_base.DbTestCase): @mock.patch.object(drac_common, 'get_drac_client', spec_set=True, autospec=True) -class DracVendorPassthruJobTestCase(db_base.DbTestCase): +class DracVendorPassthruJobTestCase(test_utils.BaseDracTest): def setUp(self): super(DracVendorPassthruJobTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) self.job_dict = { 'id': 'JID_001436912645', diff --git a/ironic/tests/unit/drivers/modules/drac/test_management.py b/ironic/tests/unit/drivers/modules/drac/test_management.py index c36a180578..d8b269b538 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_management.py +++ b/ironic/tests/unit/drivers/modules/drac/test_management.py @@ -27,17 +27,15 @@ from ironic.conductor import task_manager from ironic.drivers.modules.drac import common as drac_common from ironic.drivers.modules.drac import job as drac_job from ironic.drivers.modules.drac import management as drac_mgmt -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils from ironic.tests.unit.drivers.modules.drac import utils as test_utils from ironic.tests.unit.objects import utils as obj_utils -INFO_DICT = db_utils.get_test_drac_info() +INFO_DICT = test_utils.INFO_DICT @mock.patch.object(drac_common, 'get_drac_client', spec_set=True, autospec=True) -class DracManagementInternalMethodsTestCase(db_base.DbTestCase): +class DracManagementInternalMethodsTestCase(test_utils.BaseDracTest): def boot_modes(self, *next_modes): modes = [ @@ -52,9 +50,8 @@ class DracManagementInternalMethodsTestCase(db_base.DbTestCase): def setUp(self): super(DracManagementInternalMethodsTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) self.boot_device_pxe = { @@ -179,13 +176,12 @@ class DracManagementInternalMethodsTestCase(db_base.DbTestCase): @mock.patch.object(drac_common, 'get_drac_client', spec_set=True, autospec=True) -class DracManagementTestCase(db_base.DbTestCase): +class DracManagementTestCase(test_utils.BaseDracTest): def setUp(self): super(DracManagementTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) def test_get_properties(self, mock_get_drac_client): diff --git a/ironic/tests/unit/drivers/modules/drac/test_periodic_task.py b/ironic/tests/unit/drivers/modules/drac/test_periodic_task.py index 5ac80586d2..7577e4b417 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_periodic_task.py +++ b/ironic/tests/unit/drivers/modules/drac/test_periodic_task.py @@ -17,28 +17,25 @@ Test class for DRAC periodic tasks import mock -from ironic.common import driver_factory from ironic.conductor import task_manager from ironic.conductor import utils as manager_utils from ironic.drivers.modules.drac import common as drac_common from ironic.drivers.modules.drac import raid as drac_raid from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils from ironic.tests.unit.drivers.modules.drac import utils as test_utils from ironic.tests.unit.objects import utils as obj_utils -INFO_DICT = db_utils.get_test_drac_info() +INFO_DICT = test_utils.INFO_DICT class DracPeriodicTaskTestCase(db_base.DbTestCase): def setUp(self): super(DracPeriodicTaskTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) - self.driver = driver_factory.get_driver("fake_drac") + self.raid = drac_raid.DracRAID() self.job = { 'id': 'JID_001436912645', 'name': 'ConfigBIOS:BIOS.Setup.1-1', @@ -73,17 +70,16 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): {'raid_config_job_ids': ['42']})] mock_manager.iter_nodes.return_value = node_list # mock task_manager.acquire - task = mock.Mock(node=self.node, - driver=self.driver) + task = mock.Mock(node=self.node, driver=mock.Mock(raid=self.raid)) mock_acquire.return_value = mock.MagicMock( __enter__=mock.MagicMock(return_value=task)) # mock _check_node_raid_jobs - self.driver.raid._check_node_raid_jobs = mock.Mock() + self.raid._check_node_raid_jobs = mock.Mock() - self.driver.raid._query_raid_config_job_status(mock_manager, - self.context) + self.raid._query_raid_config_job_status(mock_manager, + self.context) - self.driver.raid._check_node_raid_jobs.assert_called_once_with(task) + self.raid._check_node_raid_jobs.assert_called_once_with(task) @mock.patch.object(task_manager, 'acquire', autospec=True) def test__query_raid_config_job_status_no_config_jobs(self, mock_acquire): @@ -92,16 +88,15 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): node_list = [(self.node.uuid, 'pxe_drac', {})] mock_manager.iter_nodes.return_value = node_list # mock task_manager.acquire - task = mock.Mock(node=self.node, - driver=self.driver) + task = mock.Mock(node=self.node, driver=mock.Mock(raid=self.raid)) mock_acquire.return_value = mock.MagicMock( __enter__=mock.MagicMock(return_value=task)) # mock _check_node_raid_jobs - self.driver.raid._check_node_raid_jobs = mock.Mock() + self.raid._check_node_raid_jobs = mock.Mock() - self.driver.raid._query_raid_config_job_status(mock_manager, None) + self.raid._query_raid_config_job_status(mock_manager, None) - self.assertEqual(0, self.driver.raid._check_node_raid_jobs.call_count) + self.assertEqual(0, self.raid._check_node_raid_jobs.call_count) def test__query_raid_config_job_status_no_nodes(self): # mock manager @@ -109,11 +104,11 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): node_list = [] mock_manager.iter_nodes.return_value = node_list # mock _check_node_raid_jobs - self.driver.raid._check_node_raid_jobs = mock.Mock() + self.raid._check_node_raid_jobs = mock.Mock() - self.driver.raid._query_raid_config_job_status(mock_manager, None) + self.raid._query_raid_config_job_status(mock_manager, None) - self.assertEqual(0, self.driver.raid._check_node_raid_jobs.call_count) + self.assertEqual(0, self.raid._check_node_raid_jobs.call_count) @mock.patch.object(drac_common, 'get_drac_client', spec_set=True, autospec=True) @@ -130,7 +125,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): mock_client.get_job.return_value = test_utils.dict_to_namedtuple( values=self.job) - self.driver.raid._check_node_raid_jobs(task) + self.raid._check_node_raid_jobs(task) mock_client.get_job.assert_called_once_with('42') self.assertEqual(0, mock_client.list_virtual_disks.call_count) @@ -168,7 +163,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): 'logical_disks': [expected_logical_disk] } - self.driver.raid._check_node_raid_jobs(task) + self.raid._check_node_raid_jobs(task) mock_client.get_job.assert_called_once_with('42') self.node.refresh() @@ -198,7 +193,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): mock_client.list_virtual_disks.return_value = [ test_utils.dict_to_namedtuple(values=self.virtual_disk)] - self.driver.raid._check_node_raid_jobs(task) + self.raid._check_node_raid_jobs(task) mock_client.get_job.assert_called_once_with('42') self.assertEqual(0, mock_client.list_virtual_disks.call_count) @@ -237,7 +232,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): 'logical_disks': [expected_logical_disk] } - self.driver.raid._check_node_raid_jobs(task) + self.raid._check_node_raid_jobs(task) mock_client.get_job.assert_called_once_with('42') self.node.refresh() @@ -276,7 +271,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): 'logical_disks': [expected_logical_disk] } - self.driver.raid._check_node_raid_jobs(task) + self.raid._check_node_raid_jobs(task) mock_client.get_job.assert_has_calls([mock.call('42'), mock.call('36')]) @@ -321,7 +316,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase): 'logical_disks': [expected_logical_disk] } - self.driver.raid._check_node_raid_jobs(task) + self.raid._check_node_raid_jobs(task) mock_client.get_job.assert_has_calls([mock.call('42'), mock.call('36')]) diff --git a/ironic/tests/unit/drivers/modules/drac/test_power.py b/ironic/tests/unit/drivers/modules/drac/test_power.py index a6e27ac202..27cc759818 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_power.py +++ b/ironic/tests/unit/drivers/modules/drac/test_power.py @@ -24,22 +24,20 @@ from ironic.common import states from ironic.conductor import task_manager from ironic.drivers.modules.drac import common as drac_common from ironic.drivers.modules.drac import power as drac_power -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.drac import utils as test_utils from ironic.tests.unit.objects import utils as obj_utils -INFO_DICT = db_utils.get_test_drac_info() +INFO_DICT = test_utils.INFO_DICT @mock.patch.object(drac_common, 'get_drac_client', spec_set=True, autospec=True) -class DracPowerTestCase(db_base.DbTestCase): +class DracPowerTestCase(test_utils.BaseDracTest): def setUp(self): super(DracPowerTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) def test_get_properties(self, mock_get_drac_client): diff --git a/ironic/tests/unit/drivers/modules/drac/test_raid.py b/ironic/tests/unit/drivers/modules/drac/test_raid.py index cf04b8b15d..a713cccd6a 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_raid.py +++ b/ironic/tests/unit/drivers/modules/drac/test_raid.py @@ -24,23 +24,20 @@ from ironic.conductor import task_manager from ironic.drivers.modules.drac import common as drac_common from ironic.drivers.modules.drac import job as drac_job from ironic.drivers.modules.drac import raid as drac_raid -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils from ironic.tests.unit.drivers.modules.drac import utils as test_utils from ironic.tests.unit.objects import utils as obj_utils -INFO_DICT = db_utils.get_test_drac_info() +INFO_DICT = test_utils.INFO_DICT @mock.patch.object(drac_common, 'get_drac_client', spec_set=True, autospec=True) -class DracQueryRaidConfigurationTestCase(db_base.DbTestCase): +class DracQueryRaidConfigurationTestCase(test_utils.BaseDracTest): def setUp(self): super(DracQueryRaidConfigurationTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) raid_controller_dict = { @@ -145,13 +142,12 @@ class DracQueryRaidConfigurationTestCase(db_base.DbTestCase): @mock.patch.object(drac_common, 'get_drac_client', spec_set=True, autospec=True) -class DracManageVirtualDisksTestCase(db_base.DbTestCase): +class DracManageVirtualDisksTestCase(test_utils.BaseDracTest): def setUp(self): super(DracManageVirtualDisksTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) @mock.patch.object(drac_job, 'validate_job_queue', spec_set=True, @@ -270,13 +266,12 @@ class DracManageVirtualDisksTestCase(db_base.DbTestCase): 'controller1') -class DracCreateRaidConfigurationHelpersTestCase(db_base.DbTestCase): +class DracCreateRaidConfigurationHelpersTestCase(test_utils.BaseDracTest): def setUp(self): super(DracCreateRaidConfigurationHelpersTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) self.physical_disk = { @@ -523,13 +518,12 @@ class DracCreateRaidConfigurationHelpersTestCase(db_base.DbTestCase): logical_disks) -class DracRaidInterfaceTestCase(db_base.DbTestCase): +class DracRaidInterfaceTestCase(test_utils.BaseDracTest): def setUp(self): super(DracRaidInterfaceTestCase, self).setUp() - self.config(enabled_drivers=['fake_drac']) self.node = obj_utils.create_test_node(self.context, - driver='fake_drac', + driver='idrac', driver_info=INFO_DICT) self.physical_disk = { diff --git a/ironic/tests/unit/drivers/modules/drac/utils.py b/ironic/tests/unit/drivers/modules/drac/utils.py index ea0958ef20..4884a2cd0e 100644 --- a/ironic/tests/unit/drivers/modules/drac/utils.py +++ b/ironic/tests/unit/drivers/modules/drac/utils.py @@ -13,6 +13,23 @@ import collections +from ironic.tests.unit.db import base as db_base +from ironic.tests.unit.db import utils as db_utils + + +INFO_DICT = db_utils.get_test_drac_info() + + +class BaseDracTest(db_base.DbTestCase): + def setUp(self): + super(BaseDracTest, self).setUp() + self.config(enabled_hardware_types=['idrac', 'fake-hardware'], + enabled_power_interfaces=['idrac', 'fake'], + enabled_management_interfaces=['idrac', 'fake'], + enabled_inspect_interfaces=['idrac', 'fake', 'no-inspect'], + enabled_vendor_interfaces=['idrac', 'fake', 'no-vendor'], + enabled_raid_interfaces=['idrac', 'fake', 'no-raid']) + def dict_to_namedtuple(name='GenericNamedTuple', values=None): """Converts a dict to a collections.namedtuple""" diff --git a/ironic/tests/unit/drivers/modules/ilo/test_common.py b/ironic/tests/unit/drivers/modules/ilo/test_common.py index 9744b92c57..efb217eec8 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_common.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_common.py @@ -24,6 +24,7 @@ from ironic_lib import utils as ironic_utils import mock from oslo_config import cfg from oslo_utils import importutils +from oslo_utils import uuidutils import six import six.moves.builtins as __builtin__ @@ -52,13 +53,23 @@ if six.PY3: CONF = cfg.CONF -class IloValidateParametersTestCase(db_base.DbTestCase): +class BaseIloTest(db_base.DbTestCase): def setUp(self): - super(IloValidateParametersTestCase, self).setUp() + super(BaseIloTest, self).setUp() + self.config(enabled_hardware_types=['ilo', 'fake-hardware'], + enabled_boot_interfaces=['ilo-pxe', 'ilo-virtual-media', + 'fake'], + enabled_power_interfaces=['ilo', 'fake'], + enabled_management_interfaces=['ilo', 'fake'], + enabled_inspect_interfaces=['ilo', 'fake', 'no-inspect']) + self.info = INFO_DICT.copy() self.node = obj_utils.create_test_node( - self.context, driver='fake_ilo', - driver_info=INFO_DICT) + self.context, uuid=uuidutils.generate_uuid(), + driver='ilo', driver_info=self.info) + + +class IloValidateParametersTestCase(BaseIloTest): @mock.patch.object(os.path, 'isfile', return_value=True, autospec=True) def _test_parse_driver_info(self, isFile_mock): @@ -209,14 +220,7 @@ class IloValidateParametersTestCase(db_base.DbTestCase): self.assertIn('client_timeout', str(e)) -class IloCommonMethodsTestCase(db_base.DbTestCase): - - def setUp(self): - super(IloCommonMethodsTestCase, self).setUp() - self.config(enabled_drivers=['fake_ilo']) - self.info = db_utils.get_test_ilo_info() - self.node = obj_utils.create_test_node( - self.context, driver='fake_ilo', driver_info=self.info) +class IloCommonMethodsTestCase(BaseIloTest): @mock.patch.object(os.path, 'isfile', return_value=True, autospec=True) @mock.patch.object(ilo_client, 'IloClient', spec_set=True, diff --git a/ironic/tests/unit/drivers/modules/ilo/test_inspect.py b/ironic/tests/unit/drivers/modules/ilo/test_inspect.py index 80a9f0397e..8c73d5c761 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_inspect.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_inspect.py @@ -27,21 +27,10 @@ from ironic.drivers.modules.ilo import common as ilo_common from ironic.drivers.modules.ilo import inspect as ilo_inspect from ironic.drivers.modules.ilo import power as ilo_power from ironic import objects -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils -from ironic.tests.unit.objects import utils as obj_utils +from ironic.tests.unit.drivers.modules.ilo import test_common -INFO_DICT = db_utils.get_test_ilo_info() - - -class IloInspectTestCase(db_base.DbTestCase): - - def setUp(self): - super(IloInspectTestCase, self).setUp() - self.config(enabled_drivers=['fake_ilo']) - self.node = obj_utils.create_test_node( - self.context, driver='fake_ilo', driver_info=INFO_DICT) +class IloInspectTestCase(test_common.BaseIloTest): def test_get_properties(self): with task_manager.acquire(self.context, self.node.uuid, @@ -265,13 +254,7 @@ class IloInspectTestCase(db_base.DbTestCase): create_port_mock.assert_called_once_with(task, macs) -class TestInspectPrivateMethods(db_base.DbTestCase): - - def setUp(self): - super(TestInspectPrivateMethods, self).setUp() - self.config(enabled_drivers=['fake_ilo']) - self.node = obj_utils.create_test_node( - self.context, driver='fake_ilo', driver_info=INFO_DICT) +class TestInspectPrivateMethods(test_common.BaseIloTest): @mock.patch.object(ilo_inspect.LOG, 'info', spec_set=True, autospec=True) @mock.patch.object(objects, 'Port', spec_set=True, autospec=True) diff --git a/ironic/tests/unit/drivers/modules/ilo/test_management.py b/ironic/tests/unit/drivers/modules/ilo/test_management.py index e2b20e1d94..fe6cf3b1f5 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_management.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_management.py @@ -27,22 +27,13 @@ from ironic.drivers.modules.ilo import common as ilo_common from ironic.drivers.modules.ilo import management as ilo_management from ironic.drivers.modules import ipmitool from ironic.drivers import utils as driver_utils -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.ilo import test_common from ironic.tests.unit.objects import utils as obj_utils ilo_error = importutils.try_import('proliantutils.exception') -INFO_DICT = db_utils.get_test_ilo_info() - -class IloManagementTestCase(db_base.DbTestCase): - - def setUp(self): - super(IloManagementTestCase, self).setUp() - self.config(enabled_drivers=['fake_ilo']) - self.node = obj_utils.create_test_node( - self.context, driver='fake_ilo', driver_info=INFO_DICT) +class IloManagementTestCase(test_common.BaseIloTest): def test_get_properties(self): with task_manager.acquire(self.context, self.node.uuid, diff --git a/ironic/tests/unit/drivers/modules/ilo/test_power.py b/ironic/tests/unit/drivers/modules/ilo/test_power.py index bcb190edfa..48783d0518 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_power.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_power.py @@ -27,8 +27,8 @@ from ironic.conductor import task_manager from ironic.conductor import utils as manager_utils from ironic.drivers.modules.ilo import common as ilo_common from ironic.drivers.modules.ilo import power as ilo_power -from ironic.tests.unit.db import base as db_base from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.ilo import test_common from ironic.tests.unit.objects import utils as obj_utils ilo_error = importutils.try_import('proliantutils.exception') @@ -38,15 +38,12 @@ CONF = cfg.CONF @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True, autospec=True) -class IloPowerInternalMethodsTestCase(db_base.DbTestCase): +class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): def setUp(self): super(IloPowerInternalMethodsTestCase, self).setUp() - driver_info = INFO_DICT - self.config(enabled_drivers=['fake_ilo']) - self.node = db_utils.create_test_node( - driver='fake_ilo', - driver_info=driver_info, + self.node = obj_utils.create_test_node( + self.context, driver='ilo', driver_info=INFO_DICT, instance_uuid=uuidutils.generate_uuid()) CONF.set_override('power_retry', 2, 'ilo') CONF.set_override('power_wait', 0, 'ilo') @@ -163,15 +160,7 @@ class IloPowerInternalMethodsTestCase(db_base.DbTestCase): self.assertFalse(set_boot_device_mock.called) -class IloPowerTestCase(db_base.DbTestCase): - - def setUp(self): - super(IloPowerTestCase, self).setUp() - driver_info = INFO_DICT - self.config(enabled_drivers=['fake_ilo']) - self.node = obj_utils.create_test_node(self.context, - driver='fake_ilo', - driver_info=driver_info) +class IloPowerTestCase(test_common.BaseIloTest): def test_get_properties(self): expected = ilo_common.COMMON_PROPERTIES diff --git a/ironic/tests/unit/drivers/modules/irmc/test_common.py b/ironic/tests/unit/drivers/modules/irmc/test_common.py index 047162716c..0ab12894ac 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_common.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_common.py @@ -29,14 +29,23 @@ from ironic.tests.unit.drivers import third_party_driver_mock_specs \ from ironic.tests.unit.objects import utils as obj_utils -class IRMCValidateParametersTestCase(db_base.DbTestCase): +class BaseIRMCTest(db_base.DbTestCase): def setUp(self): - super(IRMCValidateParametersTestCase, self).setUp() + super(BaseIRMCTest, self).setUp() + self.config(enabled_hardware_types=['irmc', 'fake-hardware'], + enabled_power_interfaces=['irmc', 'fake'], + enabled_management_interfaces=['irmc', 'fake'], + enabled_boot_interfaces=['irmc-pxe', 'fake'], + enabled_inspect_interfaces=['irmc', 'no-inspect', 'fake']) + self.info = db_utils.get_test_irmc_info() self.node = obj_utils.create_test_node( self.context, - driver='fake_irmc', - driver_info=db_utils.get_test_irmc_info()) + driver='irmc', + driver_info=self.info) + + +class IRMCValidateParametersTestCase(BaseIRMCTest): def test_parse_driver_info(self): info = irmc_common.parse_driver_info(self.node) @@ -138,16 +147,7 @@ class IRMCValidateParametersTestCase(db_base.DbTestCase): irmc_common.parse_driver_info, self.node) -class IRMCCommonMethodsTestCase(db_base.DbTestCase): - - def setUp(self): - super(IRMCCommonMethodsTestCase, self).setUp() - self.config(enabled_drivers=['fake_irmc']) - self.info = db_utils.get_test_irmc_info() - self.node = obj_utils.create_test_node( - self.context, - driver='fake_irmc', - driver_info=self.info) +class IRMCCommonMethodsTestCase(BaseIRMCTest): @mock.patch.object(irmc_common, 'scci', spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) diff --git a/ironic/tests/unit/drivers/modules/irmc/test_inspect.py b/ironic/tests/unit/drivers/modules/irmc/test_inspect.py index b7d28f414a..8b4499217d 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_inspect.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_inspect.py @@ -27,25 +27,13 @@ from ironic.drivers.modules.irmc import common as irmc_common from ironic.drivers.modules.irmc import inspect as irmc_inspect from ironic.drivers.modules.irmc import power as irmc_power from ironic import objects -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils from ironic.tests.unit.drivers import ( third_party_driver_mock_specs as mock_specs ) -from ironic.tests.unit.objects import utils as obj_utils - -INFO_DICT = db_utils.get_test_irmc_info() +from ironic.tests.unit.drivers.modules.irmc import test_common -class IRMCInspectInternalMethodsTestCase(db_base.DbTestCase): - - def setUp(self): - super(IRMCInspectInternalMethodsTestCase, self).setUp() - driver_info = INFO_DICT - self.config(enabled_drivers=['fake_irmc']) - self.node = obj_utils.create_test_node(self.context, - driver='fake_irmc', - driver_info=driver_info) +class IRMCInspectInternalMethodsTestCase(test_common.BaseIRMCTest): @mock.patch('ironic.drivers.modules.irmc.inspect.snmp.SNMPClient', spec_set=True, autospec=True) @@ -134,15 +122,7 @@ class IRMCInspectInternalMethodsTestCase(db_base.DbTestCase): self.assertFalse(_get_mac_addresses_mock.called) -class IRMCInspectTestCase(db_base.DbTestCase): - - def setUp(self): - super(IRMCInspectTestCase, self).setUp() - driver_info = INFO_DICT - self.config(enabled_drivers=['fake_irmc']) - self.node = obj_utils.create_test_node(self.context, - driver='fake_irmc', - driver_info=driver_info) +class IRMCInspectTestCase(test_common.BaseIRMCTest): def test_get_properties(self): with task_manager.acquire(self.context, self.node.uuid, diff --git a/ironic/tests/unit/drivers/modules/irmc/test_management.py b/ironic/tests/unit/drivers/modules/irmc/test_management.py index e6461261c4..00d5946452 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_management.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_management.py @@ -22,23 +22,19 @@ import xml.etree.ElementTree as ET 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.conductor import utils as manager_utils +from ironic.drivers.modules import fake from ironic.drivers.modules import ipmitool from ironic.drivers.modules.irmc import common as irmc_common from ironic.drivers.modules.irmc import management as irmc_management from ironic.drivers.modules.irmc import power as irmc_power from ironic.drivers import utils as driver_utils -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.irmc import test_common from ironic.tests.unit.drivers import third_party_driver_mock_specs \ as mock_specs -from ironic.tests.unit.objects import utils as obj_utils - -INFO_DICT = db_utils.get_test_irmc_info() @mock.patch.object(irmc_management.irmc, 'elcm', @@ -48,16 +44,9 @@ INFO_DICT = db_utils.get_test_irmc_info() @mock.patch.object(irmc_power.IRMCPower, 'get_power_state', return_value=states.POWER_ON, specset=True, autospec=True) -class IRMCManagementFunctionsTestCase(db_base.DbTestCase): +class IRMCManagementFunctionsTestCase(test_common.BaseIRMCTest): def setUp(self): super(IRMCManagementFunctionsTestCase, self).setUp() - driver_info = INFO_DICT - - self.config(enabled_drivers=['fake_irmc']) - self.driver = driver_factory.get_driver("fake_irmc") - self.node = obj_utils.create_test_node(self.context, - driver='fake_irmc', - driver_info=driver_info) self.info = irmc_common.parse_driver_info(self.node) irmc_management.irmc.scci.SCCIError = Exception @@ -151,16 +140,9 @@ class IRMCManagementFunctionsTestCase(db_base.DbTestCase): self.assertTrue(mock_elcm.restore_bios_config.called) -class IRMCManagementTestCase(db_base.DbTestCase): +class IRMCManagementTestCase(test_common.BaseIRMCTest): def setUp(self): super(IRMCManagementTestCase, self).setUp() - driver_info = INFO_DICT - - self.config(enabled_drivers=['fake_irmc']) - self.driver = driver_factory.get_driver("fake_irmc") - self.node = obj_utils.create_test_node(self.context, - driver='fake_irmc', - driver_info=driver_info) self.info = irmc_common.parse_driver_info(self.node) def test_get_properties(self): @@ -169,6 +151,9 @@ class IRMCManagementTestCase(db_base.DbTestCase): expected.update(ipmitool.CONSOLE_PROPERTIES) with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: + # Remove the boot and deploy interfaces properties + task.driver.boot = fake.FakeBoot() + task.driver.deploy = fake.FakeDeploy() self.assertEqual(expected, task.driver.get_properties()) @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, @@ -208,7 +193,7 @@ class IRMCManagementTestCase(db_base.DbTestCase): task.node.properties['capabilities'] = '' if boot_mode: driver_utils.add_node_capability(task, 'boot_mode', boot_mode) - self.driver.management.set_boot_device(task, **params) + irmc_management.IRMCManagement().set_boot_device(task, **params) send_raw_mock.assert_has_calls([ mock.call(task, "0x00 0x08 0x03 0x08"), mock.call(task, expected_raw_code)]) @@ -367,7 +352,7 @@ class IRMCManagementTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: driver_utils.add_node_capability(task, 'boot_mode', 'uefi') self.assertRaises(exception.InvalidParameterValue, - self.driver.management.set_boot_device, + irmc_management.IRMCManagement().set_boot_device, task, "unknown") @@ -389,7 +374,8 @@ class IRMCManagementTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: task.node.driver_info['irmc_sensor_method'] = 'scci' - sensor_dict = self.driver.management.get_sensors_data(task) + sensor_dict = irmc_management.IRMCManagement().get_sensors_data( + task) expected = { 'Fan (4)': { @@ -437,7 +423,8 @@ class IRMCManagementTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: task.node.driver_info['irmc_sensor_method'] = 'scci' - sensor_dict = self.driver.management.get_sensors_data(task) + sensor_dict = irmc_management.IRMCManagement().get_sensors_data( + task) self.assertEqual(len(sensor_dict), 0) @@ -467,9 +454,9 @@ class IRMCManagementTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: task.node.driver_info['irmc_sensor_method'] = 'scci' - e = self.assertRaises(exception.FailedToGetSensorData, - self.driver.management.get_sensors_data, - task) + e = self.assertRaises( + exception.FailedToGetSensorData, + irmc_management.IRMCManagement().get_sensors_data, task) self.assertEqual("Failed to get sensor data for node 1be26c0b-" "03f2-4d2e-ae87-c02d7f33c123. Error: Fake Error", str(e)) @@ -482,7 +469,7 @@ class IRMCManagementTestCase(db_base.DbTestCase): mock_log): irmc_client = mock_get_irmc_client.return_value with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.management.inject_nmi(task) + irmc_management.IRMCManagement().inject_nmi(task) irmc_client.assert_called_once_with( irmc_management.irmc.scci.POWER_RAISE_NMI) @@ -500,7 +487,7 @@ class IRMCManagementTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises(exception.IRMCOperationError, - self.driver.management.inject_nmi, + irmc_management.IRMCManagement().inject_nmi, task) irmc_client.assert_called_once_with( diff --git a/ironic/tests/unit/drivers/modules/irmc/test_power.py b/ironic/tests/unit/drivers/modules/irmc/test_power.py index 3e3839065f..66dbb4e660 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_power.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_power.py @@ -17,7 +17,6 @@ Test class for iRMC Power Driver """ import mock -from oslo_utils import uuidutils from ironic.common import exception from ironic.common import states @@ -25,23 +24,10 @@ from ironic.conductor import task_manager from ironic.drivers.modules.irmc import boot as irmc_boot from ironic.drivers.modules.irmc import common as irmc_common from ironic.drivers.modules.irmc import power as irmc_power -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils -from ironic.tests.unit.objects import utils as obj_utils - -INFO_DICT = db_utils.get_test_irmc_info() +from ironic.tests.unit.drivers.modules.irmc import test_common -class IRMCPowerInternalMethodsTestCase(db_base.DbTestCase): - - def setUp(self): - super(IRMCPowerInternalMethodsTestCase, self).setUp() - self.config(enabled_drivers=['fake_irmc']) - driver_info = INFO_DICT - self.node = db_utils.create_test_node( - driver='fake_irmc', - driver_info=driver_info, - instance_uuid=uuidutils.generate_uuid()) +class IRMCPowerInternalMethodsTestCase(test_common.BaseIRMCTest): def test__is_expected_power_state(self): target_state = states.SOFT_POWER_OFF @@ -284,14 +270,7 @@ class IRMCPowerInternalMethodsTestCase(db_base.DbTestCase): task, states.SOFT_POWER_OFF, timeout=None) -class IRMCPowerTestCase(db_base.DbTestCase): - def setUp(self): - super(IRMCPowerTestCase, self).setUp() - driver_info = INFO_DICT - self.config(enabled_drivers=['fake_irmc']) - self.node = obj_utils.create_test_node(self.context, - driver='fake_irmc', - driver_info=driver_info) +class IRMCPowerTestCase(test_common.BaseIRMCTest): def test_get_properties(self): with task_manager.acquire(self.context, self.node.uuid, diff --git a/ironic/tests/unit/drivers/modules/oneview/test_common.py b/ironic/tests/unit/drivers/modules/oneview/test_common.py index bc7cd5bcda..7a28fdd250 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_common.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_common.py @@ -26,21 +26,33 @@ from ironic.tests.unit.objects import utils as obj_utils hponeview_client = importutils.try_import('hpOneView.oneview_client') -class OneViewCommonTestCase(db_base.DbTestCase): +class BaseOneViewTest(db_base.DbTestCase): def setUp(self): - super(OneViewCommonTestCase, self).setUp() + super(BaseOneViewTest, self).setUp() + self.config(enabled_hardware_types=['oneview', 'fake-hardware'], + enabled_deploy_interfaces=['oneview-direct', + 'oneview-iscsi', 'fake'], + enabled_management_interfaces=['oneview', 'fake'], + enabled_inspect_interfaces=['oneview', 'fake', + 'no-inspect'], + enabled_power_interfaces=['oneview', 'fake']) self.node = obj_utils.create_test_node( - self.context, driver='fake_oneview', + self.context, driver='oneview', properties=db_utils.get_test_oneview_properties(), driver_info=db_utils.get_test_oneview_driver_info(), ) + + +class OneViewCommonTestCase(BaseOneViewTest): + + def setUp(self): + super(OneViewCommonTestCase, self).setUp() self.config(manager_url='https://1.2.3.4', group='oneview') self.config(username='user', group='oneview') self.config(password='password', group='oneview') self.config(tls_cacert_file='ca_file', group='oneview') self.config(allow_insecure_connections=False, group='oneview') - self.config(enabled_drivers=['fake_oneview']) def test_prepare_manager_url(self): self.assertEqual( diff --git a/ironic/tests/unit/drivers/modules/oneview/test_deploy.py b/ironic/tests/unit/drivers/modules/oneview/test_deploy.py index ba210a8de1..6a3f8f2ce1 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_deploy.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_deploy.py @@ -27,6 +27,7 @@ from ironic.drivers.modules.oneview import deploy from ironic.drivers.modules.oneview import deploy_utils from ironic.tests.unit.db import base as db_base from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.oneview import test_common from ironic.tests.unit.objects import utils as obj_utils METHODS = ['iter_nodes', 'update_node', 'do_provisioning_action'] @@ -37,10 +38,10 @@ oneview_error = common.SERVER_HARDWARE_ALLOCATION_ERROR maintenance_reason = common.NODE_IN_USE_BY_ONEVIEW driver_internal_info = {'oneview_error': oneview_error} -nodes_taken_by_oneview = [(1, 'fake_oneview')] -nodes_freed_by_oneview = [(1, 'fake_oneview', maintenance_reason)] -nodes_taken_on_cleanfail = [(1, 'fake_oneview', driver_internal_info)] -nodes_taken_on_cleanfail_no_info = [(1, 'fake_oneview', {})] +nodes_taken_by_oneview = [(1, 'oneview')] +nodes_freed_by_oneview = [(1, 'oneview', maintenance_reason)] +nodes_taken_on_cleanfail = [(1, 'oneview', driver_internal_info)] +nodes_taken_on_cleanfail_no_info = [(1, 'oneview', {})] GET_POWER_STATE_RETRIES = 5 @@ -78,12 +79,12 @@ def _setup_node_in_cleanfailed_state_without_oneview_error(node): class OneViewDriverDeploy(deploy.OneViewPeriodicTasks): - oneview_driver = 'fake_oneview' + oneview_driver = 'oneview' @mock.patch('ironic.objects.Node', spec_set=True, autospec=True) @mock.patch.object(deploy_utils, 'is_node_in_use_by_oneview') -class OneViewPeriodicTasks(db_base.DbTestCase): +class OneViewPeriodicTasks(test_common.BaseOneViewTest): def setUp(self): super(OneViewPeriodicTasks, self).setUp() @@ -91,15 +92,8 @@ class OneViewPeriodicTasks(db_base.DbTestCase): self.config(username='user', group='oneview') self.config(password='password', group='oneview') - self.config(enabled_drivers=['fake_oneview']) - self.driver = driver_factory.get_driver('fake_oneview') self.deploy = OneViewDriverDeploy() self.os_primary = mock.MagicMock(spec=METHODS) - self.node = obj_utils.create_test_node( - self.context, driver='fake_oneview', - properties=db_utils.get_test_oneview_properties(), - driver_info=db_utils.get_test_oneview_driver_info(), - ) def test_node_manageable_maintenance_when_in_use_by_oneview( self, mock_is_node_in_use_by_oneview, mock_node_get diff --git a/ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py b/ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py index b034bc216f..e97a6eac81 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py @@ -16,36 +16,25 @@ import mock from oslo_utils import importutils -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.modules.oneview import common from ironic.drivers.modules.oneview import deploy_utils from ironic import objects -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils -from ironic.tests.unit.objects import utils as obj_utils +from ironic.tests.unit.drivers.modules.oneview import test_common oneview_models = importutils.try_import('oneview_client.models') @mock.patch.object(common, 'get_hponeview_client') -class OneViewDeployUtilsTestCase(db_base.DbTestCase): +class OneViewDeployUtilsTestCase(test_common.BaseOneViewTest): def setUp(self): super(OneViewDeployUtilsTestCase, self).setUp() self.config(manager_url='https://1.2.3.4', group='oneview') self.config(username='user', group='oneview') self.config(password='password', group='oneview') - self.config(enabled_drivers=['fake_oneview']) - self.driver = driver_factory.get_driver('fake_oneview') - - self.node = obj_utils.create_test_node( - self.context, driver='fake_oneview', - properties=db_utils.get_test_oneview_properties(), - driver_info=db_utils.get_test_oneview_driver_info(), - ) self.info = common.get_oneview_info(self.node) deploy_utils.is_node_in_use_by_oneview = mock.Mock(return_value=False) deploy_utils.is_node_in_use_by_ironic = mock.Mock(return_value=True) diff --git a/ironic/tests/unit/drivers/modules/oneview/test_management.py b/ironic/tests/unit/drivers/modules/oneview/test_management.py index 2b58ceb82d..b897dbd563 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_management.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_management.py @@ -18,35 +18,25 @@ from oslo_utils import importutils from oslo_utils import uuidutils from ironic.common import boot_devices -from ironic.common import driver_factory from ironic.common import exception from ironic.conductor import task_manager from ironic.drivers.modules.oneview import common from ironic.drivers.modules.oneview import deploy_utils from ironic.drivers.modules.oneview import management -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.oneview import test_common from ironic.tests.unit.objects import utils as obj_utils client_exception = importutils.try_import('hpOneView.exceptions') @mock.patch.object(common, 'get_hponeview_client') -class OneViewManagementDriverFunctionsTestCase(db_base.DbTestCase): +class OneViewManagementDriverFunctionsTestCase(test_common.BaseOneViewTest): def setUp(self): super(OneViewManagementDriverFunctionsTestCase, self).setUp() self.config(manager_url='https://1.2.3.4', group='oneview') self.config(username='user', group='oneview') self.config(password='password', group='oneview') - self.config(enabled_drivers=['fake_oneview']) - self.driver = driver_factory.get_driver("fake_oneview") - - self.node = obj_utils.create_test_node( - self.context, driver='fake_oneview', - properties=db_utils.get_test_oneview_properties(), - driver_info=db_utils.get_test_oneview_driver_info(), - ) self.info = common.get_oneview_info(self.node) @mock.patch.object(common, 'get_ilorest_client') @@ -212,7 +202,7 @@ class OneViewManagementDriverFunctionsTestCase(db_base.DbTestCase): ) -class OneViewManagementDriverTestCase(db_base.DbTestCase): +class OneViewManagementDriverTestCase(test_common.BaseOneViewTest): def setUp(self): super(OneViewManagementDriverTestCase, self).setUp() @@ -221,15 +211,6 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): self.config(password='password', group='oneview') self.config(tls_cacert_file='ca_file', group='oneview') self.config(allow_insecure_connections=False, group='oneview') - - self.config(enabled_drivers=['fake_oneview']) - self.driver = driver_factory.get_driver("fake_oneview") - - self.node = obj_utils.create_test_node( - self.context, driver='fake_oneview', - properties=db_utils.get_test_oneview_properties(), - driver_info=db_utils.get_test_oneview_driver_info(), - ) self.info = common.get_oneview_info(self.node) @mock.patch.object(deploy_utils, 'is_node_in_use_by_ironic', @@ -254,7 +235,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): def test_validate_fail(self): node = obj_utils.create_test_node( self.context, uuid=uuidutils.generate_uuid(), - id=999, driver='fake_oneview' + id=999, driver='oneview' ) with task_manager.acquire(self.context, node.uuid) as task: self.assertRaises(exception.MissingParameterValue, @@ -271,7 +252,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): def test_get_properties(self): expected = common.COMMON_PROPERTIES self.assertItemsEqual(expected, - self.driver.management.get_properties()) + management.OneViewManagement().get_properties()) def test_set_boot_device_persistent_true(self): with task_manager.acquire(self.context, self.node.uuid) as task: @@ -326,7 +307,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): profile = {'boot': {'order': [oneview_device]}} oneview_client.server_profiles.get.return_value = profile expected = {'boot_device': ironic_device, 'persistent': True} - response = self.driver.management.get_boot_device(task) + response = management.OneViewManagement().get_boot_device(task) self.assertEqual(expected, response) self.assertTrue(oneview_client.server_profiles.get.called) self.assertTrue(ilo_client.get.called) @@ -344,7 +325,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): 'boot_device': boot_devices.DISK, 'persistent': True } - response = self.driver.management.get_boot_device(task) + response = management.OneViewManagement().get_boot_device(task) self.assertEqual(expected_response, response) self.assertFalse(ilo_client.get.called) @@ -358,7 +339,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, - self.driver.management.get_boot_device, + management.OneViewManagement().get_boot_device, task ) self.assertTrue(client.server_profiles.get.called) diff --git a/ironic/tests/unit/drivers/modules/oneview/test_power.py b/ironic/tests/unit/drivers/modules/oneview/test_power.py index ca5f517c09..e55eca9f4c 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_power.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_power.py @@ -17,7 +17,6 @@ import mock from oslo_utils import importutils 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 task_manager @@ -25,14 +24,13 @@ from ironic.drivers.modules.oneview import common from ironic.drivers.modules.oneview import deploy_utils from ironic.drivers.modules.oneview import management from ironic.drivers.modules.oneview import power -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils +from ironic.tests.unit.drivers.modules.oneview import test_common from ironic.tests.unit.objects import utils as obj_utils client_exception = importutils.try_import('hpOneView.exceptions') -class OneViewPowerDriverTestCase(db_base.DbTestCase): +class OneViewPowerDriverTestCase(test_common.BaseOneViewTest): def setUp(self): super(OneViewPowerDriverTestCase, self).setUp() @@ -41,14 +39,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): self.config(password='password', group='oneview') self.config(tls_cacert_file='ca_file', group='oneview') self.config(allow_insecure_connections=False, group='oneview') - self.config(enabled_drivers=['fake_oneview']) - self.driver = driver_factory.get_driver('fake_oneview') - self.node = obj_utils.create_test_node( - self.context, driver='fake_oneview', - properties=db_utils.get_test_oneview_properties(), - driver_info=db_utils.get_test_oneview_driver_info(), - ) self.info = common.get_oneview_info(self.node) deploy_utils.is_node_in_use_by_oneview = mock.Mock(return_value=False) @@ -61,7 +52,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): def test_validate_missing_parameter(self): node = obj_utils.create_test_node( self.context, uuid=uuidutils.generate_uuid(), - id=999, driver='fake_oneview') + id=999, driver='oneview') with task_manager.acquire(self.context, node.uuid) as task: self.assertRaises( exception.MissingParameterValue, @@ -87,7 +78,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): def test_get_properties(self): expected = common.COMMON_PROPERTIES - self.assertEqual(expected, self.driver.power.get_properties()) + self.assertEqual(expected, power.OneViewPower().get_properties()) @mock.patch.object(common, 'get_hponeview_client') def test_get_power_state(self, mock_get_ov_client): @@ -95,7 +86,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): server_hardware = {'powerState': 'On'} client.server_hardware.get.return_value = server_hardware with task_manager.acquire(self.context, self.node.uuid) as task: - power_state = self.driver.power.get_power_state(task) + power_state = power.OneViewPower().get_power_state(task) self.assertEqual(states.POWER_ON, power_state) @mock.patch.object(common, 'get_hponeview_client') @@ -106,7 +97,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, - self.driver.power.get_power_state, + power.OneViewPower().get_power_state, task) @mock.patch.object(common, 'get_hponeview_client') @@ -115,7 +106,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client = mock_get_ov_client() server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.set_power_state(task, states.POWER_ON) + power.OneViewPower().set_power_state(task, states.POWER_ON) self.assertTrue(mock_set_boot_device.called) update = client.server_hardware.update_power_state update.assert_called_once_with(power.POWER_ON, server_hardware, @@ -128,7 +119,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client = mock_get_ov_client() server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.set_power_state(task, states.POWER_ON, timeout=2) + power.OneViewPower().set_power_state(task, states.POWER_ON, + timeout=2) self.assertTrue(mock_set_boot_device.called) update = client.server_hardware.update_power_state update.assert_called_once_with(power.POWER_ON, server_hardware, @@ -140,7 +132,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client = mock_get_ov_client() server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.set_power_state(task, states.POWER_OFF) + power.OneViewPower().set_power_state(task, states.POWER_OFF) self.assertFalse(mock_set_boot_device.called) update = client.server_hardware.update_power_state update.assert_called_once_with(power.POWER_OFF, server_hardware, @@ -153,8 +145,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client = mock_get_ov_client() server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.set_power_state(task, states.POWER_OFF, - timeout=2) + power.OneViewPower().set_power_state(task, states.POWER_OFF, + timeout=2) self.assertFalse(mock_set_boot_device.called) update = client.server_hardware.update_power_state update.assert_called_once_with(power.POWER_OFF, server_hardware, @@ -166,7 +158,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client = mock_get_ov_client() server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.set_power_state(task, states.REBOOT) + power.OneViewPower().set_power_state(task, states.REBOOT) calls = [mock.call(power.POWER_OFF, server_hardware, timeout=-1), mock.call(power.POWER_ON, server_hardware, timeout=-1)] update = client.server_hardware.update_power_state @@ -177,10 +169,11 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): def test_set_power_soft_reboot( self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() - self.driver.power.client = client + interface = power.OneViewPower() + interface.client = client server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.set_power_state(task, states.SOFT_REBOOT) + interface.set_power_state(task, states.SOFT_REBOOT) calls = [mock.call(power.SOFT_POWER_OFF, server_hardware, timeout=-1), mock.call(power.POWER_ON, server_hardware, timeout=-1)] @@ -196,7 +189,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, - self.driver.power.set_power_state, + power.OneViewPower().set_power_state, task, states.POWER_ON) mock_set_boot_device.assert_called_once_with(task) @@ -211,7 +204,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, - self.driver.power.set_power_state, + power.OneViewPower().set_power_state, task, states.POWER_OFF) self.assertFalse(mock_set_boot_device.called) @@ -225,11 +218,12 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client.server_hardware.get.return_value = server_hardware exc = client_exception.HPOneViewException() client.server_hardware.update_power_state.side_effect = exc - self.driver.power.client = client + interface = power.OneViewPower() + interface.client = client with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, - self.driver.power.reboot, + interface.reboot, task) self.assertFalse(mock_set_boot_device.called) @@ -245,7 +239,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, - self.driver.power.reboot, + power.OneViewPower().reboot, task) mock_set_boot_device.assert_called_once_with(task) @@ -254,7 +248,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.InvalidParameterValue, - self.driver.power.set_power_state, + power.OneViewPower().set_power_state, task, 'fake_state') self.assertFalse(mock_set_boot_device.called) @@ -268,7 +262,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client.server_hardware.get.return_value = server_hardware server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.reboot(task) + power.OneViewPower().reboot(task) calls = [mock.call(power.POWER_OFF, server_hardware, timeout=-1), mock.call(power.POWER_ON, server_hardware, timeout=-1)] update = client.server_hardware.update_power_state @@ -284,7 +278,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client.server_hardware.get.return_value = server_hardware server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.reboot(task, timeout=-1) + power.OneViewPower().reboot(task, timeout=-1) update = client.server_hardware.update_power_state update.assert_called_once_with(power.POWER_ON, server_hardware, timeout=-1) @@ -299,7 +293,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): client.server_hardware.get.return_value = server_hardware server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: - self.driver.power.reboot(task, timeout=2) + power.OneViewPower().reboot(task, timeout=2) update = client.server_hardware.update_power_state update.assert_called_once_with(power.POWER_ON, server_hardware, timeout=2) diff --git a/ironic/tests/unit/drivers/modules/ucs/test_helper.py b/ironic/tests/unit/drivers/modules/ucs/test_helper.py index 0031eb16a4..a1341423f9 100644 --- a/ironic/tests/unit/drivers/modules/ucs/test_helper.py +++ b/ironic/tests/unit/drivers/modules/ucs/test_helper.py @@ -27,17 +27,25 @@ from ironic.tests.unit.objects import utils as obj_utils ucs_error = importutils.try_import('UcsSdk.utils.exception') -INFO_DICT = db_utils.get_test_ucs_info() + +class BaseUcsTest(db_base.DbTestCase): + + def setUp(self): + super(BaseUcsTest, self).setUp() + self.config(enabled_hardware_types=['cisco-ucs-managed', + 'fake-hardware'], + enabled_power_interfaces=['ucsm', 'fake'], + enabled_management_interfaces=['ucsm', 'fake']) + self.info = db_utils.get_test_ucs_info() + self.node = obj_utils.create_test_node(self.context, + driver='cisco-ucs-managed', + driver_info=self.info) -class UcsValidateParametersTestCase(db_base.DbTestCase): +class UcsValidateParametersTestCase(BaseUcsTest): def setUp(self): super(UcsValidateParametersTestCase, self).setUp() - self.config(enabled_drivers=['fake_ucs']) - self.node = obj_utils.create_test_node(self.context, - driver='fake_ucs', - driver_info=INFO_DICT) with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: self.helper = ucs_helper.CiscoUcsHelper(task) @@ -45,10 +53,10 @@ class UcsValidateParametersTestCase(db_base.DbTestCase): def test_parse_driver_info(self): info = ucs_helper.parse_driver_info(self.node) - self.assertEqual(INFO_DICT['ucs_address'], info['ucs_address']) - self.assertEqual(INFO_DICT['ucs_username'], info['ucs_username']) - self.assertEqual(INFO_DICT['ucs_password'], info['ucs_password']) - self.assertEqual(INFO_DICT['ucs_service_profile'], + self.assertEqual(self.info['ucs_address'], info['ucs_address']) + self.assertEqual(self.info['ucs_username'], info['ucs_username']) + self.assertEqual(self.info['ucs_password'], info['ucs_password']) + self.assertEqual(self.info['ucs_service_profile'], info['ucs_service_profile']) def test_parse_driver_info_missing_address(self): @@ -110,15 +118,11 @@ class UcsValidateParametersTestCase(db_base.DbTestCase): self.helper.logout() -class UcsCommonMethodsTestcase(db_base.DbTestCase): +class UcsCommonMethodsTestcase(BaseUcsTest): def setUp(self): super(UcsCommonMethodsTestcase, self).setUp() self.dbapi = dbapi.get_instance() - self.config(enabled_drivers=['fake_ucs']) - self.node = obj_utils.create_test_node(self.context, - driver='fake_ucs', - driver_info=INFO_DICT.copy()) with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: self.helper = ucs_helper.CiscoUcsHelper(task) diff --git a/ironic/tests/unit/drivers/modules/ucs/test_management.py b/ironic/tests/unit/drivers/modules/ucs/test_management.py index 4eba685e96..27225fddb5 100644 --- a/ironic/tests/unit/drivers/modules/ucs/test_management.py +++ b/ironic/tests/unit/drivers/modules/ucs/test_management.py @@ -24,23 +24,15 @@ from ironic.common import exception from ironic.conductor import task_manager from ironic.drivers.modules.ucs import helper as ucs_helper from ironic.drivers.modules.ucs import management as ucs_mgmt -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils -from ironic.tests.unit.objects import utils as obj_utils +from ironic.tests.unit.drivers.modules.ucs import test_helper ucs_error = importutils.try_import('UcsSdk.utils.exception') -INFO_DICT = db_utils.get_test_ucs_info() - -class UcsManagementTestCase(db_base.DbTestCase): +class UcsManagementTestCase(test_helper.BaseUcsTest): def setUp(self): super(UcsManagementTestCase, self).setUp() - self.config(enabled_drivers=['fake_ucs']) - self.node = obj_utils.create_test_node(self.context, - driver='fake_ucs', - driver_info=INFO_DICT) self.interface = ucs_mgmt.UcsManagement() self.task = mock.Mock() self.task.node = self.node diff --git a/ironic/tests/unit/drivers/modules/ucs/test_power.py b/ironic/tests/unit/drivers/modules/ucs/test_power.py index a243213c63..22f76371c7 100644 --- a/ironic/tests/unit/drivers/modules/ucs/test_power.py +++ b/ironic/tests/unit/drivers/modules/ucs/test_power.py @@ -20,27 +20,20 @@ from oslo_utils import importutils from ironic.common import exception from ironic.common import states from ironic.conductor import task_manager +from ironic.drivers.modules import fake from ironic.drivers.modules.ucs import helper as ucs_helper from ironic.drivers.modules.ucs import power as ucs_power -from ironic.tests.unit.db import base as db_base -from ironic.tests.unit.db import utils as db_utils -from ironic.tests.unit.objects import utils as obj_utils +from ironic.tests.unit.drivers.modules.ucs import test_helper ucs_error = importutils.try_import('UcsSdk.utils.exception') -INFO_DICT = db_utils.get_test_ucs_info() CONF = cfg.CONF -class UcsPowerTestCase(db_base.DbTestCase): +class UcsPowerTestCase(test_helper.BaseUcsTest): def setUp(self): super(UcsPowerTestCase, self).setUp() - driver_info = INFO_DICT - self.config(enabled_drivers=['fake_ucs']) - self.node = obj_utils.create_test_node(self.context, - driver='fake_ucs', - driver_info=driver_info) CONF.set_override('max_retry', 2, 'cisco_ucs') CONF.set_override('action_interval', 0, 'cisco_ucs') self.interface = ucs_power.Power() @@ -50,6 +43,9 @@ class UcsPowerTestCase(db_base.DbTestCase): expected.update(ucs_helper.COMMON_PROPERTIES) with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: + # Remove properties from boot and deploy interfaces + task.driver.boot = fake.FakeBoot() + task.driver.deploy = fake.FakeDeploy() self.assertEqual(expected, task.driver.get_properties()) @mock.patch.object(ucs_helper, 'parse_driver_info', diff --git a/releasenotes/notes/no-fake-308b50d4ab83ca7a.yaml b/releasenotes/notes/no-fake-308b50d4ab83ca7a.yaml index 2e351b4aa4..cc84d4d96a 100644 --- a/releasenotes/notes/no-fake-308b50d4ab83ca7a.yaml +++ b/releasenotes/notes/no-fake-308b50d4ab83ca7a.yaml @@ -1,15 +1,23 @@ --- upgrade: - | - The following deprecated classic drivers were removed: + All fake classic drivers, deprecated in the Queens release, have been + removed. This includes: * ``fake`` * ``fake_agent`` + * ``fake_cimc`` + * ``fake_drac`` + * ``fake_ilo`` * ``fake_inspector`` * ``fake_ipmitool`` * ``fake_ipmitool_socat`` + * ``fake_irmc`` + * ``fake_oneview`` * ``fake_pxe`` * ``fake_snmp`` * ``fake_soft_power`` + * ``fake_ucs`` - Please use the ``fake-hardware`` hardware type instead. + Please use the ``fake-hardware`` hardware type instead (you can combine + it with any other interfaces, fake or real). diff --git a/setup.cfg b/setup.cfg index 4596a81108..807a72f7ce 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,12 +59,6 @@ ironic.drivers = agent_irmc = ironic.drivers.irmc:IRMCVirtualMediaAgentDriver agent_pxe_oneview = ironic.drivers.oneview:AgentPXEOneViewDriver agent_ucs = ironic.drivers.agent:AgentAndUcsDriver - fake_ilo = ironic.drivers.fake:FakeIloDriver - fake_drac = ironic.drivers.fake:FakeDracDriver - fake_irmc = ironic.drivers.fake:FakeIRMCDriver - fake_ucs = ironic.drivers.fake:FakeUcsDriver - fake_cimc = ironic.drivers.fake:FakeCIMCDriver - fake_oneview = ironic.drivers.fake:FakeOneViewDriver iscsi_ilo = ironic.drivers.ilo:IloVirtualMediaIscsiDriver iscsi_irmc = ironic.drivers.irmc:IRMCVirtualMediaIscsiDriver iscsi_pxe_oneview = ironic.drivers.oneview:ISCSIPXEOneViewDriver